public virtual void GenerateFunctionCallReturnMarshal(Function function) { var ctx = new MarshalContext(Context, CurrentIndentation) { ArgName = Helpers.ReturnIdentifier, ReturnVarName = Helpers.ReturnIdentifier, ReturnType = function.ReturnType }; var marshal = new CppMarshalNativeToManagedPrinter(ctx); function.ReturnType.Visit(marshal); if (!string.IsNullOrWhiteSpace(marshal.Context.Before)) { Write(marshal.Context.Before); } WriteLine($"return {marshal.Context.Return};"); }
public void GenerateFunctionCall(Function function) { var @params = GenerateFunctionParamsMarshal(function.Parameters, function); var needsReturn = !function.ReturnType.Type.IsPrimitiveType(PrimitiveType.Void); if (needsReturn) { CTypePrinter.PushContext(TypePrinterContextKind.Native); var returnType = function.ReturnType.Visit(CTypePrinter); CTypePrinter.PopContext(); Write($"{returnType} {Helpers.ReturnIdentifier} = "); } var method = function as Method; var @class = function.Namespace as Class; var property = method?.AssociatedDeclaration as Property; var field = property?.Field; if (field != null) { Write($"((::{@class.QualifiedOriginalName}*){Helpers.InstanceIdentifier})->"); Write($"{field.OriginalName}"); var isGetter = property.GetMethod == method; if (isGetter) { WriteLine(";"); } else { WriteLine($" = {@params[0].Name};"); } } else { if (IsNativeFunctionOrStaticMethod(function)) { Write($"::{function.QualifiedOriginalName}("); } else { if (IsNativeMethod(function)) { Write($"((::{@class.QualifiedOriginalName}*){Helpers.InstanceIdentifier})->"); } Write($"{base.GetMethodIdentifier(function, TypePrinterContextKind.Native)}("); } GenerateFunctionParams(@params); WriteLine(");"); } foreach (var paramInfo in @params) { var param = paramInfo.Param; if (param.Usage != ParameterUsage.Out && param.Usage != ParameterUsage.InOut) { continue; } if (param.Type.IsPointer() && !param.Type.GetFinalPointee().IsPrimitiveType()) { param.QualifiedType = new QualifiedType(param.Type.GetFinalPointee()); } var nativeVarName = paramInfo.Name; var ctx = new MarshalContext(Context, CurrentIndentation) { ArgName = nativeVarName, ReturnVarName = nativeVarName, ReturnType = param.QualifiedType }; var marshal = new CppMarshalNativeToManagedPrinter(ctx); param.Visit(marshal); if (!string.IsNullOrWhiteSpace(marshal.Context.Before)) { Write(marshal.Context.Before); } WriteLine($"{param.Name} = {marshal.Context.Return};"); } if (needsReturn) { GenerateFunctionCallReturnMarshal(function); } }