Skip to content

Commit 3add8b2

Browse files
committed
Improvements in skeleton generator processing
- Fix conditions to include (or not) method declarations. - Fix check for types with derived types in classes to include and ignored attributes. - Add missing flags to type defintion constants. - Minor fix in templates. Signed-off-by: José Simões <[email protected]>
1 parent ce9da11 commit 3add8b2

File tree

6 files changed

+68
-38
lines changed

6 files changed

+68
-38
lines changed

source/MetadataProcessor.Core/Extensions/TypeDefinitionExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public static bool IncludeInStub(this TypeDefinition value)
2020
}
2121

2222
// Only generate a stub for classes and value types.
23-
if ( (value.IsClass ||
24-
value.IsValueType) &&
25-
!value.IsEnum)
23+
if ( typeDefFlags.HasFlag(nanoTypeDefinitionFlags.TD_Semantics_Class) ||
24+
typeDefFlags.HasFlag(nanoTypeDefinitionFlags.TD_Semantics_ValueType) )
2625
{
2726
return true;
2827
}

source/MetadataProcessor.Core/SkeletonGenerator/SkeletonTemplates.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ struct Library_{{AssemblyName}}_{{Name}}
5050
};
5151
5252
{{/Classes}}
53-
5453
extern const CLR_RT_NativeAssemblyData g_CLR_AssemblyNative_{{Name}};
5554
5655
#endif //_{{ShortNameUpper}}_H_

source/MetadataProcessor.Core/Tables/nanoTablesContext.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public sealed class nanoTablesContext
3636

