public void visit(CallCommand that) { Console.Write("{0}(", that.Identifier); foreach (Expression argument in that.Arguments) { argument.visit(this); if (argument != that.Arguments[that.Arguments.Length - 1]) Console.Write(", "); } Console.WriteLine(");"); #if false switch (that.Identifier) { case "getint": // To get the parameters ?? // getint( xx ) if (that.Arguments.Length != 1) throw new CoderError(that.Position, "Incorrect number of parameters in function call"); VariableExpression argument = that.Arguments[0] as VariableExpression; if (argument == null) throw new CoderError("Variable expected"); Console.WriteLine("Arg = {0}", argument.Name); break; case "putint": break; } foreach (Expression argument in that.Arguments) argument.visit(this); #endif }
public void visit(CallCommand that) { // let the arguments resolve their types foreach (Expression argument in that.Arguments) argument.visit(this); // mangle the parameter list so as to be able to look up the mangled symbol System.Text.StringBuilder mangled = new System.Text.StringBuilder(64); that.Encode(mangled); string name = mangled.ToString(); // look up the function name Declaration declaration = _symbols.Lookup(name); if (declaration == null) throw new CheckerError(that.Position, "Unknown function name '" + Demangler.Decode(name) + "' in call command"); switch (declaration.Kind) { case SymbolKind.Constant: throw new CheckerError(that.Position, "Cannot call constant"); case SymbolKind.Function: break; case SymbolKind.Parameter: throw new CheckerError(that.Position, "Cannot call parameter"); case SymbolKind.Variable: throw new CheckerError(that.Position, "Cannot call variable"); default: throw new CheckerError(declaration.Position, "Unknown symbol kind: " + declaration.Kind.ToString()); } // check that the expected number of parameters is specified FunctionDeclaration function = (FunctionDeclaration) declaration; if (that.Arguments.Length != function.Parameters.Length) throw new CheckerError(that.Position, "Incorrect number of parameters in function call"); // check that the argument types match the parameter types for (int i = 0; i < that.Arguments.Length; i++) { if (that.Arguments[i].Type.Kind != function.Parameters[i].Type.Kind) throw new CheckerError(that.Arguments[i].Position, "Type mismatch in argument to procedure"); } }