MCPcopy Index your code
hub / github.com/beanshell/beanshell / eval

Method eval

src/bsh/BSHForStatement.java:47–133  ·  view source on GitHub ↗
(CallStack callstack , Interpreter interpreter)

Source from the content-addressed store, hash-verified

45 BSHForStatement(int id) { super(id); }
46
47 public Object eval(CallStack callstack , Interpreter interpreter)
48 throws EvalError
49 {
50 int i = 0;
51 if(hasForInit)
52 forInit = ((SimpleNode)jjtGetChild(i++));
53 if(hasExpression)
54 expression = ((SimpleNode)jjtGetChild(i++));
55 if(hasForUpdate)
56 forUpdate = ((SimpleNode)jjtGetChild(i++));
57 if(i < jjtGetNumChildren()) // should normally be
58 statement = ((SimpleNode)jjtGetChild(i));
59
60 NameSpace enclosingNameSpace= callstack.top();
61 BlockNameSpace forNameSpace = new BlockNameSpace( enclosingNameSpace );
62
63 /*
64 Note: some interesting things are going on here.
65
66 1) We swap instead of push... The primary mode of operation
67 acts like we are in the enclosing namespace... (super must be
68 preserved, etc.)
69
70 2) We do *not* call the body block eval with the namespace
71 override. Instead we allow it to create a second subordinate
72 BlockNameSpace child of the forNameSpace. Variable propagation
73 still works through the chain, but the block's child cleans the
74 state between iteration.
75 (which is correct Java behavior... see forscope4.bsh)
76 */
77
78 // put forNameSpace it on the top of the stack
79 // Note: it's important that there is only one exit point from this
80 // method so that we can swap back the namespace.
81 callstack.swap( forNameSpace );
82
83 // Do the for init
84 if ( hasForInit )
85 forInit.eval( callstack, interpreter );
86
87 Object returnControl = Primitive.VOID;
88 while(true)
89 {
90 if ( hasExpression )
91 {
92 boolean cond = BSHIfStatement.evaluateCondition(
93 expression, callstack, interpreter );
94
95 if ( !cond )
96 break;
97 }
98
99 boolean breakout = false; // switch eats a multi-level break here?
100 if ( statement != null ) // not empty statement
101 {
102 // do *not* invoke special override for block... (see above)
103 Object ret = statement.eval( callstack, interpreter );
104

Callers

nothing calls this directly

Calls 6

evaluateConditionMethod · 0.95
topMethod · 0.80
swapMethod · 0.80
jjtGetChildMethod · 0.65
jjtGetNumChildrenMethod · 0.65
evalMethod · 0.65

Tested by

no test coverage detected