Implementation of the for(;;) statement.
| 30 | Implementation of the for(;;) statement. |
| 31 | */ |
| 32 | class BSHForStatement extends SimpleNode implements ParserConstants |
| 33 | { |
| 34 | public boolean hasForInit; |
| 35 | public boolean hasExpression; |
| 36 | public boolean hasForUpdate; |
| 37 | |
| 38 | private SimpleNode forInit; |
| 39 | private SimpleNode expression; |
| 40 | private SimpleNode forUpdate; |
| 41 | private SimpleNode statement; |
| 42 | |
| 43 | private boolean parsed; |
| 44 | |
| 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 | { |
nothing calls this directly
no outgoing calls
no test coverage detected