diff --git a/Editor/ABI/TypeCreatorBase.cs b/Editor/ABI/TypeCreatorBase.cs index b96bdc2..d8d0f32 100644 --- a/Editor/ABI/TypeCreatorBase.cs +++ b/Editor/ABI/TypeCreatorBase.cs @@ -136,7 +136,7 @@ namespace HybridCLR.Editor.ABI (int typeSize, int typeAligment) = ComputeSizeAndAligment(type); if (TryCreateCustomValueTypeInfo(type, typeSize, typeAligment, out var typeInfo)) { - Debug.Log($"[{GetType().Name}] CustomeValueType:{type} => {typeInfo.CreateSigName()}"); + //Debug.Log($"[{GetType().Name}] CustomeValueType:{type} => {typeInfo.CreateSigName()}"); return typeInfo; } else diff --git a/Editor/AOT/Analyzer.cs b/Editor/AOT/Analyzer.cs index ea446e2..a30410e 100644 --- a/Editor/AOT/Analyzer.cs +++ b/Editor/AOT/Analyzer.cs @@ -79,7 +79,7 @@ namespace HybridCLR.Editor.AOT return IsAotType(method.DeclaringType) && method.HasGenericParameters; } - private void OnNewMethod(GenericMethod method) + private void OnNewMethod(MethodDef methodDef, List klassGenericInst, List methodGenericInst, GenericMethod method) { if(method == null) { diff --git a/Editor/Commands/MethodBridgeGeneratorCommand.cs b/Editor/Commands/MethodBridgeGeneratorCommand.cs index 923892b..2c7d3e5 100644 --- a/Editor/Commands/MethodBridgeGeneratorCommand.cs +++ b/Editor/Commands/MethodBridgeGeneratorCommand.cs @@ -37,6 +37,7 @@ namespace HybridCLR.Editor.Commands OutputFile = outputFile, GenericMethods = analyzer.GenericMethods, NotGenericMethods = analyzer.NotGenericMethods, + SpeicalPreserveMethods = analyzer.SpeicalPreserveMethods, }); g.PrepareMethods(); diff --git a/Editor/Meta/MethodReferenceAnalyzer.cs b/Editor/Meta/MethodReferenceAnalyzer.cs index 7fd8ccd..4f9ceb0 100644 --- a/Editor/Meta/MethodReferenceAnalyzer.cs +++ b/Editor/Meta/MethodReferenceAnalyzer.cs @@ -1,4 +1,5 @@ using dnlib.DotNet; +using HybridCLR.Editor.ABI; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -10,11 +11,11 @@ namespace HybridCLR.Editor.Meta { public class MethodReferenceAnalyzer { - private readonly Action _onNewMethod; + private readonly Action, List, GenericMethod> _onNewMethod; private readonly ConcurrentDictionary> _methodEffectInsts = new ConcurrentDictionary>(); - public MethodReferenceAnalyzer(Action onNewMethod) + public MethodReferenceAnalyzer(Action, List, GenericMethod> onNewMethod) { _onNewMethod = onNewMethod; } @@ -37,7 +38,7 @@ namespace HybridCLR.Editor.Meta foreach (var met in effectInsts) { var resolveMet = GenericMethod.ResolveMethod(met, ctx)?.ToGenericShare(); - _onNewMethod(resolveMet); + _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); } return; } @@ -69,7 +70,7 @@ namespace HybridCLR.Editor.Meta continue; } effectInsts.Add(met); - _onNewMethod(resolveMet); + _onNewMethod(method, klassGenericInst, methodGenericInst, resolveMet); break; } case ITokenOperand token: diff --git a/Editor/MethodBridge/Analyzer.cs b/Editor/MethodBridge/Analyzer.cs index 33d24e5..d686389 100644 --- a/Editor/MethodBridge/Analyzer.cs +++ b/Editor/MethodBridge/Analyzer.cs @@ -30,6 +30,8 @@ namespace HybridCLR.Editor.MethodBridge private readonly HashSet _genericTypes = new HashSet(); private readonly HashSet _genericMethods = new HashSet(); + private readonly HashSet _speicalPreserveMethods = new HashSet(); + private List _processingMethods = new List(); private List _newMethods = new List(); @@ -37,6 +39,8 @@ namespace HybridCLR.Editor.MethodBridge public IReadOnlyList NotGenericMethods => _notGenericMethods; + public HashSet SpeicalPreserveMethods => _speicalPreserveMethods; + public IReadOnlyCollection GenericTypes => _genericTypes; public IReadOnlyCollection GenericMethods => _genericMethods; @@ -67,7 +71,7 @@ namespace HybridCLR.Editor.MethodBridge } } - private void OnNewMethod(GenericMethod method) + private void OnNewMethod(MethodDef methodDef, List klassGenericInst, List methodGenericInst, GenericMethod method) { lock(_lock) { @@ -75,6 +79,10 @@ namespace HybridCLR.Editor.MethodBridge { _newMethods.Add(method); } + if (methodDef.HasGenericParameters) + { + _speicalPreserveMethods.Add(method); + } if (method.KlassInst != null) { TryAddAndWalkGenericType(new GenericClass(method.Method.DeclaringType, method.KlassInst)); diff --git a/Editor/MethodBridge/Generator.cs b/Editor/MethodBridge/Generator.cs index c6b9281..7eee4b7 100644 --- a/Editor/MethodBridge/Generator.cs +++ b/Editor/MethodBridge/Generator.cs @@ -4,6 +4,7 @@ using HybridCLR.Editor.Meta; using HybridCLR.Editor.Template; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.IO; using System.Linq; using System.Reflection; @@ -28,6 +29,8 @@ namespace HybridCLR.Editor.MethodBridge public IReadOnlyList NotGenericMethods { get; set; } public IReadOnlyCollection GenericMethods { get; set; } + + public HashSet SpeicalPreserveMethods { get; set; } } private PlatformABI _platformABI; @@ -36,6 +39,8 @@ namespace HybridCLR.Editor.MethodBridge private readonly IReadOnlyCollection _genericMethods; + private readonly HashSet _preservedMethods; + private readonly string _templateCode; private readonly string _outputFile; @@ -61,6 +66,7 @@ namespace HybridCLR.Editor.MethodBridge _platformABI = options.PlatformABI; _notGenericMethods = options.NotGenericMethods; _genericMethods = options.GenericMethods; + _preservedMethods = options.SpeicalPreserveMethods; _templateCode = options.TemplateCode; _outputFile = options.OutputFile; _platformAdaptor = CreatePlatformAdaptor(options.PlatformABI); @@ -122,7 +128,14 @@ namespace HybridCLR.Editor.MethodBridge { if (method.IsPrivate || (method.IsAssembly && !method.IsPublic && !method.IsFamily)) { - return; + if (!_preservedMethods.Contains(new GenericMethod(method, klassInst, methodInst))) + { + return; + } + else + { + //Debug.Log($"[PreservedMethod] method:{method}"); + } } TypeSig returnType;