1999-05-18 22:50:53 +00:00
|
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
class SwitchNode extends ControlNode {
|
|
|
|
|
|
|
|
|
|
|
|
SwitchNode(ExpressionNode e)
|
|
|
|
{
|
|
|
|
super(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addCase(ExpressionNode e, ControlNode c)
|
|
|
|
{
|
|
|
|
if (e == null)
|
|
|
|
defaultCode = c;
|
|
|
|
else {
|
|
|
|
caseExpr.addElement(e);
|
|
|
|
caseCode.addElement(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ControlNode eval(Environment theEnv)
|
|
|
|
{
|
|
|
|
ControlNode n = super.eval(theEnv);
|
1999-05-20 21:16:11 +00:00
|
|
|
JSValue v = theEnv.theStack.pop();
|
1999-05-18 22:50:53 +00:00
|
|
|
int count = caseExpr.size();
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
ExpressionNode e = (ExpressionNode)(caseExpr.elementAt(i));
|
|
|
|
e.eval(theEnv);
|
1999-05-20 21:16:11 +00:00
|
|
|
v.eq(theEnv);
|
1999-05-26 01:01:07 +00:00
|
|
|
if (theEnv.theStack.pop().toJSBoolean(theEnv).isTrue())
|
1999-05-18 22:50:53 +00:00
|
|
|
return (ControlNode)(caseCode.elementAt(i));
|
|
|
|
}
|
|
|
|
if (defaultCode != null)
|
|
|
|
return defaultCode;
|
|
|
|
else
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector caseExpr = new Vector();
|
|
|
|
Vector caseCode = new Vector();
|
|
|
|
|
|
|
|
ControlNode defaultCode;
|
|
|
|
|
|
|
|
}
|