Skip to content

Commit 03b6607

Browse files
authored
Hide duplicate properties in MethodAnalysisContext (#354)
1 parent d9048e9 commit 03b6607

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ public void AnalyzeCustomAttributeData(bool allowAnalysis = true)
200200
var attributeTypeContext = AppContext.ResolveContextForType(typeDef) ?? throw new("Unable to find type " + typeDef.FullName);
201201

202202
AnalyzedCustomAttribute attribute;
203-
if (attributeTypeContext.Methods.FirstOrDefault(c => c.MethodName == ".ctor" && c.Definition!.parameterCount == 0) is { } constructor)
203+
if (attributeTypeContext.Methods.FirstOrDefault(c => c.Name == ".ctor" && c.Definition!.parameterCount == 0) is { } constructor)
204204
{
205205
attribute = new(constructor);
206206
}
207-
else if (attributeTypeContext.Methods.FirstOrDefault(c => c.MethodName == ".ctor") is { } anyConstructor)
207+
else if (attributeTypeContext.Methods.FirstOrDefault(c => c.Name == ".ctor") is { } anyConstructor)
208208
{
209209
//TODO change this to actual constructor w/ params once anaylsis is available
210210
attribute = new(anyConstructor);

Cpp2IL.Core/Model/Contexts/MethodAnalysisContext.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class MethodAnalysisContext : HasCustomAttributesAndName, IMethodInfoProv
7979
protected Memory<byte>? rawMethodBody;
8080

8181

82-
private static List<IBlockProcessor> blockProcessors =
82+
private static readonly List<IBlockProcessor> blockProcessors =
8383
[
8484
new MetadataProcessor(),
8585
new CallProcessor()
@@ -103,7 +103,8 @@ public MethodAnalysisContext(Il2CppMethodDefinition? definition, TypeAnalysisCon
103103
else
104104
rawMethodBody = Array.Empty<byte>();
105105
}
106-
106+
107+
[MemberNotNull(nameof(rawMethodBody))]
107108
public void EnsureRawBytes()
108109
{
109110
rawMethodBody ??= InitRawBytes();
@@ -173,17 +174,18 @@ public void ReleaseAnalysisData()
173174

174175
#region StableNameDot implementation
175176

176-
public ITypeInfoProvider ReturnType =>
177+
ITypeInfoProvider IMethodInfoProvider.ReturnType =>
177178
Definition!.RawReturnType!.ThisOrElementIsGenericParam()
178179
? new GenericParameterTypeInfoProviderWrapper(Definition.RawReturnType!.GetGenericParamName())
179180
: TypeAnalysisContext.GetSndnProviderForType(AppContext, Definition!.RawReturnType);
180181

181-
public IEnumerable<IParameterInfoProvider> ParameterInfoProviders => Parameters;
182-
public string MethodName => Name;
182+
IEnumerable<IParameterInfoProvider> IMethodInfoProvider.ParameterInfoProviders => Parameters;
183+
184+
string IMethodInfoProvider.MethodName => Name;
183185

184-
public MethodAttributes MethodAttributes => Attributes;
186+
MethodAttributes IMethodInfoProvider.MethodAttributes => Attributes;
185187

186-
public MethodSemantics MethodSemantics
188+
MethodSemantics IMethodInfoProvider.MethodSemantics
187189
{
188190
get
189191
{

Cpp2IL.Core/ProcessingLayers/CallAnalysisProcessingLayer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private static void InjectAttribute(ApplicationAnalysisContext appContext)
7373

7474
if (convertedIsil is { Count: 0 })
7575
{
76-
if ((m.MethodAttributes & MethodAttributes.Abstract) == 0)
76+
if ((m.Attributes & MethodAttributes.Abstract) == 0)
7777
{
7878
AttributeInjectionUtils.AddZeroParameterAttribute(m, analysisNotSupportedConstructor);
7979
}

Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ private static void CopyMethodsInType(ReferenceImporter importer, TypeAnalysisCo
403403

404404
var signature = methodCtx.IsStatic ? MethodSignature.CreateStatic(returnType, parameterTypes) : MethodSignature.CreateInstance(returnType, parameterTypes);
405405

406-
var managedMethod = new MethodDefinition(methodCtx.MethodName, (MethodAttributes)methodCtx.Attributes, signature);
406+
var managedMethod = new MethodDefinition(methodCtx.Name, (MethodAttributes)methodCtx.Attributes, signature);
407407

408408
if (methodCtx.Definition != null)
409409
{

Cpp2IL.Core/Utils/AttributeInjectionUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static void ApplyAttributeUsageAttribute(ApplicationAnalysisContext appC
9595
var mscorlibAssembly = appContext.GetAssemblyByName("mscorlib") ?? throw new("Could not find mscorlib");
9696
var targetsEnumType = GetAttributeTargetsType(mscorlibAssembly);
9797
var usageAttribute = mscorlibAssembly.GetTypeByFullName($"System.{nameof(AttributeUsageAttribute)}") ?? throw new("Could not find AttributeUsageAttribute");
98-
var usageConstructor = usageAttribute.Methods.First(m => (m.MethodAttributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public && m.Name == ".ctor");
98+
var usageConstructor = usageAttribute.Methods.First(m => (m.Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public && m.Name == ".ctor");
9999
var allowMultipleProperty = usageAttribute.Properties.First(p => p.Name == nameof(AttributeUsageAttribute.AllowMultiple));
100100
foreach (var injectedType in multiAssemblyInjectedType.InjectedTypes)
101101
{

0 commit comments

Comments
 (0)