Browse Source

Set the correct enum integer type in GenerateEnumFromMacros.

pull/1511/head
Joao Matos 5 years ago committed by João Matos
parent
commit
35a7f19cf1
  1. 26
      src/Generator/Library.cs

26
src/Generator/Library.cs

@ -186,13 +186,39 @@ namespace CppSharp @@ -186,13 +186,39 @@ namespace CppSharp
if (@enum.Items.Count > 0)
{
@enum.BuiltinType = new BuiltinType(GetUnderlyingTypeForEnumValue(maxValue));
@enum.Type = @enum.BuiltinType;
@enum.Namespace = unitToAttach;
unitToAttach.Declarations.Add(@enum);
}
return @enum;
}
private static PrimitiveType GetUnderlyingTypeForEnumValue(ulong maxValue)
{
if (maxValue < (byte)sbyte.MaxValue)
return PrimitiveType.SChar;
if (maxValue < byte.MaxValue)
return PrimitiveType.UChar;
if (maxValue < (ushort)short.MaxValue)
return PrimitiveType.Short;
if (maxValue < ushort.MaxValue)
return PrimitiveType.UShort;
if (maxValue < int.MaxValue)
return PrimitiveType.Int;
if (maxValue < uint.MaxValue)
return PrimitiveType.UInt;
throw new NotImplementedException();
}
#endregion
#region Class Helpers

Loading…
Cancel
Save