Skip to content

Commit 64b1efd

Browse files
committed
Generate valid C# for parameters typedef-ed to mapped types
Fixes #1256. Signed-off-by: Dimitar Dobrev <[email protected]>
1 parent c7de364 commit 64b1efd

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/Generator/Generators/CSharp/CSharpTypePrinter.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ public override TypePrinterResult VisitTypedefType(TypedefType typedef,
252252
{
253253
Kind = ContextKind,
254254
MarshalKind = MarshalKind,
255-
Type = typedef
255+
Type = typedef,
256+
Parameter = Parameter
256257
};
257258

258259
return typeMap.CSharpSignatureType(typePrinterContext).ToString();

tests/Common/Common.Tests.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public unsafe void TestCodeGeneration()
1919
Assert.That(changedAccessOfInheritedProperty.Property, Is.EqualTo(2));
2020
}
2121
Foo.NestedAbstract a;
22-
var renamedEmptyEnum = Foo.RenamedEmptyEnum.EmptyEnum1;
22+
Foo.RenamedEmptyEnum.EmptyEnum1.GetHashCode();
2323
using (var foo = new Foo())
2424
{
2525
Bar bar = foo;
@@ -1084,4 +1084,11 @@ public void TestPointerToTypedefPointerTestMethod()
10841084
Assert.AreEqual(100, lp.Val);
10851085
}
10861086
}
1087+
1088+
[Test]
1089+
public void TestTakeTypedefedMappedType()
1090+
{
1091+
const string @string = "string";
1092+
Assert.That(Common.TakeTypedefedMappedType(@string), Is.EqualTo(@string));
1093+
}
10871094
}

tests/Common/Common.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,12 @@ const char* takeReturnUTF8(const char* utf8)
11681168
return UTF8.data();
11691169
}
11701170

1171+
LPCSTR TakeTypedefedMappedType(LPCSTR string)
1172+
{
1173+
UTF8 = string;
1174+
return UTF8.data();
1175+
}
1176+
11711177
StructWithCopyCtor::StructWithCopyCtor() {}
11721178
StructWithCopyCtor::StructWithCopyCtor(const StructWithCopyCtor& other) : mBits(other.mBits) {}
11731179

@@ -1196,4 +1202,4 @@ TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
11961202
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
11971203
{
11981204
(*(*lp)).val = valToSet;
1199-
}
1205+
}

tests/Common/Common.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,8 @@ DLL_API void takeVoidStarStar(void** p);
15411541
DLL_API void overloadPointer(void* p, int i = 0);
15421542
DLL_API void overloadPointer(const void* p, int i = 0);
15431543
DLL_API const char* takeReturnUTF8(const char* utf8);
1544+
typedef const char* LPCSTR;
1545+
DLL_API LPCSTR TakeTypedefedMappedType(LPCSTR string);
15441546
DLL_API std::string UTF8;
15451547

15461548
struct DLL_API StructWithCopyCtor
@@ -1603,4 +1605,4 @@ struct DLL_API PointerToTypedefPointerTest
16031605
};
16041606
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;
16051607

1606-
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);
1608+
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);

0 commit comments

Comments
 (0)