Model: Add basic concrete generic method definitions from MethodSpecs

This commit is contained in:
Katy Coe
2020-02-02 03:56:50 +01:00
parent e33206a360
commit d2cb63dc95
4 changed files with 29 additions and 4 deletions

View File

@@ -91,10 +91,7 @@ namespace Il2CppInspector.Reflection
if (!GenericMethods.ContainsKey(declaringType))
GenericMethods.Add(declaringType, new List<MethodInfo>());
// TODO: Add generic method resolver here
// Get list of pointers to type parameters (both unresolved and concrete)
var genericTypeArguments = ResolveGenericArguments(spec.methodIndexIndex);
GenericMethods[declaringType].Add(new MethodInfo(this, spec, declaringType));
}
}
}

View File

@@ -83,6 +83,7 @@ namespace Il2CppInspector.Reflection
// Regular method
: Name;
// Initialize a method from a method definition (MethodDef)
protected MethodBase(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(declaringType) {
Definition = pkg.Methods[methodIndex];
Index = methodIndex;
@@ -141,6 +142,20 @@ namespace Il2CppInspector.Reflection
DeclaredParameters.Add(new ParameterInfo(pkg, p, this));
}
// Initialize a method from a concrete generic method (MethodSpec)
protected MethodBase(Il2CppModel model, Il2CppMethodSpec spec, TypeInfo declaringType) : base(declaringType) {
var methodDef = model.MethodsByDefinitionIndex[spec.methodDefinitionIndex];
Name = methodDef.Name;
Attributes = methodDef.Attributes;
IsGenericMethod = true;
genericArguments = model.ResolveGenericArguments(spec.methodIndexIndex);
// TODO: Substitute generic type arguments for concrete type arguments
// TODO: Populate VirtualAddress via Il2CppGenericMethodFunctionsDefinitions
}
public string GetAccessModifierString() => this switch {
// Static constructors can not have an access level modifier
{ IsConstructor: true, IsStatic: true } => "",

View File

@@ -30,6 +30,14 @@ namespace Il2CppInspector.Reflection
ReturnParameter = new ParameterInfo(pkg, -1, this);
}
public MethodInfo(Il2CppModel model, Il2CppMethodSpec spec, TypeInfo declaringType) : base(model, spec, declaringType) {
var methodDef = model.MethodsByDefinitionIndex[spec.methodDefinitionIndex];
// Add return parameter
returnTypeReference = methodDef.Definition.returnType;
ReturnParameter = ((MethodInfo) methodDef).ReturnParameter;
}
public override string ToString() => ReturnType.Name + " " + Name + GetFullTypeParametersString() + "(" + string.Join(", ",
DeclaredParameters.Select(x => x.ParameterType.IsByRef? x.ParameterType.Name.TrimEnd('&') + " ByRef" : x.ParameterType.Name)) + ")";

View File

@@ -95,6 +95,11 @@ namespace Il2CppInspector.Reflection
}
}
// Create a concrete type parameter from a generic type parameter
public ParameterInfo(Il2CppModel model, ParameterInfo generic, TypeInfo concrete) {
// TODO: Implement generic parameter substitution
}
// ref will be handled as part of the type name
public string GetModifierString() =>
(IsIn ? "in " : "")