From 0fd058b9679b87169de631ca3275ec9bb60fb97a Mon Sep 17 00:00:00 2001 From: Jason Orendorff Date: Fri, 14 Jun 2013 16:30:40 -0500 Subject: [PATCH] Bug 872735, part 4 - Remove setBinaryRHS from the ParseHandler protocol. It was only used in parsing switch statements. It is replaced by a newCaseOrDefault method. r=Waldo. --- js/src/frontend/FullParseHandler.h | 11 ++++++----- js/src/frontend/Parser.cpp | 27 +++++++++++++-------------- js/src/frontend/SyntaxParseHandler.h | 4 +++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/js/src/frontend/FullParseHandler.h b/js/src/frontend/FullParseHandler.h index b6172b4339e3..e44243a87587 100644 --- a/js/src/frontend/FullParseHandler.h +++ b/js/src/frontend/FullParseHandler.h @@ -162,11 +162,6 @@ class FullParseHandler ParseContext *pc, JSOp op = JSOP_NOP) { return ParseNode::newBinaryOrAppend(kind, op, left, right, this, pc, foldConstants); } - void setBinaryRHS(ParseNode *pn, ParseNode *rhs) { - JS_ASSERT(pn->isArity(PN_BINARY)); - pn->pn_right = rhs; - pn->pn_pos.end = rhs->pn_pos.end; - } ParseNode *newTernary(ParseNodeKind kind, ParseNode *first, ParseNode *second, ParseNode *third, @@ -178,12 +173,18 @@ class FullParseHandler return new_(label, stmt, begin); } + ParseNode *newCaseOrDefault(uint32_t begin, ParseNode *expr, ParseNode *body) { + TokenPos pos = TokenPos::make(begin, body->pn_pos.end); + return new_(expr ? PNK_CASE : PNK_DEFAULT, JSOP_NOP, pos, expr, body); + } + ParseNode *newBreak(PropertyName *label, uint32_t begin, uint32_t end) { return new_(label, begin, end); } ParseNode *newContinue(PropertyName *label, uint32_t begin, uint32_t end) { return new_(label, begin, end); } + ParseNode *newDebuggerStatement(const TokenPos &pos) { return new_(pos); } diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index e7f4585f93b5..fd717fea7677 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -3525,7 +3525,10 @@ Parser::switchStatement() bool seenDefault = false; TokenKind tt; while ((tt = tokenStream.getToken()) != TOK_RC) { - Node casepn; + uint32_t caseBegin = tokenStream.currentToken().pos.begin; + + ParseNodeKind caseKind; + Node caseExpr; switch (tt) { case TOK_DEFAULT: if (seenDefault) { @@ -3533,21 +3536,16 @@ Parser::switchStatement() return null(); } seenDefault = true; - casepn = handler.newBinary(PNK_DEFAULT); - if (!casepn) - return null(); + caseKind = PNK_DEFAULT; + caseExpr = null(); break; case TOK_CASE: - { - Node left = expr(); - if (!left) - return null(); - casepn = handler.newBinary(PNK_CASE, left); - if (!casepn) + caseKind = PNK_CASE; + caseExpr = expr(); + if (!caseExpr) return null(); break; - } case TOK_ERROR: return null(); @@ -3557,8 +3555,6 @@ Parser::switchStatement() return null(); } - handler.addList(caseList, casepn); - MUST_MATCH_TOKEN(TOK_COLON, JSMSG_COLON_AFTER_CASE); Node body = handler.newList(PNK_STATEMENTLIST); @@ -3576,7 +3572,10 @@ Parser::switchStatement() handler.addList(body, stmt); } - handler.setBinaryRHS(casepn, body); + Node casepn = handler.newCaseOrDefault(caseBegin, caseExpr, body); + if (!casepn) + return null(); + handler.addList(caseList, casepn); } /* diff --git a/js/src/frontend/SyntaxParseHandler.h b/js/src/frontend/SyntaxParseHandler.h index 9dd7da639a86..7a237c0196e8 100644 --- a/js/src/frontend/SyntaxParseHandler.h +++ b/js/src/frontend/SyntaxParseHandler.h @@ -90,7 +90,6 @@ class SyntaxParseHandler ParseContext *pc, JSOp op = JSOP_NOP) { return NodeGeneric; } - void setBinaryRHS(Node pn, Node rhs) {} Node newTernary(ParseNodeKind kind, Node first, Node second, Node third, JSOp op = JSOP_NOP) { return NodeGeneric; @@ -99,6 +98,9 @@ class SyntaxParseHandler Node newLabeledStatement(PropertyName *label, Node stmt, uint32_t begin) { return NodeGeneric; } + Node newCaseOrDefault(uint32_t begin, Node expr, Node body) { + return NodeGeneric; + } Node newBreak(PropertyName *label, uint32_t begin, uint32_t end) { return NodeGeneric; }