Switch statement start.

This commit is contained in:
rogerl%netscape.com 2002-10-28 17:52:33 +00:00
parent 61c7b053ba
commit 19a5012358
2 changed files with 71 additions and 0 deletions

View File

@ -219,6 +219,23 @@ namespace MetaData {
targetList.pop_back();
}
break;
case StmtNode::Switch:
{
SwitchStmtNode *sw = checked_cast<SwitchStmtNode *>(p);
ValidateExpression(cxt, env, sw->expr);
StmtNode *s = sw->statements;
while (s) {
if (s->getKind() == StmtNode::Case) {
ExprStmtNode *c = checked_cast<ExprStmtNode *>(s);
if (c->expr)
ValidateExpression(cxt, env, c->expr);
}
else
ValidateStmt(cxt, env, s);
s = s->next;
}
}
break;
case StmtNode::While:
case StmtNode::DoWhile:
{
@ -831,6 +848,58 @@ namespace MetaData {
bCon->setLabel(f->breakLabelID);
}
break;
case StmtNode::Switch:
/*
<swexpr>
eLexicalWrite <switchTemp>
Pop
// test sequence in source order except
// the default is moved to end.
eLexicalRead <switchTemp>
<case1expr>
Equal
BranchTrue --> case1StmtLabel
eLexicalRead <switchTemp>
<case2expr>
Equal
BranchTrue --> case2StmtLabel
Branch --> default, if there is one, or break label
case1StmtLabel:
<stmt>
case2StmtLabel:
<stmt>
defaultLabel:
<stmt>
case3StmtLabel:
<stmt>
..etc.. // all in source order
breakLabel:
*/
{
SwitchStmtNode *sw = checked_cast<SwitchStmtNode *>(p);
Reference *r = EvalExprNode(env, phase, sw->expr);
if (r) r->emitReadBytecode(bCon, p->pos);
StmtNode *s = sw->statements;
while (s) {
if (s->getKind() == StmtNode::Case) {
ExprStmtNode *c = checked_cast<ExprStmtNode *>(s);
if (c->expr) {
Reference *r = EvalExprNode(env, phase, c->expr);
if (r) r->emitReadBytecode(bCon, p->pos);
}
}
else
EvalStmt(env, phase, s);
s = s->next;
}
}
break;
case StmtNode::While:
{
UnaryStmtNode *w = checked_cast<UnaryStmtNode *>(p);

View File

@ -520,7 +520,9 @@ namespace JavaScript {
struct ExprStmtNode: StmtNode {
ExprNode *expr; // The expression statement's expression. May be nil for default: or return-with-no-expression statements.
#ifdef DIKDIK
uint32 label; // Used for case statements' code generation
#endif
ExprStmtNode(size_t pos, Kind kind, ExprNode *expr): StmtNode(pos, kind), expr(expr) {}