( CallStack callstack, Interpreter interpreter)
| 33 | BSHAssignment(int id) { super(id); } |
| 34 | |
| 35 | public Object eval( |
| 36 | CallStack callstack, Interpreter interpreter) |
| 37 | throws EvalError |
| 38 | { |
| 39 | BSHPrimaryExpression lhsNode = |
| 40 | (BSHPrimaryExpression)jjtGetChild(0); |
| 41 | |
| 42 | if ( lhsNode == null ) |
| 43 | throw new InterpreterError( "Error, null LHSnode" ); |
| 44 | |
| 45 | boolean strictJava = interpreter.getStrictJava(); |
| 46 | LHS lhs = lhsNode.toLHS( callstack, interpreter); |
| 47 | if ( lhs == null ) |
| 48 | throw new InterpreterError( "Error, null LHS" ); |
| 49 | |
| 50 | // For operator-assign operations save the lhs value before evaluating |
| 51 | // the rhs. This is correct Java behavior for postfix operations |
| 52 | // e.g. i=1; i+=i++; // should be 2 not 3 |
| 53 | Object lhsValue = null; |
| 54 | if ( operator != ASSIGN ) // assign doesn't need the pre-value |
| 55 | try { |
| 56 | lhsValue = lhs.getValue(); |
| 57 | } catch ( UtilEvalError e ) { |
| 58 | throw e.toEvalError( this, callstack ); |
| 59 | } |
| 60 | |
| 61 | SimpleNode rhsNode = (SimpleNode)jjtGetChild(1); |
| 62 | |
| 63 | Object rhs; |
| 64 | |
| 65 | // implement "blocks" foo = { }; |
| 66 | // if ( rhsNode instanceof BSHBlock ) |
| 67 | // rsh = |
| 68 | // else |
| 69 | rhs = rhsNode.eval(callstack, interpreter); |
| 70 | |
| 71 | if ( rhs == Primitive.VOID ) |
| 72 | throw new EvalError("Void assignment.", this, callstack ); |
| 73 | |
| 74 | try { |
| 75 | switch(operator) |
| 76 | { |
| 77 | case ASSIGN: |
| 78 | return lhs.assign( rhs, strictJava ); |
| 79 | |
| 80 | case PLUSASSIGN: |
| 81 | return lhs.assign( |
| 82 | operation(lhsValue, rhs, PLUS), strictJava ); |
| 83 | |
| 84 | case MINUSASSIGN: |
| 85 | return lhs.assign( |
| 86 | operation(lhsValue, rhs, MINUS), strictJava ); |
| 87 | |
| 88 | case STARASSIGN: |
| 89 | return lhs.assign( |
| 90 | operation(lhsValue, rhs, STAR), strictJava ); |
| 91 | |
| 92 | case SLASHASSIGN: |
nothing calls this directly
no test coverage detected