public Object eval( CallStack callstack, Interpreter interpreter) throws EvalError { if ( isDefault ) return null; // should probably error SimpleNode label = ((SimpleNode)jjtGetChild(0)); return label.eval( callstack, interpreter ); } }
/** Print the error with line number and stack trace. */ public String getMessage() { String trace; if ( node != null ) trace = " : at Line: "+ node.getLineNumber() + " : in file: "+ node.getSourceFile() + " : "+node.getText(); else // Users should not normally see this. trace = ": <at unknown location>"; if ( callstack != null ) trace = trace +"\n" + getScriptStackTrace(); return getRawMessage() + trace; }
node.setSourceFile( sourceFileInfo ); node.dump(">"); if ( TRACE ) println( "// " +node.getText() ); Object ret = node.eval( callstack, this );
node.setSourceFile( sourceFileInfo ); println( "// " +node.getText() ); retVal = node.eval( callstack, localInterpreter );
public List bshParse(String sourceFileInfo, Reader in) throws ParseException { List parsedLineNodes = new LinkedList(); Parser parser = new Parser(in); boolean eof = false; while(!eof) { try { eof = parser.Line(); if (parser.jjtree.nodeArity() > 0) { SimpleNode node = (SimpleNode) parser.jjtree.rootNode(); // nodes remember from where they were sourced node.setSourceFile(sourceFileInfo); parsedLineNodes.add(node); if (Debug.verboseOn()) Debug.logVerbose("// " + node.getText()); } } catch (ParseException e) { // add the source file info and throw again e.setErrorSourceFile(sourceFileInfo); Debug.logError(e); throw e; } finally { parser.jjtree.reset(); } } return parsedLineNodes; }
public String getErrorText() { if ( node != null ) return node.getText() ; else return "<unknown error>"; }
/** */ static int getIndexAux(Object obj, int idx, CallStack callstack, Interpreter interpreter, SimpleNode callerInfo ) throws EvalError { int index; try { Object indexVal = ((SimpleNode) callerInfo.jjtGetChild(idx)).eval( callstack, interpreter ); if ( !(indexVal instanceof Primitive) ) indexVal = Types.castObject( indexVal, Integer.TYPE, Types.ASSIGNMENT ); index = ((Primitive) indexVal).intValue(); } catch( UtilEvalError e ) { Interpreter.debug("doIndex: "+e); throw e.toEvalError( "Arrays may only be indexed by integer types.", callerInfo, callstack ); } return index; }
/** We may not always have a type node (loose typed resources). * Then we create the BSHType node and get the type * from the BSHVariableDeclarator AllocationExpression nodes. */ private void renderTypeNode() { if (jjtGetNumChildren() == 1) { SimpleNode tNode = new BSHType(ParserTreeConstants.JJTTYPE); Node ambigName = jjtGetChild(0); while (ambigName.jjtGetNumChildren() > 0) if ((ambigName = ambigName.jjtGetChild(0)) instanceof BSHAmbiguousName) break; BSHAmbiguousName ambigNew = new BSHAmbiguousName(ParserTreeConstants.JJTAMBIGUOUSNAME); ambigNew.jjtSetParent(tNode); ambigNew.text = ((BSHAmbiguousName) ambigName).text; tNode.jjtAddChild(ambigNew, 0); tNode.jjtSetParent(this); Node[] n = new Node[2]; n[0] = tNode; n[1] = children[0]; children = n; } } }
public int getErrorLineNumber() { if ( node != null ) return node.getLineNumber() ; else return -1; }
public String getErrorSourceFile() { if ( node != null ) return node.getSourceFile() ; else return "<unknown file>"; }
/** Detach this node from its parent. This is primarily useful in node serialization. (see BSHMethodDeclaration) */ public void prune() { jjtSetParent( null ); }
public SimpleNode getChild( int i ) { return (SimpleNode)jjtGetChild(i); }
boolean isStatic(SimpleNode node) { if ( null != node.jjtGetParent() && node.jjtGetParent().jjtGetParent() instanceof BSHClassDeclaration && ((BSHClassDeclaration) node.jjtGetParent().jjtGetParent()).type == Type.INTERFACE ) return true; if (node instanceof BSHTypedVariableDeclaration) return ((BSHTypedVariableDeclaration) node).modifiers != null && ((BSHTypedVariableDeclaration) node).modifiers.hasModifier("static"); if (node instanceof BSHMethodDeclaration) return ((BSHMethodDeclaration) node).modifiers != null && ((BSHMethodDeclaration) node).modifiers.hasModifier("static"); if (node instanceof BSHBlock) return ((BSHBlock) node).isStatic; return false; } }
/** Gets the invocation text. * @return the invocation text */ public String getInvocationText() { final SimpleNode node = this.getNode(); if (node != null) return node.getText(); else return "<invoked from Java code>"; }
/** Gets the invocation line. * @return the invocation line */ public int getInvocationLine() { final SimpleNode node = this.getNode(); if (node != null) return node.getLineNumber(); else return -1; }
/** Get the name of the source file (or more generally source) of the text from which this node was parsed. This will recursively search up the chain of parent nodes until a source is found or return a string indicating that the source is unknown. */ public String getSourceFile() { if ( sourceFile == null ) if ( parent != null ) return ((SimpleNode)parent).getSourceFile(); else return "<unknown file>"; else return sourceFile; }
public Object eval( CallStack callstack, Interpreter interpreter) throws EvalError { SimpleNode cond = (SimpleNode)jjtGetChild(0), evalTrue = (SimpleNode)jjtGetChild(1), evalFalse = (SimpleNode)jjtGetChild(2); if ( BSHIfStatement.evaluateCondition( cond, callstack, interpreter ) ) return evalTrue.eval( callstack, interpreter ); else return evalFalse.eval( callstack, interpreter ); }
public String getScriptStackTrace() { if ( callstack == null ) return "<Unknown>"; String trace = ""; CallStack stack = callstack.copy(); while ( stack.depth() > 0 ) { NameSpace ns = stack.pop(); SimpleNode node = ns.getNode(); if ( ns.isMethod ) { trace = trace + "\nCalled from method: " + ns.getName(); if ( node != null ) trace += " : at Line: "+ node.getLineNumber() + " : in file: "+ node.getSourceFile() + " : "+node.getText(); } } return trace; }