MCPcopy Create free account
hub / github.com/beanshell/beanshell / BSHUnaryExpression

Class BSHUnaryExpression

src/bsh/BSHUnaryExpression.java:29–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27package bsh;
28
29class BSHUnaryExpression extends SimpleNode implements ParserConstants
30{
31 public int kind;
32 public boolean postfix = false;
33
34 BSHUnaryExpression(int id) { super(id); }
35
36 public Object eval( CallStack callstack, Interpreter interpreter)
37 throws EvalError
38 {
39 SimpleNode node = (SimpleNode)jjtGetChild(0);
40
41 // If this is a unary increment of decrement (either pre or postfix)
42 // then we need an LHS to which to assign the result. Otherwise
43 // just do the unary operation for the value.
44 try {
45 if ( kind == INCR || kind == DECR ) {
46 LHS lhs = ((BSHPrimaryExpression)node).toLHS(
47 callstack, interpreter );
48 return lhsUnaryOperation( lhs, interpreter.getStrictJava() );
49 } else
50 return
51 unaryOperation( node.eval(callstack, interpreter), kind );
52 } catch ( UtilEvalError e ) {
53 throw e.toEvalError( this, callstack );
54 }
55 }
56
57 private Object lhsUnaryOperation( LHS lhs, boolean strictJava )
58 throws UtilEvalError
59 {
60 if ( Interpreter.DEBUG ) Interpreter.debug("lhsUnaryOperation");
61 Object prevalue, postvalue;
62 prevalue = lhs.getValue();
63 postvalue = unaryOperation(prevalue, kind);
64
65 Object retVal;
66 if ( postfix )
67 retVal = prevalue;
68 else
69 retVal = postvalue;
70
71 lhs.assign( postvalue, strictJava );
72 return retVal;
73 }
74
75 private Object unaryOperation( Object op, int kind ) throws UtilEvalError
76 {
77 if (op instanceof Boolean || op instanceof Character
78 || op instanceof Number)
79 return primitiveWrapperUnaryOperation( op, kind );
80
81 if ( !(op instanceof Primitive) )
82 throw new UtilEvalError( "Unary operation " + tokenImage[kind]
83 + " inappropriate for object" );
84
85
86 return Primitive.unaryOperation((Primitive)op, kind);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected