public void WriteWrappedMemberCall(string callName, bool isStatic, AST.IVariable retType, params AST.Parameter[] args) { AST.Parameter ctxarg = null; if (!isStatic) { ctxarg = new AST.Parameter() { Type = BasicTypes.IntPtr, Name = "IPtr", Context = AST.VariableContext.In } } ; Line("Check();"); WriteWrappedCall(false, MemberCallScope(isStatic) + callName, retType, ctxarg, args); }
public static AST.Parameter InContext(this AST.IVariable v, AST.VariableContext newContext, string newName = null) { var p = new AST.Parameter(); p.Context = newContext; p.Name = newName ?? v.Name; p.Type = v.Type; p.IsArray = v.IsArray; var vp = v as AST.Parameter; if (vp != null) { p.HasDefaultValue = vp.HasDefaultValue; p.DefaultValue = vp.DefaultValue; } return(p); }
public void WriteWrappedCall(bool doConversion, bool isCallback, string callName, AST.IVariable retType, AST.Parameter contextArg, params AST.Parameter[] args) { var argConv = VarConversion.Get(this, isCallback, args); var retConv = VarConversion.Get(retType, this, isCallback); if (isCallback) { if (doConversion) { foreach (var arg in argConv) { arg.WritePrefix(this); } } if (retConv != null && retConv.Item != null) { Code("{0} ", retConv.Item); } Code("{0}(", callName); List(() => { if (contextArg != null) { ListItem(contextArg.Name); } foreach (var arg in argConv) { arg.WriteItem(this); } }); Line(");"); if (doConversion) { foreach (var arg in argConv) { arg.WriteSuffix(this); } } if (retConv != null) { retConv.WriteSuffix(this); } Line("return HResult.S_OK;"); } else { if (retConv != null) { argConv.Add(retConv); } if (doConversion) { foreach (var arg in argConv) { arg.WritePrefix(this); } } Code("Native.Throw({0}(", callName); List(() => { if (contextArg != null) { ListItem(contextArg.Name); } foreach (var arg in argConv) { arg.WriteItem(this); } }); Line("));"); if (doConversion) { foreach (var arg in argConv) { arg.WriteSuffix(this); } } } }
public void WriteWrappedCall(bool isCallback, string callName, AST.IVariable retType, AST.Parameter contextArg, params AST.Parameter[] args) { WriteWrappedCall(true, isCallback, callName, retType, contextArg, args); }
public void CallToABIMethodBody(AST.ICallSignature m, params string[] prependArgs) { AST.IVariable returnArg; bool isCtor = m.Return == null; if (!isCtor) { returnArg = m.Return.Morph("___ret", AST.VariableContext.Out); } else { returnArg = new AST.Parameter(BasicTypes.Void, "", AST.VariableContext.Return, false); } foreach (var arg in m.Parameters) { if (arg.IsArray || arg.Type.IsDelegate) { if (arg.IsWriteable()) { Line("ABICallbackRef<{0}> {1}_abi({1});", TypeRef(arg), arg.Name); } else { Line("auto {0}_abi = ABIUtil<{1}>::ToABI({0});", arg.Name, TypeRef(arg)); } } } if (!returnArg.IsVoid) { Line("{0} {1};", VariableType(returnArg, AST.VariableContext.Member, isCtor), returnArg.Name); if (returnArg.IsArray || returnArg.Type.IsDelegate) { Line("{"); Indent++; Line("ABICallbackRef<{0}> {1}_abi({1});", TypeRef(returnArg), returnArg.Name); } } Line($"TRANSLATE_TO_EXCEPTIONS({m.Name}("); Indent++; List(CodeListStyle.MultiLine, () => { foreach (var arg in prependArgs) { ListItem(arg); } Action <AST.IVariable, string> translateArg = (arg, name) => { if (arg.IsArray || arg.Type.IsDelegate) { name += "_abi"; } if (arg.IsArray) { if (arg.IsWriteable() || arg.Context == AST.VariableContext.Return) { ListItem("&{0}.Data, &{0}.Count", name); } else { ListItem("{0}.begin(), {0}.size()", name); } } else if (arg.Type.IsDelegate) { if (arg.IsWriteable() || arg.Context == AST.VariableContext.Return) { ListItem("({0}*)&{1}.Fn, &{1}.Ctx", TypeRef(arg, true), name); } else { ListItem("({0}){1}.Fn, {1}.Ctx", TypeRef(arg, true), name); } } else if (arg.IsWriteable() || arg.Context == AST.VariableContext.Return) { ListItem("ABICallbackRef<{0}>({1})", TypeRef(arg), name); } else if (CppRender.RequiresABITranslation(arg)) { ListItem("ABIUtil<{0}>::ToABI({1})", TypeRef(arg), name); } else { ListItem(name); } }; foreach (var arg in m.Parameters) { translateArg(arg, arg.Name); } if (isCtor) { ListItem("&instance"); } else if (!returnArg.IsVoid) { translateArg(returnArg, returnArg.Name); } }); Indent--; Line("));"); //if (!returnArg.IsVoid) //{ // Line("{0} {1};", VariableType(returnArg, AST.VariableContext.Member, isCtor), returnArg.Name); // if (returnArg.IsArray || returnArg.Type.IsDelegate) if (!returnArg.IsVoid) { if (returnArg.IsArray || returnArg.Type.IsDelegate) { Indent--; Line("}"); } Line("return {0};", returnArg.Name); } }