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

43 lines
1013 B
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)
{
1999-05-28 19:00:48 +00:00
JSValue v = expr.eval(theEnv);
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));
1999-05-28 19:00:48 +00:00
JSBoolean b = v.eq(theEnv, e.eval(theEnv)).toJSBoolean(theEnv);
if (b.isTrue())
1999-05-18 22:50:53 +00:00
return (ControlNode)(caseCode.elementAt(i));
}
if (defaultCode != null)
return defaultCode;
else
1999-05-28 19:00:48 +00:00
return next;
1999-05-18 22:50:53 +00:00
}
Vector caseExpr = new Vector();
Vector caseCode = new Vector();
ControlNode defaultCode;
}