Browse Source

Added suffixes to generated variables to avoid conflicts.

Signed-off-by: Dimitar Dobrev <dpldobrev@yahoo.com>
pull/48/head
Dimitar Dobrev 13 years ago
parent
commit
0ae181b2cf
  1. 6
      src/Generator/Generators/CSharp/CSharpMarshal.cs
  2. 4
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -59,6 +59,8 @@ namespace CppSharp.Generators.CSharp @@ -59,6 +59,8 @@ namespace CppSharp.Generators.CSharp
Context.MarshalToManaged = this;
}
public int VarSuffix { get; set; }
public static string QualifiedIdentifier(Declaration decl)
{
var names = new List<string> { decl.Name };
@ -207,6 +209,8 @@ namespace CppSharp.Generators.CSharp @@ -207,6 +209,8 @@ namespace CppSharp.Generators.CSharp
if (ctx.Kind == CSharpMarshalKind.NativeField)
{
string copy = Generator.GeneratedIdentifier("copy");
if (VarSuffix > 0)
copy += VarSuffix;
Context.SupportBefore.WriteLine(
"var {0} = new global::System.IntPtr(&{1});", copy, instance);
instance = copy;
@ -215,6 +219,8 @@ namespace CppSharp.Generators.CSharp @@ -215,6 +219,8 @@ namespace CppSharp.Generators.CSharp
if (@class.IsRefType)
{
var instanceName = Generator.GeneratedIdentifier("instance");
if (VarSuffix > 0)
instanceName += VarSuffix;
// Allocate memory for a new native object and call the ctor.
Context.SupportBefore.WriteLine("var {0} = Marshal.AllocHGlobal({1});",

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

@ -503,8 +503,9 @@ namespace CppSharp.Generators.CSharp @@ -503,8 +503,9 @@ namespace CppSharp.Generators.CSharp
GenerateStructMarshalingFields(@base.Class);
}
foreach (var field in @class.Fields)
for (int i = 0; i < @class.Fields.Count; i++)
{
var field = @class.Fields[i];
if (ASTUtils.CheckIgnoreField(field)) continue;
var nativeField = string.Format("{0}->{1}",
@ -519,6 +520,7 @@ namespace CppSharp.Generators.CSharp @@ -519,6 +520,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
marshal.VarSuffix = i;
field.Visit(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))

Loading…
Cancel
Save