Browse Source

Generate valid C# for parameters typedef-ed to mapped types

Fixes https://github.com/mono/CppSharp/issues/1256.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1338/head
Dimitar Dobrev 5 years ago
parent
commit
64b1efd1e7
  1. 3
      src/Generator/Generators/CSharp/CSharpTypePrinter.cs
  2. 9
      tests/Common/Common.Tests.cs
  3. 8
      tests/Common/Common.cpp
  4. 4
      tests/Common/Common.h

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

@ -252,7 +252,8 @@ namespace CppSharp.Generators.CSharp
{ {
Kind = ContextKind, Kind = ContextKind,
MarshalKind = MarshalKind, MarshalKind = MarshalKind,
Type = typedef Type = typedef,
Parameter = Parameter
}; };
return typeMap.CSharpSignatureType(typePrinterContext).ToString(); return typeMap.CSharpSignatureType(typePrinterContext).ToString();

9
tests/Common/Common.Tests.cs

@ -19,7 +19,7 @@ public class CommonTests : GeneratorTestFixture
Assert.That(changedAccessOfInheritedProperty.Property, Is.EqualTo(2)); Assert.That(changedAccessOfInheritedProperty.Property, Is.EqualTo(2));
} }
Foo.NestedAbstract a; Foo.NestedAbstract a;
var renamedEmptyEnum = Foo.RenamedEmptyEnum.EmptyEnum1; Foo.RenamedEmptyEnum.EmptyEnum1.GetHashCode();
using (var foo = new Foo()) using (var foo = new Foo())
{ {
Bar bar = foo; Bar bar = foo;
@ -1084,4 +1084,11 @@ This is a very long string. This is a very long string. This is a very long stri
Assert.AreEqual(100, lp.Val); Assert.AreEqual(100, lp.Val);
} }
} }
[Test]
public void TestTakeTypedefedMappedType()
{
const string @string = "string";
Assert.That(Common.TakeTypedefedMappedType(@string), Is.EqualTo(@string));
}
} }

8
tests/Common/Common.cpp

@ -1168,6 +1168,12 @@ const char* takeReturnUTF8(const char* utf8)
return UTF8.data(); return UTF8.data();
} }
LPCSTR TakeTypedefedMappedType(LPCSTR string)
{
UTF8 = string;
return UTF8.data();
}
StructWithCopyCtor::StructWithCopyCtor() {} StructWithCopyCtor::StructWithCopyCtor() {}
StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {} StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {}
@ -1196,4 +1202,4 @@ TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet) void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
{ {
(*(*lp)).val = valToSet; (*(*lp)).val = valToSet;
} }

4
tests/Common/Common.h

@ -1541,6 +1541,8 @@ DLL_API void takeVoidStarStar(void** p);
DLL_API void overloadPointer(void* p, int i = 0); DLL_API void overloadPointer(void* p, int i = 0);
DLL_API void overloadPointer(const void* p, int i = 0); DLL_API void overloadPointer(const void* p, int i = 0);
DLL_API const char* takeReturnUTF8(const char* utf8); DLL_API const char* takeReturnUTF8(const char* utf8);
typedef const char* LPCSTR;
DLL_API LPCSTR TakeTypedefedMappedType(LPCSTR string);
DLL_API std::string UTF8; DLL_API std::string UTF8;
struct DLL_API StructWithCopyCtor struct DLL_API StructWithCopyCtor
@ -1603,4 +1605,4 @@ struct DLL_API PointerToTypedefPointerTest
}; };
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest; typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet); void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);

Loading…
Cancel
Save