Browse Source

Renamed members related to indentation for more clarity.

Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>
pull/1129/head
Dimitar Dobrev 7 years ago committed by João Matos
parent
commit
b7d3d36ff1
  1. 4
      src/Core/Diagnostics.cs
  2. 72
      src/Generator/Generators/CLI/CLIHeaders.cs
  3. 14
      src/Generator/Generators/CLI/CLIMarshal.cs
  4. 106
      src/Generator/Generators/CLI/CLISources.cs
  5. 36
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  6. 276
      src/Generator/Generators/CSharp/CSharpSources.cs
  7. 8
      src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs
  8. 10
      src/Generator/Generators/Marshal.cs
  9. 12
      src/Generator/Types/Std/Stdlib.cs
  10. 36
      src/Generator/Utils/BlockGenerator.cs
  11. 36
      src/Generator/Utils/TextGenerator.cs
  12. 4
      src/Generator/Utils/Utils.cs

4
src/Core/Diagnostics.cs

@ -117,8 +117,8 @@ namespace CppSharp @@ -117,8 +117,8 @@ namespace CppSharp
if (info.Kind < Level)
return;
var currentIndent = Indents.Sum();
var message = new string(' ', currentIndent) + info.Message;
var currentIndentation = Indents.Sum();
var message = new string(' ', currentIndentation) + info.Message;
if(info.Kind == DiagnosticKind.Error)
{

72
src/Generator/Generators/CLI/CLIHeaders.cs

@ -194,14 +194,14 @@ namespace CppSharp.Generators.CLI @@ -194,14 +194,14 @@ namespace CppSharp.Generators.CLI
WriteLine("namespace {0}", isTopLevel
? @namespace.TranslationUnit.Module.OutputNamespace
: @namespace.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
GenerateDeclContext(@namespace);
if (generateNamespace)
{
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
}
@ -224,7 +224,7 @@ namespace CppSharp.Generators.CLI @@ -224,7 +224,7 @@ namespace CppSharp.Generators.CLI
WriteLine("public ref class {0}", TranslationUnit.FileNameWithoutExtension);
WriteLine("{");
WriteLine("public:");
PushIndent();
Indent();
// Generate all the function declarations for the module.
foreach (var function in decl.Functions)
@ -232,7 +232,7 @@ namespace CppSharp.Generators.CLI @@ -232,7 +232,7 @@ namespace CppSharp.Generators.CLI
GenerateFunction(function);
}
PopIndent();
Unindent();
WriteLine("};");
PopBlock(NewLineKind.BeforeNextBlock);
@ -259,9 +259,9 @@ namespace CppSharp.Generators.CLI @@ -259,9 +259,9 @@ namespace CppSharp.Generators.CLI
NewLine();
// Process the nested types.
PushIndent();
Indent();
GenerateDeclContext(@class);
PopIndent();
Unindent();
var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName);
@ -308,20 +308,20 @@ namespace CppSharp.Generators.CLI @@ -308,20 +308,20 @@ namespace CppSharp.Generators.CLI
{
WriteLineIndent("property {0} NativePtr;", nativeType);
PushIndent();
Indent();
WriteLine("property System::IntPtr {0}", Helpers.InstanceIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("virtual System::IntPtr get();");
WriteLine("virtual void set(System::IntPtr instance);");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
PopIndent();
Unindent();
}
public void GenerateClassGenericMethods(Class @class)
{
PushIndent();
Indent();
foreach (var template in @class.Templates)
{
if (!template.IsGenerated) continue;
@ -368,7 +368,7 @@ namespace CppSharp.Generators.CLI @@ -368,7 +368,7 @@ namespace CppSharp.Generators.CLI
PopBlock(NewLineKind.BeforeNextBlock);
}
PopIndent();
Unindent();
}
public void GenerateClassConstructors(Class @class, string nativeType)
@ -376,7 +376,7 @@ namespace CppSharp.Generators.CLI @@ -376,7 +376,7 @@ namespace CppSharp.Generators.CLI
if (@class.IsStatic)
return;
PushIndent();
Indent();
// Output a default constructor that takes the native pointer.
WriteLine("{0}({1} native);", @class.Name, nativeType);
@ -407,7 +407,7 @@ namespace CppSharp.Generators.CLI @@ -407,7 +407,7 @@ namespace CppSharp.Generators.CLI
}
}
PopIndent();
Unindent();
}
private void GenerateClassDestructor(Class @class)
@ -436,7 +436,7 @@ namespace CppSharp.Generators.CLI @@ -436,7 +436,7 @@ namespace CppSharp.Generators.CLI
}
}
PushIndent();
Indent();
// check for value types because some of the ignored fields may back properties;
// not the case for ref types because the NativePtr pattern is used there
foreach (var field in @class.Fields.Where(f => !ASTUtils.CheckIgnoreField(f)))
@ -447,7 +447,7 @@ namespace CppSharp.Generators.CLI @@ -447,7 +447,7 @@ namespace CppSharp.Generators.CLI
GenerateField(@class, field);
}
}
PopIndent();
Unindent();
}
private void GenerateField(Class @class, Field field)
@ -473,7 +473,7 @@ namespace CppSharp.Generators.CLI @@ -473,7 +473,7 @@ namespace CppSharp.Generators.CLI
var cppArgs = cppTypePrinter.VisitParameters(@event.Parameters, hasNames: true);
WriteLine("private:");
PushIndent();
Indent();
var delegateName = string.Format("_{0}Delegate", @event.Name);
WriteLine("delegate void {0}({1});", delegateName, cppArgs);
@ -482,12 +482,12 @@ namespace CppSharp.Generators.CLI @@ -482,12 +482,12 @@ namespace CppSharp.Generators.CLI
WriteLine("void _{0}Raise({1});", @event.Name, cppArgs);
WriteLine("{0} _{1};", @event.Type, @event.Name);
PopIndent();
Unindent();
WriteLine("public:");
PushIndent();
Indent();
WriteLine("event {0} {1}", @event.Type, @event.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("void add({0} evt);", @event.Type);
WriteLine("void remove({0} evt);", @event.Type);
@ -496,8 +496,8 @@ namespace CppSharp.Generators.CLI @@ -496,8 +496,8 @@ namespace CppSharp.Generators.CLI
var cliArgs = cliTypePrinter.VisitParameters(@event.Parameters, hasNames: true);
WriteLine("void raise({0});", cliArgs);
WriteCloseBraceIndent();
PopIndent();
UnindentAndWriteCloseBrace();
Unindent();
}
}
@ -506,7 +506,7 @@ namespace CppSharp.Generators.CLI @@ -506,7 +506,7 @@ namespace CppSharp.Generators.CLI
if (methods.Count == 0)
return;
PushIndent();
Indent();
var @class = (Class) methods[0].Namespace;
@ -535,12 +535,12 @@ namespace CppSharp.Generators.CLI @@ -535,12 +535,12 @@ namespace CppSharp.Generators.CLI
foreach(var method in staticMethods)
GenerateMethod(method);
PopIndent();
Unindent();
}
public void GenerateClassVariables(Class @class)
{
PushIndent();
Indent();
foreach(var variable in @class.Variables)
{
@ -555,7 +555,7 @@ namespace CppSharp.Generators.CLI @@ -555,7 +555,7 @@ namespace CppSharp.Generators.CLI
WriteLine("static property {0} {1}", type, variable.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0} get();", type);
@ -564,12 +564,12 @@ namespace CppSharp.Generators.CLI @@ -564,12 +564,12 @@ namespace CppSharp.Generators.CLI
if (!qualifiedType.Qualifiers.IsConst)
WriteLine("void set({0});", type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
PopIndent();
Unindent();
}
public override void GenerateClassSpecifier(Class @class)
@ -612,7 +612,7 @@ namespace CppSharp.Generators.CLI @@ -612,7 +612,7 @@ namespace CppSharp.Generators.CLI
}
}
PushIndent();
Indent();
foreach (var prop in @class.Properties.Where(
prop => !ASTUtils.CheckIgnoreProperty(prop) && !TypeIgnored(prop.Type)))
{
@ -625,7 +625,7 @@ namespace CppSharp.Generators.CLI @@ -625,7 +625,7 @@ namespace CppSharp.Generators.CLI
GenerateDeclarationCommon(prop);
GenerateProperty(prop);
}
PopIndent();
Unindent();
}
public void GenerateIndexer(Property property)
@ -636,7 +636,7 @@ namespace CppSharp.Generators.CLI @@ -636,7 +636,7 @@ namespace CppSharp.Generators.CLI
var indexParameterType = indexParameter.QualifiedType.Visit(TypePrinter);
WriteLine("property {0} default[{1}]", type, indexParameterType);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (property.HasGetter)
WriteLine("{0} get({1} {2});", type, indexParameterType, indexParameter.Name);
@ -644,7 +644,7 @@ namespace CppSharp.Generators.CLI @@ -644,7 +644,7 @@ namespace CppSharp.Generators.CLI
if (property.HasSetter)
WriteLine("void set({1} {2}, {0} value);", type, indexParameterType, indexParameter.Name);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
public void GenerateProperty(Property property)
@ -665,7 +665,7 @@ namespace CppSharp.Generators.CLI @@ -665,7 +665,7 @@ namespace CppSharp.Generators.CLI
else
{
WriteLine("property {0} {1}", type, property.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (property.HasGetter)
WriteLine("{0} get();", type);
@ -673,7 +673,7 @@ namespace CppSharp.Generators.CLI @@ -673,7 +673,7 @@ namespace CppSharp.Generators.CLI
if (property.HasSetter)
WriteLine("void set({0});", type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
PopBlock(NewLineKind.BeforeNextBlock);
@ -835,11 +835,11 @@ namespace CppSharp.Generators.CLI @@ -835,11 +835,11 @@ namespace CppSharp.Generators.CLI
Write(" : {0}", typeName);
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
GenerateEnumItems(@enum);
PopIndent();
Unindent();
WriteLine("};");
PopBlock(NewLineKind.BeforeNextBlock);

14
src/Generator/Generators/CLI/CLIMarshal.cs

@ -47,7 +47,7 @@ namespace CppSharp.Generators.CLI @@ -47,7 +47,7 @@ namespace CppSharp.Generators.CLI
string value = Generator.GeneratedIdentifier("array") + Context.ParameterIndex;
Context.Before.WriteLine("cli::array<{0}>^ {1} = nullptr;", array.Type, value, array.Size);
Context.Before.WriteLine("if ({0} != 0)", Context.ReturnVarName);
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
Context.Before.WriteLine("{0} = gcnew cli::array<{1}>({2});", value, array.Type, array.Size);
Context.Before.WriteLine("for (int i = 0; i < {0}; i++)", array.Size);
if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void))
@ -55,7 +55,7 @@ namespace CppSharp.Generators.CLI @@ -55,7 +55,7 @@ namespace CppSharp.Generators.CLI
value, Context.ReturnVarName);
else
Context.Before.WriteLineIndent("{0}[i] = {1}[i];", value, Context.ReturnVarName);
Context.Before.WriteCloseBraceIndent();
Context.Before.UnindentAndWriteCloseBrace();
Context.Return.Write(value);
break;
case ArrayType.ArraySize.Incomplete:
@ -468,12 +468,12 @@ namespace CppSharp.Generators.CLI @@ -468,12 +468,12 @@ namespace CppSharp.Generators.CLI
{
var supportBefore = Context.Before;
supportBefore.WriteLine("if ({0} != nullptr)", Context.ArgName);
supportBefore.WriteStartBraceIndent();
supportBefore.WriteOpenBraceAndIndent();
supportBefore.WriteLine("for (int i = 0; i < {0}; i++)", array.Size);
supportBefore.WriteLineIndent("{0}[i] = {1}[i]{2};",
Context.ReturnVarName, Context.ArgName,
array.Type.IsPointerToPrimitiveType(PrimitiveType.Void) ? ".ToPointer()" : string.Empty);
supportBefore.WriteCloseBraceIndent();
supportBefore.UnindentAndWriteCloseBrace();
}
break;
default:
@ -775,7 +775,7 @@ namespace CppSharp.Generators.CLI @@ -775,7 +775,7 @@ namespace CppSharp.Generators.CLI
var fieldRef = string.Format("{0}.{1}", Context.Parameter.Name,
property.Name);
var marshalCtx = new MarshalContext(Context.Context, Context.Indent)
var marshalCtx = new MarshalContext(Context.Context, Context.Indentation)
{
ArgName = fieldRef,
ParameterIndex = Context.ParameterIndex++,
@ -799,14 +799,14 @@ namespace CppSharp.Generators.CLI @@ -799,14 +799,14 @@ namespace CppSharp.Generators.CLI
if (isRef)
{
Context.Before.WriteLine("if ({0} != nullptr)", fieldRef);
Context.Before.PushIndent();
Context.Before.Indent();
}
Context.Before.WriteLine("{0}.{1} = {2};", marshalVar,
property.Field.OriginalName, marshal.Context.Return);
if (isRef)
Context.Before.PopIndent();
Context.Before.Unindent();
}
public override bool VisitFieldDecl(Field field)

