Skip to content

Commit

Permalink
Generate valid C# for parameters typedef-ed to mapped types
Browse files Browse the repository at this point in the history
Fixes #1256.

Signed-off-by: Dimitar Dobrev <[email protected]>
  • Loading branch information
ddobrev committed Apr 15, 2020
1 parent c7de364 commit 64b1efd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Generator/Generators/CSharp/CSharpTypePrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion tests/Common/Common.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
8 changes: 7 additions & 1 deletion tests/Common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Expand Down Expand Up @@ -1196,4 +1202,4 @@ TestFixedNonPrimitiveArrays::TestFixedNonPrimitiveArrays()
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet)
{
(*(*lp)).val = valToSet;
}
}
4 changes: 3 additions & 1 deletion tests/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1603,4 +1605,4 @@ struct DLL_API PointerToTypedefPointerTest
};
typedef PointerToTypedefPointerTest *LPPointerToTypedefPointerTest;

void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);
void DLL_API PointerToTypedefPointerTestMethod(LPPointerToTypedefPointerTest* lp, int valToSet);

0 comments on commit 64b1efd

Please sign in to comment.