Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/MetadataProcessor.Core/DumpGenerator/DumpTemplates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -43,6 +45,7 @@ internal partial class DumpTemplates
{{/InterfaceDefinitions}}

{{/TypeDefinitions}}

{{#UserStrings}}
UserString [{{ReferenceId}}]: '{{Content}}'
{{/UserStrings}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
33 changes: 30 additions & 3 deletions source/MetadataProcessor.Core/Tables/nanoTablesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -56,7 +64,6 @@ public sealed class nanoTablesContext
// Not supported attributes
"System.MTAThreadAttribute",
"System.STAThreadAttribute",
//"System.Reflection.DefaultMemberAttribute",
};

public nanoTablesContext(
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -241,7 +268,7 @@ public ushort GetMethodReferenceId(

public nanoResourceFileTable ResourceFileTable { get; private set; }

public List<string> ClassNamesToExclude { get; private set; }
public static List<string> ClassNamesToExclude { get; private set; }

private IEnumerable<Tuple<CustomAttribute, ushort>> GetAttributes(
IEnumerable<ICustomAttributeProvider> types,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint, List<Tuple<uint, uint>>>();
Expand Down
15 changes: 8 additions & 7 deletions source/MetadataProcessor.Core/nanoAssemblyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//

using Mono.Cecil;
using nanoFramework.Tools.MetadataProcessor.Core.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -339,7 +340,7 @@ private HashSet<MetadataToken> 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);
}
Expand All @@ -350,7 +351,7 @@ private HashSet<MetadataToken> 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);
}
Expand All @@ -359,7 +360,7 @@ private HashSet<MetadataToken> 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);
}
Expand All @@ -368,7 +369,7 @@ private HashSet<MetadataToken> 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);
}
Expand All @@ -387,7 +388,7 @@ private HashSet<MetadataToken> 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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion source/MetadataProcessor.Core/nanoDumperGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 6 additions & 11 deletions source/MetadataProcessor.Core/nanoSkeletonGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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()
{
Expand All @@ -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))
{
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand Down