Browse Source

Simplified generated code dealing with hidden structure parameters.

pull/45/merge
triton 12 years ago
parent
commit
62078d449e
  1. 21
      src/Generator/Generators/CSharp/CSharpTextTemplate.cs

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

@ -1628,16 +1628,15 @@ namespace CppSharp.Generators.CSharp @@ -1628,16 +1628,15 @@ namespace CppSharp.Generators.CSharp
var needsFixedThis = needsInstance && isValueType;
var @params = GenerateFunctionParamsMarshal(parameters, function);
Class retClass = null;
if (function.HasHiddenStructParameter)
{
var hiddenParam = function.Parameters[0];
if (hiddenParam.Kind != ParameterKind.HiddenStructureReturn)
throw new NotSupportedException("Expected hidden structure parameter kind");
Class retClass = null;
hiddenParam.Type.Desugar().IsTagDecl(out retClass);
WriteLine("var {0} = new {1}.Internal();", GeneratedIdentifier("udt"),
retClass.OriginalName);
WriteLine("var ret = new {0}.Internal();", retClass.OriginalName);
}
var names = new List<string>();
@ -1654,7 +1653,7 @@ namespace CppSharp.Generators.CSharp @@ -1654,7 +1653,7 @@ namespace CppSharp.Generators.CSharp
if (function.HasHiddenStructParameter)
{
var name = string.Format("new IntPtr(&{0})", GeneratedIdentifier("udt"));
var name = string.Format("new IntPtr(&ret)");
names.Insert(0, name);
}
@ -1701,15 +1700,6 @@ namespace CppSharp.Generators.CSharp @@ -1701,15 +1700,6 @@ namespace CppSharp.Generators.CSharp
}
if (needsReturn)
{
if (function.HasHiddenStructParameter)
{
WriteLine("var ret = new {0}({1});", retClass.Name,
GeneratedIdentifier("udt"));
WriteLine("return ret;");
}
else
{
var ctx = new CSharpMarshalContext(Driver)
{
@ -1719,7 +1709,7 @@ namespace CppSharp.Generators.CSharp @@ -1719,7 +1709,7 @@ namespace CppSharp.Generators.CSharp
};
var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
function.ReturnType.CSharpMarshalToManaged(marshal);
retType.CSharpMarshalToManaged(marshal);
if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore))
Write(marshal.Context.SupportBefore);
@ -1727,7 +1717,6 @@ namespace CppSharp.Generators.CSharp @@ -1727,7 +1717,6 @@ namespace CppSharp.Generators.CSharp
WriteLine("return {0};", marshal.Context.Return);
}
}
}
private void GenerateFunctionCallOutParams(IEnumerable<ParamMarshal> @params,
ICollection<TextGenerator> cleanups)
@ -2146,7 +2135,7 @@ namespace CppSharp.Generators.CSharp @@ -2146,7 +2135,7 @@ namespace CppSharp.Generators.CSharp
}
WriteLine("public static extern {0} {1}({2});", retType,
GetFunctionIdentifier(function),
GetFunctionNativeIdentifier(function),
string.Join(", ", @params));
PopBlock(NewLineKind.BeforeNextBlock);

Loading…
Cancel
Save