diff --git a/src/Refasmer/Filters/IImportFilter.cs b/src/Refasmer/Filters/IImportFilter.cs index 30d3ce7..64ed1cb 100644 --- a/src/Refasmer/Filters/IImportFilter.cs +++ b/src/Refasmer/Filters/IImportFilter.cs @@ -4,7 +4,6 @@ namespace JetBrains.Refasmer.Filters { public interface IImportFilter { - bool AllowImport( TypeDefinition type, MetadataReader reader ); bool AllowImport( MethodDefinition method, MetadataReader reader ); bool AllowImport( FieldDefinition field, MetadataReader reader ); diff --git a/src/Refasmer/Importer/ImportLogic.cs b/src/Refasmer/Importer/ImportLogic.cs index 545810f..a398b4c 100644 --- a/src/Refasmer/Importer/ImportLogic.cs +++ b/src/Refasmer/Importer/ImportLogic.cs @@ -5,34 +5,11 @@ using System.Reflection; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -using JetBrains.Refasmer.Filters; namespace JetBrains.Refasmer { public partial class MetadataImporter { - private bool AllowImportType( EntityHandle typeHandle ) - { - if (typeHandle.IsNil) - return false; - - if (Filter == null) - return true; - - switch (typeHandle.Kind) - { - case HandleKind.TypeDefinition: - return Filter.AllowImport(_reader.GetTypeDefinition((TypeDefinitionHandle) typeHandle), _reader); - case HandleKind.TypeReference: - return true; - case HandleKind.TypeSpecification: - return AllowImportType(_reader.GetGenericType((TypeSpecificationHandle)typeHandle)); - - default: - throw new ArgumentOutOfRangeException(nameof (typeHandle)); - } - } - private TypeDefinitionHandle ImportTypeDefinitionSkeleton( TypeDefinitionHandle srcHandle ) { var src = _reader.GetTypeDefinition(srcHandle); @@ -68,7 +45,6 @@ private TypeDefinitionHandle ImportTypeDefinitionSkeleton( TypeDefinitionHandle var implementations = src.GetMethodImplementations() .Select(_reader.GetMethodImplementation) - .Where(mi => AllowImportType(_reader.GetMethodClass(mi.MethodDeclaration))) .Select(mi => (MethodDefinitionHandle)mi.MethodBody) .ToImmutableHashSet(); @@ -413,50 +389,9 @@ public ReservedBlob Import() var index = 1; Debug?.Invoke("Preparing type list for import"); - var checker = new CachedAttributeChecker(); - foreach (var srcHandle in _reader.TypeDefinitions) { - bool shouldImport; - - var src = _reader.GetTypeDefinition(srcHandle); - - // Special type - if (srcHandle.GetHashCode() == 1 && _reader.GetString(src.Name) == "") - { - shouldImport = true; - } - else if (checker.HasAttribute(_reader, src, FullNames.Embedded) && - checker.HasAttribute(_reader, src, FullNames.CompilerGenerated)) - { - Trace?.Invoke($"Embedded type found {_reader.ToString(srcHandle)}"); - shouldImport = true; - } - else if (_reader.GetString(src.Namespace) == FullNames.CompilerServices && - _reader.GetFullname(src.BaseType) == FullNames.Attribute) - { - Trace?.Invoke($"CompilerServices attribute found {_reader.ToString(srcHandle)}"); - shouldImport = true; - } - else if (_reader.GetString(src.Namespace) == FullNames.CodeAnalysis && - _reader.GetFullname(src.BaseType) == FullNames.Attribute) - { - Trace?.Invoke($"CodeAnalysis attribute found {_reader.ToString(srcHandle)}"); - shouldImport = true; - } - else - { - shouldImport = Filter?.AllowImport(_reader.GetTypeDefinition(srcHandle), _reader) != false; - } - - if (shouldImport) - { - _typeDefinitionCache[srcHandle] = MetadataTokens.TypeDefinitionHandle(index++); - } - else - { - Trace?.Invoke($"Type filtered and will not be imported {_reader.ToString(srcHandle)}"); - } + _typeDefinitionCache[srcHandle] = MetadataTokens.TypeDefinitionHandle(index++); } Debug?.Invoke("Importing type definitions"); diff --git a/src/Refasmer/Importer/SignatureImport.cs b/src/Refasmer/Importer/SignatureImport.cs index fb59695..58ddf6e 100644 --- a/src/Refasmer/Importer/SignatureImport.cs +++ b/src/Refasmer/Importer/SignatureImport.cs @@ -19,71 +19,40 @@ public UnknownTypeInSignature( EntityHandle handle, string message ) private BlobHandle ImportTypeSignature( BlobHandle srcHandle ) { - try - { - var blobReader = _reader.GetBlobReader(srcHandle); - var blobBuilder = new BlobBuilder(blobReader.Length); - - ImportTypeSignature(ref blobReader, blobBuilder); - return _builder.GetOrAddBlob(blobBuilder); - } - catch (UnknownTypeInSignature e) - { - if (e.Handle.Kind != HandleKind.TypeDefinition) - throw; - - var typeDef = _reader.GetTypeDefinition((TypeDefinitionHandle) e.Handle); + var blobReader = _reader.GetBlobReader(srcHandle); + var blobBuilder = new BlobBuilder(blobReader.Length); - if (Filter?.AllowImport(typeDef, _reader) == true) - throw; - - } - return default; + ImportTypeSignature(ref blobReader, blobBuilder); + return _builder.GetOrAddBlob(blobBuilder); } private BlobHandle ImportSignatureWithHeader( BlobHandle srcHandle ) { - try - { - var blobReader = _reader.GetBlobReader(srcHandle); - var blobBuilder = new BlobBuilder(blobReader.Length); - - var header = blobReader.ReadSignatureHeader(); - blobBuilder.WriteByte(header.RawValue); - - switch (header.Kind) - { - case SignatureKind.Method: - case SignatureKind.Property: - ImportMethodSignature(header, ref blobReader, blobBuilder); - break; - case SignatureKind.Field: - ImportFieldSignature(ref blobReader, blobBuilder); - break; - case SignatureKind.LocalVariables: - ImportLocalSignature(ref blobReader, blobBuilder); - break; - case SignatureKind.MethodSpecification: - ImportMethodSpecSignature(ref blobReader, blobBuilder); - break; - default: - throw new BadImageFormatException(); - } - return _builder.GetOrAddBlob(blobBuilder); - } - catch (UnknownTypeInSignature e) - { - if (e.Handle.Kind != HandleKind.TypeDefinition) - throw; - - var typeDef = _reader.GetTypeDefinition((TypeDefinitionHandle) e.Handle); - - if (Filter?.AllowImport(typeDef, _reader) == true) - throw; + var blobReader = _reader.GetBlobReader(srcHandle); + var blobBuilder = new BlobBuilder(blobReader.Length); + + var header = blobReader.ReadSignatureHeader(); + blobBuilder.WriteByte(header.RawValue); + switch (header.Kind) + { + case SignatureKind.Method: + case SignatureKind.Property: + ImportMethodSignature(header, ref blobReader, blobBuilder); + break; + case SignatureKind.Field: + ImportFieldSignature(ref blobReader, blobBuilder); + break; + case SignatureKind.LocalVariables: + ImportLocalSignature(ref blobReader, blobBuilder); + break; + case SignatureKind.MethodSpecification: + ImportMethodSpecSignature(ref blobReader, blobBuilder); + break; + default: + throw new BadImageFormatException(); } - return default; - + return _builder.GetOrAddBlob(blobBuilder); } private void ImportMethodSignature( SignatureHeader header, ref BlobReader blobReader, BlobBuilder blobBuilder )