From 64b1efd1e7062b059abfeca01c7b0a24d49f7ff7 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Wed, 15 Apr 2020 23:23:07 +0300 Subject: [PATCH] Generate valid C# for parameters typedef-ed to mapped types Fixes https://github.com/mono/CppSharp/issues/1256. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTypePrinter.cs | 3 ++- tests/Common/Common.Tests.cs | 9 ++++++++- tests/Common/Common.cpp | 8 +++++++- tests/Common/Common.h | 4 +++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs index 75554c1e0d..c1e0835d45 100644 --- a/src/Generator/Generators/CSharp/CSharpTypePrinter.cs +++ b/src/Generator/Generators/CSharp/CSharpTypePrinter.cs @@ -252,7 +252,8 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef, { Kind = ContextKind, MarshalKind = MarshalKind, - Type = typedef + Type = typedef, + Parameter = Parameter }; return typeMap.CSharpSignatureType(typePrinterContext).ToString(); diff --git a/tests/Common/Common.Tests.cs b/tests/Common/Common.Tests.cs index 2c79a587b1..5f60e7d5b7 100644 --- a/tests/Common/Common.Tests.cs +++ b/tests/Common/Common.Tests.cs @@ -19,7 +19,7 @@ public unsafe void TestCodeGeneration() Assert.That(changedAccessOfInheritedProperty.Property, Is.EqualTo(2)); } Foo.NestedAbstract a; - var renamedEmptyEnum = Foo.RenamedEmptyEnum.EmptyEnum1; + Foo.RenamedEmptyEnum.EmptyEnum1.GetHashCode(); using (var foo = new Foo()) { Bar bar = foo; @@ -1084,4 +1084,11 @@ public void TestPointerToTypedefPointerTestMethod() Assert.AreEqual(100, lp.Val); } } + + [Test] + public void TestTakeTypedefedMappedType() + { + const string @string = "string"; + Assert.That(Common.TakeTypedefedMappedType(@string), Is.EqualTo(@string)); + } } diff --git a/tests/Common/Common.cpp b/tests/Common/Common.cpp index e84aded254..4de55acfba 100644 --- a/tests/Common/Common.cpp +++ b/tests/Common/Common.cpp @@ -1168,6 +1168,12 @@ const char* takeReturnUTF8(const char* utf8) return UTF8.data(); } +LPCSTR TakeTypedefedMappedType(LPCSTR string) +{ + UTF8 = string; + return UTF8.data(); +} + StructWithCopyCtor::StructWithCopyCtor() {} StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {} @@ -1196,4 +1202,4 @@ TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays() void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet) { (*(*lp)).val = valToSet; -} \ No newline at end of file +} diff --git a/tests/Common/Common.h b/tests/Common/Common.h index c0fe456826..3a2960ec74 100644 --- a/tests/Common/Common.h +++ b/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(const void* p, int i = 0); DLL_API const char* takeReturnUTF8(const char* utf8); +typedef const char* LPCSTR; +DLL_API LPCSTR TakeTypedefedMappedType(LPCSTR string); DLL_API std::string UTF8; struct DLL_API StructWithCopyCtor @@ -1603,4 +1605,4 @@ struct DLL_API PointerToTypedefPointerTest }; typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest; -void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet); \ No newline at end of file +void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);