Browse Source

Fixed code generation for enum pointers as parameters.

Fixes issue #217.
pull/226/merge
triton 11 years ago
parent
commit
d68b7b3b56
  1. 15
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 11
      src/Generator/Generators/CLI/CLITypePrinter.cs
  3. 6
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  4. 8
      tests/Basic/Basic.Tests.cs
  5. 13
      tests/Basic/Basic.h

15
src/Generator/Generators/CLI/CLIMarshal.cs

@ -419,11 +419,20 @@ namespace CppSharp.Generators.CLI
var cppTypeName = pointer.Visit(cppTypePrinter, quals); var cppTypeName = pointer.Visit(cppTypePrinter, quals);
return VisitDelegateType(function, cppTypeName); return VisitDelegateType(function, cppTypeName);
}
Enumeration @enum;
if (pointee.IsTagDecl(out @enum))
{
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0})*{1}", @enum.QualifiedOriginalName,
Context.Parameter.Name);
return true;
} }
Class @class; Class @class;
if (pointee.IsTagDecl(out @class) && @class.IsValueType) if (pointee.IsTagDecl(out @class) && @class.IsValueType)
{ {
if (Context.Function == null) if (Context.Function == null)
Context.Return.Write("&"); Context.Return.Write("&");
return pointee.Visit(this, quals); return pointee.Visit(this, quals);

11
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -129,7 +129,7 @@ namespace CppSharp.Generators.CLI
public string VisitPointerType(PointerType pointer, TypeQualifiers quals) public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{ {
var pointee = pointer.Pointee; var pointee = pointer.Pointee.Desugar();
if (pointee is FunctionType) if (pointee is FunctionType)
{ {
@ -143,7 +143,7 @@ namespace CppSharp.Generators.CLI
} }
PrimitiveType primitive; PrimitiveType primitive;
if (pointee.Desugar().IsPrimitiveType(out primitive)) if (pointee.IsPrimitiveType(out primitive))
{ {
var param = Context.Parameter; var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut)) if (param != null && (param.IsOut || param.IsInOut))
@ -152,6 +152,13 @@ namespace CppSharp.Generators.CLI
return VisitPrimitiveType(primitive, quals) + "*"; return VisitPrimitiveType(primitive, quals) + "*";
} }
Enumeration @enum;
if (pointee.IsTagDecl(out @enum))
{
var typeName = @enum.Visit(this);
return string.Format("{0}*", typeName);
}
return pointee.Visit(this, quals); return pointee.Visit(this, quals);
} }

6
src/Generator/Generators/CSharp/CSharpTypePrinter.cs

@ -222,6 +222,12 @@ namespace CppSharp.Generators.CSharp
return VisitPrimitiveType(primitive, quals) + "*"; return VisitPrimitiveType(primitive, quals) + "*";
} }
Enumeration @enum;
if (desugared.IsTagDecl(out @enum))
{
return @enum.Name + "*";
}
Class @class; Class @class;
if ((desugared.IsDependent || desugared.IsTagDecl(out @class)) if ((desugared.IsDependent || desugared.IsTagDecl(out @class))
&& ContextKind == CSharpTypePrinterContextKind.Native) && ContextKind == CSharpTypePrinterContextKind.Native)

8
tests/Basic/Basic.Tests.cs

@ -257,5 +257,13 @@ public class BasicTests : GeneratorTestFixture
prop.FieldValue = 10; prop.FieldValue = 10;
Assert.That(prop.FieldValue, Is.EqualTo(10)); Assert.That(prop.FieldValue, Is.EqualTo(10));
} }
[Test]
public unsafe void TestArraysPointers()
{
var values = MyEnum.A;
var arrays = new TestArraysPointers(&values, 1);
Assert.That(arrays.Value, Is.EqualTo(MyEnum.A));
}
} }

13
tests/Basic/Basic.h

@ -350,3 +350,16 @@ struct DLL_API TestProperties
int getFieldValue() { return Field; } int getFieldValue() { return Field; }
void setFieldValue(int Value) { Field = Value; } void setFieldValue(int Value) { Field = Value; }
}; };
enum struct MyEnum { A, B, C };
class DLL_API TestArraysPointers
{
public:
TestArraysPointers(MyEnum *values, int count)
{
if (values && count) Value = values[0];
}
MyEnum Value;
};
Loading…
Cancel
Save