106
src/Generator/Generators/CLI/CLISources.cs

@ -140,18 +140,18 @@ namespace CppSharp.Generators.CLI @@ -140,18 +140,18 @@ namespace CppSharp.Generators.CLI
PushBlock(BlockKind.Method);
WriteLine("System::IntPtr {0}::{1}::get()",
qualifiedIdentifier, Helpers.InstanceIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("return System::IntPtr(NativePtr);");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(BlockKind.Method);
WriteLine("void {0}::{1}::set(System::IntPtr object)",
qualifiedIdentifier, Helpers.InstanceIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName);
WriteLine("NativePtr = ({0})object.ToPointer();", nativeType);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -247,7 +247,7 @@ namespace CppSharp.Generators.CLI @@ -247,7 +247,7 @@ namespace CppSharp.Generators.CLI
PushBlock(BlockKind.Destructor);
WriteLine("{0}::~{1}()", QualifiedIdentifier(@class), @class.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (CLIGenerator.ShouldGenerateClassNativeField(@class))
{
@ -256,14 +256,14 @@ namespace CppSharp.Generators.CLI @@ -256,14 +256,14 @@ namespace CppSharp.Generators.CLI
else if (@class.HasNonTrivialDestructor)
{
WriteLine("if (NativePtr)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("auto __nativePtr = NativePtr;");
WriteLine("NativePtr = 0;");
WriteLine("delete (::{0}*) __nativePtr;", @class.QualifiedOriginalName);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -273,12 +273,12 @@ namespace CppSharp.Generators.CLI @@ -273,12 +273,12 @@ namespace CppSharp.Generators.CLI
PushBlock(BlockKind.Finalizer);
WriteLine("{0}::!{1}()", QualifiedIdentifier(@class), @class.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (CLIGenerator.ShouldGenerateClassNativeField(@class))
WriteLine("delete NativePtr;");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -307,12 +307,12 @@ namespace CppSharp.Generators.CLI @@ -307,12 +307,12 @@ namespace CppSharp.Generators.CLI
QualifiedIdentifier(function.Namespace), function.Name,
GenerateParametersList(function.Parameters));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var @class = function.Namespace as Class;
GenerateFunctionCall(function, @class);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
PopBlock(NewLineKind.BeforeNextBlock);
@ -367,7 +367,7 @@ namespace CppSharp.Generators.CLI @@ -367,7 +367,7 @@ namespace CppSharp.Generators.CLI
WriteLine("void {0}::{1}::set({2})", QualifiedIdentifier(@class),
name, string.Join(", ", args));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (decl is Function && !isIndexer)
{
@ -380,7 +380,7 @@ namespace CppSharp.Generators.CLI @@ -380,7 +380,7 @@ namespace CppSharp.Generators.CLI
if (@class.IsValueType && decl is Field)
{
WriteLine("{0} = value;", decl.Name);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
return;
}
@ -396,7 +396,7 @@ namespace CppSharp.Generators.CLI @@ -396,7 +396,7 @@ namespace CppSharp.Generators.CLI
else
variable = $"((::{@class.QualifiedOriginalName}*)NativePtr)->{decl.OriginalName}";
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
Parameter = param,
ArgName = param.Name,
@ -408,7 +408,7 @@ namespace CppSharp.Generators.CLI @@ -408,7 +408,7 @@ namespace CppSharp.Generators.CLI
if (isIndexer)
{
var ctx2 = new MarshalContext(Context, CurrentIndent)
var ctx2 = new MarshalContext(Context, CurrentIndentation)
{
Parameter = indexParameter,
ArgName = indexParameter.Name
@ -432,7 +432,7 @@ namespace CppSharp.Generators.CLI @@ -432,7 +432,7 @@ namespace CppSharp.Generators.CLI
}
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
}
@ -456,7 +456,7 @@ namespace CppSharp.Generators.CLI @@ -456,7 +456,7 @@ namespace CppSharp.Generators.CLI
WriteLine("{0} {1}::{2}::get({3})", type, QualifiedIdentifier(@class),
name, string.Join(", ", args));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (decl is Function)
{
@ -471,7 +471,7 @@ namespace CppSharp.Generators.CLI @@ -471,7 +471,7 @@ namespace CppSharp.Generators.CLI
if (@class.IsValueType && decl is Field)
{
WriteLine("return {0};", decl.Name);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
return;
}
@ -483,7 +483,7 @@ namespace CppSharp.Generators.CLI @@ -483,7 +483,7 @@ namespace CppSharp.Generators.CLI
variable = string.Format("((::{0}*)NativePtr)->{1}",
@class.QualifiedOriginalName, decl.OriginalName);
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
Declaration = decl,
ArgName = decl.Name,
@ -501,7 +501,7 @@ namespace CppSharp.Generators.CLI @@ -501,7 +501,7 @@ namespace CppSharp.Generators.CLI
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
}
@ -524,12 +524,12 @@ namespace CppSharp.Generators.CLI @@ -524,12 +524,12 @@ namespace CppSharp.Generators.CLI
{
WriteLine("void {0}::{1}::add({2} evt)", QualifiedIdentifier(@class),
@event.Name, @event.Type);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var delegateName = string.Format("_{0}Delegate", @event.Name);
WriteLine("if (!{0}Instance)", delegateName);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var typePrinter = new CppTypePrinter();
var args = typePrinter.VisitParameters(@event.Parameters, hasNames: false);
@ -543,24 +543,24 @@ namespace CppSharp.Generators.CLI @@ -543,24 +543,24 @@ namespace CppSharp.Generators.CLI
WriteLine("((::{0}*)NativePtr)->{1}.Connect(_fptr);", @class.QualifiedOriginalName,
@event.OriginalName);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteLine("_{0} = static_cast<{1}>(System::Delegate::Combine(_{0}, evt));",
@event.Name, @event.Type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateEventRemove(Event @event, Class @class)
{
WriteLine("void {0}::{1}::remove({2} evt)", QualifiedIdentifier(@class),
@event.Name, @event.Type);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("_{0} = static_cast<{1}>(System::Delegate::Remove(_{0}, evt));",
@event.Name, @event.Type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateEventRaise(Event @event, Class @class)
@ -571,12 +571,12 @@ namespace CppSharp.Generators.CLI @@ -571,12 +571,12 @@ namespace CppSharp.Generators.CLI
WriteLine("void {0}::{1}::raise({2})", QualifiedIdentifier(@class),
@event.Name, args);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var paramNames = @event.Parameters.Select(param => param.Name).ToList();
WriteLine("_{0}({1});", @event.Name, string.Join(", ", paramNames));
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateEventRaiseWrapper(Event @event, Class @class)
@ -587,12 +587,12 @@ namespace CppSharp.Generators.CLI @@ -587,12 +587,12 @@ namespace CppSharp.Generators.CLI
WriteLine("void {0}::_{1}Raise({2})", QualifiedIdentifier(@class),
@event.Name, args);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var returns = new List<string>();
foreach (var param in @event.Parameters)
{
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ReturnVarName = param.Name,
ReturnType = param.QualifiedType
@ -608,7 +608,7 @@ namespace CppSharp.Generators.CLI @@ -608,7 +608,7 @@ namespace CppSharp.Generators.CLI
Write("{0}", string.Join(", ", returns));
WriteLine(");");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateVariable(Variable variable, Class @class)
@ -634,14 +634,14 @@ namespace CppSharp.Generators.CLI @@ -634,14 +634,14 @@ namespace CppSharp.Generators.CLI
if (CLIGenerator.ShouldGenerateClassNativeField(@class))
{
PushIndent();
Indent();
Write(hasBase ? "," : ":");
PopIndent();
Unindent();
WriteLine(" {0}(false)", Helpers.OwnsNativeInstanceIdentifier);
}
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
const string nativePtr = "native";
@ -657,15 +657,15 @@ namespace CppSharp.Generators.CLI @@ -657,15 +657,15 @@ namespace CppSharp.Generators.CLI
GenerateStructMarshaling(@class, nativePtr + "->");
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
WriteLine("{0}^ {0}::{1}(::System::IntPtr native)", qualifiedIdentifier, Helpers.CreateInstanceIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("return gcnew ::{0}(({1}) native.ToPointer());", qualifiedIdentifier, nativeType);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
}
@ -686,7 +686,7 @@ namespace CppSharp.Generators.CLI @@ -686,7 +686,7 @@ namespace CppSharp.Generators.CLI
var nativeField = string.Format("{0}{1}",
nativeVar, property.Field.OriginalName);
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ArgName = property.Name,
ReturnVarName = nativeField,
@ -713,7 +713,7 @@ namespace CppSharp.Generators.CLI @@ -713,7 +713,7 @@ namespace CppSharp.Generators.CLI
if (!@class.IsValueType)
{
PushIndent();
Indent();
var baseClass = @class.Bases[0].Class;
Write(": {0}(", QualifiedIdentifier(baseClass));
@ -726,7 +726,7 @@ namespace CppSharp.Generators.CLI @@ -726,7 +726,7 @@ namespace CppSharp.Generators.CLI
WriteLine("{0})", method != null ? "nullptr" : "native");
PopIndent();
Unindent();
}
return true;
@ -753,7 +753,7 @@ namespace CppSharp.Generators.CLI @@ -753,7 +753,7 @@ namespace CppSharp.Generators.CLI
if (method.IsConstructor)
GenerateClassConstructorBase(@class, method: method);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
PushBlock(BlockKind.MethodBody, method);
@ -792,7 +792,7 @@ namespace CppSharp.Generators.CLI @@ -792,7 +792,7 @@ namespace CppSharp.Generators.CLI
PopBlock();
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
if (method.OperatorKind == CXXOperatorKind.EqualEqual)
{
@ -814,7 +814,7 @@ namespace CppSharp.Generators.CLI @@ -814,7 +814,7 @@ namespace CppSharp.Generators.CLI
NewLine();
var qualifiedIdentifier = QualifiedIdentifier(@class);
WriteLine("bool {0}::Equals(::System::Object^ obj)", qualifiedIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (@class.IsRefType)
{
WriteLine("return this == safe_cast<{0}^>(obj);", qualifiedIdentifier);
@ -823,7 +823,7 @@ namespace CppSharp.Generators.CLI @@ -823,7 +823,7 @@ namespace CppSharp.Generators.CLI
{
WriteLine("return *this == safe_cast<{0}>(obj);", qualifiedIdentifier);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
}
@ -834,7 +834,7 @@ namespace CppSharp.Generators.CLI @@ -834,7 +834,7 @@ namespace CppSharp.Generators.CLI
var paramIndex = 0;
foreach (var param in method.Parameters)
{
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
Function = method,
Parameter = param,
@ -870,7 +870,7 @@ namespace CppSharp.Generators.CLI @@ -870,7 +870,7 @@ namespace CppSharp.Generators.CLI
var varName = string.Format("_native.{0}", property.Field.OriginalName);
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ReturnVarName = varName,
ReturnType = property.QualifiedType
@ -908,11 +908,11 @@ namespace CppSharp.Generators.CLI @@ -908,11 +908,11 @@ namespace CppSharp.Generators.CLI
}
WriteLine(")");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
GenerateFunctionCall(function);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
public void GenerateFunctionCall(Function function, Class @class = null, Type publicRetType = null)
@ -946,7 +946,7 @@ namespace CppSharp.Generators.CLI @@ -946,7 +946,7 @@ namespace CppSharp.Generators.CLI
WriteLine("auto {0} = ::{1}();", valueMarshalName, @class.QualifiedOriginalName);
var param = new Parameter { Name = "(*this)" , Namespace = function.Namespace };
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
MarshalVarPrefix = valueMarshalName,
Parameter = param
@ -1021,7 +1021,7 @@ namespace CppSharp.Generators.CLI @@ -1021,7 +1021,7 @@ namespace CppSharp.Generators.CLI
var nativeVarName = paramInfo.Name;
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ArgName = nativeVarName,
ReturnVarName = nativeVarName,
@ -1054,7 +1054,7 @@ namespace CppSharp.Generators.CLI @@ -1054,7 +1054,7 @@ namespace CppSharp.Generators.CLI
isIntPtr ? "System::IntPtr()" : "nullptr");
}
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
ArgName = returnIdentifier,
ReturnVarName = returnIdentifier,
@ -1167,7 +1167,7 @@ namespace CppSharp.Generators.CLI @@ -1167,7 +1167,7 @@ namespace CppSharp.Generators.CLI
QualifiedType = new QualifiedType(paramType)
};
var ctx = new MarshalContext(Context, CurrentIndent)
var ctx = new MarshalContext(Context, CurrentIndentation)
{
Parameter = effectiveParam,
ParameterIndex = paramIndex,

36
src/Generator/Generators/CSharp/CSharpMarshal.cs

@ -11,13 +11,13 @@ namespace CppSharp.Generators.CSharp @@ -11,13 +11,13 @@ namespace CppSharp.Generators.CSharp
{
public class CSharpMarshalContext : MarshalContext
{
public CSharpMarshalContext(BindingContext context, Stack<uint> indent)
: base(context, indent)
public CSharpMarshalContext(BindingContext context, Stack<uint> indentation)
: base(context, indentation)
{
ArgumentPrefix = new TextGenerator();
indent.PushTo(ArgumentPrefix.CurrentIndent);
indentation.PushTo(ArgumentPrefix.CurrentIndentation);
Cleanup = new TextGenerator();
indent.PushTo(Cleanup.CurrentIndent);
indentation.PushTo(Cleanup.CurrentIndentation);
}
public TextGenerator ArgumentPrefix { get; private set; }
@ -94,7 +94,7 @@ namespace CppSharp.Generators.CSharp @@ -94,7 +94,7 @@ namespace CppSharp.Generators.CSharp
var arrayType = array.Type.Desugar();
supportBefore.WriteLine($"{arrayType}[] {value} = null;");
supportBefore.WriteLine($"if ({Context.ReturnVarName} != null)");
supportBefore.WriteStartBraceIndent();
supportBefore.WriteOpenBraceAndIndent();
supportBefore.WriteLine($"{value} = new {arrayType}[{array.Size}];");
supportBefore.WriteLine($"for (int i = 0; i < {array.Size}; i++)");
if (array.Type.IsPointerToPrimitiveType(PrimitiveType.Void))
@ -130,7 +130,7 @@ namespace CppSharp.Generators.CSharp @@ -130,7 +130,7 @@ namespace CppSharp.Generators.CSharp
Context.ReturnVarName}[i];");
}
}
supportBefore.WriteCloseBraceIndent();
supportBefore.UnindentAndWriteCloseBrace();
Context.Return.Write(value);
break;
case ArrayType.ArraySize.Incomplete:
@ -338,7 +338,7 @@ namespace CppSharp.Generators.CSharp @@ -338,7 +338,7 @@ namespace CppSharp.Generators.CSharp
if (parameter.Usage == ParameterUsage.Unknown || parameter.IsIn)
return base.VisitParameterDecl(parameter);
var ctx = new CSharpMarshalContext(Context.Context, Context.Indent)
var ctx = new CSharpMarshalContext(Context.Context, Context.Indentation)
{
ReturnType = Context.ReturnType,
ReturnVarName = Context.ReturnVarName
@ -431,28 +431,28 @@ namespace CppSharp.Generators.CSharp @@ -431,28 +431,28 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLineIndent($"{intermediateArray} = null;");
Context.Before.WriteLine("else");
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
Context.Before.WriteLine($@"{intermediateArray} = new {
intermediateArrayType}[{Context.ReturnVarName}.Length];");
Context.Before.WriteLine($"for (int i = 0; i < {intermediateArray}.Length; i++)");
if (arrayType.IsAddress())
{
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
string element = Generator.GeneratedIdentifier("element");
Context.Before.WriteLine($"var {element} = {Context.ReturnVarName}[i];");
var intPtrZero = $"{CSharpTypePrinter.IntPtrType}.Zero";
Context.Before.WriteLine($@"{intermediateArray}[i] = {element} == {
intPtrZero} ? null : {intermediateArrayType}.{
Helpers.CreateInstanceIdentifier}({element});");
Context.Before.WriteCloseBraceIndent();
Context.Before.UnindentAndWriteCloseBrace();
}
else
Context.Before.WriteLineIndent($@"{intermediateArray}[i] = {
intermediateArrayType}.{Helpers.CreateInstanceIdentifier}({
Context.ReturnVarName}[i]);");
Context.Before.WriteCloseBraceIndent();
Context.Before.UnindentAndWriteCloseBrace();
Context.Return.Write(intermediateArray);
}
@ -507,7 +507,7 @@ namespace CppSharp.Generators.CSharp @@ -507,7 +507,7 @@ namespace CppSharp.Generators.CSharp
var supportBefore = Context.Before;
supportBefore.WriteLine($"if ({Context.ArgName} != null)");
supportBefore.WriteStartBraceIndent();
supportBefore.WriteOpenBraceAndIndent();
Class @class;
var arrayType = array.Type.Desugar();
var finalArrayType = arrayType.GetPointee() ?? arrayType;
@ -546,7 +546,7 @@ namespace CppSharp.Generators.CSharp @@ -546,7 +546,7 @@ namespace CppSharp.Generators.CSharp
(arrayType.IsPointerToPrimitiveType(PrimitiveType.Void) ?
".ToPointer()" : string.Empty)};");
}
supportBefore.WriteCloseBraceIndent();
supportBefore.UnindentAndWriteCloseBrace();
break;
case ArrayType.ArraySize.Incomplete:
MarshalArray(array);
@ -603,7 +603,7 @@ namespace CppSharp.Generators.CSharp @@ -603,7 +603,7 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLine(
$"fixed ({realPointer} {refParamPtr} = &{Context.Parameter.Name})");
Context.HasCodeBlock = true;
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
Context.Return.Write(refParamPtr);
}
return true;
@ -961,12 +961,12 @@ namespace CppSharp.Generators.CSharp @@ -961,12 +961,12 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLineIndent($"{intermediateArray} = null;");
Context.Before.WriteLine("else");
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
Context.Before.WriteLine($@"{intermediateArray} = new {
intermediateArrayType}[{Context.Parameter.Name}.Length];");
Context.Before.WriteLine($"for (int i = 0; i < {intermediateArray}.Length; i++)");
Context.Before.WriteStartBraceIndent();
Context.Before.WriteOpenBraceAndIndent();
string element = Generator.GeneratedIdentifier("element");
Context.Before.WriteLine($"var {element} = {Context.Parameter.Name}[i];");
if (elementType.IsAddress())
@ -979,9 +979,9 @@ namespace CppSharp.Generators.CSharp @@ -979,9 +979,9 @@ namespace CppSharp.Generators.CSharp
Context.Before.WriteLine($@"{intermediateArray}[i] = ReferenceEquals({
element}, null) ? new {intermediateArrayType}() : *({
intermediateArrayType}*) {element}.{Helpers.InstanceIdentifier};");
Context.Before.WriteCloseBraceIndent();
Context.Before.UnindentAndWriteCloseBrace();
Context.Before.WriteCloseBraceIndent();
Context.Before.UnindentAndWriteCloseBrace();
Context.Return.Write(intermediateArray);
}

276
src/Generator/Generators/CSharp/CSharpSources.cs

@ -71,7 +71,7 @@ namespace CppSharp.Generators.CSharp @@ -71,7 +71,7 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Namespace);
WriteLine("namespace {0}", Module.OutputNamespace);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
foreach (var unit in TranslationUnits)
@ -79,7 +79,7 @@ namespace CppSharp.Generators.CSharp @@ -79,7 +79,7 @@ namespace CppSharp.Generators.CSharp
if (!string.IsNullOrEmpty(Module.OutputNamespace))
{
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -97,7 +97,7 @@ namespace CppSharp.Generators.CSharp @@ -97,7 +97,7 @@ namespace CppSharp.Generators.CSharp
if (!string.IsNullOrEmpty(group.Key))
{
WriteLine($"namespace {group.Key}");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
foreach (var template in from s in @group
@ -115,18 +115,18 @@ namespace CppSharp.Generators.CSharp @@ -115,18 +115,18 @@ namespace CppSharp.Generators.CSharp
foreach (var declarationContext in declarationContexts)
{
WriteLine($"namespace {declarationContext.Name}");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
GenerateClassTemplateSpecializationsInternals(
template.Key, template.ToList());
foreach (var declarationContext in declarationContexts)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
if (!string.IsNullOrEmpty(group.Key))
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
}
@ -167,14 +167,14 @@ namespace CppSharp.Generators.CSharp @@ -167,14 +167,14 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Namespace);
WriteLine("namespace {0}", context.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
var ret = base.VisitNamespace(@namespace);
if (shouldGenerateNamespace)
{
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -240,11 +240,11 @@ namespace CppSharp.Generators.CSharp @@ -240,11 +240,11 @@ namespace CppSharp.Generators.CSharp
if (classes.FindAll(cls => cls.IsValueType && cls.Name == parentName && context.QualifiedLogicalName == cls.Namespace.QualifiedLogicalName).Any())
keyword = "struct";
WriteLine($"public unsafe partial {keyword} {parentName}");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
PushBlock(BlockKind.InternalsClass);
GenerateClassInternalHead();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
// Generate all the internal function declarations.
foreach (var function in context.Functions)
@ -255,7 +255,7 @@ namespace CppSharp.Generators.CSharp @@ -255,7 +255,7 @@ namespace CppSharp.Generators.CSharp
GenerateInternalFunction(function);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
foreach (var function in context.Functions)
@ -269,7 +269,7 @@ namespace CppSharp.Generators.CSharp @@ -269,7 +269,7 @@ namespace CppSharp.Generators.CSharp
v => v.IsGenerated && v.Access == AccessSpecifier.Public))
GenerateVariable(null, variable);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -292,7 +292,7 @@ namespace CppSharp.Generators.CSharp @@ -292,7 +292,7 @@ namespace CppSharp.Generators.CSharp
!classTemplate.OriginalNamespace.IsDependent ?
classTemplate.OriginalNamespace.Name + '_' : string.Empty,
classTemplate.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
foreach (var nestedTemplate in classTemplate.Classes.Where(
c => c.IsDependent && !c.Ignore && c.Specializations.Any(s => !s.Ignore)))
@ -310,21 +310,21 @@ namespace CppSharp.Generators.CSharp @@ -310,21 +310,21 @@ namespace CppSharp.Generators.CSharp
GenerateNestedInternals(group.Key, GetGeneratedClasses(nested, group));
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
private void GenerateNestedInternals(string name, IEnumerable<Class> nestedClasses)
{
WriteLine($"namespace {name}");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
foreach (var nestedClass in nestedClasses)
{
GenerateClassInternals(nestedClass);
foreach (var nestedInNested in nestedClass.Classes)
GenerateNestedInternals(nestedInNested.Name, new[] { nestedInNested });
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
}
@ -388,7 +388,7 @@ namespace CppSharp.Generators.CSharp @@ -388,7 +388,7 @@ namespace CppSharp.Generators.CSharp
GenerateClassSpecifier(@class);
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (!@class.IsAbstractImpl && !@class.IsDependent)
GenerateClassInternals(@class);
@ -440,7 +440,7 @@ namespace CppSharp.Generators.CSharp @@ -440,7 +440,7 @@ namespace CppSharp.Generators.CSharp
if (@class.IsDynamic)
GenerateVTable(@class);
exit:
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
for (int i = 0; i < typeMaps.Count; i++)
@ -463,7 +463,7 @@ namespace CppSharp.Generators.CSharp @@ -463,7 +463,7 @@ namespace CppSharp.Generators.CSharp
Write(" : IDisposable");
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
foreach (var method in @class.Methods.Where(m =>
(m.OriginalFunction == null ||
@ -505,7 +505,7 @@ namespace CppSharp.Generators.CSharp @@ -505,7 +505,7 @@ namespace CppSharp.Generators.CSharp
PopBlock(NewLineKind.BeforeNextBlock);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -518,7 +518,7 @@ namespace CppSharp.Generators.CSharp @@ -518,7 +518,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($"[StructLayout(LayoutKind.Sequential, Pack = {@class.MaxFieldAlignment})]");
GenerateClassInternalHead(@class);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
TypePrinter.PushContext(TypePrinterContextKind.Native);
@ -534,7 +534,7 @@ namespace CppSharp.Generators.CSharp @@ -534,7 +534,7 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PopContext();
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -763,14 +763,14 @@ namespace CppSharp.Generators.CSharp @@ -763,14 +763,14 @@ namespace CppSharp.Generators.CSharp
}
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
this.GenerateMember(@class, c => GenerateFunctionSetter(c, property), true);
}
else if (decl is Variable)
{
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var var = decl as Variable;
this.GenerateMember(@class, c => GenerateVariableSetter(
c is ClassTemplateSpecialization ?
@ -784,11 +784,11 @@ namespace CppSharp.Generators.CSharp @@ -784,11 +784,11 @@ namespace CppSharp.Generators.CSharp
return;
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
this.GenerateField(@class, field, GenerateFieldSetter, true);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -820,7 +820,7 @@ namespace CppSharp.Generators.CSharp @@ -820,7 +820,7 @@ namespace CppSharp.Generators.CSharp
QualifiedType = var.QualifiedType
};
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
Parameter = param,
ArgName = param.Name,
@ -835,12 +835,12 @@ namespace CppSharp.Generators.CSharp @@ -835,12 +835,12 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (ctx.HasCodeBlock)
PushIndent();
Indent();
WriteLine($"*{ptr} = {marshal.Context.Return};", marshal.Context.Return);
if (ctx.HasCodeBlock)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateFunctionSetter(Class @class, Property property)
@ -903,7 +903,7 @@ namespace CppSharp.Generators.CSharp @@ -903,7 +903,7 @@ namespace CppSharp.Generators.CSharp
QualifiedType = field.QualifiedType
};
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
Parameter = param,
ArgName = param.Name,
@ -920,7 +920,7 @@ namespace CppSharp.Generators.CSharp @@ -920,7 +920,7 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (ctx.HasCodeBlock)
PushIndent();
Indent();
if (marshal.Context.Return.StringBuilder.Length > 0)
{
@ -940,7 +940,7 @@ namespace CppSharp.Generators.CSharp @@ -940,7 +940,7 @@ namespace CppSharp.Generators.CSharp
}
if ((arrayType != null && @class.IsValueType) || ctx.HasCodeBlock)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private string HandleValueArray(ArrayType arrayType, Field field)
@ -960,7 +960,7 @@ namespace CppSharp.Generators.CSharp @@ -960,7 +960,7 @@ namespace CppSharp.Generators.CSharp
f => f.FieldPtr == field.OriginalPtr).Name;
WriteLine(string.Format("fixed ({0} {1} = {2}.{3})",
type, arrPtr, Helpers.InstanceField, SafeIdentifier(name)));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
return arrPtr;
}
@ -971,13 +971,13 @@ namespace CppSharp.Generators.CSharp @@ -971,13 +971,13 @@ namespace CppSharp.Generators.CSharp
return false;
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0} = value;", name);
WriteLine("if (!{0}{1})", name, "Initialised");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0}{1} = true;", name, "Initialised");
WriteCloseBraceIndent();
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
return true;
@ -989,7 +989,7 @@ namespace CppSharp.Generators.CSharp @@ -989,7 +989,7 @@ namespace CppSharp.Generators.CSharp
function.OriginalReturnType.Type.IsPointerTo(out type);
var @internal = TypePrinter.PrintNative(function.Namespace);
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
Parameter = new Parameter
{
@ -1033,11 +1033,11 @@ namespace CppSharp.Generators.CSharp @@ -1033,11 +1033,11 @@ namespace CppSharp.Generators.CSharp
property.GetMethod.SynthKind == FunctionSynthKind.InterfaceInstance)
{
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var to = ((Class) property.OriginalNamespace).OriginalClass;
var baseOffset = GetOffsetToBase(@class, to);
WriteLine("return {0} + {1};", Helpers.InstanceIdentifier, baseOffset);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
return;
}
@ -1052,7 +1052,7 @@ namespace CppSharp.Generators.CSharp @@ -1052,7 +1052,7 @@ namespace CppSharp.Generators.CSharp
}
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
this.GenerateMember(@class, c => GenerateFunctionGetter(c, property));
}
@ -1063,19 +1063,19 @@ namespace CppSharp.Generators.CSharp @@ -1063,19 +1063,19 @@ namespace CppSharp.Generators.CSharp
return;
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
this.GenerateField(@class, field, GenerateFieldGetter, false);
}
else if (decl is Variable)
{
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var var = decl as Variable;
this.GenerateMember(@class, c => GenerateVariableGetter(
c is ClassTemplateSpecialization ?
c.Variables.First(v => v.Name == decl.Name) : var));
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -1110,7 +1110,7 @@ namespace CppSharp.Generators.CSharp @@ -1110,7 +1110,7 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PopContext();
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ArgName = var.Name,
ReturnType = new QualifiedType(var.Type)
@ -1134,12 +1134,12 @@ namespace CppSharp.Generators.CSharp @@ -1134,12 +1134,12 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (ctx.HasCodeBlock)
PushIndent();
Indent();
WriteLine("return {0};", marshal.Context.Return);
if (ctx.HasCodeBlock)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateFunctionGetter(Class @class, Property property)
@ -1193,7 +1193,7 @@ namespace CppSharp.Generators.CSharp @@ -1193,7 +1193,7 @@ namespace CppSharp.Generators.CSharp
returnVar = $"new {CSharpTypePrinter.IntPtrType}(&{returnVar})";
}
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ArgName = field.Name,
Declaration = field,
@ -1209,7 +1209,7 @@ namespace CppSharp.Generators.CSharp @@ -1209,7 +1209,7 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (ctx.HasCodeBlock)
PushIndent();
Indent();
Write("return ");
@ -1233,7 +1233,7 @@ namespace CppSharp.Generators.CSharp @@ -1233,7 +1233,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($"{@return};");
if ((arrayType != null && @class.IsValueType) || ctx.HasCodeBlock)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private bool WrapGetterArrayOfPointers(string name, Type fieldType)
@ -1242,14 +1242,14 @@ namespace CppSharp.Generators.CSharp @@ -1242,14 +1242,14 @@ namespace CppSharp.Generators.CSharp
if (arrayType != null && arrayType.Type.IsPointerToPrimitiveType())
{
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("if (!{0}{1})", name, "Initialised");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0} = null;", name);
WriteLine("{0}{1} = true;", name, "Initialised");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteLine("return {0};", name);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
return true;
}
@ -1368,7 +1368,7 @@ namespace CppSharp.Generators.CSharp @@ -1368,7 +1368,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($@"{printedType} {
prop.ExplicitInterfaceImpl.Name}.{GetPropertyName(prop)}");
}
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (prop.Field != null)
{
@ -1387,7 +1387,7 @@ namespace CppSharp.Generators.CSharp @@ -1387,7 +1387,7 @@ namespace CppSharp.Generators.CSharp
GeneratePropertySetter(prop.SetMethod, @class, prop.IsPure, prop);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
}
@ -1416,7 +1416,7 @@ namespace CppSharp.Generators.CSharp @@ -1416,7 +1416,7 @@ namespace CppSharp.Generators.CSharp
var variableType = variable.Type.Visit(TypePrinter);
TypePrinter.PopMarshalKind();
WriteLine($"public static {variableType} {variable.Name}");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
GeneratePropertyGetter(variable, @class);
@ -1424,7 +1424,7 @@ namespace CppSharp.Generators.CSharp @@ -1424,7 +1424,7 @@ namespace CppSharp.Generators.CSharp
!(variable.Type.Desugar() is ArrayType))
GeneratePropertySetter(variable, @class);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -1474,7 +1474,7 @@ namespace CppSharp.Generators.CSharp @@ -1474,7 +1474,7 @@ namespace CppSharp.Generators.CSharp
{
const string destructorOnly = "destructorOnly";
WriteLine("private void SetupVTables(bool {0} = false)", destructorOnly);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("if (__OriginalVTables != null)");
WriteLineIndent("return;");
@ -1492,7 +1492,7 @@ namespace CppSharp.Generators.CSharp @@ -1492,7 +1492,7 @@ namespace CppSharp.Generators.CSharp
// Get the _Thunks
WriteLine("if (_Thunks == null)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("_Thunks = new void*[{0}];", wrappedEntries.Count);
var uniqueEntries = new HashSet<VTableComponent>();
@ -1508,32 +1508,32 @@ namespace CppSharp.Generators.CSharp @@ -1508,32 +1508,32 @@ namespace CppSharp.Generators.CSharp
WriteLine("_Thunks[{0}] = Marshal.GetFunctionPointerForDelegate({1}).ToPointer();",
i, instance);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
if (hasVirtualDtor)
{
WriteLine("if ({0})", destructorOnly);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("if (__ManagedVTablesDtorOnly == null)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
AllocateNewVTables(@class, wrappedEntries, true);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteLine("else");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
WriteLine("if (__ManagedVTables == null)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
AllocateNewVTables(@class, wrappedEntries, false);
if (hasVirtualDtor)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
}
@ -1577,7 +1577,7 @@ namespace CppSharp.Generators.CSharp @@ -1577,7 +1577,7 @@ namespace CppSharp.Generators.CSharp
@class.Layout.VTablePointers[i].Offset, i, destructorOnly);
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
for (int i = 0; i < @class.Layout.VTablePointers.Count; i++)
@ -1603,7 +1603,7 @@ namespace CppSharp.Generators.CSharp @@ -1603,7 +1603,7 @@ namespace CppSharp.Generators.CSharp
AllocateNewVTableEntries(@class.Layout.Layout.Components,
wrappedEntries, @class.Layout.VTablePointers[0].Offset, 0, destructorOnly);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
var offset = @class.Layout.VTablePointers[0].Offset;
@ -1669,7 +1669,7 @@ namespace CppSharp.Generators.CSharp @@ -1669,7 +1669,7 @@ namespace CppSharp.Generators.CSharp
if (param.Kind == ParameterKind.IndirectReturnType)
continue;
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ReturnType = param.QualifiedType,
ReturnVarName = param.Name,
@ -1687,7 +1687,7 @@ namespace CppSharp.Generators.CSharp @@ -1687,7 +1687,7 @@ namespace CppSharp.Generators.CSharp
marshals.Add(marshal.Context.Return);
if (ctx.HasCodeBlock)
{
PushIndent();
Indent();
numBlocks++;
}
}
@ -1726,7 +1726,7 @@ namespace CppSharp.Generators.CSharp @@ -1726,7 +1726,7 @@ namespace CppSharp.Generators.CSharp
};
// Marshal the managed result to native
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ArgName = Helpers.ReturnIdentifier,
Parameter = param,
@ -1757,7 +1757,7 @@ namespace CppSharp.Generators.CSharp @@ -1757,7 +1757,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("return false;");
for (var i = 0; i < numBlocks; ++i)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateVTableMethodDelegates(Class @class, Method method)
@ -1787,7 +1787,7 @@ namespace CppSharp.Generators.CSharp @@ -1787,7 +1787,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("private static {0} {1}Hook({2})", retType, vTableMethodDelegateName,
string.Join(", ", @params));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("if (!NativeToManagedMap.ContainsKey(instance))");
WriteLineIndent("throw new global::System.Exception(\"No managed instance was found\");");
@ -1799,7 +1799,7 @@ namespace CppSharp.Generators.CSharp @@ -1799,7 +1799,7 @@ namespace CppSharp.Generators.CSharp
WriteLineIndent("{0}.SetupVTables();", Helpers.TargetIdentifier);
GenerateVTableManagedCall(method);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.Always);
}
@ -1839,14 +1839,14 @@ namespace CppSharp.Generators.CSharp @@ -1839,14 +1839,14 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} {1};", @event.Type, delegateInstance);
WriteLine("public event {0} {1}", @event.Type, @event.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
GenerateEventAdd(@event, delegateRaise, delegateName, delegateInstance);
NewLine();
GenerateEventRemove(@event, delegateInstance);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
GenerateEventRaiseWrapper(@event, delegateInstance);
@ -1858,10 +1858,10 @@ namespace CppSharp.Generators.CSharp @@ -1858,10 +1858,10 @@ namespace CppSharp.Generators.CSharp
private void GenerateEventAdd(Event @event, string delegateRaise, string delegateName, string delegateInstance)
{
WriteLine("add");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("if ({0} == null)", delegateRaise);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0} = new {1}(_{2}Raise);", delegateRaise, delegateName, @event.Name);
@ -1873,23 +1873,23 @@ namespace CppSharp.Generators.CSharp @@ -1873,23 +1873,23 @@ namespace CppSharp.Generators.CSharp
//WriteLine("((::{0}*)NativePtr)->{1}.Connect(_fptr);", @class.QualifiedOriginalName,
// @event.OriginalName);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteLine("{0} = ({1})System.Delegate.Combine({0}, value);",
delegateInstance, @event.Type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateEventRemove(ITypedDecl @event, string delegateInstance)
{
WriteLine("remove");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0} = ({1})System.Delegate.Remove({0}, value);",
delegateInstance, @event.Type);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private void GenerateEventRaiseWrapper(Event @event, string delegateInstance)
@ -1899,12 +1899,12 @@ namespace CppSharp.Generators.CSharp @@ -1899,12 +1899,12 @@ namespace CppSharp.Generators.CSharp
TypePrinter.PopContext();
WriteLine("void _{0}Raise({1})", @event.Name, args);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var returns = new List<string>();
foreach (var param in @event.Parameters)
{
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ReturnVarName = param.Name,
ReturnType = param.QualifiedType
@ -1917,11 +1917,11 @@ namespace CppSharp.Generators.CSharp @@ -1917,11 +1917,11 @@ namespace CppSharp.Generators.CSharp
}
WriteLine("if ({0} != null)", delegateInstance);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("{0}({1});", delegateInstance, string.Join(", ", returns));
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
#endregion
@ -1969,9 +1969,9 @@ namespace CppSharp.Generators.CSharp @@ -1969,9 +1969,9 @@ namespace CppSharp.Generators.CSharp
PushBlock(BlockKind.Finalizer);
WriteLine("~{0}()", @class.Name);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("Dispose(false);");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -1985,13 +1985,13 @@ namespace CppSharp.Generators.CSharp @@ -1985,13 +1985,13 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Method);
WriteLine("public void Dispose()");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
WriteLine("Dispose(disposing: true);");
if (Options.GenerateFinalizers)
WriteLine("GC.SuppressFinalize(this);");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2002,7 +2002,7 @@ namespace CppSharp.Generators.CSharp @@ -2002,7 +2002,7 @@ namespace CppSharp.Generators.CSharp
Write(hasBaseClass ? "override " : "virtual ");
WriteLine("void Dispose(bool disposing)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (@class.IsRefType)
{
@ -2044,9 +2044,9 @@ namespace CppSharp.Generators.CSharp @@ -2044,9 +2044,9 @@ namespace CppSharp.Generators.CSharp
{
WriteLine("if (disposing)");
if (@class.IsDependent || dtor.IsVirtual)
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
else
PushIndent();
Indent();
if (dtor.IsVirtual)
this.GenerateMember(@class, c => GenerateDestructorCall(
c is ClassTemplateSpecialization ?
@ -2054,9 +2054,9 @@ namespace CppSharp.Generators.CSharp @@ -2054,9 +2054,9 @@ namespace CppSharp.Generators.CSharp
else
this.GenerateMember(@class, c => GenerateMethodBody(c, dtor), true);
if (@class.IsDependent || dtor.IsVirtual)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
else
PopIndent();
Unindent();
}
}
@ -2064,7 +2064,7 @@ namespace CppSharp.Generators.CSharp @@ -2064,7 +2064,7 @@ namespace CppSharp.Generators.CSharp
WriteLineIndent("Marshal.FreeHGlobal({0});", Helpers.InstanceIdentifier);
WriteLine("{0} = IntPtr.Zero;", Helpers.InstanceIdentifier);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2074,11 +2074,11 @@ namespace CppSharp.Generators.CSharp @@ -2074,11 +2074,11 @@ namespace CppSharp.Generators.CSharp
GenerateVirtualFunctionCall(dtor, @class, true);
if (@class.IsAbstract)
{
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
WriteLine("else");
PushIndent();
Indent();
GenerateInternalFunctionCall(dtor);
PopIndent();
Unindent();
}
}
@ -2099,11 +2099,11 @@ namespace CppSharp.Generators.CSharp @@ -2099,11 +2099,11 @@ namespace CppSharp.Generators.CSharp
WriteLine("internal static {0}{1} {2}(global::System.IntPtr native, bool skipVTables = false)",
@class.NeedsBase && !@class.BaseClass.IsInterface ? "new " : string.Empty,
printedClass, Helpers.CreateInstanceIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var suffix = @class.IsAbstract ? "Internal" : string.Empty;
var ctorCall = $"{printedClass}{suffix}";
WriteLine("return new {0}(native.ToPointer(), skipVTables);", ctorCall);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2118,7 +2118,7 @@ namespace CppSharp.Generators.CSharp @@ -2118,7 +2118,7 @@ namespace CppSharp.Generators.CSharp
if (hasBaseClass)
WriteLineIndent(": base((void*) null)", @class.BaseClass.Visit(TypePrinter));
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (@class.IsRefType)
{
@ -2138,7 +2138,7 @@ namespace CppSharp.Generators.CSharp @@ -2138,7 +2138,7 @@ namespace CppSharp.Generators.CSharp
if (setupVTables)
{
WriteLine("if (skipVTables)");
PushIndent();
Indent();
}
if (@class.IsAbstractImpl || hasVTables)
@ -2146,11 +2146,11 @@ namespace CppSharp.Generators.CSharp @@ -2146,11 +2146,11 @@ namespace CppSharp.Generators.CSharp
if (setupVTables)
{
PopIndent();
Unindent();
WriteLine("else");
PushIndent();
Indent();
GenerateVTableClassSetupCall(@class, destructorOnly: true);
PopIndent();
Unindent();
}
}
else
@ -2158,7 +2158,7 @@ namespace CppSharp.Generators.CSharp @@ -2158,7 +2158,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($"{Helpers.InstanceField} = *({TypePrinter.PrintNative(@class)}*) native;");
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2171,10 +2171,10 @@ namespace CppSharp.Generators.CSharp @@ -2171,10 +2171,10 @@ namespace CppSharp.Generators.CSharp
PushBlock(BlockKind.Method);
WriteLine("internal static {0} {1}({2} native, bool skipVTables = false)",
returnType, Helpers.CreateInstanceIdentifier, @internal);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var suffix = @class.IsAbstract ? "Internal" : "";
WriteLine($"return new {returnType}{suffix}(native, skipVTables);");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2182,7 +2182,7 @@ namespace CppSharp.Generators.CSharp @@ -2182,7 +2182,7 @@ namespace CppSharp.Generators.CSharp
{
PushBlock(BlockKind.Method);
WriteLine($"private static void* __CopyValue({@internal} native)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var copyCtorMethod = @class.Methods.FirstOrDefault(method =>
method.IsCopyConstructor);
if (@class.HasNonTrivialCopyConstructor && copyCtorMethod != null &&
@ -2201,7 +2201,7 @@ namespace CppSharp.Generators.CSharp @@ -2201,7 +2201,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($"*({@internal}*) ret = native;");
WriteLine("return ret.ToPointer();");
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
if (!@class.IsAbstract)
@ -2210,7 +2210,7 @@ namespace CppSharp.Generators.CSharp @@ -2210,7 +2210,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("{0} {1}({2} native, bool skipVTables = false)",
@class.IsAbstractImpl ? "internal" : "private", @class.Name, @internal);
WriteLineIndent(@class.IsRefType ? ": this(__CopyValue(native), skipVTables)" : ": this()");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (@class.IsRefType)
{
WriteLine($"{Helpers.OwnsNativeInstanceIdentifier} = true;");
@ -2220,7 +2220,7 @@ namespace CppSharp.Generators.CSharp @@ -2220,7 +2220,7 @@ namespace CppSharp.Generators.CSharp
{
WriteLine($"{Helpers.InstanceField} = native;");
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
}
@ -2231,13 +2231,13 @@ namespace CppSharp.Generators.CSharp @@ -2231,13 +2231,13 @@ namespace CppSharp.Generators.CSharp
if (hasBase && !@class.IsValueType)
{
PushIndent();
Indent();
Write(": this(");
Write(method != null ? "(void*) null" : "native");
WriteLine(")");
PopIndent();
Unindent();
}
if (@class.IsValueType)
@ -2259,14 +2259,14 @@ namespace CppSharp.Generators.CSharp @@ -2259,14 +2259,14 @@ namespace CppSharp.Generators.CSharp
Write("public static {0} {1}(", function.OriginalReturnType, functionName);
Write(FormatMethodParameters(function.Parameters));
WriteLine(")");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (function.SynthKind == FunctionSynthKind.DefaultValueOverload)
GenerateOverloadCall(function);
else
GenerateInternalFunctionCall(function);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);
}
@ -2342,7 +2342,7 @@ namespace CppSharp.Generators.CSharp @@ -2342,7 +2342,7 @@ namespace CppSharp.Generators.CSharp
method.SynthKind != FunctionSynthKind.DefaultValueOverload)
GenerateClassConstructorBase(@class, method);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (method.IsProxy)
goto SkipImpl;
@ -2369,7 +2369,7 @@ namespace CppSharp.Generators.CSharp @@ -2369,7 +2369,7 @@ namespace CppSharp.Generators.CSharp
SkipImpl:
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
if (method.OperatorKind == CXXOperatorKind.EqualEqual)
{
@ -2505,7 +2505,7 @@ namespace CppSharp.Generators.CSharp @@ -2505,7 +2505,7 @@ namespace CppSharp.Generators.CSharp
{
NewLine();
WriteLine("public override bool Equals(object obj)");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
var printedClass = @class.Visit(TypePrinter);
if (@class.IsRefType)
{
@ -2516,17 +2516,17 @@ namespace CppSharp.Generators.CSharp @@ -2516,17 +2516,17 @@ namespace CppSharp.Generators.CSharp
WriteLine($"if (!(obj is {printedClass})) return false;");
WriteLine($"return this == ({printedClass}) obj;");
}
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
NewLine();
WriteLine("public override int GetHashCode()");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
if (@class.IsRefType)
this.GenerateMember(@class, GenerateGetHashCode);
else
WriteLine($"return {Helpers.InstanceIdentifier}.GetHashCode();");
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
}
@ -2580,7 +2580,7 @@ namespace CppSharp.Generators.CSharp @@ -2580,7 +2580,7 @@ namespace CppSharp.Generators.CSharp
if (method.IsDestructor && @class.IsAbstract)
{
WriteLine("if ({0} != null)", Helpers.SlotIdentifier);
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
var @delegate = GetVTableMethodDelegateName(@virtual);
@ -2810,7 +2810,7 @@ namespace CppSharp.Generators.CSharp @@ -2810,7 +2810,7 @@ namespace CppSharp.Generators.CSharp
WriteLine($@"fixed ({Helpers.InternalStruct}{
Helpers.GetSuffixForInternal(originalFunction.Namespace)}* __instancePtr = &{
Helpers.InstanceField})");
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
}
else
{
@ -2856,7 +2856,7 @@ namespace CppSharp.Generators.CSharp @@ -2856,7 +2856,7 @@ namespace CppSharp.Generators.CSharp
if (needsReturn)
{
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
ArgName = Helpers.ReturnIdentifier,
ReturnVarName = Helpers.ReturnIdentifier,
@ -2872,20 +2872,20 @@ namespace CppSharp.Generators.CSharp @@ -2872,20 +2872,20 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (ctx.HasCodeBlock)
PushIndent();
Indent();
WriteLine($"return {marshal.Context.Return};");
if (ctx.HasCodeBlock)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
if (needsFixedThis && operatorParam == null)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
var numFixedBlocks = @params.Count(param => param.HasUsingBlock);
for(var i = 0; i < numFixedBlocks; ++i)
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
}
private string GetInstanceParam(Function function)
@ -2947,7 +2947,7 @@ namespace CppSharp.Generators.CSharp @@ -2947,7 +2947,7 @@ namespace CppSharp.Generators.CSharp
var nativeVarName = paramInfo.Name;
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
Parameter = param,
ArgName = nativeVarName,
@ -3015,7 +3015,7 @@ namespace CppSharp.Generators.CSharp @@ -3015,7 +3015,7 @@ namespace CppSharp.Generators.CSharp
}
}
var ctx = new CSharpMarshalContext(Context, CurrentIndent)
var ctx = new CSharpMarshalContext(Context, CurrentIndentation)
{
Parameter = param,
ParameterIndex = paramIndex,
@ -3035,7 +3035,7 @@ namespace CppSharp.Generators.CSharp @@ -3035,7 +3035,7 @@ namespace CppSharp.Generators.CSharp
Write(marshal.Context.Before);
if (paramMarshal.HasUsingBlock)
PushIndent();
Indent();
if (marshal.Context.Return.ToString() == param.Name)
paramMarshal.Name = param.Name;
@ -3120,9 +3120,9 @@ namespace CppSharp.Generators.CSharp @@ -3120,9 +3120,9 @@ namespace CppSharp.Generators.CSharp
NewLine();
WriteStartBraceIndent();
WriteOpenBraceAndIndent();
GenerateEnumItems(@enum);
WriteCloseBraceIndent();
UnindentAndWriteCloseBrace();
PopBlock(NewLineKind.BeforeNextBlock);

8
src/Generator/Generators/CSharp/CSharpSourcesExtensions.cs

@ -43,13 +43,13 @@ namespace CppSharp.Generators.CSharp @@ -43,13 +43,13 @@ namespace CppSharp.Generators.CSharp
foreach (var specialization in @class.Specializations.Where(s => s.IsGenerated))
{
WriteTemplateSpecializationCheck(gen, @class, specialization);
gen.WriteStartBraceIndent();
gen.WriteOpenBraceAndIndent();
var specializedField = specialization.Fields.First(
f => f.OriginalName == field.OriginalName);
generate(specializedField, specialization, field.QualifiedType);
if (isVoid)
gen.WriteLine("return;");
gen.WriteCloseBraceIndent();
gen.UnindentAndWriteCloseBrace();
}
ThrowException(gen, @class);
}
@ -79,11 +79,11 @@ namespace CppSharp.Generators.CSharp @@ -79,11 +79,11 @@ namespace CppSharp.Generators.CSharp
foreach (var specialization in @class.Specializations.Where(s => s.IsGenerated))
{
WriteTemplateSpecializationCheck(gen, @class, specialization);
gen.WriteStartBraceIndent();
gen.WriteOpenBraceAndIndent();
generate(specialization);
if (isVoid)
gen.WriteLine("return;");
gen.WriteCloseBraceIndent();
gen.UnindentAndWriteCloseBrace();
}
ThrowException(gen, @class);
}

10
src/Generator/Generators/Marshal.cs

@ -5,15 +5,15 @@ namespace CppSharp.Generators @@ -5,15 +5,15 @@ namespace CppSharp.Generators
{
public class MarshalContext : TypePrinter
{
public MarshalContext(BindingContext context, Stack<uint> indent)
public MarshalContext(BindingContext context, Stack<uint> indentation)
{
Context = context;
Before = new TextGenerator();
indent.PushTo(Before.CurrentIndent);
indentation.PushTo(Before.CurrentIndentation);
Return = new TextGenerator();
indent.PushTo(Return.CurrentIndent);
indentation.PushTo(Return.CurrentIndentation);
MarshalVarPrefix = string.Empty;
this.Indent = indent;
this.Indentation = indentation;
}
public BindingContext Context { get; }
@ -31,7 +31,7 @@ namespace CppSharp.Generators @@ -31,7 +31,7 @@ namespace CppSharp.Generators
public Function Function { get; set; }
public string MarshalVarPrefix { get; set; }
public Stack<uint> Indent { get; }
public Stack<uint> Indentation { get; }
}
public abstract class MarshalPrinter<T> : AstVisitor where T : MarshalContext

12
src/Generator/Types/Std/Stdlib.cs

@ -227,7 +227,7 @@ namespace CppSharp.Types.Std @@ -227,7 +227,7 @@ namespace CppSharp.Types.Std
tmpVarName, nativeType);
ctx.Before.WriteLine("for each({0} _element in {1})",
managedType, entryString);
ctx.Before.WriteStartBraceIndent();
ctx.Before.WriteOpenBraceAndIndent();
{
var param = new Parameter
{
@ -235,7 +235,7 @@ namespace CppSharp.Types.Std @@ -235,7 +235,7 @@ namespace CppSharp.Types.Std
QualifiedType = type
};
var elementCtx = new MarshalContext(ctx.Context, ctx.Indent)
var elementCtx = new MarshalContext(ctx.Context, ctx.Indentation)
{
Parameter = param,
ArgName = param.Name,
@ -258,7 +258,7 @@ namespace CppSharp.Types.Std @@ -258,7 +258,7 @@ namespace CppSharp.Types.Std
tmpVarName);
}
ctx.Before.WriteCloseBraceIndent();
ctx.Before.UnindentAndWriteCloseBrace();
ctx.Return.Write(tmpVarName);
}
@ -278,9 +278,9 @@ namespace CppSharp.Types.Std @@ -278,9 +278,9 @@ namespace CppSharp.Types.Std
tmpVarName, managedType);
ctx.Before.WriteLine("for(auto _element : {0})",
ctx.ReturnVarName);
ctx.Before.WriteStartBraceIndent();
ctx.Before.WriteOpenBraceAndIndent();
{
var elementCtx = new MarshalContext(ctx.Context, ctx.Indent)
var elementCtx = new MarshalContext(ctx.Context, ctx.Indentation)
{
ReturnVarName = "_element",
ReturnType = type
@ -302,7 +302,7 @@ namespace CppSharp.Types.Std @@ -302,7 +302,7 @@ namespace CppSharp.Types.Std
ctx.Before.WriteLine("{0}->Add(_marshalElement);",
tmpVarName);
}
ctx.Before.WriteCloseBraceIndent();
ctx.Before.UnindentAndWriteCloseBrace();
ctx.Return.Write(tmpVarName);
}

