static string BuildArgumentValues( IFunctionInstance function, NamedCollection <IArgumentDeclaration> arguments, INamedExpressionTuple expressions, ICppScope scope, string kind) { if (arguments.IsEmpty()) { return(string.Empty); } var name = scope.MakeLocalName(); var typeName = GetFunctionTypeName(function.Name, kind); scope.Runtime.AddLine($"{typeName} {name};"); var argN = 0; foreach (var expression in expressions.Tuple) { var argument = arguments[argN]; argN++; var value = Dynamic((dynamic)expression.Expression, scope); if (argument.IsAssignable) { scope.Runtime.AddLine($"{name}.{CppEscape(argument.Name)} = &{value};"); } else { scope.Runtime.AddLine($"{name}.{CppEscape(argument.Name)} = {value};"); } } return(name); }
static void DeclareFunctionBody(IFunctionDeclaration function, ICppScope scope) { var noResult = function.Results.IsEmpty(); var noLeft = function.LeftArguments.IsEmpty(); var noRight = function.RightArguments.IsEmpty(); var resultType = noResult ? "void" : GetFunctionTypeName(function.Name, kind: "Result"); var left = string.Empty; var leftLocal = string.Empty; var right = string.Empty; var rightLocal = string.Empty; if (!noLeft) { leftLocal = scope.MakeLocalName(hint: "left"); left = GetFunctionTypeName(function.Name, kind: "Left") + " " + leftLocal; } if (!noRight) { rightLocal = scope.MakeLocalName(hint: "right"); right = (noLeft ? "" : ", ") + GetFunctionTypeName(function.Name, kind: "Right") + " " + rightLocal; } scope.Declaration.AddLine($"inline {resultType} {CppEscape(function.Name)}({left}{right}) {{"); scope.WithDeclarationIndented( innerScope => { MakeArgumentLocals(function.LeftArguments, leftLocal, innerScope); MakeArgumentLocals(function.RightArguments, rightLocal, innerScope); MakeResultLocals(function.Results, innerScope); Dynamic(function.Implementation, innerScope); if (!noResult) { var resultLocal = scope.MakeLocalName(hint: "result"); innerScope.Runtime.AddLine($"{resultType} {resultLocal};"); AssignResultsFromLocals(resultLocal, function.Results, innerScope); innerScope.Runtime.AddLine($"return {resultLocal};"); } }); scope.Declaration.AddLine(line: "}"); }
static string BuildResultValues(IFunctionInstance function, ICppScope scope, ref string name) { var argumentDeclarations = function.Declaration.Results; if (argumentDeclarations.IsEmpty()) { return(string.Empty); } name = scope.MakeLocalName(); var typeName = GetFunctionTypeName(function.Name, kind: "Result"); return($"{typeName} {name} = "); }