public void handleFunction(ASTFunction node) { // Get the function's symbol table, set it's previous to the // calling function's, and then set it to current. connector.startSnap(node.getLineNumber()); if (node.getName().equals("main")) { connector.addQuestion(startQuestion); connector.showScope("main"); } else { } connector.endSnap(); if (!node.getUsed()) { return; } SymbolTable currentSymbolTable = node.getSymbolTable(); for (String p : node.getParameters()) { ByNameVariable v = new ByNameVariable(); v.setParam(); currentSymbolTable.put(p, v); } Global.setCurrentSymbolTable(currentSymbolTable); node.jjtGetChild(0).jjtAccept(this, null); leaveScope(); }
private static Operation astToFunction(ASTFunction node) throws SyntaxException { // Convert each of the arguments and check that the operation can appear // in a restricted context. int count = node.jjtGetNumChildren(); Operation[] ops = new Operation[count]; for (int i = 0; i < count; i++) { ops[i] = (astToDml((ASTOperation) node.jjtGetChild(i), true)); ops[i].checkRestrictedContext(); } // Explicitly disallow automatic variables being called as functions. if (AUTOMATIC_VARIABLES.contains(node.getName())) { throw SyntaxException.create( node.getSourceRange(), MSG_INVALID_FUNCTION_NAME, node.getName()); } // Process 'normal' built-in functions. These don't need special // processing of the arguments. The constructor takes a source range and // a list of operations. Method c = functionConstructors.get(node.getName()); if (c != null) { // Built-in function. Look up constructor in table and create new // instance. try { return (Operation) c.invoke(null, node.getSourceRange(), ops); } catch (InvocationTargetException ite) { // There may be SyntaxExceptions thrown during construction. // If so, rethrow them. All other exceptions are not expected // and should generate a compiler error. Throwable t = ite.getCause(); if (t instanceof SyntaxException) { throw (SyntaxException) t; } else { CompilerError error = CompilerError.create(MSG_UNEXPECTED_EXCEPTION_ENCOUNTERED); error.initCause(t); throw error; } } catch (IllegalAccessException iae) { CompilerError error = CompilerError.create(MSG_UNEXPECTED_EXCEPTION_ENCOUNTERED); error.initCause(iae); throw error; } catch (ClassCastException cce) { CompilerError error = CompilerError.create(MSG_UNEXPECTED_EXCEPTION_ENCOUNTERED); error.initCause(cce); throw error; } } else { // User-defined function. Create generic function wrapper. return new Function(node.getSourceRange(), node.getName(), ops); } }