Commit Graph

14 Commits

Author SHA1 Message Date
Robert Xiao
3ccbab2461 Add/modify copyright notices 2020-06-29 22:10:45 +02:00
Robert Xiao
4ba48b9c75 Add generics support to TypeInfo.GetVTable
This patch fixes TypeInfo.GetVTable so that it specializes the vtable
for generic type instances. Also fix a minor bug in PropertyInfo that
would pass null pointers to GetMethodByDefinition.
2020-06-29 22:10:45 +02:00
Katy Coe
2791721dd1 Model: Implement MethodBase.GetMethodBody() 2020-06-22 17:35:23 +02:00
Katy Coe
ed1d80aa15 CS: "unsafe" goes after "static" to avoid IntelliSense notice 2020-06-20 20:34:51 +02:00
Robert Xiao
44df54b639 Suppress new on operator methods.
Per the C# language reference
(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/basic-concepts#hiding-through-inheritance):

> The rules governing operator declarations (Operators) make it
> impossible for a derived class to declare an operator with the same
> signature as an operator in a base class. Thus, operators never hide
> one another.

Therefore, new is not necessary or permitted on operators, even if the
method signatures are identical. This situation can arise if, for
example, an explicit conversion operator from the same target class
exists in both a base class and a derived class.
2020-06-20 10:17:48 +02:00
Robert Xiao
1a12567227 Fix method signature comparison.
Now that we generate methods in instantiated generic types, we were
getting test failures from methods that were being detected as new
methods. In actuality, they weren't new, but they differed only in
generic type parameters from some base type method, and
GetSignatureString ignores generic parameters completely.

This fix eliminates the hacky GetSignatureString and replaces it with
more-or-less proper signature comparison. This even manages to fix an
incorrect test case from Methods.cs (because GetSignatureString was
incorrectly incorporating the return type - when the return type should
not be examined for signature checking).
2020-06-20 10:17:48 +02:00
Robert Xiao
652d76d6fe Implement constructors & methods on constructed generics.
We adopt roughly the same approach as the C# Reflection API: a
GenericMethodDefinition is a method which has no method parameters
substituted, but lives in a open or closed type with some or all
type parameters substituted. To ensure the uniqueness of the MethodInfo,
we cache by the method type arguments, and also cache generated
DeclaredConstructors/DeclaredMethods in the TypeInfo.

This also enables MakeGenericMethod, albeit in a slightly different form
than the Reflection API: MakeGenericMethod lives in MethodBase, so it's
callable from a constructor (even though in C# constructors cannot be
generic). This slight violation of the spec reduces code duplication, so
it's probably worth it.

Finally, VirtualAddress gets set when populating GenericMethods, and so
it'll work whether or not the methods get cached/generated ahead of
time.
2020-06-20 10:17:48 +02:00
Robert Xiao
202a802274 Fix ContainsGenericParameters and IsGenericMethodDefinition
IsGenericMethodDefinition needs the same treatment as
IsGenericTypeDefinition, i.e. it should depend on whether the class is a
definition as opposed to merely checking if the type args are generic
parameters (which could happen in a partially specialized method).

Also, array/ref/pointer types of generic types are considered to have
generic parameters, so correct ContainsGenericParameters accordingly.
2020-06-20 10:17:48 +02:00
Robert Xiao
c73aad08b8 Add non-generic methods in generic types to GenericMethods
GenericMethods should contain all MethodSpec-referenced methods,
including those which are non-generic methods inside generic types. This
patch adds those methods, and also implements parameter substitution for
type arguments in parameters & return types.
2020-06-20 10:17:48 +02:00
Robert Xiao
50ea6dac36 Dedup param, array and byref/pointer types
We're aiming to make TypeInfo instances unique - no two TypeInfo
instances within a given model should refer to the same type. This will
allow us to use simple reference equality for comparing types.
2020-06-20 10:17:48 +02:00
Robert Xiao
2c164aec02 Change generic params/args to arrays
The C# functions for GetGenericParameters/GetGenericArguments use
Type[], not lists, so we should conform to that.

Also fix the definition of IsGenericTypeDefinition - because it's
possible for a class to be instantiated with all generic parameters.
2020-06-20 10:17:48 +02:00
Robert Xiao
71bf353ae0 Remove ResolveGenericArguments(int) entirely
It's not really needed anymore, and it is clearer without that method.
2020-06-20 10:17:48 +02:00
Robert Xiao
6ddb502e96 Refactor TypeInfo names and fix out/in
Replace the deeply nested ternaries in TypeInfo with if-statements for
clarity.
Remove in/out from CSharpName, keeping it only on immediate type params
in CSharpTypeDeclarationName (refactored to a method).
Rearrange name-related properties and methods to group them all together
into a region for easier navigation.
2020-06-20 10:17:48 +02:00
Katy Coe
e971cb8502 Refactor solution layout 2020-02-06 02:51:42 +01:00