Skip to content

Commit

Permalink
CLI.Gen.cs: fix omitted typemap from previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deadlocklogic committed Dec 4, 2023
1 parent 6e0a7be commit a835dbf
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions tests/dotnet/CLI/CLI.Gen.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CppSharp.AST;
using CppSharp.Generators;
using CppSharp.Generators.C;
using CppSharp.Passes;
using CppSharp.Types;
using CppSharp.Utils;

Expand All @@ -21,32 +20,49 @@ public override void MarshalToManaged(MarshalContext ctx, GeneratorKind kind)
}
}

[TypeMap("TestMappedTypeNonConstRefParam", GeneratorKindID = GeneratorKind.CLI_ID)]
public class TestMappedTypeNonConstRefParamTypeMap : TypeMap
namespace CLI
{
public override Type SignatureType(TypePrinterContext ctx, GeneratorKind kind)
{
return new CILType(typeof(string));
}

public override void MarshalToManaged(MarshalContext ctx, GeneratorKind kind)
[TypeMap("TestMappedTypeNonConstRefParam", GeneratorKindID = GeneratorKind.CLI_ID)]
public class TestMappedTypeNonConstRefParamTypeMap : TypeMap
{
ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0}.m_str)", ctx.ReturnVarName);
}
public override Type SignatureType(TypePrinterContext ctx, GeneratorKind kind)
{
return new CILType(typeof(string));
}

public override void MarshalToNative(MarshalContext ctx, GeneratorKind kind)
{
if (ctx.Parameter.Usage == ParameterUsage.InOut)
public override void MarshalToManaged(MarshalContext ctx, GeneratorKind kind)
{
ctx.Before.WriteLine($"System::String^ _{ctx.Parameter.Name} = {ctx.Parameter.Name};");
ctx.Return.Write("clix::marshalString<clix::E_UTF8>({0}.m_str)", ctx.ReturnVarName);
}

string paramName = ctx.Parameter.Usage == ParameterUsage.InOut ? $"_{ctx.Parameter.Name}" : ctx.Parameter.Name;
public override void MarshalToNative(MarshalContext ctx, GeneratorKind kind)
{
if (ctx.Parameter.Usage == ParameterUsage.InOut)
{
ctx.Before.WriteLine($"System::String^ _{ctx.Parameter.Name} = {ctx.Parameter.Name};");
}

ctx.Before.WriteLine(
$"::TestMappedTypeNonConstRefParam _{ctx.ArgName} = clix::marshalString<clix::E_UTF8>({paramName});");
string paramName = ctx.Parameter.Usage == ParameterUsage.InOut ? $"_{ctx.Parameter.Name}" : ctx.Parameter.Name;

ctx.Return.Write("_{0}", ctx.ArgName);
ctx.Before.WriteLine(
$"::TestMappedTypeNonConstRefParam _{ctx.ArgName} = clix::marshalString<clix::E_UTF8>({paramName});");

ctx.Return.Write("_{0}", ctx.ArgName);
}
}
}

namespace Cpp
{
[TypeMap("TestMappedTypeNonConstRefParam", GeneratorKindID = GeneratorKind.CPlusPlus_ID)]
public class TestMappedTypeNonConstRefParamTypeMap : TypeMap
{
public override Type SignatureType(TypePrinterContext ctx, GeneratorKind kind)
{
var tagType = ctx.Type as TagType;
var typePrinter = new CppTypePrinter(Context);
return new CustomType(tagType.Declaration.Visit(typePrinter));
}
}
}

Expand Down

0 comments on commit a835dbf

Please sign in to comment.