forked from SamboyCoding/Cpp2IL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Type Parameters in Call Analysis (SamboyCoding#255)
- Loading branch information
Showing
16 changed files
with
334 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using AsmResolver.DotNet; | ||
using AsmResolver.DotNet.Signatures.Types; | ||
using Cpp2IL.Core.Utils; | ||
using LibCpp2IL.BinaryStructures; | ||
|
||
namespace Cpp2IL.Core.Model.Contexts; | ||
|
||
public class ArrayTypeAnalysisContext : WrappedTypeAnalysisContext | ||
{ | ||
public ArrayTypeAnalysisContext(TypeAnalysisContext elementType, int rank, AssemblyAnalysisContext referencedFrom) : base(elementType, referencedFrom) | ||
{ | ||
Rank = rank; | ||
} | ||
|
||
public ArrayTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) | ||
: this(referencedFrom.ResolveIl2CppType(rawType.GetArrayElementType()), rawType.GetArrayRank(), referencedFrom) | ||
{ | ||
} | ||
|
||
public override Il2CppTypeEnum Type => Il2CppTypeEnum.IL2CPP_TYPE_ARRAY; | ||
|
||
public override string DefaultName => $"{ElementType.Name}[{Rank}]"; | ||
|
||
public int Rank { get; } | ||
|
||
public override TypeSignature ToTypeSignature(ModuleDefinition parentModule) | ||
{ | ||
return ElementType.ToTypeSignature(parentModule).MakeArrayType(Rank); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AsmResolver.DotNet; | ||
using AsmResolver.DotNet.Signatures.Types; | ||
using LibCpp2IL.BinaryStructures; | ||
|
||
namespace Cpp2IL.Core.Model.Contexts; | ||
|
||
public class ByRefTypeAnalysisContext : WrappedTypeAnalysisContext | ||
{ | ||
public ByRefTypeAnalysisContext(TypeAnalysisContext elementType, AssemblyAnalysisContext referencedFrom) : base(elementType, referencedFrom) | ||
{ | ||
} | ||
|
||
public ByRefTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) | ||
: this(default(TypeAnalysisContext)!, referencedFrom) | ||
{ | ||
} | ||
|
||
public override Il2CppTypeEnum Type => Il2CppTypeEnum.IL2CPP_TYPE_BYREF; | ||
|
||
public override string DefaultName => $"{ElementType.Name}&"; | ||
|
||
protected override TypeAnalysisContext ElementType => base.ElementType ?? throw new("TODO Support TYPE_BYREF"); | ||
|
||
public override TypeSignature ToTypeSignature(ModuleDefinition parentModule) | ||
{ | ||
return ElementType.ToTypeSignature(parentModule).MakeByReferenceType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 32 additions & 5 deletions
37
Cpp2IL.Core/Model/Contexts/GenericParameterTypeAnalysisContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,43 @@ | ||
using LibCpp2IL.BinaryStructures; | ||
using System; | ||
using AsmResolver.DotNet; | ||
using AsmResolver.DotNet.Signatures.Types; | ||
using LibCpp2IL.BinaryStructures; | ||
using LibCpp2IL.Metadata; | ||
|
||
namespace Cpp2IL.Core.Model.Contexts; | ||
|
||
public class GenericParameterTypeAnalysisContext : ReferencedTypeAnalysisContext | ||
{ | ||
public override string DefaultName { get; } | ||
|
||
public int Index { get; } | ||
|
||
public override Il2CppTypeEnum Type { get; } | ||
|
||
protected override TypeAnalysisContext ElementType => throw new("Attempted to get element type of a generic parameter"); | ||
|
||
public GenericParameterTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) : base(rawType, referencedFrom) | ||
public GenericParameterTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) | ||
: this(rawType.GetGenericParameterDef(), rawType.Type, referencedFrom) | ||
{ | ||
} | ||
|
||
public GenericParameterTypeAnalysisContext(Il2CppGenericParameter genericParameter, Il2CppTypeEnum type, AssemblyAnalysisContext referencedFrom) | ||
: this(genericParameter.Name ?? "T", genericParameter.genericParameterIndexInOwner, type, referencedFrom) | ||
{ | ||
if(rawType.Type is not Il2CppTypeEnum.IL2CPP_TYPE_VAR and not Il2CppTypeEnum.IL2CPP_TYPE_MVAR) | ||
throw new($"Generic parameter type is not a generic parameter, but {rawType.Type}"); | ||
} | ||
|
||
public GenericParameterTypeAnalysisContext(string name, int index, Il2CppTypeEnum type, AssemblyAnalysisContext referencedFrom) : base(referencedFrom) | ||
{ | ||
if (type is not Il2CppTypeEnum.IL2CPP_TYPE_VAR and not Il2CppTypeEnum.IL2CPP_TYPE_MVAR) | ||
throw new ArgumentException($"Generic parameter type is not a generic parameter, but {type}", nameof(type)); | ||
|
||
GenericParameter = rawType.GetGenericParameterDef(); | ||
DefaultName = name; | ||
Index = index; | ||
Type = type; | ||
} | ||
|
||
public override TypeSignature ToTypeSignature(ModuleDefinition parentModule) | ||
{ | ||
return new GenericParameterSignature(Type == Il2CppTypeEnum.IL2CPP_TYPE_VAR ? GenericParameterType.Type : GenericParameterType.Method, Index); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using AsmResolver.DotNet; | ||
using AsmResolver.DotNet.Signatures.Types; | ||
using Cpp2IL.Core.Utils; | ||
using LibCpp2IL.BinaryStructures; | ||
|
||
namespace Cpp2IL.Core.Model.Contexts; | ||
|
||
public class PointerTypeAnalysisContext : WrappedTypeAnalysisContext | ||
{ | ||
public PointerTypeAnalysisContext(TypeAnalysisContext elementType, AssemblyAnalysisContext referencedFrom) : base(elementType, referencedFrom) | ||
{ | ||
} | ||
|
||
public PointerTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) | ||
: this(referencedFrom.ResolveIl2CppType(rawType.GetEncapsulatedType()), referencedFrom) | ||
{ | ||
} | ||
|
||
public override Il2CppTypeEnum Type => Il2CppTypeEnum.IL2CPP_TYPE_PTR; | ||
|
||
public override string DefaultName => $"{ElementType.Name}*"; | ||
|
||
public override TypeSignature ToTypeSignature(ModuleDefinition parentModule) | ||
{ | ||
return ElementType.ToTypeSignature(parentModule).MakePointerType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using AsmResolver.DotNet; | ||
using AsmResolver.DotNet.Signatures.Types; | ||
using Cpp2IL.Core.Utils; | ||
using LibCpp2IL.BinaryStructures; | ||
|
||
namespace Cpp2IL.Core.Model.Contexts; | ||
|
||
public class SzArrayTypeAnalysisContext : WrappedTypeAnalysisContext | ||
{ | ||
public SzArrayTypeAnalysisContext(TypeAnalysisContext elementType, AssemblyAnalysisContext referencedFrom) : base(elementType, referencedFrom) | ||
{ | ||
} | ||
|
||
public SzArrayTypeAnalysisContext(Il2CppType rawType, AssemblyAnalysisContext referencedFrom) | ||
: this(referencedFrom.ResolveIl2CppType(rawType.GetEncapsulatedType()), referencedFrom) | ||
{ | ||
} | ||
|
||
public override Il2CppTypeEnum Type => Il2CppTypeEnum.IL2CPP_TYPE_SZARRAY; | ||
|
||
public override string DefaultName => $"{ElementType.Name}[]"; | ||
|
||
public override TypeSignature ToTypeSignature(ModuleDefinition parentModule) | ||
{ | ||
return ElementType.ToTypeSignature(parentModule).MakeSzArrayType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.