public AstPrinterNode Visit(FunctionCall node) { var printer = new AstPrinterNode(node.ToString()); // printer.AddChild(node.FuncIdent.Accept(this)); foreach (var param in node.ParamList) { printer.AddChild(param.Accept(this)); } return(printer); }
public static string InferFunctionSignature(TranslatorContext context, FunctionCall node, bool forceNameLookup = false) { Debug.Assert(node.Arguments != null); if (!forceNameLookup && node.Expression is MemberAccess memberAccess) { Debug.Assert(memberAccess.ReferencedDeclaration != null); FunctionDefinition function = context.GetASTNodeById(memberAccess.ReferencedDeclaration.Value) as FunctionDefinition; Debug.Assert(function != null, $"Could not find function {node.ToString()}"); StringBuilder builder = new StringBuilder(); builder.Append(function.Name).Append("("); if (function.Parameters.Parameters != null && function.Parameters.Parameters.Count > 0) { foreach (VariableDeclaration varDecl in function.Parameters.Parameters) { //builder.Append(varDecl.TypeDescriptions.TypeString).Append(", "); builder.Append(InferTypeFromTypeString(varDecl.TypeDescriptions.TypeString)).Append(", "); } builder.Length -= 2; } builder.Append(")"); return(builder.ToString()); } else { string functionName = GetFuncNameFromFuncCall(node); StringBuilder builder = new StringBuilder(); builder.Append(functionName).Append("("); if (node.Arguments.Count > 0) { foreach (Expression argument in node.Arguments) { string typeString = InferTypeFromTypeString(argument.TypeDescriptions.TypeString); builder.Append(typeString).Append(", "); } builder.Length -= 2; } builder.Append(")"); return(builder.ToString()); } }
public static string InferFunctionSignature(TranslatorContext context, FunctionCall node) { Debug.Assert(node.Arguments != null); if (node.Expression is MemberAccess memberAccess) { Debug.Assert(memberAccess.ReferencedDeclaration != null); FunctionDefinition function = context.GetASTNodeById(memberAccess.ReferencedDeclaration.Value) as FunctionDefinition; Debug.Assert(function != null, $"Could not find function {node.ToString()}"); StringBuilder builder = new StringBuilder(); builder.Append(function.Name).Append("("); if (function.Parameters.Parameters != null && function.Parameters.Parameters.Count > 0) { foreach (VariableDeclaration varDecl in function.Parameters.Parameters) { builder.Append(varDecl.TypeDescriptions.TypeString).Append(", "); } builder.Length -= 2; } builder.Append(")"); return(builder.ToString()); } else { string functionName = GetFuncNameFromFunctionCall(node); StringBuilder builder = new StringBuilder(); builder.Append(functionName).Append("("); if (node.Arguments.Count > 0) { foreach (Expression argument in node.Arguments) { string typeString = argument.TypeDescriptions.TypeString; if (typeString.StartsWith("int_const")) { typeString = "int256"; } if (typeString.StartsWith("uint_const")) { typeString = "int256"; } if (typeString.StartsWith("string") || typeString.StartsWith("literal_string")) { typeString = "string"; } if (typeString.StartsWith("bytes ")) { typeString = "bytes"; //"bytes storage ref" } if (typeString.Contains(" memory")) //"struct Foo memory" { typeString = typeString.Substring(0, typeString.IndexOf(" memory")); } if (typeString.Contains(" storage")) { typeString = typeString.Substring(0, typeString.IndexOf(" storage")); } builder.Append(typeString).Append(", "); } builder.Length -= 2; } builder.Append(")"); return(builder.ToString()); } }
public void AcceptCall(CallStatement stmt) { GenerateComments(stmt); FunctionCall tmp = new FunctionCall() { Callee = stmt.Callee, Arguments = stmt.Arguments }; _tw.Write(tmp.ToString(_vhdg)); _tw.WriteLine(";"); }