Skip to content

Commit

Permalink
Fix processing of generic type (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Dec 29, 2020
1 parent b2b663f commit 3206add
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
22 changes: 22 additions & 0 deletions MetadataProcessor.Core/Tables/nanoMethodDefinitionTable.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace nanoFramework.Tools.MetadataProcessor
{
Expand All @@ -11,6 +12,8 @@ namespace nanoFramework.Tools.MetadataProcessor
public sealed class nanoMethodDefinitionTable :
nanoReferenceTableBase<MethodDefinition>
{
private const int sizeOf_CLR_RECORD_METHODDEF = 16;

/// <summary>
/// Helper class for comparing two instances of <see cref="MethodDefinition"/> objects
/// using <see cref="MethodDefinition.FullName"/> property as unique key for comparison.
Expand Down Expand Up @@ -62,6 +65,8 @@ protected override void WriteSingleItem(
nanoBinaryWriter writer,
MethodDefinition item)
{
var writerStartPosition = writer.BaseStream.Position;

if (!_context.MinimizeComplete)
{
return;
Expand Down Expand Up @@ -118,6 +123,10 @@ protected override void WriteSingleItem(
}

writer.WriteUInt16(methodSignature);

var writerEndPosition = writer.BaseStream.Position;

Debug.Assert((writerEndPosition - writerStartPosition) == sizeOf_CLR_RECORD_METHODDEF);
}

public static uint GetFlags(MethodDefinition method)
Expand Down Expand Up @@ -149,6 +158,9 @@ public static uint GetFlags(MethodDefinition method)
const uint MD_DelegateBeginInvoke = 0x00040000;
const uint MD_DelegateEndInvoke = 0x00080000;

const uint MD_ContainsGenericParameter = 0x00100000;
const uint MD_HasGenericParameter = 0x00200000;

const uint MD_Synchronized = 0x01000000;
const uint MD_GloballySynchronized = 0x02000000;
const uint MD_Patched = 0x04000000;
Expand Down Expand Up @@ -276,6 +288,16 @@ public static uint GetFlags(MethodDefinition method)
}
}

if (method.ContainsGenericParameter)
{
flag |= MD_ContainsGenericParameter;
}

if (method.HasGenericParameters)
{
flag |= MD_HasGenericParameter;
}

return flag;
}
}
Expand Down
22 changes: 13 additions & 9 deletions MetadataProcessor.Core/Tables/nanoSignaturesTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ public void WriteDataType(
return;
}

if (typeDefinition.MetadataType == MetadataType.Var)
{
writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_MVAR);

if (alsoWriteSubType)
{
// following ECMA-335 VI.B.4.3 Metadata
writer.WriteByte((byte)(typeDefinition as GenericParameter).Position);
}

return;
}

if (typeDefinition.IsArray)
{
writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_SZARRAY);
Expand Down Expand Up @@ -371,15 +384,6 @@ public void WriteDataType(
return;
}

if (typeDefinition.IsGenericParameter)
{
// following ECMA-335 VI.B.4.3 Metadata

writer.WriteByte((byte)nanoCLR_DataType.DATATYPE_MVAR);
writer.WriteByte((byte)(typeDefinition as GenericParameter).Position);
return;
}

writer.WriteByte(0x00);
}

Expand Down

0 comments on commit 3206add

Please sign in to comment.