Browse Source

By reference enum param fixes (#1321)

Fix generated C++/CLI of pointers to enums

Co-authored-by: Build Agent <admin@sage.com>
pull/1322/head
Ali Alamiri 6 years ago committed by GitHub
parent
commit
d2f5c26da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/Generator/Generators/CLI/CLIMarshal.cs
  2. 7
      src/Generator/Generators/CLI/CLITypePrinter.cs
  3. 9
      tests/CLI/CLI.Tests.cs
  4. 7
      tests/CLI/CLI.cpp
  5. 14
      tests/CLI/CLI.h

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

@ -517,10 +517,15 @@ namespace CppSharp.Generators.CLI @@ -517,10 +517,15 @@ namespace CppSharp.Generators.CLI
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
var isRef = Context.Parameter.Type.IsReference() ||
Context.Parameter.Usage == ParameterUsage.Out ||
Context.Parameter.Usage == ParameterUsage.InOut;
ArgumentPrefix.Write("&");
if(!isRef)
{
ArgumentPrefix.Write("&");
}
Context.Return.Write("(::{0}){1}{2}", @enum.QualifiedOriginalName,
isRef ? string.Empty : "*", Context.Parameter.Name);
return true;

7
src/Generator/Generators/CLI/CLITypePrinter.cs

@ -146,11 +146,12 @@ namespace CppSharp.Generators.CLI @@ -146,11 +146,12 @@ namespace CppSharp.Generators.CLI
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var typeName = @enum.Visit(this);
var typeName = VisitDeclaration(@enum, quals);
// Skip one indirection if passed by reference
if (Parameter != null && (Parameter.IsOut || Parameter.IsInOut)
&& pointee == finalPointee)
if (Parameter != null && (Parameter.Type.IsReference()
|| ((Parameter.IsOut || Parameter.IsInOut)
&& pointee == finalPointee)))
return typeName;
return $"{typeName}*";

9
tests/CLI/CLI.Tests.cs

@ -17,4 +17,13 @@ public class CLITests : GeneratorTestFixture @@ -17,4 +17,13 @@ public class CLITests : GeneratorTestFixture
{
Assert.AreEqual("test_test", new Date(0, 0, 0).TestStdString("test"));
}
[Test]
public void TestByRefEnumParam()
{
using (var byRefEnumParam = new TestByRefEnumParam())
{
Assert.AreEqual(EnumParam.E1, byRefEnumParam.GetPassedEnumParam(EnumParam.E1));
}
}
}

7
tests/CLI/CLI.cpp

@ -25,4 +25,9 @@ IncompleteStruct* createIncompleteStruct() @@ -25,4 +25,9 @@ IncompleteStruct* createIncompleteStruct()
DLL_API void useIncompleteStruct(IncompleteStruct * a)
{
return;
}
}
EnumParam TestByRefEnumParam::GetPassedEnumParam(EnumParam & e)
{
return e;
}

14
tests/CLI/CLI.h

@ -55,4 +55,16 @@ struct CompleteIncompleteStruct; @@ -55,4 +55,16 @@ struct CompleteIncompleteStruct;
typedef struct IncompleteStruct IncompleteStruct;
DLL_API IncompleteStruct* createIncompleteStruct();
DLL_API void useIncompleteStruct(IncompleteStruct* a);
DLL_API void useIncompleteStruct(IncompleteStruct* a);
enum EnumParam
{
E1,
E2
};
class DLL_API TestByRefEnumParam
{
public:
EnumParam GetPassedEnumParam(EnumParam& e);
};
Loading…
Cancel
Save