gecko-dev/js/js2/java/SwitchNode.java

45 lines
1.1 KiB
Java
Raw Normal View History

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);
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);
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;
}