Skip to content

Commit d976b40

Browse files
authored
Fix processing of typedef flags (#114)
***UPDATE_DEPENDENTS***
1 parent 5d7fd4d commit d976b40

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

MetadataProcessor.Core/Tables/nanoMethodDefinitionTable.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ protected override void WriteSingleItem(
120120
writer.WriteUInt16(methodSignature);
121121
}
122122

123-
public static uint GetFlags(
124-
MethodDefinition method)
123+
public static uint GetFlags(MethodDefinition method)
125124
{
126125
const uint MD_Scope_Private = 0x00000001; // Accessible only by the parent type.
127126
const uint MD_Scope_FamANDAssem = 0x00000002; // Accessible by sub-types only in this Assembly.
@@ -277,17 +276,6 @@ public static uint GetFlags(
277276
}
278277
}
279278

280-
var methodName = method.Name;
281-
if (methodName == "Finalize" &&
282-
method.ReturnType.FullName == "System.Void" &&
283-
!method.HasParameters)
284-
{
285-
flag |= MD_Finalizer;
286-
287-
// TODO
288-
// missing setting tdDst->flags |= CLR_RECORD_TYPEDEF::TD_HasFinalizer;
289-
}
290-
291279
return flag;
292280
}
293281
}

MetadataProcessor.Core/Tables/nanoTypeDefinitionTable.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ protected override void WriteSingleItem(
151151
}
152152
}
153153

154-
writer.WriteUInt16((ushort)GetFlags(item)); // flags
154+
// write flags
155+
writer.WriteUInt16(
156+
(ushort)GetFlags(
157+
item,
158+
_context.MethodDefinitionTable));
155159
}
156160

157161
private void WriteClassFields(
@@ -295,8 +299,18 @@ private ushort GetTypeReferenceOrDefinitionId(
295299
return 0xFFFF;
296300
}
297301

302+
/// <summary>
303+
/// Get flags for the Type definition.
304+
/// </summary>
305+
/// <param name="definition"><see cref="TypeDefinition"/> to get the flags</param>
306+
/// <param name="methodDefinitioTable">List with type definitions that have finalizers, if this check is required.</param>
307+
/// <returns></returns>
308+
/// <remarks>
309+
/// If the <paramref name="typesWithFinalizers"/> is null, the check for finalizer won't be checked.
310+
/// </remarks>
298311
internal static nanoTypeDefinitionFlags GetFlags(
299-
TypeDefinition definition)
312+
TypeDefinition definition,
313+
nanoMethodDefinitionTable methodDefinitioTable = null)
300314
{
301315
var flags = nanoTypeDefinitionFlags.TD_Scope_None;
302316

@@ -389,6 +403,27 @@ internal static nanoTypeDefinitionFlags GetFlags(
389403
flags |= nanoTypeDefinitionFlags.TD_Delegate;
390404
}
391405

406+
// need to check for finalizers methods
407+
if (methodDefinitioTable != null)
408+
{
409+
foreach (var m in definition.Methods)
410+
{
411+
if (methodDefinitioTable.Items.Contains(m))
412+
{
413+
var methodName = m.Name;
414+
if (methodName == "Finalize" &&
415+
m.ReturnType.FullName == "System.Void" &&
416+
!m.HasParameters)
417+
{
418+
if (m.DeclaringType.FullName != "System.Object")
419+
{
420+
flags |= nanoTypeDefinitionFlags.TD_HasFinalizer;
421+
}
422+
}
423+
}
424+
}
425+
}
426+
392427
return flags;
393428
}
394429

MetadataProcessor.Core/nanoDumperGenerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ private void DumpTypeDefinitions(DumpAllTable dumpTable)
198198
typeDef.Name = t.FullName;
199199
}
200200

201-
var typeFlags = (uint)nanoTypeDefinitionTable.GetFlags(t);
201+
var typeFlags = (uint)nanoTypeDefinitionTable.GetFlags(
202+
t,
203+
_tablesContext.MethodDefinitionTable);
204+
202205
typeDef.Flags = typeFlags.ToString("x8");
203206

204207
if (t.BaseType != null)

0 commit comments

Comments
 (0)