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

Method eval

src/bsh/BSHSwitchStatement.java:35–101  ·  view source on GitHub ↗
( CallStack callstack, Interpreter interpreter )

Source from the content-addressed store, hash-verified

33 public BSHSwitchStatement(int id) { super(id); }
34
35 public Object eval( CallStack callstack, Interpreter interpreter )
36 throws EvalError
37 {
38 int numchild = jjtGetNumChildren();
39 int child = 0;
40 SimpleNode switchExp = ((SimpleNode)jjtGetChild(child++));
41 Object switchVal = switchExp.eval( callstack, interpreter );
42
43 /*
44 Note: this could be made clearer by adding an inner class for the
45 cases and an object context for the child traversal.
46 */
47 // first label
48 BSHSwitchLabel label;
49 Object node;
50 ReturnControl returnControl=null;
51
52 // get the first label
53 if ( child >= numchild )
54 throw new EvalError("Empty switch statement.", this, callstack );
55 label = ((BSHSwitchLabel)jjtGetChild(child++));
56
57 // while more labels or blocks and haven't hit return control
58 while ( child < numchild && returnControl == null )
59 {
60 // if label is default or equals switchVal
61 if ( label.isDefault
62 || primitiveEquals(
63 switchVal, label.eval( callstack, interpreter ),
64 callstack, switchExp )
65 )
66 {
67 // execute nodes, skipping labels, until a break or return
68 while ( child < numchild )
69 {
70 node = jjtGetChild(child++);
71 if ( node instanceof BSHSwitchLabel )
72 continue;
73 // eval it
74 Object value =
75 ((SimpleNode)node).eval( callstack, interpreter );
76
77 // should check to disallow continue here?
78 if ( value instanceof ReturnControl ) {
79 returnControl = (ReturnControl)value;
80 break;
81 }
82 }
83 } else
84 {
85 // skip nodes until next label
86 while ( child < numchild )
87 {
88 node = jjtGetChild(child++);
89 if ( node instanceof BSHSwitchLabel ) {
90 label = (BSHSwitchLabel)node;
91 break;
92 }

Callers

nothing calls this directly

Calls 6

evalMethod · 0.95
primitiveEqualsMethod · 0.95
evalMethod · 0.95
jjtGetNumChildrenMethod · 0.65
jjtGetChildMethod · 0.65
evalMethod · 0.65

Tested by

no test coverage detected