36
src/Generator/Utils/BlockGenerator.cs

@ -211,26 +211,26 @@ namespace CppSharp @@ -211,26 +211,26 @@ namespace CppSharp
Text.ResetNewLine();
}
public void PushIndent(uint indent = 4u)
public void Indent(uint indentation = 4u)
{
hasIndentChanged = true;
Text.PushIndent(indent);
Text.Indent(indentation);
}
public void PopIndent()
public void Unindent()
{
hasIndentChanged = true;
Text.PopIndent();
Text.Unindent();
}
public void WriteStartBraceIndent()
public void WriteOpenBraceAndIndent()
{
Text.WriteStartBraceIndent();
Text.WriteOpenBraceAndIndent();
}
public void WriteCloseBraceIndent()
public void UnindentAndWriteCloseBrace()
{
Text.WriteCloseBraceIndent();
Text.UnindentAndWriteCloseBrace();
}
#endregion
@ -240,7 +240,7 @@ namespace CppSharp @@ -240,7 +240,7 @@ namespace CppSharp
{
public Block RootBlock { get; }
public Block ActiveBlock { get; private set; }
public Stack<uint> CurrentIndent => ActiveBlock.Text.CurrentIndent;
public Stack<uint> CurrentIndentation => ActiveBlock.Text.CurrentIndentation;
protected BlockGenerator()
{
@ -263,7 +263,7 @@ namespace CppSharp @@ -263,7 +263,7 @@ namespace CppSharp
public void PushBlock(BlockKind kind = BlockKind.Unknown, object obj = null)
{
var block = new Block { Kind = kind, Object = obj };
CurrentIndent.PushTo(block.Text.CurrentIndent);
CurrentIndentation.PushTo(block.Text.CurrentIndentation);
block.Text.IsStartOfLine = ActiveBlock.Text.IsStartOfLine;
block.Text.NeedsNewLine = ActiveBlock.Text.NeedsNewLine;
PushBlock(block);
@ -335,24 +335,24 @@ namespace CppSharp @@ -335,24 +335,24 @@ namespace CppSharp
ActiveBlock.ResetNewLine();
}
public void PushIndent(uint indent = 4u)
public void Indent(uint indentation = 4u)
{
ActiveBlock.PushIndent(indent);
ActiveBlock.Indent(indentation);
}
public void PopIndent()
public void Unindent()
{
ActiveBlock.PopIndent();
ActiveBlock.Unindent();
}
public void WriteStartBraceIndent()
public void WriteOpenBraceAndIndent()
{
ActiveBlock.WriteStartBraceIndent();
ActiveBlock.WriteOpenBraceAndIndent();
}
public void WriteCloseBraceIndent()
public void UnindentAndWriteCloseBrace()
{
ActiveBlock.WriteCloseBraceIndent();
ActiveBlock.UnindentAndWriteCloseBrace();
}
#endregion

36
src/Generator/Utils/TextGenerator.cs

@ -14,20 +14,20 @@ namespace CppSharp @@ -14,20 +14,20 @@ namespace CppSharp
void NewLineIfNeeded();
void NeedNewLine();
void ResetNewLine();
void PushIndent(uint indent = TextGenerator.DefaultIndent);
void PopIndent();
void WriteStartBraceIndent();
void WriteCloseBraceIndent();
void Indent(uint indentation = TextGenerator.DefaultIndentation);
void Unindent();
void WriteOpenBraceAndIndent();
void UnindentAndWriteCloseBrace();
}
public class TextGenerator : ITextGenerator
{
public const uint DefaultIndent = 4;
public const uint DefaultIndentation = 4;
public StringBuilder StringBuilder = new StringBuilder();
public bool IsStartOfLine { get; set; }
public bool NeedsNewLine { get; set; }
public Stack<uint> CurrentIndent { get; } = new Stack<uint>();
public Stack<uint> CurrentIndentation { get; } = new Stack<uint>();
public TextGenerator()
{
@ -38,7 +38,7 @@ namespace CppSharp @@ -38,7 +38,7 @@ namespace CppSharp
StringBuilder = new StringBuilder(generator);
IsStartOfLine = generator.IsStartOfLine;
NeedsNewLine = generator.NeedsNewLine;
CurrentIndent = new Stack<uint>(generator.CurrentIndent);
CurrentIndentation = new Stack<uint>(generator.CurrentIndentation);
}
public TextGenerator Clone()
@ -55,7 +55,7 @@ namespace CppSharp @@ -55,7 +55,7 @@ namespace CppSharp
msg = string.Format(msg, args);
if (IsStartOfLine && !string.IsNullOrWhiteSpace(msg))
StringBuilder.Append(new string(' ', (int) CurrentIndent.Sum(u => u)));
StringBuilder.Append(new string(' ', (int) CurrentIndentation.Sum(u => u)));
if (msg.Length > 0)
IsStartOfLine = msg.EndsWith(Environment.NewLine);
@ -71,9 +71,9 @@ namespace CppSharp @@ -71,9 +71,9 @@ namespace CppSharp
public void WriteLineIndent(string msg, params object[] args)
{
PushIndent();
Indent();
WriteLine(msg, args);
PopIndent();
Unindent();
}
public void NewLine()
@ -100,25 +100,25 @@ namespace CppSharp @@ -100,25 +100,25 @@ namespace CppSharp
NeedsNewLine = false;
}
public void PushIndent(uint indent = DefaultIndent)
public void Indent(uint indentation = DefaultIndentation)
{
CurrentIndent.Push(indent);
CurrentIndentation.Push(indentation);
}
public void PopIndent()
public void Unindent()
{
CurrentIndent.Pop();
CurrentIndentation.Pop();
}
public void WriteStartBraceIndent()
public void WriteOpenBraceAndIndent()
{
WriteLine("{");
PushIndent();
Indent();
}
public void WriteCloseBraceIndent()
public void UnindentAndWriteCloseBrace()
{
PopIndent();
Unindent();
WriteLine("}");
}

4
src/Generator/Utils/Utils.cs

@ -135,9 +135,9 @@ namespace CppSharp @@ -135,9 +135,9 @@ namespace CppSharp
{
var array = new T[source.Count];
source.CopyTo(array, 0);
foreach (var indent in array.Reverse())
foreach (var element in array.Reverse())
{
destination.Push(indent);
destination.Push(element);
}
}
}

Loading…
Cancel
Save