Browse Source

Extract NAPI VarPrefix and ArgumentPrefix to base class.

pull/1557/head
Joao Matos 4 years ago committed by João Matos
parent
commit
2d608dbe48
  1. 6
      src/Generator/Generators/Marshal.cs
  2. 10
      src/Generator/Generators/NAPI/NAPIMarshal.cs
  3. 4
      src/Generator/Generators/NAPI/NAPISources.cs

6
src/Generator/Generators/Marshal.cs

@ -12,7 +12,7 @@ namespace CppSharp.Generators @@ -12,7 +12,7 @@ namespace CppSharp.Generators
Cleanup = new TextGenerator { CurrentIndentation = indentation };
VarPrefix = new TextGenerator();
ArgumentPrefix = new TextGenerator();
this.Indentation = indentation;
Indentation = indentation;
}
public BindingContext Context { get; }
@ -22,8 +22,8 @@ namespace CppSharp.Generators @@ -22,8 +22,8 @@ namespace CppSharp.Generators
public TextGenerator Before { get; }
public TextGenerator Return { get; }
public TextGenerator Cleanup { get; }
public TextGenerator VarPrefix;
public TextGenerator ArgumentPrefix;
public TextGenerator VarPrefix { get; }
public TextGenerator ArgumentPrefix { get; }
public string ReturnVarName { get; set; }
public QualifiedType ReturnType { get; set; }

10
src/Generator/Generators/NAPI/NAPIMarshal.cs

@ -337,15 +337,9 @@ namespace CppSharp.Generators.NAPI @@ -337,15 +337,9 @@ namespace CppSharp.Generators.NAPI
public class NAPIMarshalManagedToNativePrinter : MarshalPrinter<MarshalContext>
{
public readonly TextGenerator VarPrefix;
public readonly TextGenerator ArgumentPrefix;
public NAPIMarshalManagedToNativePrinter(MarshalContext ctx)
: base(ctx)
{
VarPrefix = new TextGenerator();
ArgumentPrefix = new TextGenerator();
Context.MarshalToNative = this;
}
@ -421,7 +415,7 @@ namespace CppSharp.Generators.NAPI @@ -421,7 +415,7 @@ namespace CppSharp.Generators.NAPI
var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
Context.Parameter.Usage == ParameterUsage.InOut;
ArgumentPrefix.Write("&");
Context.ArgumentPrefix.Write("&");
Context.Return.Write($"(::{@enum.QualifiedOriginalName}){0}{Context.Parameter.Name}",
isRef ? string.Empty : "*");
return true;
@ -707,7 +701,7 @@ namespace CppSharp.Generators.NAPI @@ -707,7 +701,7 @@ namespace CppSharp.Generators.NAPI
var deref = isPointer ? "" : "*";
if (!isPointer && Context.Parameter.Type.IsReference())
VarPrefix.Write("&");
Context.VarPrefix.Write("&");
Context.Return.Write($"{deref}{instance}");
}

4
src/Generator/Generators/NAPI/NAPISources.cs

@ -861,9 +861,9 @@ namespace CppSharp.Generators.Cpp @@ -861,9 +861,9 @@ namespace CppSharp.Generators.Cpp
NeedNewLine();
}
WriteLine($"auto {marshal.VarPrefix}{argName} = {marshal.Context.Return};");
paramMarshal.Prefix = marshal.ArgumentPrefix;
NewLineIfNeeded();
WriteLine($"auto {marshal.Context.VarPrefix}{argName} = {marshal.Context.Return};");
paramMarshal.Prefix = marshal.Context.ArgumentPrefix;
}
paramMarshal.Name = argName;

Loading…
Cancel
Save