Bug 710932 - Create true/false/this/null parse nodes with a constructor that doesn't examine the token stream. r=jorendorff
authorJeff Walden <jwalden@mit.edu>
Wed, 14 Dec 2011 20:03:35 -0500
changeset 84787 ca3ba6070968e2952c4fc25fe0992de0e82005c7
parent 84786 b1560ef4222cfae85cf3474669144de4979512d7
child 84788 9a48747546604fdaa27df2d1b5988ea5bb1af48d
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs710932
milestone12.0a1
Bug 710932 - Create true/false/this/null parse nodes with a constructor that doesn't examine the token stream. r=jorendorff
js/src/frontend/ParseNode.h
js/src/frontend/Parser.cpp
--- a/js/src/frontend/ParseNode.h
+++ b/js/src/frontend/ParseNode.h
@@ -1193,16 +1193,33 @@ inline UseSharpExpression &
 ParseNode::asUseSharpExpression()
 {
     JS_ASSERT(isKind(PNK_USESHARP));
     JS_ASSERT(isOp(JSOP_NOP));
     JS_ASSERT(pn_arity == PN_NULLARY);
     return *static_cast<UseSharpExpression *>(this);
 }
 
+class ThisLiteral : public ParseNode {
+  public:
+    ThisLiteral(const TokenPos &pos) : ParseNode(PNK_THIS, JSOP_THIS, PN_NULLARY, pos) { }
+};
+
+class NullLiteral : public ParseNode {
+  public:
+    NullLiteral(const TokenPos &pos) : ParseNode(PNK_NULL, JSOP_NULL, PN_NULLARY, pos) { }
+};
+
+class BooleanLiteral : public ParseNode {
+  public:
+    BooleanLiteral(bool b, const TokenPos &pos)
+      : ParseNode(b ? PNK_TRUE : PNK_FALSE, b ? JSOP_TRUE : JSOP_FALSE, PN_NULLARY, pos)
+    { }
+};
+
 ParseNode *
 CloneLeftHandSide(ParseNode *opn, TreeContext *tc);
 
 /*
  * js::Definition is a degenerate subtype of the PN_FUNC and PN_NAME variants
  * of js::ParseNode, allocated only for function, var, const, and let
  * declarations that define truly lexical bindings. This means that a child of
  * a PNK_VAR list may be a Definition as well as a ParseNode. The pn_defn bit
--- a/js/src/frontend/Parser.cpp
+++ b/js/src/frontend/Parser.cpp
@@ -6560,26 +6560,16 @@ Parser::parseXMLText(JSObject *chain, bo
     }
     tokenStream.setXMLOnlyMode(false);
 
     return pn;
 }
 
 #endif /* JS_HAS_XMLSUPPORT */
 
-static ParseNode *
-PrimaryExprNode(ParseNodeKind kind, JSOp op, TreeContext *tc)
-{
-    ParseNode *pn = NullaryNode::create(kind, tc);
-    if (!pn)
-        return NULL;
-    pn->setOp(op);
-    return pn;
-}
-
 ParseNode *
 Parser::primaryExpr(TokenKind tt, JSBool afterDot)
 {
     JS_ASSERT(tokenStream.isCurrentTokenType(tt));
 
     ParseNode *pn, *pn2, *pn3;
     JSOp op;
 
@@ -7212,23 +7202,23 @@ Parser::primaryExpr(TokenKind tt, JSBool
         pn = NullaryNode::create(PNK_NUMBER, tc);
         if (!pn)
             return NULL;
         pn->setOp(JSOP_DOUBLE);
         pn->pn_dval = tokenStream.currentToken().number();
         break;
 
       case TOK_TRUE:
-        return PrimaryExprNode(PNK_TRUE, JSOP_TRUE, tc);
+        return new_<BooleanLiteral>(true, tokenStream.currentToken().pos);
       case TOK_FALSE:
-        return PrimaryExprNode(PNK_FALSE, JSOP_FALSE, tc);
+        return new_<BooleanLiteral>(false, tokenStream.currentToken().pos);
       case TOK_THIS:
-        return PrimaryExprNode(PNK_THIS, JSOP_THIS, tc);
+        return new_<ThisLiteral>(tokenStream.currentToken().pos);
       case TOK_NULL:
-        return PrimaryExprNode(PNK_NULL, JSOP_NULL, tc);
+        return new_<NullLiteral>(tokenStream.currentToken().pos);
 
       case TOK_ERROR:
         /* The scanner or one of its subroutines reported the error. */
         return NULL;
 
       default:
         reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR);
         return NULL;