Browse Source

Fix the GetFieldLocation method to take a type printing context kind and fix the code to pass the correct kind in each instance where its called.

pull/1/head
triton 13 years ago
parent
commit
383a4f73fe
  1. 23
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -357,11 +357,13 @@ namespace Cxxi.Generators.CSharp
{ {
if (CheckIgnoreField(@class, field)) continue; if (CheckIgnoreField(@class, field)) continue;
var nativeField = string.Format("*({0}*) (native + {1})", bool isRefClass;
field.Type, field.OffsetInBytes); var nativeField = GetFieldLocation(field, "native",
CSharpTypePrinterContextKind.ManagedPointer, out isRefClass);
var ctx = new CSharpMarshalContext(Driver) var ctx = new CSharpMarshalContext(Driver)
{ {
Kind = CSharpMarshalKind.NativeField,
ArgName = field.Name, ArgName = field.Name,
ReturnVarName = nativeField, ReturnVarName = nativeField,
ReturnType = field.Type ReturnType = field.Type
@ -493,12 +495,16 @@ namespace Cxxi.Generators.CSharp
} }
private string GetFieldLocation(Field field, string instance, private string GetFieldLocation(Field field, string instance,
out bool isRefClass) CSharpTypePrinterContextKind kind, out bool isRefClass)
{ {
isRefClass = false; isRefClass = false;
var typePrinter = TypePrinter as CSharpTypePrinter;
typePrinter.PushContext(kind);
var type = field.Type.Visit(typePrinter);
typePrinter.PopContext();
var fieldType = field.Type.Desugar(); var fieldType = field.Type.Desugar();
var type = field.Type.ToString() + "*";
Class fieldClass; Class fieldClass;
if (fieldType.IsTagDecl(out fieldClass) && fieldClass.IsRefType) if (fieldType.IsTagDecl(out fieldClass) && fieldClass.IsRefType)
@ -515,8 +521,11 @@ namespace Cxxi.Generators.CSharp
if (isRefClass) if (isRefClass)
type = "void**"; type = "void**";
var location = string.Format("*({0}) ({1} + {2})", var location = string.Format("({0} + {1})", instance,
type, instance, field.OffsetInBytes); field.OffsetInBytes);
if (type.TypeMap == null)
location = string.Format("*({0}*){1}", type, location);
return location; return location;
} }
@ -548,7 +557,7 @@ namespace Cxxi.Generators.CSharp
var field = decl as Field; var field = decl as Field;
var location = GetFieldLocation(field, "Instance", var location = GetFieldLocation(field, "Instance",
out isRefClass); CSharpTypePrinterContextKind.Managed, out isRefClass);
if (isRefClass && kind == PropertyMethodKind.Getter) if (isRefClass && kind == PropertyMethodKind.Getter)
location = string.Format("new System.IntPtr({0})", location); location = string.Format("new System.IntPtr({0})", location);

Loading…
Cancel
Save