Browse Source

Use UnsupportedType description for type name instead of empty string (#1339)

Use UnsupportedType description for type name instead of empty string
pull/1241/merge
Ali Alamiri 5 years ago committed by GitHub
parent
commit
eb838be70f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/Generator/Generators/C/CppTypePrinter.cs
  2. 12
      tests/CLI/CLI.Tests.cs
  3. 17
      tests/CLI/CLI.cpp
  4. 44
      tests/CLI/CLI.cs
  5. 15
      tests/CLI/CLI.h

2
src/Generator/Generators/C/CppTypePrinter.cs

@ -363,7 +363,7 @@ namespace CppSharp.Generators.C @@ -363,7 +363,7 @@ namespace CppSharp.Generators.C
public override TypePrinterResult VisitUnsupportedType(UnsupportedType type,
TypeQualifiers quals)
{
return string.Empty;
return type.Description;
}
public override TypePrinterResult VisitDeclaration(Declaration decl,

12
tests/CLI/CLI.Tests.cs

@ -44,4 +44,16 @@ public class CLITests : GeneratorTestFixture @@ -44,4 +44,16 @@ public class CLITests : GeneratorTestFixture
Assert.AreEqual(ClassWithNestedEnum.NestedEnum.E1, consumer.GetPassedEnum(ClassWithNestedEnum.NestedEnum.E1));
}
}
[Test]
public void TestChangePassedMappedTypeNonConstRefParam()
{
using (TestMappedTypeNonConstRefParamConsumer consumer = new TestMappedTypeNonConstRefParamConsumer())
{
string val = "Initial";
consumer.ChangePassedMappedTypeNonConstRefParam(ref val);
Assert.AreEqual("ChangePassedMappedTypeNonConstRefParam", val);
}
}
}

17
tests/CLI/CLI.cpp

@ -31,3 +31,20 @@ EnumParam TestByRefEnumParam::GetPassedEnumParam(EnumParam & e) @@ -31,3 +31,20 @@ EnumParam TestByRefEnumParam::GetPassedEnumParam(EnumParam & e)
{
return e;
}
TestMappedTypeNonConstRefParam::TestMappedTypeNonConstRefParam(const std::string str)
{
m_str = str;
}
const TestMappedTypeNonConstRefParam & TestMappedTypeNonConstRefParam::operator=(const std::string str)
{
m_str = str;
return *this;
}
void TestMappedTypeNonConstRefParamConsumer::ChangePassedMappedTypeNonConstRefParam(TestMappedTypeNonConstRefParam & v)
{
v = "ChangePassedMappedTypeNonConstRefParam";
}

44
tests/CLI/CLI.cs

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.C;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;
@ -19,6 +21,42 @@ namespace CppSharp.Tests @@ -19,6 +21,42 @@ namespace CppSharp.Tests
}
}
[TypeMap("TestMappedTypeNonConstRefParam")]
public class TestMappedTypeNonConstRefParamTypeMap : TypeMap
{
public override Type CLISignatureType(TypePrinterContext ctx)
{
return new CILType(typeof(string));
}
public override Type CppSignatureType(TypePrinterContext ctx)
{
var tagType = ctx.Type as TagType;
var typePrinter = new CppTypePrinter(Context);
return new CustomType(tagType.Declaration.Visit(typePrinter));
}
public override void CLIMarshalToManaged(MarshalContext ctx)
{
ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0}.m_str)", ctx.ReturnVarName);
}
public override void CLIMarshalToNative(MarshalContext ctx)
{
if (ctx.Parameter.Usage == ParameterUsage.InOut)
{
ctx.Before.WriteLine($"System::String^ _{ctx.Parameter.Name} = {ctx.Parameter.Name};");
}
string paramName = ctx.Parameter.Usage == ParameterUsage.InOut ? $"_{ctx.Parameter.Name}" : ctx.Parameter.Name;
ctx.Before.WriteLine(
$"::TestMappedTypeNonConstRefParam _{ctx.ArgName} = clix::marshalString<clix::E_UTF8>({paramName});");
ctx.Return.Write("_{0}", ctx.ArgName);
}
}
public class CLITestsGenerator : GeneratorTest
{
public CLITestsGenerator(GeneratorKind kind)
@ -33,6 +71,12 @@ namespace CppSharp.Tests @@ -33,6 +71,12 @@ namespace CppSharp.Tests
base.Setup(driver);
}
public override void Preprocess(Driver driver, ASTContext ctx)
{
LibraryHelpers.SetMethodParameterUsage(ctx, "TestMappedTypeNonConstRefParamConsumer",
"ChangePassedMappedTypeNonConstRefParam", 1, ParameterUsage.InOut);
}
public static void Main(string[] args)
{
ConsoleDriver.Run(new CLITestsGenerator(GeneratorKind.CLI));

15
tests/CLI/CLI.h

@ -73,4 +73,19 @@ class DLL_API TestByRefEnumParam @@ -73,4 +73,19 @@ class DLL_API TestByRefEnumParam
{
public:
EnumParam GetPassedEnumParam(EnumParam& e);
};
class DLL_API TestMappedTypeNonConstRefParam
{
public:
TestMappedTypeNonConstRefParam(const std::string);
const TestMappedTypeNonConstRefParam& operator=(const std::string);
std::string m_str;
};
class DLL_API TestMappedTypeNonConstRefParamConsumer
{
public:
void ChangePassedMappedTypeNonConstRefParam(TestMappedTypeNonConstRefParam&);
};
Loading…
Cancel
Save