Browse Source

Fixed CLI generation with references to pointers types (added a test).

pull/147/head
triton 12 years ago
parent
commit
819df6a2a2
  1. 15
      src/AST/Type.cs
  2. 2
      src/Generator/Generators/CLI/CLIMarshal.cs
  3. 1
      tests/Basic/Basic.Tests.cs
  4. 5
      tests/Basic/Basic.cpp
  5. 1
      tests/Basic/Basic.h

15
src/AST/Type.cs

@ -152,6 +152,21 @@ namespace CppSharp.AST
return this; return this;
} }
public Type SkipPointerRefs()
{
var type = this as PointerType;
if (type != null)
{
var pointee = type.Pointee;
if (type.IsReference())
return pointee.Desugar().SkipPointerRefs();
}
return this;
}
public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals public abstract T Visit<T>(ITypeVisitor<T> visitor, TypeQualifiers quals
= new TypeQualifiers()); = new TypeQualifiers());

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

@ -575,7 +575,7 @@ namespace CppSharp.Generators.CLI
return; return;
} }
if (!Context.Parameter.Type.IsPointer()) if (!Context.Parameter.Type.SkipPointerRefs().IsPointer())
{ {
Context.Return.Write("*"); Context.Return.Write("*");

1
tests/Basic/Basic.Tests.cs

@ -19,6 +19,7 @@ public class BasicTests : GeneratorTestFixture
var foo = new Foo { A = 4, B = 7 }; var foo = new Foo { A = 4, B = 7 };
Assert.That(hello.AddFoo(foo), Is.EqualTo(11)); Assert.That(hello.AddFoo(foo), Is.EqualTo(11));
Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11)); Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11));
Assert.That(hello.AddFooPtr(foo), Is.EqualTo(11));
Assert.That(hello.AddFooRef(foo), Is.EqualTo(11)); Assert.That(hello.AddFooRef(foo), Is.EqualTo(11));
var bar = new Bar { A = 4, B = 7 }; var bar = new Bar { A = 4, B = 7 };

5
tests/Basic/Basic.cpp

@ -107,6 +107,11 @@ int Hello::AddFooPtr(Foo* foo)
return AddFoo(*foo); return AddFoo(*foo);
} }
int Hello::AddFooPtrRef(Foo*& foo)
{
return AddFoo(*foo);
}
int Hello::AddFoo2(Foo2 foo) int Hello::AddFoo2(Foo2 foo)
{ {
return (int)(foo.A + foo.B + foo.C); return (int)(foo.A + foo.B + foo.C);

1
tests/Basic/Basic.h

@ -103,6 +103,7 @@ public:
int AddFoo(Foo); int AddFoo(Foo);
int AddFooRef(Foo&); int AddFooRef(Foo&);
int AddFooPtr(Foo*); int AddFooPtr(Foo*);
int AddFooPtrRef(Foo*&);
Foo RetFoo(int a, float b); Foo RetFoo(int a, float b);
int AddFoo2(Foo2); int AddFoo2(Foo2);

Loading…
Cancel
Save