Browse Source

Fixed code generation for enum pointers as parameters.

Fixes issue #217.
pull/226/merge
triton 11 years ago
parent
commit
d68b7b3b56
  1. 9
      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

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

@ -421,6 +421,15 @@ namespace CppSharp.Generators.CLI @@ -421,6 +421,15 @@ namespace CppSharp.Generators.CLI
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;
if (pointee.IsTagDecl(out @class) && @class.IsValueType)
{

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

@ -129,7 +129,7 @@ namespace CppSharp.Generators.CLI @@ -129,7 +129,7 @@ namespace CppSharp.Generators.CLI
public string VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
var pointee = pointer.Pointee;
var pointee = pointer.Pointee.Desugar();
if (pointee is FunctionType)
{
@ -143,7 +143,7 @@ namespace CppSharp.Generators.CLI @@ -143,7 +143,7 @@ namespace CppSharp.Generators.CLI
}
PrimitiveType primitive;
if (pointee.Desugar().IsPrimitiveType(out primitive))
if (pointee.IsPrimitiveType(out primitive))
{
var param = Context.Parameter;
if (param != null && (param.IsOut || param.IsInOut))
@ -152,6 +152,13 @@ namespace CppSharp.Generators.CLI @@ -152,6 +152,13 @@ namespace CppSharp.Generators.CLI
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);
}

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

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

8
tests/Basic/Basic.Tests.cs

@ -257,5 +257,13 @@ public class BasicTests : GeneratorTestFixture @@ -257,5 +257,13 @@ public class BasicTests : GeneratorTestFixture
prop.FieldValue = 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 @@ -350,3 +350,16 @@ struct DLL_API TestProperties
int getFieldValue() { return Field; }
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