Skip to content

Commit 3206add

Browse files
authored
Fix processing of generic type (#129)
1 parent b2b663f commit 3206add

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

MetadataProcessor.Core/Tables/nanoMethodDefinitionTable.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Mono.Cecil;
22
using System;
33
using System.Collections.Generic;
4+
using System.Diagnostics;
45

56
namespace nanoFramework.Tools.MetadataProcessor
67
{
@@ -11,6 +12,8 @@ namespace nanoFramework.Tools.MetadataProcessor
1112
public sealed class nanoMethodDefinitionTable :
1213
nanoReferenceTableBase<MethodDefinition>
1314
{
15+
private const int sizeOf_CLR_RECORD_METHODDEF = 16;
16+
1417
/// <summary>
1518
/// Helper class for comparing two instances of <see cref="MethodDefinition"/> objects
1619
/// using <see cref="MethodDefinition.FullName"/> property as unique key for comparison.
@@ -62,6 +65,8 @@ protected override void WriteSingleItem(
6265
nanoBinaryWriter writer,
6366
MethodDefinition item)
6467
{
68+
var writerStartPosition = writer.BaseStream.Position;
69+
6570
if (!_context.MinimizeComplete)
6671
{
6772
return;
@@ -118,6 +123,10 @@ protected override void WriteSingleItem(
118123
}
119124

120125
writer.WriteUInt16(methodSignature);
126+
127+
var writerEndPosition = writer.BaseStream.Position;
128+
129+
Debug.Assert((writerEndPosition - writerStartPosition) == sizeOf_CLR_RECORD_METHODDEF);
121130
}
122131

123132
public static uint GetFlags(MethodDefinition method)
@@ -149,6 +158,9 @@ public static uint GetFlags(MethodDefinition method)
149158
const uint MD_DelegateBeginInvoke = 0x00040000;
150159
const uint MD_DelegateEndInvoke = 0x00080000;
151160

161+
const uint MD_ContainsGenericParameter = 0x00100000;
162+
const uint MD_HasGenericParameter = 0x00200000;
163+
152164
const uint MD_Synchronized = 0x01000000;
153165
const uint MD_GloballySynchronized = 0x02000000;
154166
const uint MD_Patched = 0x04000000;
@@ -276,6 +288,16 @@ public static uint GetFlags(MethodDefinition method)
276288
}
277289
}
278290

291+
if (method.ContainsGenericParameter)
292+
{
293+
flag |= MD_ContainsGenericParameter;
294+
}
295+
296+
if (method.HasGenericParameters)
297+
{
298+
flag |= MD_HasGenericParameter;
299+
}
300+
279301
return flag;
280302
}
281303
}

MetadataProcessor.Core/Tables/nanoSignaturesTable.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ public void WriteDataType(
316316
return;
317317
}
318318

319+
if (typeDefinition.MetadataType == MetadataType.Var)
320+
{
321+
writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_MVAR);
322+
323+
if (alsoWriteSubType)
324+
{
325+
// following ECMA-335 VI.B.4.3 Metadata
326+
writer.WriteByte((byte)(typeDefinition as GenericParameter).Position);
327+
}
328+
329+
return;
330+
}
331+
319332
if (typeDefinition.IsArray)
320333
{
321334
writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_SZARRAY);
@@ -371,15 +384,6 @@ public void WriteDataType(
371384
return;
372385
}
373386

374-
if (typeDefinition.IsGenericParameter)
375-
{
376-
// following ECMA-335 VI.B.4.3 Metadata
377-
378-
writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_MVAR);
379-
writer.WriteByte((byte)(typeDefinition as GenericParameter).Position);
380-
return;
381-
}
382-
383387
writer.WriteByte(0x00);
384388
}
385389

0 commit comments

Comments
 (0)