Browse Source

Extract the logic of managed to native marshaling of classes into methods.

pull/1/head
triton 13 years ago
parent
commit
f7c2275b59
  1. 49
      src/Generator/Generators/CLI/CLIMarshal.cs

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

@ -412,6 +412,36 @@ namespace Cxxi.Generators.CLI @@ -412,6 +412,36 @@ namespace Cxxi.Generators.CLI
public bool VisitClassDecl(Class @class)
{
if (@class.IsValueType)
{
MarshalValueClass(@class);
}
else
{
if (MarshalRefClass()) return true;
}
return true;
}
private bool MarshalRefClass()
{
if (!Context.Parameter.Type.IsPointer())
Return.Write("*");
var method = Context.Function as Method;
if (method != null
&& method.Conversion == MethodConversionKind.FunctionToInstanceMethod
&& Context.ParameterIndex == 0)
{
Return.Write("NativePtr");
return true;
}
Return.Write("{0}->NativePtr", Context.Parameter.Name);
return false;
}
private void MarshalValueClass(Class @class)
{
if (Context.Parameter.Type.IsReference())
{
@ -447,25 +477,6 @@ namespace Cxxi.Generators.CLI @@ -447,25 +477,6 @@ namespace Cxxi.Generators.CLI
ArgumentPrefix.Write("&");
}
}
else
{
if (!Context.Parameter.Type.IsPointer())
Return.Write("*");
var method = Context.Function as Method;
if (method != null
&& method.Conversion == MethodConversionKind.FunctionToInstanceMethod
&& Context.ParameterIndex == 0)
{
Return.Write("NativePtr");
return true;
}
Return.Write("{0}->NativePtr", Context.Parameter.Name);
}
return true;
}
public bool VisitFieldDecl(Field field)
{

Loading…
Cancel
Save