Skip to content

Commit 2d608db

Browse files
committed
Extract NAPI VarPrefix and ArgumentPrefix to base class.
1 parent e447a54 commit 2d608db

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/Generator/Generators/Marshal.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public MarshalContext(BindingContext context, uint indentation)
1212
Cleanup = new TextGenerator { CurrentIndentation = indentation };
1313
VarPrefix = new TextGenerator();
1414
ArgumentPrefix = new TextGenerator();
15-
this.Indentation = indentation;
15+
Indentation = indentation;
1616
}
1717

1818
public BindingContext Context { get; }
@@ -22,8 +22,8 @@ public MarshalContext(BindingContext context, uint indentation)
2222
public TextGenerator Before { get; }
2323
public TextGenerator Return { get; }
2424
public TextGenerator Cleanup { get; }
25-
public TextGenerator VarPrefix;
26-
public TextGenerator ArgumentPrefix;
25+
public TextGenerator VarPrefix { get; }
26+
public TextGenerator ArgumentPrefix { get; }
2727

2828
public string ReturnVarName { get; set; }
2929
public QualifiedType ReturnType { get; set; }

src/Generator/Generators/NAPI/NAPIMarshal.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,9 @@ public override bool VisitFunctionTemplateDecl(FunctionTemplate template)
337337

338338
public class NAPIMarshalManagedToNativePrinter : MarshalPrinter<MarshalContext>
339339
{
340-
public readonly TextGenerator VarPrefix;
341-
public readonly TextGenerator ArgumentPrefix;
342-
343340
public NAPIMarshalManagedToNativePrinter(MarshalContext ctx)
344341
: base(ctx)
345342
{
346-
VarPrefix = new TextGenerator();
347-
ArgumentPrefix = new TextGenerator();
348-
349343
Context.MarshalToNative = this;
350344
}
351345

@@ -421,7 +415,7 @@ public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
421415
var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
422416
Context.Parameter.Usage == ParameterUsage.InOut;
423417

424-
ArgumentPrefix.Write("&");
418+
Context.ArgumentPrefix.Write("&");
425419
Context.Return.Write($"(::{@enum.QualifiedOriginalName}){0}{Context.Parameter.Name}",
426420
isRef ? string.Empty : "*");
427421
return true;
@@ -707,7 +701,7 @@ private void MarshalRefClass(Class @class)
707701
var deref = isPointer ? "" : "*";
708702

709703
if (!isPointer && Context.Parameter.Type.IsReference())
710-
VarPrefix.Write("&");
704+
Context.VarPrefix.Write("&");
711705

712706
Context.Return.Write($"{deref}{instance}");
713707
}

src/Generator/Generators/NAPI/NAPISources.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,9 @@ public virtual ParamMarshal GenerateFunctionParamMarshal(Parameter param, int pa
861861
NeedNewLine();
862862
}
863863

864-
WriteLine($"auto {marshal.VarPrefix}{argName} = {marshal.Context.Return};");
865-
paramMarshal.Prefix = marshal.ArgumentPrefix;
866864
NewLineIfNeeded();
865+
WriteLine($"auto {marshal.Context.VarPrefix}{argName} = {marshal.Context.Return};");
866+
paramMarshal.Prefix = marshal.Context.ArgumentPrefix;
867867
}
868868

869869
paramMarshal.Name = argName;

0 commit comments

Comments
 (0)