3737
// Debugger-specific attributes
3838
"System.Diagnostics.DebuggableAttribute",
39-
//"System.Diagnostics.DebuggerBrowsableAttribute",
40-
//"System.Diagnostics.DebuggerBrowsableState",
39+
"System.Diagnostics.DebuggerBrowsableAttribute",
40+
"System.Diagnostics.DebuggerBrowsableState",
4141
"System.Diagnostics.DebuggerHiddenAttribute",
4242
"System.Diagnostics.DebuggerNonUserCodeAttribute",
4343
"System.Diagnostics.DebuggerStepThroughAttribute",
@@ -74,8 +74,10 @@ public nanoTablesContext(
7474
foreach (var item in assemblyDefinition.CustomAttributes)
7575
{
7676
// add it to ignore list, if it's not already there
77-
if (ClassNamesToExclude.Contains(item.AttributeType.FullName) &&
78-
!_ignoringAttributes.Contains(item.AttributeType.FullName))
77+
if ((ClassNamesToExclude.Contains(item.AttributeType.FullName) ||
78+
ClassNamesToExclude.Contains(item.AttributeType.DeclaringType?.FullName)) &&
79+
!(_ignoringAttributes.Contains(item.AttributeType.FullName) ||
80+
_ignoringAttributes.Contains(item.AttributeType.DeclaringType?.FullName)))
7981
{
8082
_ignoringAttributes.Add(item.AttributeType.FullName);
8183
}
@@ -262,9 +264,8 @@ private bool IsAttribute(
262264
MemberReference typeReference)
263265
{
264266
return
265-
_ignoringAttributes.Contains(typeReference.FullName) ||
266-
(typeReference.DeclaringType != null &&
267-
_ignoringAttributes.Contains(typeReference.DeclaringType.FullName));
267+
(_ignoringAttributes.Contains(typeReference.FullName) ||
268+
_ignoringAttributes.Contains(typeReference.DeclaringType?.FullName));
268269
}
269270

270271
private static List<TypeDefinition> GetOrderedTypes(

source/MetadataProcessor.Core/Utility/NativeMethodsCrc.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ internal void UpdateCrc(nanoTypeDefinitionTable typeDefinitionTable)
151151

152152
private bool IsClassToExclude(TypeDefinition td)
153153
{
154-
return _classNamesToExclude.Contains(td.FullName);
154+
return (_classNamesToExclude.Contains(td.FullName) ||
155+
_classNamesToExclude.Contains(td.DeclaringType?.FullName));
155156
}
156157
}
157158
}

source/MetadataProcessor.Core/Utility/nanoTypeDefinitionFlags.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ internal enum nanoTypeDefinitionFlags : ushort
1616
// these where defined @ struct CLR_RECORD_TYPEDEF
1717
TD_Scope_None = 0x0000,
1818

19+
// Class is public scope.
20+
TD_Scope_NotPublic = 0x0000,
21+
1922
// Class is public scope.
2023
TD_Scope_Public = 0x0001,
2124
// Class is nested with public visibility.
@@ -34,27 +37,30 @@ internal enum nanoTypeDefinitionFlags : ushort
3437
/// <summary>
3538
/// Mask for scope flags
3639
/// </summary>
37-
TD_Scope =
38-
TD_Scope_Public |
39-
TD_Scope_NestedPublic |
40-
TD_Scope_NestedPrivate |
41-
TD_Scope_NestedFamily |
42-
TD_Scope_NestedAssembly |
43-
TD_Scope_NestedFamANDAssem |
40+
TD_Scope =
41+
TD_Scope_NotPublic |
42+
TD_Scope_Public |
43+
TD_Scope_NestedPublic |
44+
TD_Scope_NestedPrivate |
45+
TD_Scope_NestedFamily |
46+
TD_Scope_NestedAssembly |
47+
TD_Scope_NestedFamANDAssem |
4448
TD_Scope_NestedFamORAssem,
4549

4650
TD_Serializable = 0x0008,
4751

52+
TD_Semantics_Class = 0x0000,
4853
TD_Semantics_ValueType = 0x0010,
4954
TD_Semantics_Interface = 0x0020,
5055
TD_Semantics_Enum = 0x0030,
5156

5257
/// <summary>
5358
/// Mask for semantics flags
5459
/// </summary>
55-
TD_Semantics =
56-
TD_Semantics_ValueType |
57-
TD_Semantics_Interface |
60+
TD_Semantics =
61+
TD_Semantics_Class |
62+
TD_Semantics_ValueType |
63+
TD_Semantics_Interface |
5864
TD_Semantics_Enum,
5965

6066
TD_Abstract = 0x0040,

source/MetadataProcessor.Core/nanoSkeletonGenerator.cs

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,46 @@ private void GenerateAssemblyLookup()
116116

117117
foreach (var c in _tablesContext.TypeDefinitionTable.TypeDefinitions)
118118
{
119-
if (c.IncludeInStub() && !IsClassToExclude(c))
119+
// only care about types that have methods
120+
if (c.HasMethods)
120121
{
121-
var className = NativeMethodsCrc.GetClassName(c);
122-
123-
foreach (var m in nanoTablesContext.GetOrderedMethods(c.Methods))
122+
if (c.IncludeInStub() &&
123+
!IsClassToExclude(c))
124124
{
125-
var rva = _tablesContext.ByteCodeTable.GetMethodRva(m);
125+
var className = NativeMethodsCrc.GetClassName(c);
126126

127-
// check method inclusion
128-
if ((rva == 0xFFFF &&
129-
!m.IsAbstract))
127+
foreach (var m in nanoTablesContext.GetOrderedMethods(c.Methods))
130128
{
131-
assemblyLookup.LookupTable.Add(new Method()
129+
var rva = _tablesContext.ByteCodeTable.GetMethodRva(m);
130+
131+
// check method inclusion
132+
// method is not a native implementation (RVA 0xFFFF) and is not abstract
133+
if ((rva == 0xFFFF &&
134+
!m.IsAbstract))
132135
{
133-
Declaration = $"Library_{_project}_{className}::{NativeMethodsCrc.GetMethodName(m)}"
134-
});
136+
assemblyLookup.LookupTable.Add(new Method()
137+
{
138+
Declaration = $"Library_{_project}_{className}::{NativeMethodsCrc.GetMethodName(m)}"
139+
});
140+
}
141+
else
142+
{
143+
// method won't be included, still
144+
// need to add a NULL entry for it
145+
146+
assemblyLookup.LookupTable.Add(new Method()
147+
{
148+
Declaration = "NULL"
149+
});
150+
}
135151
}
136-
else
152+
}
153+
else
154+
{
155+
// type won't be included, still
156+
// need to add a NULL entry for each method
157+
158+
for (int i = 0; i < c.Methods.Count; i++)
137159
{
138160
assemblyLookup.LookupTable.Add(new Method()
139161
{
@@ -166,7 +188,8 @@ private void GenerateAssemblyHeader()
166188

167189
foreach (var c in _tablesContext.TypeDefinitionTable.TypeDefinitions)
168190
{
169-
if (c.IncludeInStub() && !IsClassToExclude(c))
191+
if (c.IncludeInStub() &&
192+
!IsClassToExclude(c))
170193
{
171194
var classData = new Class()
172195
{
@@ -265,7 +288,8 @@ private void GenerateAssemblyHeader()
265288

266289
private bool IsClassToExclude(TypeDefinition td)
267290
{
268-
return _tablesContext.ClassNamesToExclude.Contains(td.FullName);
291+
return (_tablesContext.ClassNamesToExclude.Contains(td.FullName) ||
292+
_tablesContext.ClassNamesToExclude.Contains(td.DeclaringType?.FullName));
269293
}
270294

271295
private int GetInstanceFieldsOffset(TypeDefinition c)
@@ -298,7 +322,7 @@ private int GetNestedFieldsCount(TypeDefinition c)
298322
// now add the fields count from this type
299323
if (_tablesContext.TypeDefinitionTable.TryGetTypeReferenceId(c, out tt))
300324
{
301-
fieldCount += _tablesContext.TypeDefinitionTable.TypeDefinitions[tt].Fields.Count(f => !f.IsStatic);
325+
fieldCount += c.Fields.Count(f => !f.IsStatic && !f.IsLiteral);
302326
}
303327

304328
return fieldCount;
@@ -309,7 +333,7 @@ private int GetNestedFieldsCount(TypeDefinition c)
309333

310334
if (_tablesContext.TypeDefinitionTable.TryGetTypeReferenceId(c, out tt))
311335
{
312-
return _tablesContext.TypeDefinitionTable.TypeDefinitions[tt].Fields.Count(f => !f.IsStatic);
336+
return c.Fields.Count(f => !f.IsStatic && !f.IsLiteral);
313337
}
314338
else
315339
{

0 commit comments

Comments
 (0)