From cd8d893601025eb61ae43721ddeaf55f2d31a0db Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Aug 2013 18:47:49 +0300 Subject: [PATCH 01/15] Fixed the class containing context functions to be unsafe. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 97a758ea..b7c74d81 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -216,7 +216,7 @@ namespace CppSharp.Generators.CSharp if (context.HasFunctions) { PushBlock(CSharpBlockKind.Functions); - WriteLine("public partial class {0}{1}", SafeIdentifier(Options.OutputNamespace), + WriteLine("public unsafe partial class {0}{1}", SafeIdentifier(Options.OutputNamespace), TranslationUnit.FileNameWithoutExtension); WriteStartBraceIndent(); From 712a3904a68201758330dd8e8e0dbb9d3fc2e599 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Aug 2013 22:56:51 +0300 Subject: [PATCH 02/15] Removed the "protected" modifier of setters when in a structure. Changed a generated local variable to a non-conflicting name. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index b7c74d81..40e1dfb0 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -324,8 +324,8 @@ namespace CppSharp.Generators.CSharp if (ShouldGenerateClassNativeField(@class)) { PushBlock(CSharpBlockKind.Field); - WriteLine("public global::System.IntPtr {0} {{ get; protected set; }}", - Helpers.InstanceIdentifier); + WriteLine("public global::System.IntPtr {0} {{ get; {1} set; }}", + Helpers.InstanceIdentifier, @class.IsValueType ? "private" : "protected"); PopBlock(NewLineKind.BeforeNextBlock); } @@ -1636,7 +1636,7 @@ namespace CppSharp.Generators.CSharp Class retClass = null; hiddenParam.Type.Desugar().IsTagDecl(out retClass); - WriteLine("var ret = new {0}.Internal();", retClass.OriginalName); + WriteLine("var __ret = new {0}.Internal();", retClass.OriginalName); } var names = new List(); @@ -1653,7 +1653,7 @@ namespace CppSharp.Generators.CSharp if (function.HasHiddenStructParameter) { - var name = string.Format("new IntPtr(&ret)"); + var name = string.Format("new IntPtr(&__ret)"); names.Insert(0, name); } @@ -1672,7 +1672,7 @@ namespace CppSharp.Generators.CSharp } if (needsReturn && !function.HasHiddenStructParameter) - Write("var ret = "); + Write("var __ret = "); WriteLine("{0}({1});", functionName, string.Join(", ", names)); @@ -1703,8 +1703,8 @@ namespace CppSharp.Generators.CSharp { var ctx = new CSharpMarshalContext(Driver) { - ArgName = "ret", - ReturnVarName = "ret", + ArgName = "__ret", + ReturnVarName = "__ret", ReturnType = retType }; From f163ceac63f17617b9a41060efe436c6dd364fbc Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Aug 2013 22:58:21 +0300 Subject: [PATCH 03/15] Replaced an expression with a variable so that the & operator works. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 545cd683..0d420440 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -206,7 +206,9 @@ namespace CppSharp.Generators.CSharp string instance = Context.ReturnVarName; if (ctx.Kind == CSharpMarshalKind.NativeField) { - instance = string.Format("new global::System.IntPtr(&{0})", instance); + Context.SupportBefore.WriteLine( + "var __copy = new global::System.IntPtr(&{0});", instance); + instance = "__copy"; } if (@class.IsRefType) From 64fb8ecbc07b727859805b2daf5c54210b90c030 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Mon, 19 Aug 2013 23:16:30 +0300 Subject: [PATCH 04/15] Used the qualified identifier when allocating return values, to handle nested types. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 40e1dfb0..d1a8309a 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -537,7 +537,7 @@ namespace CppSharp.Generators.CSharp { var marshalVar = Helpers.GeneratedIdentifier("native"); - WriteLine("var {0} = new {1}.Internal();", marshalVar, @class.Name); + WriteLine("var {0} = new {1}.Internal();", marshalVar, QualifiedIdentifier(@class)); GenerateStructInternalMarshalingFields(@class, marshalVar); WriteLine("return {0};", marshalVar); @@ -1636,7 +1636,7 @@ namespace CppSharp.Generators.CSharp Class retClass = null; hiddenParam.Type.Desugar().IsTagDecl(out retClass); - WriteLine("var __ret = new {0}.Internal();", retClass.OriginalName); + WriteLine("var __ret = new {0}.Internal();", QualifiedIdentifier(retClass)); } var names = new List(); From 01d3779e2b88f6b646658724fc1bbb742158d873 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 00:29:13 +0300 Subject: [PATCH 05/15] Corrected the generation of the native constructor when in a structure. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index d1a8309a..25a04d1b 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1362,7 +1362,8 @@ namespace CppSharp.Generators.CSharp PopBlock(NewLineKind.BeforeNextBlock); PushBlock(CSharpBlockKind.Method); - WriteLine("internal {0}(global::System.IntPtr native)", SafeIdentifier(@class.Name)); + WriteLine("internal {0}(global::System.IntPtr native){1}", SafeIdentifier(@class.Name), + @class.IsValueType ? " : this()" : string.Empty); var hasBaseClass = @class.HasBaseClass && @class.BaseClass.IsRefType; if (hasBaseClass) From 8312ff0a20bd6e966e26d0c384a2ad1e5cd285e3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 00:30:26 +0300 Subject: [PATCH 06/15] Removed the hard-coded "ret" variable. Signed-off-by: Dimitar Dobrev --- .../Generators/CSharp/CSharpTextTemplate.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 25a04d1b..b73f595f 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -28,7 +28,7 @@ namespace CppSharp.Generators.CSharp public static string GeneratedIdentifier(string id) { - return "_" + id; + return "__" + id; } public static string SafeIdentifier(string id) @@ -1637,7 +1637,7 @@ namespace CppSharp.Generators.CSharp Class retClass = null; hiddenParam.Type.Desugar().IsTagDecl(out retClass); - WriteLine("var __ret = new {0}.Internal();", QualifiedIdentifier(retClass)); + WriteLine("var {0} = new {1}.Internal();", GeneratedIdentifier("ret"), QualifiedIdentifier(retClass)); } var names = new List(); @@ -1654,7 +1654,7 @@ namespace CppSharp.Generators.CSharp if (function.HasHiddenStructParameter) { - var name = string.Format("new IntPtr(&__ret)"); + var name = string.Format("new IntPtr(&{0})", GeneratedIdentifier("ret")); names.Insert(0, name); } @@ -1673,7 +1673,7 @@ namespace CppSharp.Generators.CSharp } if (needsReturn && !function.HasHiddenStructParameter) - Write("var __ret = "); + Write("var {0} = ", GeneratedIdentifier("ret")); WriteLine("{0}({1});", functionName, string.Join(", ", names)); @@ -1704,8 +1704,8 @@ namespace CppSharp.Generators.CSharp { var ctx = new CSharpMarshalContext(Driver) { - ArgName = "__ret", - ReturnVarName = "__ret", + ArgName = GeneratedIdentifier("ret"), + ReturnVarName = GeneratedIdentifier("ret"), ReturnType = retType }; From 0c1240d97ebda02cf919cb850b7461718ce44152 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 13:46:22 +0300 Subject: [PATCH 07/15] Added a compilation test for a free function with a class parameter named "ret". Signed-off-by: Dimitar Dobrev --- tests/Basic/Basic.cpp | 7 ++++++- tests/Basic/Basic.h | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/Basic/Basic.cpp b/tests/Basic/Basic.cpp index 99ea4654..4b01f651 100644 --- a/tests/Basic/Basic.cpp +++ b/tests/Basic/Basic.cpp @@ -69,4 +69,9 @@ Foo Hello::RetFoo(int a, float b) int Hello::RetEnum(Enum e) { return (int)e; -} \ No newline at end of file +} + +int unsafeFunction(const Bar& ret) +{ + return ret.A; +} diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 4a464848..e7030bc4 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -60,4 +60,6 @@ public: int AddBar2(Bar2); int RetEnum(Enum); -}; \ No newline at end of file +}; + +int unsafeFunction(const Bar& ret); From ca0e67529e51afb1508771feee8287a4f25b8964 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 17:18:29 +0300 Subject: [PATCH 08/15] Added a compilation test for the class member of a nested type - that is, when &IntPtr code is generated. Signed-off-by: Dimitar Dobrev --- tests/Basic/Basic.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index e7030bc4..bf8c2ebd 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -15,6 +15,10 @@ public: class DLL_API Foo2 : public Foo { + struct Copy { + Foo A; + }* copy; + public: int C; From bf2dfd375c124baf603ab7b54e77eeb204f27269 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 18:19:26 +0300 Subject: [PATCH 09/15] Fixed the "ret" conflict in the CLI back-end as well. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CLI/CLISourcesTemplate.cs | 6 +++--- tests/Basic/Basic.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Generator/Generators/CLI/CLISourcesTemplate.cs b/src/Generator/Generators/CLI/CLISourcesTemplate.cs index 1a13b35e..07f127ec 100644 --- a/src/Generator/Generators/CLI/CLISourcesTemplate.cs +++ b/src/Generator/Generators/CLI/CLISourcesTemplate.cs @@ -740,7 +740,7 @@ namespace CppSharp.Generators.CLI var @params = GenerateFunctionParamsMarshal(function.Parameters, function); if (needsReturn) - Write("auto {0}ret = ",(function.ReturnType.Type.IsReference())? "&": string.Empty); + Write("auto {0}__ret = ",(function.ReturnType.Type.IsReference())? "&": string.Empty); if (!IsNativeFunctionOrStaticMethod(function)) { @@ -799,8 +799,8 @@ namespace CppSharp.Generators.CLI { var ctx = new MarshalContext(Driver) { - ArgName = "ret", - ReturnVarName = "ret", + ArgName = "__ret", + ReturnVarName = "__ret", ReturnType = retType }; diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index bf8c2ebd..1639627f 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -66,4 +66,4 @@ public: int RetEnum(Enum); }; -int unsafeFunction(const Bar& ret); +int DLL_API unsafeFunction(const Bar& ret); From 7971d0a33eec378a13e68f80f32b0b618eb21018 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 18:22:42 +0300 Subject: [PATCH 10/15] Fixed the generation of unions by considering all unions non-reference types. Signed-off-by: Dimitar Dobrev --- src/AST/Class.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AST/Class.cs b/src/AST/Class.cs index aa756db2..cce81845 100644 --- a/src/AST/Class.cs +++ b/src/AST/Class.cs @@ -145,7 +145,7 @@ namespace CppSharp.AST public bool IsRefType { - get { return Type == ClassType.RefType; } + get { return Type == ClassType.RefType && !IsUnion; } } public IEnumerable Constructors From 3caecadbbe85378e36fa3dff164fb2d2de286de3 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 18:25:57 +0300 Subject: [PATCH 11/15] Added a union to the test header to check for compilable generated union wrappers. Signed-off-by: Dimitar Dobrev --- tests/Basic/Basic.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Basic/Basic.h b/tests/Basic/Basic.h index 1639627f..079be9bd 100644 --- a/tests/Basic/Basic.h +++ b/tests/Basic/Basic.h @@ -46,6 +46,11 @@ enum Enum class DLL_API Hello { + union { + int i; + float b; + }; + public: Hello (); From cd65094792bf2dff4898f893805d997f9c63d982 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 18:42:00 +0300 Subject: [PATCH 12/15] Fixed the generation of virtual tables to use the new format of internal generated identifiers. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpTextTemplate.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index b73f595f..9b4f6898 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -1377,7 +1377,7 @@ namespace CppSharp.Generators.CSharp { WriteLine("{0} = native;", Helpers.InstanceIdentifier); if (Options.GenerateVirtualTables && @class.IsDynamic) - WriteLine("SetupVTables(_Instance);"); + WriteLine("SetupVTables({0});", Helpers.GeneratedIdentifier("Instance")); } } else @@ -1581,7 +1581,7 @@ namespace CppSharp.Generators.CSharp GenerateFunctionParams(@params); WriteLine(");"); if (Options.GenerateVirtualTables && @class.IsDynamic) - WriteLine("SetupVTables(_Instance);"); + WriteLine("SetupVTables({0});", Helpers.GeneratedIdentifier("Instance")); } public void GenerateInternalFunctionCall(Function function, From fe1387331d19fc799ed2b123c32781eb681a2f22 Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 19:23:03 +0300 Subject: [PATCH 13/15] Removed a hard-coded "__". Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CSharp/CSharpMarshal.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 0d420440..737cae62 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -206,9 +206,10 @@ namespace CppSharp.Generators.CSharp string instance = Context.ReturnVarName; if (ctx.Kind == CSharpMarshalKind.NativeField) { + string copy = Helpers.GeneratedIdentifier("copy"); Context.SupportBefore.WriteLine( - "var __copy = new global::System.IntPtr(&{0});", instance); - instance = "__copy"; + "var {0} = new global::System.IntPtr(&{1});", copy, instance); + instance = copy; } if (@class.IsRefType) From 5208fafef791493b4749a67bf9d47e5d88d892df Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Tue, 20 Aug 2013 19:28:03 +0300 Subject: [PATCH 14/15] Moved GeneratedIdentifier to the base Generator so that the former is available to all back-ends. Signed-off-by: Dimitar Dobrev --- src/Generator/Generators/CLI/CLIMarshal.cs | 2 +- .../Generators/CSharp/CSharpMarshal.cs | 12 +++--- .../Generators/CSharp/CSharpTextTemplate.cs | 41 ++++++++----------- src/Generator/Generators/Generator.cs | 5 +++ .../Passes/CheckOperatorsOverloads.cs | 3 +- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Generator/Generators/CLI/CLIMarshal.cs b/src/Generator/Generators/CLI/CLIMarshal.cs index 6e1e6d90..e9634456 100644 --- a/src/Generator/Generators/CLI/CLIMarshal.cs +++ b/src/Generator/Generators/CLI/CLIMarshal.cs @@ -180,7 +180,7 @@ namespace CppSharp.Generators.CLI if (@class.IsRefType) { - var name = Helpers.GeneratedIdentifier(Context.ReturnVarName); + var name = Generator.GeneratedIdentifier(Context.ReturnVarName); Context.SupportBefore.WriteLine("auto {0} = new ::{1}({2});", name, @class.QualifiedOriginalName, Context.ReturnVarName); instance = name; diff --git a/src/Generator/Generators/CSharp/CSharpMarshal.cs b/src/Generator/Generators/CSharp/CSharpMarshal.cs index 737cae62..08de1719 100644 --- a/src/Generator/Generators/CSharp/CSharpMarshal.cs +++ b/src/Generator/Generators/CSharp/CSharpMarshal.cs @@ -185,7 +185,7 @@ namespace CppSharp.Generators.CSharp FunctionType function; if (decl.Type.IsPointerTo(out function)) { - var ptrName = Helpers.GeneratedIdentifier("ptr") + + var ptrName = Generator.GeneratedIdentifier("ptr") + Context.ParameterIndex; Context.SupportBefore.WriteLine("var {0} = {1};", ptrName, @@ -206,7 +206,7 @@ namespace CppSharp.Generators.CSharp string instance = Context.ReturnVarName; if (ctx.Kind == CSharpMarshalKind.NativeField) { - string copy = Helpers.GeneratedIdentifier("copy"); + string copy = Generator.GeneratedIdentifier("copy"); Context.SupportBefore.WriteLine( "var {0} = new global::System.IntPtr(&{1});", copy, instance); instance = copy; @@ -214,7 +214,7 @@ namespace CppSharp.Generators.CSharp if (@class.IsRefType) { - var instanceName = Helpers.GeneratedIdentifier("instance"); + var instanceName = Generator.GeneratedIdentifier("instance"); // Allocate memory for a new native object and call the ctor. Context.SupportBefore.WriteLine("var {0} = Marshal.AllocHGlobal({1});", @@ -366,17 +366,17 @@ namespace CppSharp.Generators.CSharp if (Context.Parameter.Usage == ParameterUsage.Out) { Context.SupportBefore.WriteLine("var {0} = new {1}.Internal();", - Helpers.GeneratedIdentifier(Context.ArgName), @class.Name); + Generator.GeneratedIdentifier(Context.ArgName), @class.Name); } else { Context.SupportBefore.WriteLine("var {0} = {1}.ToInternal();", - Helpers.GeneratedIdentifier(Context.ArgName), + Generator.GeneratedIdentifier(Context.ArgName), Helpers.SafeIdentifier(Context.Parameter.Name)); } Context.Return.Write("new global::System.IntPtr(&{0})", - Helpers.GeneratedIdentifier(Context.ArgName)); + Generator.GeneratedIdentifier(Context.ArgName)); return true; } diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 9b4f6898..2e40d40b 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -26,11 +26,6 @@ namespace CppSharp.Generators.CSharp "void", "partial", "yield", "where" }; - public static string GeneratedIdentifier(string id) - { - return "__" + id; - } - public static string SafeIdentifier(string id) { id = new string(((IEnumerable)id) @@ -59,7 +54,7 @@ namespace CppSharp.Generators.CSharp public static string InstanceIdentifier { - get { return GeneratedIdentifier("Instance"); } + get { return Generator.GeneratedIdentifier("Instance"); } } } @@ -124,7 +119,7 @@ namespace CppSharp.Generators.CSharp public static string GeneratedIdentifier(string id) { - return Helpers.GeneratedIdentifier(id); + return Generator.GeneratedIdentifier(id); } public static string SafeIdentifier(string id) @@ -513,7 +508,7 @@ namespace CppSharp.Generators.CSharp if (ASTUtils.CheckIgnoreField(field)) continue; var nativeField = string.Format("{0}->{1}", - Helpers.GeneratedIdentifier("ptr"), field.OriginalName); + Generator.GeneratedIdentifier("ptr"), field.OriginalName); var ctx = new CSharpMarshalContext(Driver) { @@ -535,7 +530,7 @@ namespace CppSharp.Generators.CSharp private void GenerateStructInternalMarshaling(Class @class) { - var marshalVar = Helpers.GeneratedIdentifier("native"); + var marshalVar = Generator.GeneratedIdentifier("native"); WriteLine("var {0} = new {1}.Internal();", marshalVar, QualifiedIdentifier(@class)); GenerateStructInternalMarshalingFields(@class, marshalVar); @@ -746,7 +741,7 @@ namespace CppSharp.Generators.CSharp var field = decl as Field; WriteLine("var {0} = (Internal*){1}.ToPointer();", - Helpers.GeneratedIdentifier("ptr"), Helpers.InstanceIdentifier); + Generator.GeneratedIdentifier("ptr"), Helpers.InstanceIdentifier); var marshal = new CSharpMarshalManagedToNativePrinter(ctx); param.Visit(marshal); @@ -754,7 +749,7 @@ namespace CppSharp.Generators.CSharp if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore)) Write(marshal.Context.SupportBefore); - Write("{0}->{1} = {2}", Helpers.GeneratedIdentifier("ptr"), + Write("{0}->{1} = {2}", Generator.GeneratedIdentifier("ptr"), Helpers.SafeIdentifier(field.OriginalName), marshal.Context.Return); WriteLine(";"); @@ -781,13 +776,13 @@ namespace CppSharp.Generators.CSharp var field = decl as Field; WriteLine("var {0} = (Internal*){1}.ToPointer();", - Helpers.GeneratedIdentifier("ptr"), Helpers.InstanceIdentifier); + Generator.GeneratedIdentifier("ptr"), Helpers.InstanceIdentifier); var ctx = new CSharpMarshalContext(Driver) { Kind = CSharpMarshalKind.NativeField, ArgName = decl.Name, - ReturnVarName = string.Format("{0}->{1}", Helpers.GeneratedIdentifier("ptr"), + ReturnVarName = string.Format("{0}->{1}", Generator.GeneratedIdentifier("ptr"), Helpers.SafeIdentifier(field.OriginalName)), ReturnType = decl.QualifiedType }; @@ -810,7 +805,7 @@ namespace CppSharp.Generators.CSharp var location = string.Format("CppSharp.SymbolResolver.ResolveSymbol(\"{0}\", \"{1}\")", libSymbol.Item1, libSymbol.Item2); - WriteLine("var {0} = ({1}*){2};", Helpers.GeneratedIdentifier("ptr"), + WriteLine("var {0} = ({1}*){2};", Generator.GeneratedIdentifier("ptr"), @var.Type, location); TypePrinter.PopContext(); @@ -818,7 +813,7 @@ namespace CppSharp.Generators.CSharp var ctx = new CSharpMarshalContext(Driver) { ArgName = decl.Name, - ReturnVarName = "*" + Helpers.GeneratedIdentifier("ptr"), + ReturnVarName = "*" + Generator.GeneratedIdentifier("ptr"), ReturnType = new QualifiedType(var.Type) }; @@ -1185,7 +1180,7 @@ namespace CppSharp.Generators.CSharp var args = TypePrinter.VisitParameters(@event.Parameters, hasNames: true); TypePrinter.PopContext(); - delegateInstance = Helpers.GeneratedIdentifier(@event.OriginalName); + delegateInstance = Generator.GeneratedIdentifier(@event.OriginalName); delegateName = delegateInstance + "Delegate"; delegateRaise = delegateInstance + "RaiseInstance"; @@ -1221,7 +1216,7 @@ namespace CppSharp.Generators.CSharp WriteLine("{0} = new {1}(_{2}Raise);", delegateRaise, delegateName, @event.Name); WriteLine("var {0} = Marshal.GetFunctionPointerForDelegate({1}).ToPointer();", - Helpers.GeneratedIdentifier("ptr"), delegateInstance); + Generator.GeneratedIdentifier("ptr"), delegateInstance); // Call type map here. @@ -1377,13 +1372,13 @@ namespace CppSharp.Generators.CSharp { WriteLine("{0} = native;", Helpers.InstanceIdentifier); if (Options.GenerateVirtualTables && @class.IsDynamic) - WriteLine("SetupVTables({0});", Helpers.GeneratedIdentifier("Instance")); + WriteLine("SetupVTables({0});", Generator.GeneratedIdentifier("Instance")); } } else { WriteLine("var {0} = (Internal*){1}.ToPointer();", - Helpers.GeneratedIdentifier("ptr"), "native"); + Generator.GeneratedIdentifier("ptr"), "native"); GenerateStructMarshalingFields(@class); } @@ -1402,7 +1397,7 @@ namespace CppSharp.Generators.CSharp PushBlock(CSharpBlockKind.Method); WriteLine("internal void FromInternal(Internal* native)"); WriteStartBraceIndent(); - WriteLine("var {0} = {1};", Helpers.GeneratedIdentifier("ptr"), "native"); + WriteLine("var {0} = {1};", Generator.GeneratedIdentifier("ptr"), "native"); GenerateStructMarshalingFields(@class); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); @@ -1581,7 +1576,7 @@ namespace CppSharp.Generators.CSharp GenerateFunctionParams(@params); WriteLine(");"); if (Options.GenerateVirtualTables && @class.IsDynamic) - WriteLine("SetupVTables({0});", Helpers.GeneratedIdentifier("Instance")); + WriteLine("SetupVTables({0});", Generator.GeneratedIdentifier("Instance")); } public void GenerateInternalFunctionCall(Function function, @@ -1669,7 +1664,7 @@ namespace CppSharp.Generators.CSharp //WriteLine("fixed({0}* {1} = &this)", @class.QualifiedName, // GeneratedIdentifier("instance")); //WriteStartBraceIndent(); - WriteLine("var {0} = ToInternal();", Helpers.GeneratedIdentifier("instance")); + WriteLine("var {0} = ToInternal();", Generator.GeneratedIdentifier("instance")); } if (needsReturn && !function.HasHiddenStructParameter) @@ -1697,7 +1692,7 @@ namespace CppSharp.Generators.CSharp if (needsFixedThis) { // WriteCloseBraceIndent(); - WriteLine("FromInternal(&{0});", Helpers.GeneratedIdentifier("instance")); + WriteLine("FromInternal(&{0});", Generator.GeneratedIdentifier("instance")); } if (needsReturn) diff --git a/src/Generator/Generators/Generator.cs b/src/Generator/Generators/Generator.cs index 87a05003..9f078639 100644 --- a/src/Generator/Generators/Generator.cs +++ b/src/Generator/Generators/Generator.cs @@ -98,5 +98,10 @@ namespace CppSharp.Generators /// Generates the outputs for a given translation unit. /// public abstract List