/** Occasionally we need to freeze the callstack for error reporting purposes, etc. */ public CallStack copy() { CallStack cs = new CallStack(); cs.stack.addAll(this.stack); return cs; } }
/** Occasionally we need to freeze the callstack for error reporting purposes, etc. */ public CallStack copy() { CallStack cs = new CallStack(); cs.stack.addAll(this.stack); return cs; } }
/** Resolve name to an object through this namespace. * @param name the name * @param interpreter the interpreter * @return the object * @throws UtilEvalError the util eval error */ public Object get(final String name, final Interpreter interpreter) throws UtilEvalError { final CallStack callstack = new CallStack(this); return this.getNameResolver(name).toObject(callstack, interpreter); }
/** Unassign the variable name. Name should evaluate to a variable. */ public void unset( String name ) throws EvalError { /* We jump through some hoops here to handle arbitrary cases like unset("bsh.foo"); */ CallStack callstack = new CallStack(); try { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( callstack, this ); if ( lhs.type != LHS.VARIABLE ) throw new EvalError("Can't unset, not a variable: "+name, SimpleNode.JAVACODE, new CallStack()); lhs.nameSpace.unsetVariable( name ); } catch ( UtilEvalError e ) { throw new EvalError( e.getMessage(), SimpleNode.JAVACODE, new CallStack(), e); } }
/** Unassign the variable name. Name should evaluate to a variable. */ public void unset( String name ) throws EvalError { /* We jump through some hoops here to handle arbitrary cases like unset("bsh.foo"); */ CallStack callstack = new CallStack(); try { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( new BshEvaluatingVisitor(callstack, this) ); if ( lhs.type != LHS.VARIABLE ) throw new EvalError("Can't unset, not a variable: "+name, SimpleNode.JAVACODE, new CallStack() ); //lhs.assign( null, false ); lhs.nameSpace.unsetVariable( name ); } catch ( UtilEvalError e ) { throw new EvalError( e.getMessage(), SimpleNode.JAVACODE, new CallStack() ); } }
/** Resolve name to an object through this namespace. */ public Object get( String name, Interpreter interpreter ) throws UtilEvalError { CallStack callstack = new CallStack( this ); return getNameResolver( name ).toObject( new BshEvaluatingVisitor(callstack, interpreter) ); }
/** Get the value of the name. name may be any value. e.g. a variable or field */ public Object get( String name ) throws EvalError { try { Object ret = globalNameSpace.get( name, this ); return Primitive.unwrap( ret ); } catch ( UtilEvalError e ) { throw e.toEvalError( SimpleNode.JAVACODE, new CallStack() ); } }
/** Get the value of the name. name may be any value. e.g. a variable or field */ public Object get( String name ) throws EvalError { try { Object ret = globalNameSpace.get( name, this ); return Primitive.unwrap( ret ); } catch ( UtilEvalError e ) { throw e.toEvalError( SimpleNode.JAVACODE, new CallStack() ); } }
CallStack callstack = new CallStack( namespace );
/** Simplified method for class generated method stubs. Uses This.namespace and declaringInterpreter and retains callerInfo from namespace.getNode(). Also unwraps Primitives for convenience. */ public Object invokeMethod( String methodName, Object [] args, boolean declaredOnly ) throws EvalError { CallStack callstack = new CallStack(namespace); SimpleNode node = namespace.getNode(); namespace.setNode(null); try { return Primitive.unwrap(invokeMethod( methodName, args, declaringInterpreter, callstack, node, declaredOnly)); } catch (Exception e) { throw new EvalError(e.getMessage(), node, callstack, e); } }
/** Lazy initialize static context implementation. * Called from <clinit> after static This was populated we will now * proceed to evaluate the static block node. * @param genClass the generated class. * @param className name of the class. * @throws UtilEvalError combined exceptions. */ public static void initStatic(Class<?> genClass) throws UtilEvalError { String className = genClass.getSimpleName(); try { This staticThis = Reflect.getClassStaticThis(genClass, className); NameSpace classStaticNameSpace = staticThis.getNameSpace(); Interpreter interpreter = staticThis.declaringInterpreter; if (null == interpreter) throw new UtilEvalError("No namespace or interpreter for statitc This." +" Start interpreter for class not implemented yet."); //startInterpreterForClass(genClass); ??? BSHBlock block = (BSHBlock) classStaticNameSpace.getVariable(BSHINIT.toString()); CallStack callstack = new CallStack(classStaticNameSpace); // evaluate the static portion of the block in the static space block.evalBlock(callstack, interpreter, true/*override*/, CLASSSTATIC); // Validate that static final variables were set for (Variable var : Reflect.getVariables(classStaticNameSpace)) var.validateFinalIsSet(true); } catch (Exception e) { throw new UtilEvalError("Exception in static init block <clinit> for class " + className + ". With message: " + e.getMessage(), e); } }
/** Assign the value to the name. name may evaluate to anything assignable. e.g. a variable or field. */ public void set( String name, Object value ) throws EvalError { // map null to Primtive.NULL coming in... if ( value == null ) value = Primitive.NULL; CallStack callstack = new CallStack(); try { if ( Name.isCompound( name ) ) { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( callstack, this ); lhs.assign( value, false ); } else // optimization for common case globalNameSpace.setVariable( name, value, false ); } catch ( UtilEvalError e ) { throw e.toEvalError( SimpleNode.JAVACODE, callstack ); } }
/** Assign the value to the name. name may evaluate to anything assignable. e.g. a variable or field. */ public void set( String name, Object value ) throws EvalError { // map null to Primtive.NULL coming in... if ( value == null ) value = Primitive.NULL; CallStack callstack = new CallStack(); try { if ( Name.isCompound( name ) ) { LHS lhs = globalNameSpace.getNameResolver( name ).toLHS( new BshEvaluatingVisitor(callstack, this) ); lhs.assign( value, false ); } else // optimization for common case globalNameSpace.setVariable( name, value, false ); } catch ( UtilEvalError e ) { throw e.toEvalError( SimpleNode.JAVACODE, callstack ); } }
instanceInitBlock.evalBlock(new CallStack(instanceNameSpace), instanceThis.declaringInterpreter, true/*override*/, CLASSINSTANCE); } catch (Exception e) { throw new InterpreterError("Error in class instance This initialization: " + e, e);
CallStack callstack = new CallStack(); callstack.push(consArgsNameSpace); Object[] args = constructor.getConstructorArgs();
CallStack callstack = new CallStack(); Interpreter interpreter; NameSpace instanceNameSpace;
CallStack callstack = new CallStack( globalNameSpace );
CallStack callstack = new CallStack(); callstack.push(nameSpace);
CallStack callstack = new CallStack(); callstack.push(consArgsNameSpace); Object[] args;
in, out, err, false, nameSpace, this, sourceFileInfo ); CallStack callstack = new CallStack( nameSpace );