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

Method eval

src/bsh/BSHBinaryExpression.java:41–202  ·  view source on GitHub ↗
( CallStack callstack, Interpreter interpreter)

Source from the content-addressed store, hash-verified

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 */

Callers

nothing calls this directly

Calls 12

isJavaBaseAssignableMethod · 0.95
isPrimitiveValueMethod · 0.95
isWrapperMethod · 0.95
binaryOperationMethod · 0.95
getClassMethod · 0.80
booleanValueMethod · 0.80
evalMethod · 0.65
jjtGetChildMethod · 0.65
getTypeMethod · 0.45
getValueMethod · 0.45
toEvalErrorMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected