Permalink
Browse files

Revert "Simplified the C# marshalling of Boolean fields."

This reverts commit dc270ef.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
  • Loading branch information...
ddobrev committed Jul 11, 2017
1 parent dc270ef commit 54f3af1459eddfe224022adb5a1b507777d339dc
@@ -216,6 +216,14 @@ public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers
goto default;
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("{0} != 0", Context.ReturnVarName);
return true;
}
goto default;
default:
Context.Return.Write(Context.ReturnVarName);
return true;
@@ -641,6 +649,14 @@ public override bool VisitPrimitiveType(PrimitiveType primitive, TypeQualifiers
goto default;
case PrimitiveType.Char16:
return false;
case PrimitiveType.Bool:
if (Context.MarshalKind == MarshalKind.NativeField)
{
// returned structs must be blittable and bool isn't
Context.Return.Write("(byte) ({0} ? 1 : 0)", Context.Parameter.Name);
return true;
}
goto default;
default:
Context.Return.Write(Context.Parameter.Name);
return true;
@@ -612,13 +612,19 @@ where @base.IsClass
private void GenerateClassInternalsField(LayoutField field, Class @class)
{
Declaration decl;
field.QualifiedType.Type.TryGetDeclaration(out decl);
var arrayType = field.QualifiedType.Type.Desugar() as ArrayType;
var coreType = field.QualifiedType.Type.Desugar();
if (arrayType != null && arrayType.SizeType == ArrayType.ArraySize.Constant)
coreType = arrayType.Type.Desugar();
TypePrinterResult retType = TypePrinter.VisitFieldDecl(
new Field { Name = field.Name, QualifiedType = field.QualifiedType });
PushBlock(BlockKind.Field);
if (field.QualifiedType.Type.Desugar().IsPrimitiveType(PrimitiveType.Bool))
WriteLine("[MarshalAs(UnmanagedType.I1)]");
if (!Options.GenerateSequentialLayout || @class.IsUnion)
WriteLine($"[FieldOffset({field.Offset})]");
Write($"internal {retType}{retType.NameSuffix}");
@@ -494,7 +494,10 @@ static string GetIntString(PrimitiveType primitive, ParserTargetInfo targetInfo)
{
switch (primitive)
{
case PrimitiveType.Bool: return "bool";
case PrimitiveType.Bool:
// returned structs must be blittable and bool isn't
return MarshalKind == MarshalKind.NativeField ?
"byte" : "bool";
case PrimitiveType.Void: return "void";
case PrimitiveType.Char16:
case PrimitiveType.Char32:

0 comments on commit 54f3af1

Please sign in to comment.