Browse Source

Convert the C# backend to the new blocks system.

pull/13/merge
triton 12 years ago
parent
commit
f47dc5bb07
  1. 159
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

159
src/Generator/Generators/CSharp/CSharpTextTemplate.cs

@ -4,7 +4,6 @@ using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using CppSharp.AST; using CppSharp.AST;
using CppSharp.Passes;
namespace CppSharp.Generators.CSharp namespace CppSharp.Generators.CSharp
{ {
@ -65,7 +64,20 @@ namespace CppSharp.Generators.CSharp
public class CSharpBlockKind public class CSharpBlockKind
{ {
public const int Usings = BlockKind.LAST + 1;
public const int Namespace = BlockKind.LAST + 2;
public const int Enum = BlockKind.LAST + 3;
public const int Typedef = BlockKind.LAST + 4;
public const int Class = BlockKind.LAST + 5;
public const int InternalsClass = BlockKind.LAST + 6;
public const int InternalsClassMethod = BlockKind.LAST + 7;
public const int Functions = BlockKind.LAST + 8;
public const int Function = BlockKind.LAST + 9;
public const int Method = BlockKind.LAST + 10;
public const int Event = BlockKind.LAST + 11;
public const int Variable = BlockKind.LAST + 12;
public const int Property = BlockKind.LAST + 13;
public const int Field = BlockKind.LAST + 14;
} }
public class CSharpTextTemplate : Template public class CSharpTextTemplate : Template
@ -121,13 +133,15 @@ namespace CppSharp.Generators.CSharp
{ {
GenerateHeader(); GenerateHeader();
PushBlock(CSharpBlockKind.Usings);
WriteLine("using System;"); WriteLine("using System;");
WriteLine("using System.Runtime.InteropServices;"); WriteLine("using System.Runtime.InteropServices;");
WriteLine("using System.Security;"); WriteLine("using System.Security;");
NewLine(); PopBlock(NewLineKind.BeforeNextBlock);
if (Options.GenerateLibraryNamespace) if (Options.GenerateLibraryNamespace)
{ {
PushBlock(CSharpBlockKind.Namespace);
WriteLine("namespace {0}", SafeIdentifier(Driver.Options.OutputNamespace)); WriteLine("namespace {0}", SafeIdentifier(Driver.Options.OutputNamespace));
WriteStartBraceIndent(); WriteStartBraceIndent();
} }
@ -135,15 +149,20 @@ namespace CppSharp.Generators.CSharp
GenerateDeclContext(TranslationUnit); GenerateDeclContext(TranslationUnit);
if (Options.GenerateLibraryNamespace) if (Options.GenerateLibraryNamespace)
{
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
} }
public void GenerateHeader() public void GenerateHeader()
{ {
PushBlock(BlockKind.Header);
WriteLine("//----------------------------------------------------------------------------"); WriteLine("//----------------------------------------------------------------------------");
WriteLine("// This is autogenerated code by CppSharp."); WriteLine("// This is autogenerated code by CppSharp.");
WriteLine("// Do not edit this file or all your changes will be lost after re-generation."); WriteLine("// Do not edit this file or all your changes will be lost after re-generation.");
WriteLine("//----------------------------------------------------------------------------"); WriteLine("//----------------------------------------------------------------------------");
PopBlock();
} }
private void GenerateDeclContext(DeclarationContext context) private void GenerateDeclContext(DeclarationContext context)
@ -155,6 +174,7 @@ namespace CppSharp.Generators.CSharp
if (shouldGenerateNamespace) if (shouldGenerateNamespace)
{ {
PushBlock(CSharpBlockKind.Namespace);
WriteLine("namespace {0}", context.Name); WriteLine("namespace {0}", context.Name);
WriteStartBraceIndent(); WriteStartBraceIndent();
} }
@ -165,9 +185,7 @@ namespace CppSharp.Generators.CSharp
if (@enum.Ignore || @enum.IsIncomplete) if (@enum.Ignore || @enum.IsIncomplete)
continue; continue;
NewLineIfNeeded();
GenerateEnum(@enum); GenerateEnum(@enum);
NeedNewLine();
} }
// Generate all the typedef declarations. // Generate all the typedef declarations.
@ -175,12 +193,7 @@ namespace CppSharp.Generators.CSharp
{ {
if (typedef.Ignore) continue; if (typedef.Ignore) continue;
NewLineIfNeeded(); GenerateTypedef(typedef);
if (!GenerateTypedef(typedef))
continue;
NeedNewLine();
} }
// Generate all the struct/class declarations. // Generate all the struct/class declarations.
@ -192,18 +205,17 @@ namespace CppSharp.Generators.CSharp
if (@class.IsDependent) if (@class.IsDependent)
continue; continue;
NewLineIfNeeded();
GenerateClass(@class); GenerateClass(@class);
NeedNewLine();
} }
if (context.HasFunctions) if (context.HasFunctions)
{ {
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Functions);
WriteLine("public partial class {0}{1}", SafeIdentifier(Options.OutputNamespace), WriteLine("public partial class {0}{1}", SafeIdentifier(Options.OutputNamespace),
TranslationUnit.FileNameWithoutExtension); TranslationUnit.FileNameWithoutExtension);
WriteStartBraceIndent(); WriteStartBraceIndent();
PushBlock(CSharpBlockKind.InternalsClass);
GenerateClassInternalHead(); GenerateClassInternalHead();
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -212,39 +224,38 @@ namespace CppSharp.Generators.CSharp
{ {
if (function.Ignore) continue; if (function.Ignore) continue;
NewLineIfNeeded();
GenerateInternalFunction(function); GenerateInternalFunction(function);
NeedNewLine();
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
foreach (var function in context.Functions) foreach (var function in context.Functions)
{ {
if (function.Ignore) continue; if (function.Ignore) continue;
NewLineIfNeeded();
GenerateFunction(function); GenerateFunction(function);
NeedNewLine();
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
foreach (var @event in context.Events) foreach (var @event in context.Events)
{ {
if (@event.Ignore) continue; if (@event.Ignore) continue;
NewLineIfNeeded();
GenerateEvent(@event); GenerateEvent(@event);
NeedNewLine();
} }
foreach(var childNamespace in context.Namespaces) foreach(var childNamespace in context.Namespaces)
GenerateDeclContext(childNamespace); GenerateDeclContext(childNamespace);
if (shouldGenerateNamespace) if (shouldGenerateNamespace)
{
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
} }
public void GenerateDeclarationCommon(Declaration decl) public void GenerateDeclarationCommon(Declaration decl)
@ -288,6 +299,7 @@ namespace CppSharp.Generators.CSharp
if (@class.Ignore || @class.IsIncomplete) if (@class.Ignore || @class.IsIncomplete)
return; return;
PushBlock(CSharpBlockKind.Class);
GenerateDeclarationCommon(@class); GenerateDeclarationCommon(@class);
if (@class.IsUnion) if (@class.IsUnion)
@ -309,10 +321,10 @@ namespace CppSharp.Generators.CSharp
if (ShouldGenerateClassNativeField(@class)) if (ShouldGenerateClassNativeField(@class))
{ {
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Field);
WriteLine("public System.IntPtr {0} {{ get; protected set; }}", WriteLine("public System.IntPtr {0} {{ get; protected set; }}",
Helpers.InstanceIdentifier); Helpers.InstanceIdentifier);
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
GenerateClassConstructors(@class); GenerateClassConstructors(@class);
@ -323,23 +335,38 @@ namespace CppSharp.Generators.CSharp
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
public void GenerateClassInternals(Class @class) public void GenerateClassInternals(Class @class)
{ {
PushBlock(CSharpBlockKind.InternalsClass);
WriteLine("[StructLayout(LayoutKind.Explicit, Size = {0})]", WriteLine("[StructLayout(LayoutKind.Explicit, Size = {0})]",
@class.Layout.Size); @class.Layout.Size);
GenerateClassInternalHead(@class); GenerateClassInternalHead(@class);
WriteStartBraceIndent(); WriteStartBraceIndent();
ResetNewLine();
var typePrinter = TypePrinter as CSharpTypePrinter; var typePrinter = TypePrinter as CSharpTypePrinter;
typePrinter.PushContext(CSharpTypePrinterContextKind.Native); typePrinter.PushContext(CSharpTypePrinterContextKind.Native);
GenerateClassFields(@class, isInternal: true); GenerateClassFields(@class, isInternal: true);
var functions = GatherClassInternalFunctions(@class);
foreach (var function in functions)
{
GenerateInternalFunction(function);
}
typePrinter.PopContext();
WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
}
private static HashSet<Function> GatherClassInternalFunctions(Class @class)
{
var functions = new HashSet<Function>(); var functions = new HashSet<Function>();
foreach (var ctor in @class.Constructors) foreach (var ctor in @class.Constructors)
@ -378,17 +405,7 @@ namespace CppSharp.Generators.CSharp
if (prop.SetMethod != null) if (prop.SetMethod != null)
functions.Add(prop.SetMethod); functions.Add(prop.SetMethod);
} }
return functions;
foreach (var function in functions)
{
NewLineIfNeeded();
GenerateInternalFunction(function);
}
typePrinter.PopContext();
WriteCloseBraceIndent();
NeedNewLine();
} }
private void GenerateClassInternalHead(Class @class = null) private void GenerateClassInternalHead(Class @class = null)
@ -565,7 +582,7 @@ namespace CppSharp.Generators.CSharp
{ {
if (ASTUtils.CheckIgnoreField(@class, field)) continue; if (ASTUtils.CheckIgnoreField(@class, field)) continue;
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Field);
if (isInternal) if (isInternal)
{ {
@ -592,7 +609,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("public {0} {1};", field.Type, SafeIdentifier(field.Name)); WriteLine("public {0} {1};", field.Type, SafeIdentifier(field.Name));
} }
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
} }
@ -602,16 +619,17 @@ namespace CppSharp.Generators.CSharp
{ {
var @class = field.Class; var @class = field.Class;
PushBlock(CSharpBlockKind.Property);
GenerateDeclarationCommon(field); GenerateDeclarationCommon(field);
WriteLine("public {0} {1}", field.Type, SafeIdentifier(field.Name)); WriteLine("public {0} {1}", field.Type, SafeIdentifier(field.Name));
WriteStartBraceIndent(); WriteStartBraceIndent();
GeneratePropertyGetter(field, @class); GeneratePropertyGetter(field, @class);
NewLine();
GeneratePropertySetter(field, @class); GeneratePropertySetter(field, @class);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
private Tuple<string, string> GetDeclarationLibrarySymbol(IMangledDecl decl) private Tuple<string, string> GetDeclarationLibrarySymbol(IMangledDecl decl)
@ -638,6 +656,7 @@ namespace CppSharp.Generators.CSharp
private void GeneratePropertySetter<T>(T decl, Class @class) private void GeneratePropertySetter<T>(T decl, Class @class)
where T : Declaration, ITypedDecl where T : Declaration, ITypedDecl
{ {
PushBlock(CSharpBlockKind.Method);
WriteLine("set"); WriteLine("set");
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -685,11 +704,13 @@ namespace CppSharp.Generators.CSharp
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
private void GeneratePropertyGetter<T>(T decl, Class @class) private void GeneratePropertyGetter<T>(T decl, Class @class)
where T : Declaration, ITypedDecl where T : Declaration, ITypedDecl
{ {
PushBlock(CSharpBlockKind.Method);
WriteLine("get"); WriteLine("get");
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -758,6 +779,7 @@ namespace CppSharp.Generators.CSharp
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
public void GenerateClassMethods(Class @class) public void GenerateClassMethods(Class @class)
@ -777,16 +799,12 @@ namespace CppSharp.Generators.CSharp
continue; continue;
} }
NewLineIfNeeded();
GenerateMethod(method, @class); GenerateMethod(method, @class);
NeedNewLine();
} }
foreach (var method in staticMethods) foreach (var method in staticMethods)
{ {
NewLineIfNeeded();
GenerateMethod(method, @class); GenerateMethod(method, @class);
NeedNewLine();
} }
} }
@ -801,9 +819,7 @@ namespace CppSharp.Generators.CSharp
var type = variable.Type; var type = variable.Type;
NewLineIfNeeded();
GenerateVariable(@class, type, variable); GenerateVariable(@class, type, variable);
NeedNewLine();
} }
} }
@ -813,26 +829,25 @@ namespace CppSharp.Generators.CSharp
{ {
if (prop.Ignore) continue; if (prop.Ignore) continue;
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Property);
WriteLine("public {0} {1}", prop.Type, prop.Name); WriteLine("public {0} {1}", prop.Type, prop.Name);
WriteStartBraceIndent(); WriteStartBraceIndent();
GeneratePropertyGetter(prop.GetMethod, @class); GeneratePropertyGetter(prop.GetMethod, @class);
NeedNewLine();
if (prop.SetMethod != null) if (prop.SetMethod != null)
{ {
NewLineIfNeeded();
GeneratePropertySetter(prop.SetMethod, @class); GeneratePropertySetter(prop.SetMethod, @class);
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
} }
private void GenerateVariable(Class @class, AST.Type type, Variable variable) private void GenerateVariable(Class @class, AST.Type type, Variable variable)
{ {
PushBlock(CSharpBlockKind.Variable);
WriteLine("public static {0} {1}", type, variable.Name); WriteLine("public static {0} {1}", type, variable.Name);
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -842,6 +857,7 @@ namespace CppSharp.Generators.CSharp
GeneratePropertySetter(variable, @class); GeneratePropertySetter(variable, @class);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
#region Events #region Events
@ -852,6 +868,7 @@ namespace CppSharp.Generators.CSharp
private void GenerateEvent(Event @event) private void GenerateEvent(Event @event)
{ {
PushBlock(CSharpBlockKind.Event);
TypePrinter.PushContext(CSharpTypePrinterContextKind.Native); TypePrinter.PushContext(CSharpTypePrinterContextKind.Native);
var args = TypePrinter.VisitParameters(@event.Parameters, hasNames: true); var args = TypePrinter.VisitParameters(@event.Parameters, hasNames: true);
TypePrinter.PopContext(); TypePrinter.PopContext();
@ -878,7 +895,7 @@ namespace CppSharp.Generators.CSharp
NewLine(); NewLine();
GenerateEventRaiseWrapper(@event); GenerateEventRaiseWrapper(@event);
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
private void GenerateEventAdd(Event @event) private void GenerateEventAdd(Event @event)
@ -956,8 +973,6 @@ namespace CppSharp.Generators.CSharp
public void GenerateClassConstructors(Class @class) public void GenerateClassConstructors(Class @class)
{ {
NewLineIfNeeded();
// Output a default constructor that takes the native pointer. // Output a default constructor that takes the native pointer.
GenerateNativeConstructor(@class); GenerateNativeConstructor(@class);
@ -966,9 +981,7 @@ namespace CppSharp.Generators.CSharp
if (ASTUtils.CheckIgnoreMethod(@class, ctor)) if (ASTUtils.CheckIgnoreMethod(@class, ctor))
continue; continue;
NewLineIfNeeded();
GenerateMethod(ctor, @class); GenerateMethod(ctor, @class);
NeedNewLine();
} }
if (@class.IsRefType) if (@class.IsRefType)
@ -982,7 +995,7 @@ namespace CppSharp.Generators.CSharp
// Generate the IDispose Dispose() method. // Generate the IDispose Dispose() method.
if (!hasBaseClass) if (!hasBaseClass)
{ {
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Method);
WriteLine("public void Dispose()"); WriteLine("public void Dispose()");
WriteStartBraceIndent(); WriteStartBraceIndent();
@ -990,11 +1003,11 @@ namespace CppSharp.Generators.CSharp
WriteLine("GC.SuppressFinalize(this);"); WriteLine("GC.SuppressFinalize(this);");
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
// Generate Dispose(bool) method // Generate Dispose(bool) method
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Method);
Write("protected "); Write("protected ");
Write(hasBaseClass ? "override " : "virtual "); Write(hasBaseClass ? "override " : "virtual ");
@ -1009,25 +1022,28 @@ namespace CppSharp.Generators.CSharp
WriteLine("base.Dispose(disposing);"); WriteLine("base.Dispose(disposing);");
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
private void GenerateNativeConstructor(Class @class) private void GenerateNativeConstructor(Class @class)
{ {
PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}({1}.Internal* native)", SafeIdentifier(@class.Name), WriteLine("internal {0}({1}.Internal* native)", SafeIdentifier(@class.Name),
@class.Name); @class.Name);
WriteLineIndent(": this(new System.IntPtr(native))"); WriteLineIndent(": this(new System.IntPtr(native))");
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NewLine(); PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}({1}.Internal native)", SafeIdentifier(@class.Name), WriteLine("internal {0}({1}.Internal native)", SafeIdentifier(@class.Name),
@class.Name); @class.Name);
WriteLineIndent(": this(&native)"); WriteLineIndent(": this(&native)");
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NewLine(); PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(CSharpBlockKind.Method);
WriteLine("internal {0}(System.IntPtr native)", SafeIdentifier(@class.Name)); WriteLine("internal {0}(System.IntPtr native)", SafeIdentifier(@class.Name));
var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType; var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType;
@ -1049,23 +1065,24 @@ namespace CppSharp.Generators.CSharp
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
if (@class.IsValueType) if (@class.IsValueType)
{ {
NewLineIfNeeded(); PushBlock(CSharpBlockKind.Method);
WriteLine("internal Internal ToInternal()"); WriteLine("internal Internal ToInternal()");
WriteStartBraceIndent(); WriteStartBraceIndent();
GenerateStructInternalMarshaling(@class); GenerateStructInternalMarshaling(@class);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NewLine(); PopBlock(NewLineKind.BeforeNextBlock);
PushBlock(CSharpBlockKind.Method);
WriteLine("internal void FromInternal(Internal* native)"); WriteLine("internal void FromInternal(Internal* native)");
WriteStartBraceIndent(); WriteStartBraceIndent();
WriteLine("var {0} = {1};", Helpers.GeneratedIdentifier("ptr"), "native"); WriteLine("var {0} = {1};", Helpers.GeneratedIdentifier("ptr"), "native");
GenerateStructMarshalingFields(@class); GenerateStructMarshalingFields(@class);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
} }
@ -1099,6 +1116,7 @@ namespace CppSharp.Generators.CSharp
public void GenerateFunction(Function function) public void GenerateFunction(Function function)
{ {
PushBlock(CSharpBlockKind.Function);
GenerateDeclarationCommon(function); GenerateDeclarationCommon(function);
var functionName = GetFunctionIdentifier(function); var functionName = GetFunctionIdentifier(function);
@ -1110,10 +1128,12 @@ namespace CppSharp.Generators.CSharp
GenerateInternalFunctionCall(function); GenerateInternalFunctionCall(function);
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
public void GenerateMethod(Method method, Class @class) public void GenerateMethod(Method method, Class @class)
{ {
PushBlock(CSharpBlockKind.Method);
GenerateDeclarationCommon(method); GenerateDeclarationCommon(method);
Write("public "); Write("public ");
@ -1173,6 +1193,7 @@ namespace CppSharp.Generators.CSharp
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
private static string GetOperatorOverloadPair(CXXOperatorKind kind) private static string GetOperatorOverloadPair(CXXOperatorKind kind)
@ -1528,14 +1549,17 @@ namespace CppSharp.Generators.CSharp
if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void) if (typedef.Type.IsPointerToPrimitiveType(PrimitiveType.Void)
|| typedef.Type.IsPointerTo<TagType>(out tag)) || typedef.Type.IsPointerTo<TagType>(out tag))
{ {
PushBlock(CSharpBlockKind.Typedef);
WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }"); WriteLine("public class " + SafeIdentifier(typedef.Name) + @" { }");
PopBlock(NewLineKind.BeforeNextBlock);
} }
else if (typedef.Type.IsPointerTo<FunctionType>(out function)) else if (typedef.Type.IsPointerTo<FunctionType>(out function))
{ {
PushBlock(CSharpBlockKind.Typedef);
WriteLine("public {0};", WriteLine("public {0};",
string.Format(TypePrinter.VisitDelegate(function).Type, string.Format(TypePrinter.VisitDelegate(function).Type,
SafeIdentifier(typedef.Name))); SafeIdentifier(typedef.Name)));
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
} }
else if (typedef.Type.IsEnumType()) else if (typedef.Type.IsEnumType())
{ {
@ -1554,6 +1578,8 @@ namespace CppSharp.Generators.CSharp
public void GenerateEnum(Enumeration @enum) public void GenerateEnum(Enumeration @enum)
{ {
if (@enum.Ignore) return; if (@enum.Ignore) return;
PushBlock(CSharpBlockKind.Enum);
GenerateDeclarationCommon(@enum); GenerateDeclarationCommon(@enum);
if (@enum.IsFlags) if (@enum.IsFlags)
@ -1585,6 +1611,8 @@ namespace CppSharp.Generators.CSharp
NewLine(); NewLine();
} }
WriteCloseBraceIndent(); WriteCloseBraceIndent();
PopBlock(NewLineKind.BeforeNextBlock);
} }
public static string GetOperatorIdentifier(CXXOperatorKind kind, public static string GetOperatorIdentifier(CXXOperatorKind kind,
@ -1732,6 +1760,7 @@ namespace CppSharp.Generators.CSharp
if (!function.IsProcessed || function.ExplicityIgnored) if (!function.IsProcessed || function.ExplicityIgnored)
return; return;
PushBlock(CSharpBlockKind.InternalsClassMethod);
GenerateDeclarationCommon(function); GenerateDeclarationCommon(function);
WriteLine("[SuppressUnmanagedCodeSecurity]"); WriteLine("[SuppressUnmanagedCodeSecurity]");
@ -1800,7 +1829,7 @@ namespace CppSharp.Generators.CSharp
WriteLine("public static extern {0} {1}({2});", retType, WriteLine("public static extern {0} {1}({2});", retType,
GetFunctionIdentifier(function), GetFunctionIdentifier(function),
string.Join(", ", @params)); string.Join(", ", @params));
NeedNewLine(); PopBlock(NewLineKind.BeforeNextBlock);
typePrinter.PopContext(); typePrinter.PopContext();
} }

Loading…
Cancel
Save