Skip to content

Commit

Permalink
Handle processing the new API layout for UnmanagedCallersOnlyAttribute (
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronRobinsonMSFT committed Jun 24, 2020
1 parent 06a1a5e commit b85ad53
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/dnne-gen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Reflection;
using System.Reflection.Metadata;
using System.Reflection.PortableExecutable;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

Expand Down Expand Up @@ -125,6 +126,31 @@ public void Emit(TextWriter outputStream)
callConv = (CallingConvention)arg.Value;
break;

case KnownType.SystemTypeArray:
if (arg.Value != null)
{
foreach (var cct in (ImmutableArray<CustomAttributeTypedArgument<KnownType>>)arg.Value)
{
Debug.Assert(cct.Type == KnownType.SystemType);
switch ((KnownType)cct.Value)
{
case KnownType.CallConvCdecl:
callConv = CallingConvention.Cdecl;
break;
case KnownType.CallConvStdcall:
callConv = CallingConvention.StdCall;
break;
case KnownType.CallConvThiscall:
callConv = CallingConvention.ThisCall;
break;
case KnownType.CallConvFastcall:
callConv = CallingConvention.FastCall;
break;
}
}
}
break;

case KnownType.String:
exportName = (string)arg.Value;
break;
Expand Down Expand Up @@ -225,7 +251,7 @@ private ExportType GetExportAttributeType(CustomAttribute attribute)
{
return ExportType.Export;
}
else if (IsAttributeType(this.mdReader, attribute, "System.Runtime.InteropServices", "UnmanagedCallersOnlyAttribute"))
else if (IsAttributeType(this.mdReader, attribute, "System.Runtime.InteropServices", nameof(UnmanagedCallersOnlyAttribute)))
{
return ExportType.UnmanagedCallersOnly;
}
Expand Down Expand Up @@ -412,7 +438,12 @@ private enum KnownType
Unknown,
I4,
CallingConvention,
CallConvCdecl,
CallConvStdcall,
CallConvThiscall,
CallConvFastcall,
String,
SystemTypeArray,
SystemType
}

Expand All @@ -435,7 +466,12 @@ public KnownType GetSystemType()

public KnownType GetSZArrayType(KnownType elementType)
{
return KnownType.Unknown;
if (elementType == KnownType.SystemType)
{
return KnownType.SystemTypeArray;
}

throw new BadImageFormatException("Unexpectedly got an array of unsupported type.");
}

public KnownType GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind)
Expand All @@ -454,6 +490,22 @@ public KnownType GetTypeFromSerializedName(string name)
{
return KnownType.CallingConvention;
}
else if (Type.GetType(name).Name.Equals(nameof(CallConvCdecl)))
{
return KnownType.CallConvCdecl;
}
else if (Type.GetType(name).Name.Equals(nameof(CallConvStdcall)))
{
return KnownType.CallConvStdcall;
}
else if (Type.GetType(name).Name.Equals(nameof(CallConvThiscall)))
{
return KnownType.CallConvThiscall;
}
else if (Type.GetType(name).Name.Equals(nameof(CallConvFastcall)))
{
return KnownType.CallConvFastcall;
}

return KnownType.Unknown;
}
Expand Down

0 comments on commit b85ad53

Please sign in to comment.