( CallStack callstack, Interpreter interpreter)
| 39 | BSHBinaryExpression(int id) { super(id); } |
| 40 | |
| 41 | public Object eval( CallStack callstack, Interpreter interpreter) |
| 42 | throws EvalError |
| 43 | { |
| 44 | Object lhs = ((SimpleNode)jjtGetChild(0)).eval(callstack, interpreter); |
| 45 | |
| 46 | /* |
| 47 | Doing instanceof? Next node is a type. |
| 48 | */ |
| 49 | if (kind == INSTANCEOF) |
| 50 | { |
| 51 | // null object ref is not instance of any type |
| 52 | if ( lhs == Primitive.NULL ) |
| 53 | return Primitive.FALSE; |
| 54 | |
| 55 | Class rhs = ((BSHType)jjtGetChild(1)).getType( |
| 56 | callstack, interpreter ); |
| 57 | /* |
| 58 | // primitive (number or void) cannot be tested for instanceof |
| 59 | if (lhs instanceof Primitive) |
| 60 | throw new EvalError("Cannot be instance of primitive type." ); |
| 61 | */ |
| 62 | /* |
| 63 | Primitive (number or void) is not normally an instanceof |
| 64 | anything. But for internal use we'll test true for the |
| 65 | bsh.Primitive class. |
| 66 | i.e. (5 instanceof bsh.Primitive) will be true |
| 67 | */ |
| 68 | if ( lhs instanceof Primitive ) |
| 69 | if ( rhs == bsh.Primitive.class ) |
| 70 | return Primitive.TRUE; |
| 71 | else |
| 72 | return Primitive.FALSE; |
| 73 | |
| 74 | // General case - performe the instanceof based on assignability |
| 75 | boolean ret = Types.isJavaBaseAssignable( rhs, lhs.getClass() ); |
| 76 | return new Primitive(ret); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | // The following two boolean checks were tacked on. |
| 81 | // This could probably be smoothed out. |
| 82 | |
| 83 | /* |
| 84 | Look ahead and short circuit evaluation of the rhs if: |
| 85 | we're a boolean AND and the lhs is false. |
| 86 | */ |
| 87 | if ( kind == BOOL_AND || kind == BOOL_ANDX ) { |
| 88 | Object obj = lhs; |
| 89 | if ( isPrimitiveValue(lhs) ) |
| 90 | obj = ((Primitive)lhs).getValue(); |
| 91 | if ( obj instanceof Boolean && |
| 92 | ( ((Boolean)obj).booleanValue() == false ) ) |
| 93 | return Primitive.FALSE; |
| 94 | } |
| 95 | /* |
| 96 | Look ahead and short circuit evaluation of the rhs if: |
| 97 | we're a boolean AND and the lhs is false. |
| 98 | */ |
nothing calls this directly
no test coverage detected