diff --git a/source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs b/source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs index a6f03003..33b06882 100644 --- a/source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs +++ b/source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs @@ -12,12 +12,14 @@ internal partial class DumpTemplates {{#AssemblyReferences}} AssemblyRefProps [{{ReferenceId}}]: Flags: {{Flags}} '{{Name}}' {{/AssemblyReferences}} + {{#TypeReferences}} TypeRefProps [{{ReferenceId}}]: Scope: {{Scope}} '{{Name}}' {{#MemberReferences}} MemberRefProps [{{ReferenceId}}]: '{{Name}}' [{{Signature}}] {{/MemberReferences}} {{/TypeReferences}} + {{#TypeDefinitions}} TypeDefProps [{{ReferenceId}}]: Flags: {{Flags}} Extends: {{ExtendsType}} Enclosed: {{EnclosedType}} '{{Name}}' {{#FieldDefinitions}} @@ -43,6 +45,7 @@ internal partial class DumpTemplates {{/InterfaceDefinitions}} {{/TypeDefinitions}} + {{#UserStrings}} UserString [{{ReferenceId}}]: '{{Content}}' {{/UserStrings}} diff --git a/source/MetadataProcessor.Core/Extensions/TypeDefinitionExtensions.cs b/source/MetadataProcessor.Core/Extensions/TypeDefinitionExtensions.cs index c67a8923..6601c82e 100644 --- a/source/MetadataProcessor.Core/Extensions/TypeDefinitionExtensions.cs +++ b/source/MetadataProcessor.Core/Extensions/TypeDefinitionExtensions.cs @@ -28,5 +28,11 @@ public static bool IncludeInStub(this TypeDefinition value) return false; } + + public static bool IsClassToExclude(this TypeDefinition value) + { + return nanoTablesContext.ClassNamesToExclude.Contains(value.FullName) || + nanoTablesContext.ClassNamesToExclude.Contains(value.DeclaringType?.FullName); + } } } diff --git a/source/MetadataProcessor.Core/Tables/nanoTablesContext.cs b/source/MetadataProcessor.Core/Tables/nanoTablesContext.cs index 1af40652..c02f8d6a 100644 --- a/source/MetadataProcessor.Core/Tables/nanoTablesContext.cs +++ b/source/MetadataProcessor.Core/Tables/nanoTablesContext.cs @@ -19,6 +19,14 @@ public sealed class nanoTablesContext // Assembly-level attributes "System.Runtime.InteropServices.ComVisibleAttribute", "System.Runtime.InteropServices.GuidAttribute", + "System.Reflection.AssemblyTitleAttribute", + "System.Reflection.AssemblyDescriptionAttribute", + "System.Reflection.AssemblyConfigurationAttribute", + "System.Reflection.AssemblyCompanyAttribute", + "System.Reflection.AssemblyProductAttribute", + "System.Reflection.AssemblyCopyrightAttribute", + "System.Reflection.AssemblyTrademarkAttribute", + "System.Reflection.AssemblyFileVersionAttribute", // Compiler-specific attributes //"System.ParamArrayAttribute", @@ -56,7 +64,6 @@ public sealed class nanoTablesContext // Not supported attributes "System.MTAThreadAttribute", "System.STAThreadAttribute", - //"System.Reflection.DefaultMemberAttribute", }; public nanoTablesContext( @@ -101,7 +108,17 @@ public nanoTablesContext( AssemblyReferenceTable = new nanoAssemblyReferenceTable( mainModule.AssemblyReferences, this); - var typeReferences = mainModule.GetTypeReferences(); + var typeReferences = mainModule.GetTypeReferences().ToList(); + + // remove types in ignore list + foreach (var a in _ignoringAttributes) + { + var typeToExclude = typeReferences.FirstOrDefault(t => t.FullName == a); + if (typeToExclude != null) + { + typeReferences.Remove(typeToExclude); + } + } TypeReferencesTable = new nanoTypeReferenceTable( typeReferences, this); @@ -123,6 +140,16 @@ public nanoTablesContext( var types = GetOrderedTypes(mainModule, explicitTypesOrder); + // remove types in ignore list + foreach (var a in _ignoringAttributes) + { + var typeToExclude = types.FirstOrDefault(t => t.FullName == a); + if(typeToExclude != null) + { + types.Remove(typeToExclude); + } + } + TypeDefinitionTable = new nanoTypeDefinitionTable(types, this); var fields = types @@ -241,7 +268,7 @@ public ushort GetMethodReferenceId( public nanoResourceFileTable ResourceFileTable { get; private set; } - public List ClassNamesToExclude { get; private set; } + public static List ClassNamesToExclude { get; private set; } private IEnumerable> GetAttributes( IEnumerable types, diff --git a/source/MetadataProcessor.Core/Tables/nanoTypeDefinitionTable.cs b/source/MetadataProcessor.Core/Tables/nanoTypeDefinitionTable.cs index 59ecf928..1d498d69 100644 --- a/source/MetadataProcessor.Core/Tables/nanoTypeDefinitionTable.cs +++ b/source/MetadataProcessor.Core/Tables/nanoTypeDefinitionTable.cs @@ -381,11 +381,6 @@ internal static nanoTypeDefinitionFlags GetFlags( return flags; } - internal bool IsClassToExclude(TypeDefinition td) - { - return _context.ClassNamesToExclude.Contains(td.FullName); - } - internal void ResetByteCodeOffsets() { _byteCodeOffsets = new Dictionary>>(); diff --git a/source/MetadataProcessor.Core/nanoAssemblyBuilder.cs b/source/MetadataProcessor.Core/nanoAssemblyBuilder.cs index 4a021d41..b2826a16 100644 --- a/source/MetadataProcessor.Core/nanoAssemblyBuilder.cs +++ b/source/MetadataProcessor.Core/nanoAssemblyBuilder.cs @@ -5,6 +5,7 @@ // using Mono.Cecil; +using nanoFramework.Tools.MetadataProcessor.Core.Extensions; using System; using System.Collections.Generic; using System.IO; @@ -101,7 +102,7 @@ public void Minimize() foreach (var t in _tablesContext.TypeDefinitionTable.TypeDefinitions) { - if (!_tablesContext.TypeDefinitionTable.IsClassToExclude(t)) + if (!t.IsClassToExclude()) { setNew.Add(t.MetadataToken); } @@ -339,7 +340,7 @@ private HashSet BuildDependencyList(MetadataToken token) // include attributes foreach(var c in td.CustomAttributes) { - if (!_tablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) { set.Add(c.AttributeType.MetadataToken); } @@ -350,7 +351,7 @@ private HashSet BuildDependencyList(MetadataToken token) foreach (var f in tdFields) { - if (!_tablesContext.ClassNamesToExclude.Contains(f.DeclaringType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(f.DeclaringType.FullName)) { set.Add(f.MetadataToken); } @@ -359,7 +360,7 @@ private HashSet BuildDependencyList(MetadataToken token) // methods foreach (var m in td.Methods) { - if (!_tablesContext.ClassNamesToExclude.Contains(m.DeclaringType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(m.DeclaringType.FullName)) { set.Add(m.MetadataToken); } @@ -368,7 +369,7 @@ private HashSet BuildDependencyList(MetadataToken token) // interfaces foreach (var i in td.Interfaces) { - if (!_tablesContext.ClassNamesToExclude.Contains(i.InterfaceType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(i.InterfaceType.FullName)) { set.Add(i.MetadataToken); } @@ -387,7 +388,7 @@ private HashSet BuildDependencyList(MetadataToken token) // attributes foreach (var c in fd.CustomAttributes) { - if (!_tablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) { set.Add(c.Constructor.MetadataToken); } @@ -464,7 +465,7 @@ i.Operand is TypeDefinition || // attributes foreach (var c in md.CustomAttributes) { - if (!_tablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) + if (!nanoTablesContext.ClassNamesToExclude.Contains(c.AttributeType.FullName)) { set.Add(c.Constructor.MetadataToken); } diff --git a/source/MetadataProcessor.Core/nanoDumperGenerator.cs b/source/MetadataProcessor.Core/nanoDumperGenerator.cs index 5abd9b99..8af2c257 100644 --- a/source/MetadataProcessor.Core/nanoDumperGenerator.cs +++ b/source/MetadataProcessor.Core/nanoDumperGenerator.cs @@ -235,10 +235,12 @@ private void DumpTypeReferences(DumpAllTable dumpTable) { ushort refId; + var metadataScopeType = _tablesContext.AssemblyReferenceTable.Items.FirstOrDefault(a => a == t.Scope); + var typeRef = new TypeRef() { Name = t.Name, - Scope = t.Scope.MetadataScopeType.ToString("x8") + Scope = _tablesContext.AssemblyReferenceTable.GetReferenceId(metadataScopeType).ToString("x8") }; if (_tablesContext.TypeReferencesTable.TryGetTypeReferenceId(t, out refId)) diff --git a/source/MetadataProcessor.Core/nanoSkeletonGenerator.cs b/source/MetadataProcessor.Core/nanoSkeletonGenerator.cs index 5c121756..88d6bea2 100644 --- a/source/MetadataProcessor.Core/nanoSkeletonGenerator.cs +++ b/source/MetadataProcessor.Core/nanoSkeletonGenerator.cs @@ -58,7 +58,8 @@ private void GenerateStubs() { foreach (var c in _tablesContext.TypeDefinitionTable.TypeDefinitions) { - if (c.IncludeInStub() && !IsClassToExclude(c)) + if (c.IncludeInStub() && + !c.IsClassToExclude()) { var className = NativeMethodsCrc.GetClassName(c); @@ -121,7 +122,7 @@ private void GenerateAssemblyLookup() if (c.IncludeInStub()) { // don't include if it's on the exclude list - if (!IsClassToExclude(c)) + if (!c.IsClassToExclude()) { var className = NativeMethodsCrc.GetClassName(c); @@ -145,7 +146,7 @@ private void GenerateAssemblyLookup() // need to add a NULL entry for it // unless it's on the exclude list - if (!IsClassToExclude(c)) + if (!c.IsClassToExclude()) { assemblyLookup.LookupTable.Add(new Method() { @@ -163,7 +164,7 @@ private void GenerateAssemblyLookup() // need to add a NULL entry for each method // unless it's on the exclude list - if (!IsClassToExclude(c)) + if (!c.IsClassToExclude()) { foreach (var m in nanoTablesContext.GetOrderedMethods(c.Methods)) { @@ -201,7 +202,7 @@ private void GenerateAssemblyHeader() foreach (var c in _tablesContext.TypeDefinitionTable.Items) { if (c.IncludeInStub() && - !IsClassToExclude(c)) + !c.IsClassToExclude()) { var classData = new Class() { @@ -297,12 +298,6 @@ private void GenerateAssemblyHeader() } } - private bool IsClassToExclude(TypeDefinition td) - { - return (_tablesContext.ClassNamesToExclude.Contains(td.FullName) || - _tablesContext.ClassNamesToExclude.Contains(td.DeclaringType?.FullName)); - } - private int GetInstanceFieldsOffset(TypeDefinition c) { // check if this type has a base type different from System.Object