[binder] Simplify the name for marshaling before/after text generators.

This commit is contained in:
Joao Matos 2017-11-07 12:31:08 +00:00
Родитель 36e32c87bf
Коммит 3c3aa90237
4 изменённых файлов: 40 добавлений и 40 удалений

Просмотреть файл

@ -50,7 +50,7 @@ namespace Embeddinator.Generators
public override bool VisitManagedArrayType(ManagedArrayType array,
TypeQualifiers quals)
{
var support = Context.SupportBefore;
var support = Context.Before;
var arrayId = CGenerator.GenId($"{Context.ArgName}_array");
support.WriteLine("MonoArray* {0} = (MonoArray*) {1};",
@ -115,8 +115,8 @@ namespace Embeddinator.Generators
var marshal = new CMarshalManagedToNative(Options, ctx) { UnboxPrimitiveValues = false };
array.Array.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
support.Write(marshal.Context.SupportBefore.ToString());
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
support.Write(marshal.Context.Before.ToString());
support.WriteLine("g_array_append_val({0}.array, {1});", nativeArrayId,
marshal.Context.Return.ToString());
@ -137,7 +137,7 @@ namespace Embeddinator.Generators
{
var typeName = @class.Visit(CTypePrinter);
var objectId = $"{Context.ArgName}_obj";
Context.SupportBefore.WriteLine("{1}* {0} = {2} ? ({1}*) mono_embeddinator_create_object({2}) : 0;",
Context.Before.WriteLine("{1}* {0} = {2} ? ({1}*) mono_embeddinator_create_object({2}) : 0;",
objectId, typeName, Context.ArgName);
Context.Return.Write("{0}", objectId);
return true;
@ -200,7 +200,7 @@ namespace Embeddinator.Generators
if (UnboxPrimitiveValues)
{
var unboxId = CGenerator.GenId("unbox");
Context.SupportBefore.WriteLine("void* {0} = mono_object_unbox({1});",
Context.Before.WriteLine("void* {0} = mono_object_unbox({1});",
unboxId, Context.ArgName);
valueId = unboxId;
}
@ -211,7 +211,7 @@ namespace Embeddinator.Generators
case PrimitiveType.String:
{
var stringId = CGenerator.GenId("string");
Context.SupportBefore.WriteLine("char* {0} = mono_string_to_utf8(" +
Context.Before.WriteLine("char* {0} = mono_string_to_utf8(" +
"(MonoString*) {1});", stringId, Context.ArgName);
Context.Return.Write("{0}", stringId);
@ -346,7 +346,7 @@ namespace Embeddinator.Generators
public override bool VisitManagedArrayType(ManagedArrayType array,
TypeQualifiers quals)
{
var support = Context.SupportBefore;
var support = Context.Before;
var contextId = CGenerator.GenId("mono_context");
var arrayId = CGenerator.GenId($"{Context.ArgName}_array");
@ -396,8 +396,8 @@ namespace Embeddinator.Generators
var marshal = new CMarshalNativeToManaged (Options, ctx) { PrimitiveValuesByValue = true };
elementType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
support.Write(marshal.Context.SupportBefore.ToString());
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
support.Write(marshal.Context.Before.ToString());
if (isValueType)
{
@ -457,14 +457,14 @@ namespace Embeddinator.Generators
var argId = GenParamId(Context);
var objId = $"{argId}_obj";
Context.SupportBefore.WriteLine($"MonoObject* {objId} = {@object};");
Context.SupportBefore.WriteLine($"MonoObject* {argId} = {objId};");
Context.Before.WriteLine($"MonoObject* {objId} = {@object};");
Context.Before.WriteLine($"MonoObject* {argId} = {objId};");
Context.SupportAfter.WriteLine($"if ({objId} != {argId})");
Context.SupportAfter.WriteStartBraceIndent();
Context.SupportAfter.WriteLine($"mono_embeddinator_destroy_object({arg});");
Context.SupportAfter.WriteLine($"{arg} = ({argId} != 0) ? mono_embeddinator_create_object({argId}) : 0;");
Context.SupportAfter.WriteCloseBraceIndent();
Context.After.WriteLine($"if ({objId} != {argId})");
Context.After.WriteStartBraceIndent();
Context.After.WriteLine($"mono_embeddinator_destroy_object({arg});");
Context.After.WriteLine($"{arg} = ({argId} != 0) ? mono_embeddinator_create_object({argId}) : 0;");
Context.After.WriteCloseBraceIndent();
Context.Return.Write($"&{argId}");
return true;
@ -499,10 +499,10 @@ namespace Embeddinator.Generators
var typePrinter = new CppTypePrinter();
var integerType = typePrinter.VisitPrimitiveType(backingType);
var newArgName = CGenerator.GenId(Context.ArgName);
Context.SupportBefore.WriteLine("{0} {1} = *(({0}*) {2});",
Context.Before.WriteLine("{0} {1} = *(({0}*) {2});",
integerType, newArgName, Context.ArgName);
Context.Return.Write("&{0}", newArgName);
Context.SupportAfter.WriteLine("*{0} = ({1}) {2};", Context.ArgName,
Context.After.WriteLine("*{0} = ({1}) {2};", Context.ArgName,
@enum.Visit(CTypePrinter), newArgName);
}
@ -582,11 +582,11 @@ namespace Embeddinator.Generators
if (IsByRefParameter)
{
@string = $"{Context.ArgName}->str";
Context.SupportAfter.WriteLine("mono_embeddinator_marshal_string_to_gstring({0}, {1});",
Context.After.WriteLine("mono_embeddinator_marshal_string_to_gstring({0}, {1});",
Context.ArgName, argId);
}
Context.SupportBefore.WriteLine("MonoString* {0} = ({2}) ? mono_string_new({1}.domain, {2}) : 0;",
Context.Before.WriteLine("MonoString* {0} = ({2}) ? mono_string_new({1}.domain, {2}) : 0;",
argId, contextId, @string);
Context.Return.Write("{0}{1}", IsByRefParameter ? "&" : string.Empty, argId);
return true;

Просмотреть файл

@ -286,8 +286,8 @@ namespace Embeddinator.Generators
var marshal = new CMarshalNativeToManaged(EmbedOptions, ctx);
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
WriteLine($"{argsId}[{paramIndex++}] = {marshal.Context.Return};");
NeedNewLine();
@ -340,10 +340,10 @@ namespace Embeddinator.Generators
foreach (var marshalContext in contexts)
{
if (!string.IsNullOrWhiteSpace(marshalContext.SupportAfter))
if (!string.IsNullOrWhiteSpace(marshalContext.After))
{
NewLineIfNeeded();
Write(marshalContext.SupportAfter);
Write(marshalContext.After);
}
}
}
@ -385,8 +385,8 @@ namespace Embeddinator.Generators
NewLineIfNeeded();
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
returnCode = marshal.Context.Return.ToString();
}
@ -481,8 +481,8 @@ namespace Embeddinator.Generators
var marshal = new CMarshalManagedToNative(EmbedOptions, ctx);
property.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
WriteLine($"return {marshal.Context.Return.ToString()};");
@ -507,8 +507,8 @@ namespace Embeddinator.Generators
var marshal = new CMarshalNativeToManaged(EmbedOptions, ctx);
property.QualifiedType.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
var valueId = GeneratedIdentifier("value");
WriteLine($"void* {valueId} = {marshal.Context.Return.ToString()};");

Просмотреть файл

@ -369,8 +369,8 @@ namespace Embeddinator.Generators
var marshal = new JavaMarshalManagedToNative(ctx);
param.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
@params.Add(marshal.Context.Return);
}
@ -404,8 +404,8 @@ namespace Embeddinator.Generators
foreach (var marshal in contexts)
{
if (!string.IsNullOrWhiteSpace(marshal.SupportAfter))
Write(marshal.SupportAfter);
if (!string.IsNullOrWhiteSpace(marshal.After))
Write(marshal.After);
}
if (hasReturn)
@ -422,8 +422,8 @@ namespace Embeddinator.Generators
if (marshal.Context.Return.ToString().Length == 0)
throw new System.Exception();
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
if (!string.IsNullOrWhiteSpace(marshal.Context.Before))
Write(marshal.Context.Before);
WriteLine($"return {marshal.Context.Return};");
}

Просмотреть файл

@ -9,8 +9,8 @@ namespace Embeddinator.Generators
public MarshalContext(BindingContext context)
{
Context = context;
SupportBefore = new TextGenerator();
SupportAfter = new TextGenerator ();
Before = new TextGenerator();
After = new TextGenerator ();
Return = new TextGenerator();
MarshalVarPrefix = string.Empty;
}
@ -19,8 +19,8 @@ namespace Embeddinator.Generators
public MarshalPrinter<MarshalContext> MarshalToNative;
public TextGenerator SupportBefore { get; private set; }
public TextGenerator SupportAfter { get; private set; }
public TextGenerator Before { get; private set; }
public TextGenerator After { get; private set; }
public TextGenerator Return { get; private set; }
public Declaration Declaration { get; set; }