From 3486aea2380f39524da268840a5496ab51fc9c2b Mon Sep 17 00:00:00 2001 From: Jeff Walden Date: Fri, 28 Oct 2011 16:06:14 -0700 Subject: [PATCH] Bug 699227 - Change ParseNode::getKind() to use a type separate from TokenKind, for greater clarity. r=jorendorff --HG-- extra : rebase_source : a7a0f9028f6094a29f013aafd1eeea4b22d08fa2 --- js/src/frontend/BytecodeCompiler.cpp | 7 +- js/src/frontend/BytecodeEmitter.cpp | 602 ++++++++-------- js/src/frontend/FoldConstants.cpp | 279 ++++---- js/src/frontend/ParseNode-inl.h | 14 +- js/src/frontend/ParseNode.cpp | 58 +- js/src/frontend/ParseNode.h | 578 ++++++++++------ js/src/frontend/Parser.cpp | 980 ++++++++++++++------------- js/src/frontend/Parser.h | 13 +- js/src/frontend/SemanticAnalysis.cpp | 16 +- js/src/frontend/TokenStream.cpp | 6 - js/src/frontend/TokenStream.h | 31 +- js/src/jsreflect.cpp | 400 +++++------ js/src/jsxml.cpp | 40 +- 13 files changed, 1606 insertions(+), 1418 deletions(-) diff --git a/js/src/frontend/BytecodeCompiler.cpp b/js/src/frontend/BytecodeCompiler.cpp index 5b58bc503ae1..46ab206da518 100644 --- a/js/src/frontend/BytecodeCompiler.cpp +++ b/js/src/frontend/BytecodeCompiler.cpp @@ -295,7 +295,7 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF goto out; #if JS_HAS_XML_SUPPORT - if (!pn->isKind(TOK_SEMI) || !pn->pn_kid || !TreeTypeIsXML(pn->pn_kid->getKind())) + if (!pn->isKind(PNK_SEMI) || !pn->pn_kid || !pn->pn_kid->isXMLItem()) onlyXML = false; #endif bce.freeTree(pn); @@ -403,8 +403,7 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *prin return false; /* FIXME: make Function format the source for a function definition. */ - tokenStream.mungeCurrentToken(TOK_NAME); - ParseNode *fn = FunctionNode::create(&funbce); + ParseNode *fn = FunctionNode::create(PNK_NAME, &funbce); if (fn) { fn->pn_body = NULL; fn->pn_cookie.makeFree(); @@ -451,7 +450,7 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun, JSPrincipals *prin pn = NULL; } else { if (fn->pn_body) { - JS_ASSERT(fn->pn_body->isKind(TOK_ARGSBODY)); + JS_ASSERT(fn->pn_body->isKind(PNK_ARGSBODY)); fn->pn_body->append(pn); fn->pn_body->pn_pos = pn->pn_pos; pn = fn->pn_body; diff --git a/js/src/frontend/BytecodeEmitter.cpp b/js/src/frontend/BytecodeEmitter.cpp index e952165eb657..47f9ece3afe2 100644 --- a/js/src/frontend/BytecodeEmitter.cpp +++ b/js/src/frontend/BytecodeEmitter.cpp @@ -1463,7 +1463,7 @@ EmitTraceOp(JSContext *cx, BytecodeEmitter *bce, ParseNode *nextpn) * instruction. nextpn is often a block, in which case the next * instruction typically comes from the first statement inside. */ - if (nextpn->isKind(TOK_LC) && nextpn->isArity(PN_LIST) && nextpn->pn_head) + if (nextpn->isKind(PNK_LC) && nextpn->isArity(PN_LIST) && nextpn->pn_head) nextpn = nextpn->pn_head; if (!UpdateLineNumberNotes(cx, bce, nextpn->pn_pos.begin.lineno)) return -1; @@ -1704,7 +1704,7 @@ JSBool frontend::DefineCompileTimeConstant(JSContext *cx, BytecodeEmitter *bce, JSAtom *atom, ParseNode *pn) { /* XXX just do numbers for now */ - if (pn->isKind(TOK_NUMBER)) { + if (pn->isKind(PNK_NUMBER)) { if (!bce->constMap.put(atom, NumberValue(pn->pn_dval))) return JS_FALSE; } @@ -1986,7 +1986,7 @@ AdjustBlockSlot(JSContext *cx, BytecodeEmitter *bce, jsint slot) static bool EmitEnterBlock(JSContext *cx, ParseNode *pn, BytecodeEmitter *bce) { - JS_ASSERT(pn->isKind(TOK_LEXICALSCOPE)); + JS_ASSERT(pn->isKind(PNK_LEXICALSCOPE)); if (!EmitObjectOp(cx, pn->pn_objbox, JSOP_ENTERBLOCK, bce)) return false; @@ -2169,7 +2169,7 @@ BindGlobal(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSAtom *atom) /* * BindNameToSlot attempts to optimize name gets and sets to stack slot loads - * and stores, given the compile-time information in bce and a TOK_NAME node pn. + * and stores, given the compile-time information in bce and a PNK_NAME node pn. * It returns false on error, true on success. * * The caller can inspect pn->pn_cookie for FREE_UPVAR_COOKIE to tell whether @@ -2192,7 +2192,7 @@ BindNameToSlot(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) JSAtom *atom; Definition::Kind dn_kind; - JS_ASSERT(pn->isKind(TOK_NAME)); + JS_ASSERT(pn->isKind(PNK_NAME)); /* Idempotency tests come first, since we may be called more than once. */ if (pn->pn_dflags & PND_BOUND) @@ -2594,11 +2594,11 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans ok &= CheckSideEffects(cx, bce, pn2, answer); } else { /* - * All invocation operations (construct: TOK_NEW, call: TOK_LP) + * All invocation operations (construct: PNK_NEW, call: PNK_LP) * are presumed to be useful, because they may have side effects * even if their main effect (their return value) is discarded. * - * TOK_LB binary trees of 3 or more nodes are flattened into lists + * PNK_LB binary trees of 3 or more nodes are flattened into lists * to avoid too much recursion. All such lists must be presumed * to be useful because each index operation could invoke a getter * (the JSOP_ARGUMENTS special case below, in the PN_BINARY case, @@ -2631,7 +2631,7 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans * declared in the function currently being compiled. */ pn2 = pn->pn_left; - if (!pn2->isKind(TOK_NAME)) { + if (!pn2->isKind(PNK_NAME)) { *answer = JS_TRUE; } else { if (!BindNameToSlot(cx, bce, pn2)) @@ -2662,10 +2662,10 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans case PN_UNARY: switch (pn->getKind()) { - case TOK_DELETE: + case PNK_DELETE: pn2 = pn->pn_kid; switch (pn2->getKind()) { - case TOK_NAME: + case PNK_NAME: if (!BindNameToSlot(cx, bce, pn2)) return JS_FALSE; if (pn2->isConst()) { @@ -2673,15 +2673,15 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans break; } /* FALL THROUGH */ - case TOK_DOT: + case PNK_DOT: #if JS_HAS_XML_SUPPORT - case TOK_DBLDOT: - JS_ASSERT_IF(pn2->getKind() == TOK_DBLDOT, !bce->inStrictMode()); + case PNK_DBLDOT: + JS_ASSERT_IF(pn2->getKind() == PNK_DBLDOT, !bce->inStrictMode()); /* FALL THROUGH */ #endif - case TOK_LP: - case TOK_LB: + case PNK_LP: + case PNK_LB: /* All these delete addressing modes have effects too. */ *answer = JS_TRUE; break; @@ -2691,10 +2691,10 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans } break; - case TOK_TYPEOF: - case TOK_VOID: - case TOK_NOT: - case TOK_BITNOT: + case PNK_TYPEOF: + case PNK_VOID: + case PNK_NOT: + case PNK_BITNOT: if (pn->isOp(JSOP_NOT)) { /* ! does not convert its operand via toString or valueOf. */ ok = CheckSideEffects(cx, bce, pn->pn_kid, answer); @@ -2704,7 +2704,7 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans default: /* - * All of TOK_INC, TOK_DEC, TOK_THROW, TOK_YIELD, and TOK_DEFSHARP + * All of PNK_INC, PNK_DEC, PNK_THROW, PNK_YIELD, and PNK_DEFSHARP * have direct effects. Of the remaining unary-arity node types, * we can't easily prove that the operand never denotes an object * with a toString or valueOf method. @@ -2720,7 +2720,7 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans * statements and property values in object initialisers, have pn_op * defaulted to JSOP_NOP). */ - if (pn->isKind(TOK_NAME) && !pn->isOp(JSOP_NOP)) { + if (pn->isKind(PNK_NAME) && !pn->isOp(JSOP_NOP)) { if (!BindNameToSlot(cx, bce, pn)) return JS_FALSE; if (!pn->isOp(JSOP_ARGUMENTS) && !pn->isOp(JSOP_CALLEE) && @@ -2734,8 +2734,8 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans } } pn2 = pn->maybeExpr(); - if (pn->isKind(TOK_DOT)) { - if (pn2->isKind(TOK_NAME) && !BindNameToSlot(cx, bce, pn2)) + if (pn->isKind(PNK_DOT)) { + if (pn2->isKind(PNK_NAME) && !BindNameToSlot(cx, bce, pn2)) return JS_FALSE; if (!(pn2->isOp(JSOP_ARGUMENTS) && pn->pn_atom == cx->runtime->atomState.lengthAtom)) { @@ -2754,7 +2754,7 @@ CheckSideEffects(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool *ans break; case PN_NULLARY: - if (pn->isKind(TOK_DEBUGGER)) + if (pn->isKind(PNK_DEBUGGER)) *answer = JS_TRUE; break; } @@ -2876,11 +2876,11 @@ EmitPropOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce, } if (callContext) { - JS_ASSERT(pn->isKind(TOK_DOT)); + JS_ASSERT(pn->isKind(PNK_DOT)); JS_ASSERT(op == JSOP_GETPROP); op = JSOP_CALLPROP; - } else if (op == JSOP_GETPROP && pn->isKind(TOK_DOT)) { - if (pn2->isKind(TOK_NAME)) { + } else if (op == JSOP_GETPROP && pn->isKind(PNK_DOT)) { + if (pn2->isKind(PNK_NAME)) { if (!BindNameToSlot(cx, bce, pn2)) return false; } @@ -2891,7 +2891,7 @@ EmitPropOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce, * list linked via pn_expr temporarily so we can iterate over it from the * bottom up (reversing again as we go), to avoid excessive recursion. */ - if (pn2->isKind(TOK_DOT)) { + if (pn2->isKind(PNK_DOT)) { pndot = pn2; pnup = NULL; top = bce->offset(); @@ -2901,7 +2901,7 @@ EmitPropOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce, JS_ASSERT(!pndot->isUsed()); pndown = pndot->pn_expr; pndot->pn_expr = pnup; - if (!pndown->isKind(TOK_DOT)) + if (!pndown->isKind(PNK_DOT)) break; pnup = pndot; pndot = pndown; @@ -3066,26 +3066,24 @@ EmitElemOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce) if (pn->isArity(PN_NAME)) { /* - * Set left and right so pn appears to be a TOK_LB node, instead - * of a TOK_DOT node. See the TOK_FOR/IN case in EmitTree, and + * Set left and right so pn appears to be a PNK_LB node, instead + * of a PNK_DOT node. See the PNK_FOR/IN case in EmitTree, and * EmitDestructuringOps nearer below. In the destructuring case, * the base expression (pn_expr) of the name may be null, which * means we have to emit a JSOP_BINDNAME. */ left = pn->maybeExpr(); if (!left) { - left = NullaryNode::create(bce); + left = NullaryNode::create(PNK_STRING, bce); if (!left) return false; - left->setKind(TOK_STRING); left->setOp(JSOP_BINDNAME); left->pn_pos = pn->pn_pos; left->pn_atom = pn->pn_atom; } - right = NullaryNode::create(bce); + right = NullaryNode::create(PNK_STRING, bce); if (!right) return false; - right->setKind(TOK_STRING); right->setOp(IsIdentifier(pn->pn_atom) ? JSOP_QNAMEPART : JSOP_STRING); right->pn_pos = pn->pn_pos; right->pn_atom = pn->pn_atom; @@ -3095,9 +3093,7 @@ EmitElemOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce) right = pn->pn_right; } - if (op == JSOP_GETELEM && - left->isKind(TOK_NAME) && - right->isKind(TOK_NUMBER)) { + if (op == JSOP_GETELEM && left->isKind(PNK_NAME) && right->isKind(PNK_NUMBER)) { if (!BindNameToSlot(cx, bce, left)) return false; } @@ -3106,7 +3102,7 @@ EmitElemOp(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce) return false; /* The right side of the descendant operator is implicitly quoted. */ - JS_ASSERT(op != JSOP_DESCENDANTS || !right->isKind(TOK_STRING) || + JS_ASSERT(op != JSOP_DESCENDANTS || !right->isKind(PNK_STRING) || right->isOp(JSOP_QNAMEPART)); if (!EmitTree(cx, bce, right)) return false; @@ -3317,7 +3313,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) pn2 = pn->pn_right; #if JS_HAS_BLOCK_SCOPE TempPopScope tps; - if (pn2->isKind(TOK_LEXICALSCOPE)) { + if (pn2->isKind(PNK_LEXICALSCOPE)) { /* * Push the body's block scope before discriminant code-gen to reflect * the order of slots on the stack. The block's locals must lie under @@ -3358,7 +3354,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) #if !JS_HAS_BLOCK_SCOPE PushStatement(bce, &stmtInfo, STMT_SWITCH, top); #else - if (pn2->isKind(TOK_LC)) { + if (pn2->isKind(PNK_LC)) { PushStatement(bce, &stmtInfo, STMT_SWITCH, top); } else { /* Re-push the switch's statement info record. */ @@ -3382,7 +3378,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (caseCount == 0 || (caseCount == 1 && - (hasDefault = (pn2->pn_head->isKind(TOK_DEFAULT))))) { + (hasDefault = (pn2->pn_head->isKind(PNK_DEFAULT))))) { caseCount = 0; low = 0; high = -1; @@ -3396,38 +3392,38 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) high = JSVAL_INT_MIN; for (pn3 = pn2->pn_head; pn3; pn3 = pn3->pn_next) { - if (pn3->isKind(TOK_DEFAULT)) { + if (pn3->isKind(PNK_DEFAULT)) { hasDefault = JS_TRUE; caseCount--; /* one of the "cases" was the default */ continue; } - JS_ASSERT(pn3->isKind(TOK_CASE)); + JS_ASSERT(pn3->isKind(PNK_CASE)); if (switchOp == JSOP_CONDSWITCH) continue; pn4 = pn3->pn_left; - while (pn4->isKind(TOK_RP)) + while (pn4->isKind(PNK_RP)) pn4 = pn4->pn_kid; Value constVal; switch (pn4->getKind()) { - case TOK_NUMBER: + case PNK_NUMBER: constVal.setNumber(pn4->pn_dval); break; - case TOK_STRING: + case PNK_STRING: constVal.setString(pn4->pn_atom); break; - case TOK_TRUE: + case PNK_TRUE: constVal.setBoolean(true); break; - case TOK_FALSE: + case PNK_FALSE: constVal.setBoolean(false); break; - case TOK_NULL: + case PNK_NULL: constVal.setNull(); break; - case TOK_NAME: + case PNK_NAME: if (!pn4->maybeExpr()) { ok = LookupCompileTimeConstant(cx, bce, pn4->pn_atom, &constVal); if (!ok) @@ -3592,7 +3588,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; } if (!pn4) { - JS_ASSERT(pn3->isKind(TOK_DEFAULT)); + JS_ASSERT(pn3->isKind(PNK_DEFAULT)); continue; } caseNoteIndex = NewSrcNote2(cx, bce, SRC_PCDELTA, 0); @@ -3655,7 +3651,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; memset(table, 0, tableSize); for (pn3 = pn2->pn_head; pn3; pn3 = pn3->pn_next) { - if (pn3->isKind(TOK_DEFAULT)) + if (pn3->isKind(PNK_DEFAULT)) continue; i = pn3->pn_pval->toInt32(); i -= low; @@ -3701,7 +3697,8 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) pn3 = table[i]; if (pn3 && (pn4 = pn3->pn_left) != NULL && - pn4->isKind(TOK_NAME)) { + pn4->isKind(PNK_NAME)) + { /* Note a propagated constant with the const's name. */ JS_ASSERT(!pn4->maybeExpr()); jsatomid index; @@ -3716,7 +3713,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } else { for (pn3 = pn2->pn_head; pn3; pn3 = pn3->pn_next) { pn4 = pn3->pn_left; - if (pn4 && pn4->isKind(TOK_NAME)) { + if (pn4 && pn4->isKind(PNK_NAME)) { /* Note a propagated constant with the const's name. */ JS_ASSERT(!pn4->maybeExpr()); jsatomid index; @@ -3735,14 +3732,14 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* Emit code for each case's statements, copying pn_offset up to pn3. */ for (pn3 = pn2->pn_head; pn3; pn3 = pn3->pn_next) { - if (switchOp == JSOP_CONDSWITCH && !pn3->isKind(TOK_DEFAULT)) + if (switchOp == JSOP_CONDSWITCH && !pn3->isKind(PNK_DEFAULT)) CHECK_AND_SET_JUMP_OFFSET_AT_CUSTOM(cx, bce, pn3->pn_offset, goto bad); pn4 = pn3->pn_right; ok = EmitTree(cx, bce, pn4); if (!ok) goto out; pn3->pn_offset = pn4->pn_offset; - if (pn3->isKind(TOK_DEFAULT)) + if (pn3->isKind(PNK_DEFAULT)) off = pn3->pn_offset - top; } @@ -3793,7 +3790,7 @@ EmitSwitch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) pc += INDEX_LEN; for (pn3 = pn2->pn_head; pn3; pn3 = pn3->pn_next) { - if (pn3->isKind(TOK_DEFAULT)) + if (pn3->isKind(PNK_DEFAULT)) continue; if (!bce->constList.append(*pn3->pn_pval)) goto bad; @@ -3815,7 +3812,7 @@ out: ok = PopStatementBCE(cx, bce); #if JS_HAS_BLOCK_SCOPE - if (ok && pn->pn_right->isKind(TOK_LEXICALSCOPE)) + if (ok && pn->pn_right->isKind(PNK_LEXICALSCOPE)) ok = EmitLeaveBlock(cx, bce, JSOP_LEAVEBLOCK, box); #endif } @@ -3917,7 +3914,7 @@ typedef JSBool static JSBool EmitDestructuringDecl(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp, ParseNode *pn) { - JS_ASSERT(pn->isKind(TOK_NAME)); + JS_ASSERT(pn->isKind(PNK_NAME)); if (!BindNameToSlot(cx, bce, pn)) return JS_FALSE; @@ -3931,21 +3928,21 @@ EmitDestructuringDecls(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp, Parse ParseNode *pn2, *pn3; DestructuringDeclEmitter emitter; - if (pn->isKind(TOK_RB)) { + if (pn->isKind(PNK_RB)) { for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { - if (pn2->isKind(TOK_COMMA)) + if (pn2->isKind(PNK_COMMA)) continue; - emitter = (pn2->isKind(TOK_NAME)) + emitter = (pn2->isKind(PNK_NAME)) ? EmitDestructuringDecl : EmitDestructuringDecls; if (!emitter(cx, bce, prologOp, pn2)) return JS_FALSE; } } else { - JS_ASSERT(pn->isKind(TOK_RC)); + JS_ASSERT(pn->isKind(PNK_RC)); for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { pn3 = pn2->pn_right; - emitter = pn3->isKind(TOK_NAME) ? EmitDestructuringDecl : EmitDestructuringDecls; + emitter = pn3->isKind(PNK_NAME) ? EmitDestructuringDecl : EmitDestructuringDecls; if (!emitter(cx, bce, prologOp, pn3)) return JS_FALSE; } @@ -3965,13 +3962,13 @@ EmitDestructuringLHS(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * pop the matched value. Otherwise emit an lvalue bytecode sequence * ending with a JSOP_ENUMELEM or equivalent op. */ - if (pn->isKind(TOK_RB) || pn->isKind(TOK_RC)) { + if (pn->isKind(PNK_RB) || pn->isKind(PNK_RC)) { if (!EmitDestructuringOpsHelper(cx, bce, pn)) return JS_FALSE; if (Emit1(cx, bce, JSOP_POP) < 0) return JS_FALSE; } else { - if (pn->isKind(TOK_NAME)) { + if (pn->isKind(PNK_NAME)) { if (!BindNameToSlot(cx, bce, pn)) return JS_FALSE; if (pn->isConst() && !pn->isInitialized()) @@ -4051,7 +4048,7 @@ EmitDestructuringOpsHelper(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) intN stackDepth = bce->stackDepth; JS_ASSERT(stackDepth != 0); JS_ASSERT(pn->isArity(PN_LIST)); - JS_ASSERT(pn->isKind(TOK_RB) || pn->isKind(TOK_RC)); + JS_ASSERT(pn->isKind(PNK_RB) || pn->isKind(PNK_RC)); #endif if (pn->pn_count == 0) { @@ -4078,15 +4075,15 @@ EmitDestructuringOpsHelper(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * to the lvalue node, which is in the value-initializing position. */ doElemOp = JS_TRUE; - if (pn->isKind(TOK_RB)) { + if (pn->isKind(PNK_RB)) { if (!EmitNumberOp(cx, index, bce)) return JS_FALSE; pn3 = pn2; } else { - JS_ASSERT(pn->isKind(TOK_RC)); - JS_ASSERT(pn2->isKind(TOK_COLON)); + JS_ASSERT(pn->isKind(PNK_RC)); + JS_ASSERT(pn2->isKind(PNK_COLON)); pn3 = pn2->pn_left; - if (pn3->isKind(TOK_NUMBER)) { + if (pn3->isKind(PNK_NUMBER)) { /* * If we are emitting an object destructuring initialiser, * annotate the index op with SRC_INITPROP so we know we are @@ -4097,7 +4094,7 @@ EmitDestructuringOpsHelper(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (!EmitNumberOp(cx, pn3->pn_dval, bce)) return JS_FALSE; } else { - JS_ASSERT(pn3->isKind(TOK_STRING) || pn3->isKind(TOK_NAME)); + JS_ASSERT(pn3->isKind(PNK_STRING) || pn3->isKind(PNK_NAME)); if (!EmitAtomOp(cx, pn3, JSOP_GETPROP, bce)) return JS_FALSE; doElemOp = JS_FALSE; @@ -4117,8 +4114,8 @@ EmitDestructuringOpsHelper(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } /* Nullary comma node makes a hole in the array destructurer. */ - if (pn3->isKind(TOK_COMMA) && pn3->isArity(PN_NULLARY)) { - JS_ASSERT(pn->isKind(TOK_RB)); + if (pn3->isKind(PNK_COMMA) && pn3->isArity(PN_NULLARY)) { + JS_ASSERT(pn->isKind(PNK_RB)); JS_ASSERT(pn2 == pn3); if (Emit1(cx, bce, JSOP_POP) < 0) return JS_FALSE; @@ -4184,7 +4181,7 @@ EmitGroupAssignment(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp, } /* MaybeEmitGroupAssignment won't call us if rhs is holey. */ - JS_ASSERT(!(pn->isKind(TOK_COMMA) && pn->isArity(PN_NULLARY))); + JS_ASSERT(!(pn->isKind(PNK_COMMA) && pn->isArity(PN_NULLARY))); if (!EmitTree(cx, bce, pn)) return JS_FALSE; ++limit; @@ -4202,7 +4199,7 @@ EmitGroupAssignment(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp, return JS_FALSE; EMIT_UINT16_IMM_OP(JSOP_GETLOCAL, slot); - if (pn->isKind(TOK_COMMA) && pn->isArity(PN_NULLARY)) { + if (pn->isKind(PNK_COMMA) && pn->isArity(PN_NULLARY)) { if (Emit1(cx, bce, JSOP_POP) < 0) return JS_FALSE; } else { @@ -4226,13 +4223,13 @@ static JSBool MaybeEmitGroupAssignment(JSContext *cx, BytecodeEmitter *bce, JSOp prologOp, ParseNode *pn, JSOp *pop) { - JS_ASSERT(pn->isKind(TOK_ASSIGN)); + JS_ASSERT(pn->isKind(PNK_ASSIGN)); JS_ASSERT(pn->isOp(JSOP_NOP)); JS_ASSERT(*pop == JSOP_POP || *pop == JSOP_POPV); ParseNode *lhs = pn->pn_left; ParseNode *rhs = pn->pn_right; - if (lhs->isKind(TOK_RB) && rhs->isKind(TOK_RB) && + if (lhs->isKind(PNK_RB) && rhs->isKind(PNK_RB) && !(rhs->pn_xflags & PNX_HOLEY) && lhs->pn_count <= rhs->pn_count) { if (!EmitGroupAssignment(cx, bce, prologOp, lhs, rhs)) @@ -4278,13 +4275,13 @@ EmitVariables(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool inLetHe first = pn2 == pn->pn_head; next = pn2->pn_next; - if (!pn2->isKind(TOK_NAME)) { + if (!pn2->isKind(PNK_NAME)) { #if JS_HAS_DESTRUCTURING - if (pn2->isKind(TOK_RB) || pn2->isKind(TOK_RC)) { + if (pn2->isKind(PNK_RB) || pn2->isKind(PNK_RC)) { /* * Emit variable binding ops, but not destructuring ops. The * parser (see Parser::variables) has ensured that our caller - * will be the TOK_FOR/TOK_IN case in EmitTree, and that case + * will be the PNK_FOR/PNK_IN case in EmitTree, and that case * will emit the destructuring code only after emitting an * enumerating opcode and a branch that tests whether the * enumeration ended. @@ -4303,7 +4300,7 @@ EmitVariables(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool inLetHe * (var x = i in o)...', this will cause the entire 'var [a, b] = * i' to be hoisted out of the loop. */ - JS_ASSERT(pn2->isKind(TOK_ASSIGN)); + JS_ASSERT(pn2->isKind(PNK_ASSIGN)); JS_ASSERT(pn2->isOp(JSOP_NOP)); JS_ASSERT(!forInVar); @@ -4313,9 +4310,9 @@ EmitVariables(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool inLetHe * here and initialize the name. */ #if !JS_HAS_DESTRUCTURING - JS_ASSERT(pn2->pn_left->isKind(TOK_NAME)); + JS_ASSERT(pn2->pn_left->isKind(PNK_NAME)); #else - if (pn2->pn_left->isKind(TOK_NAME)) + if (pn2->pn_left->isKind(PNK_NAME)) #endif { pn3 = pn2->pn_right; @@ -4417,9 +4414,9 @@ EmitVariables(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, JSBool inLetHe /* * The parser rewrites 'for (var x = i in o)' to hoist 'var x = i' -- * likewise 'for (let x = i in o)' becomes 'i; for (let x in o)' using - * a TOK_SEQ node to make the two statements appear as one. Therefore + * a PNK_SEQ node to make the two statements appear as one. Therefore * if this declaration is part of a for-in loop head, we do not need to - * emit op or any source note. Our caller, the TOK_FOR/TOK_IN case in + * emit op or any source note. Our caller, the PNK_FOR/PNK_IN case in * EmitTree, will annotate appropriately. */ JS_ASSERT_IF(pn2->isDefn(), pn3 == pn2->pn_expr); @@ -4491,7 +4488,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par jsbytecode offset = 1; switch (lhs->getKind()) { - case TOK_NAME: + case PNK_NAME: if (!BindNameToSlot(cx, bce, lhs)) return false; if (!lhs->pn_cookie.isFree()) { @@ -4506,14 +4503,14 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par } } break; - case TOK_DOT: + case PNK_DOT: if (!EmitTree(cx, bce, lhs->expr())) return false; offset++; if (!bce->makeAtomIndex(lhs->pn_atom, &atomIndex)) return false; break; - case TOK_LB: + case PNK_LB: JS_ASSERT(lhs->isArity(PN_BINARY)); if (!EmitTree(cx, bce, lhs->pn_left)) return false; @@ -4522,19 +4519,19 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par offset += 2; break; #if JS_HAS_DESTRUCTURING - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: break; #endif - case TOK_LP: + case PNK_LP: if (!EmitTree(cx, bce, lhs)) return false; offset++; break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(!bce->inStrictMode()); JS_ASSERT(lhs->isOp(JSOP_SETXMLNAME)); if (!EmitTree(cx, bce, lhs->pn_kid)) @@ -4551,7 +4548,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par if (op != JSOP_NOP) { JS_ASSERT(rhs); switch (lhs->getKind()) { - case TOK_NAME: + case PNK_NAME: if (lhs->isConst()) { if (lhs->isOp(JSOP_CALLEE)) { if (Emit1(cx, bce, JSOP_CALLEE) < 0) @@ -4571,7 +4568,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par EMIT_UINT16_IMM_OP(lhs->isOp(JSOP_SETARG) ? JSOP_GETARG : JSOP_GETLOCAL, atomIndex); } break; - case TOK_DOT: + case PNK_DOT: if (Emit1(cx, bce, JSOP_DUP) < 0) return false; if (lhs->pn_atom == cx->runtime->atomState.protoAtom) { @@ -4584,12 +4581,12 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par EMIT_INDEX_OP(isLength ? JSOP_LENGTH : JSOP_GETPROP, atomIndex); } break; - case TOK_LB: - case TOK_LP: + case PNK_LB: + case PNK_LP: #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: #endif if (Emit1(cx, bce, JSOP_DUP2) < 0) return false; @@ -4617,7 +4614,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par * declared in the current compilation unit, as in this case (just * a bit further below) we will avoid emitting the assignment op. */ - if (!lhs->isKind(TOK_NAME) || !lhs->isConst()) { + if (!lhs->isKind(PNK_NAME) || !lhs->isConst()) { if (NewSrcNote(cx, bce, SRC_ASSIGNOP) < 0) return false; } @@ -4626,10 +4623,10 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par } /* Left parts such as a.b.c and a[b].c need a decompiler note. */ - if (!lhs->isKind(TOK_NAME) && + if (!lhs->isKind(PNK_NAME) && #if JS_HAS_DESTRUCTURING - !lhs->isKind(TOK_RB) && - !lhs->isKind(TOK_RC) && + !lhs->isKind(PNK_RB) && + !lhs->isKind(PNK_RC) && #endif NewSrcNote2(cx, bce, SRC_PCBASE, bce->offset() - top) < 0) { @@ -4638,7 +4635,7 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par /* Finally, emit the specialized assignment bytecode. */ switch (lhs->getKind()) { - case TOK_NAME: + case PNK_NAME: if (lhs->isConst()) { if (!rhs) { ReportCompileErrorNumber(cx, bce->tokenStream(), lhs, JSREPORT_ERROR, @@ -4648,25 +4645,25 @@ EmitAssignment(JSContext *cx, BytecodeEmitter *bce, ParseNode *lhs, JSOp op, Par break; } /* FALL THROUGH */ - case TOK_DOT: + case PNK_DOT: EMIT_INDEX_OP(lhs->getOp(), atomIndex); break; - case TOK_LB: - case TOK_LP: + case PNK_LB: + case PNK_LP: if (Emit1(cx, bce, JSOP_SETELEM) < 0) return false; break; #if JS_HAS_DESTRUCTURING - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: if (!EmitDestructuringOps(cx, bce, JSOP_SETNAME, lhs)) return false; break; #endif #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(!bce->inStrictMode()); if (Emit1(cx, bce, JSOP_SETXMLNAME) < 0) return false; @@ -4738,22 +4735,22 @@ bool ParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp) { switch (getKind()) { - case TOK_NUMBER: + case PNK_NUMBER: vp->setNumber(pn_dval); return true; - case TOK_STRING: + case PNK_STRING: vp->setString(pn_atom); return true; - case TOK_TRUE: + case PNK_TRUE: vp->setBoolean(true); return true; - case TOK_FALSE: + case PNK_FALSE: vp->setBoolean(false); return true; - case TOK_NULL: + case PNK_NULL: vp->setNull(); return true; - case TOK_RB: { + case PNK_RB: { JS_ASSERT(isOp(JSOP_NEWINIT) && !(pn_xflags & PNX_NONCONST)); JSObject *obj = NewDenseAllocatedArray(cx, pn_count); @@ -4774,7 +4771,7 @@ ParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp) vp->setObject(*obj); return true; } - case TOK_RC: { + case PNK_RC: { JS_ASSERT(isOp(JSOP_NEWINIT) && !(pn_xflags & PNX_NONCONST)); gc::AllocKind kind = GuessObjectGCKind(pn_count, false); @@ -4788,7 +4785,7 @@ ParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp) return false; ParseNode *pnid = pn->pn_left; - if (pnid->isKind(TOK_NUMBER)) { + if (pnid->isKind(PNK_NUMBER)) { Value idvalue = NumberValue(pnid->pn_dval); jsid id; if (idvalue.isInt32() && INT_FITS_IN_JSID(idvalue.toInt32())) @@ -4798,8 +4795,7 @@ ParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp) if (!obj->defineGeneric(cx, id, value, NULL, NULL, JSPROP_ENUMERATE)) return false; } else { - JS_ASSERT(pnid->isKind(TOK_NAME) || - pnid->isKind(TOK_STRING)); + JS_ASSERT(pnid->isKind(PNK_NAME) || pnid->isKind(PNK_STRING)); JS_ASSERT(pnid->pn_atom != cx->runtime->atomState.protoAtom); jsid id = ATOM_TO_JSID(pnid->pn_atom); if (!DefineNativeProperty(cx, obj, id, value, NULL, NULL, @@ -4878,8 +4874,8 @@ EmitCatch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) ParseNode *pn2 = pn->pn_kid1; switch (pn2->getKind()) { #if JS_HAS_DESTRUCTURING - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: if (!EmitDestructuringOps(cx, bce, JSOP_NOP, pn2)) return false; if (Emit1(cx, bce, JSOP_POP) < 0) @@ -4887,7 +4883,7 @@ EmitCatch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #endif - case TOK_NAME: + case PNK_NAME: /* Inline and specialize BindNameToSlot for pn2. */ JS_ASSERT(!pn2->pn_cookie.isFree()); EMIT_UINT16_IMM_OP(JSOP_SETLOCALPOP, pn2->pn_cookie.asInteger()); @@ -4920,7 +4916,7 @@ EmitCatch(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* * Annotate the JSOP_LEAVEBLOCK that will be emitted as we unwind via - * our TOK_LEXICALSCOPE parent, so the decompiler knows to pop. + * our PNK_LEXICALSCOPE parent, so the decompiler knows to pop. */ ptrdiff_t off = bce->stackDepth; if (NewSrcNote2(cx, bce, SRC_CATCH, off) < 0) @@ -5048,7 +5044,7 @@ EmitTry(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* * Annotate the JSOP_ENTERBLOCK that's about to be generated * by the call to EmitTree immediately below. Save this - * source note's index in stmtInfo for use by the TOK_CATCH: + * source note's index in stmtInfo for use by the PNK_CATCH: * case, where the length of the catch guard is set as the * note's offset. */ @@ -5062,7 +5058,7 @@ EmitTry(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * block object population via count, for use when targeting * guardJump at the next catch (the guard mismatch case). */ - JS_ASSERT(pn3->isKind(TOK_LEXICALSCOPE)); + JS_ASSERT(pn3->isKind(PNK_LEXICALSCOPE)); count = OBJ_BLOCK_COUNT(cx, pn3->pn_objbox->object); prevBox = pn3->pn_objbox; if (!EmitTree(cx, bce, pn3)) @@ -5238,7 +5234,7 @@ EmitIf(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* Ensure the branch-if-false comes here, then emit the else. */ CHECK_AND_SET_JUMP_OFFSET_AT(cx, bce, beq); - if (pn3->isKind(TOK_IF)) { + if (pn3->isKind(PNK_IF)) { pn = pn3; goto if_again; } @@ -5328,7 +5324,7 @@ EmitXMLTag(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) { jsatomid index; - JSAtom *tagAtom = (pn->isKind(TOK_XMLETAGO)) + JSAtom *tagAtom = (pn->isKind(PNK_XMLETAGO)) ? cx->runtime->atomState.etagoAtom : cx->runtime->atomState.stagoAtom; if (!bce->makeAtomIndex(tagAtom, &index)) @@ -5338,7 +5334,7 @@ EmitXMLTag(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) JS_ASSERT(pn->pn_count != 0); ParseNode *pn2 = pn->pn_head; - if (pn2->isKind(TOK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) + if (pn2->isKind(PNK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) return false; if (!EmitTree(cx, bce, pn2)) return false; @@ -5347,11 +5343,11 @@ EmitXMLTag(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) uint32 i; for (pn2 = pn2->pn_next, i = 0; pn2; pn2 = pn2->pn_next, i++) { - if (pn2->isKind(TOK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) + if (pn2->isKind(PNK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) return false; if (!EmitTree(cx, bce, pn2)) return false; - if ((i & 1) && pn2->isKind(TOK_LC)) { + if ((i & 1) && pn2->isKind(PNK_LC)) { if (Emit1(cx, bce, JSOP_TOATTRVAL) < 0) return false; } @@ -5361,7 +5357,7 @@ EmitXMLTag(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) { jsatomid index; - JSAtom *tmp = (pn->isKind(TOK_XMLPTAGC)) ? cx->runtime->atomState.ptagcAtom + JSAtom *tmp = (pn->isKind(PNK_XMLPTAGC)) ? cx->runtime->atomState.ptagcAtom : cx->runtime->atomState.tagcAtom; if (!bce->makeAtomIndex(tmp, &index)) return false; @@ -5409,11 +5405,12 @@ EmitLexicalScope(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * statements get braces by default from the decompiler. */ ptrdiff_t noteIndex = -1; - TokenKind type = pn->expr()->getKind(); - if (type != TOK_CATCH && type != TOK_LET && type != TOK_FOR && + ParseNodeKind kind = pn->expr()->getKind(); + if (kind != PNK_CATCH && kind != PNK_LET && kind != PNK_FOR && (!(stmt = stmtInfo.down) ? !bce->inFunction() - : stmt->type == STMT_BLOCK)) { + : stmt->type == STMT_BLOCK)) + { #if defined DEBUG_brendan || defined DEBUG_mrbkap /* There must be no source note already output for the next op. */ JS_ASSERT(bce->noteCount() == 0 || @@ -5486,8 +5483,8 @@ EmitForIn(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) */ bool forLet = false; if (ParseNode *decl = forHead->pn_kid1) { - JS_ASSERT(TokenKindIsDecl(decl->getKind())); - forLet = decl->isKind(TOK_LET); + JS_ASSERT(decl->isKind(PNK_VAR) || decl->isKind(PNK_LET)); + forLet = decl->isKind(PNK_LET); bce->flags |= TCF_IN_FOR_INIT; if (!EmitTree(cx, bce, decl)) return false; @@ -5622,7 +5619,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) } else { bce->flags |= TCF_IN_FOR_INIT; #if JS_HAS_DESTRUCTURING - if (pn3->isKind(TOK_ASSIGN)) { + if (pn3->isKind(PNK_ASSIGN)) { JS_ASSERT(pn3->isOp(JSOP_NOP)); if (!MaybeEmitGroupAssignment(cx, bce, op, pn3, &op)) return false; @@ -5631,7 +5628,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) if (op == JSOP_POP) { if (!EmitTree(cx, bce, pn3)) return false; - if (TokenKindIsDecl(pn3->getKind())) { + if (pn3->isKind(PNK_VAR) || pn3->isKind(PNK_LET)) { /* * Check whether a destructuring-initialized var decl * was optimized to a group assignment. If so, we do @@ -5693,7 +5690,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) if (pn3) { op = JSOP_POP; #if JS_HAS_DESTRUCTURING - if (pn3->isKind(TOK_ASSIGN)) { + if (pn3->isKind(PNK_ASSIGN)) { JS_ASSERT(pn3->isOp(JSOP_NOP)); if (!MaybeEmitGroupAssignment(cx, bce, op, pn3, &op)) return false; @@ -5753,7 +5750,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) static inline bool EmitFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top) { - return pn->pn_left->isKind(TOK_IN) + return pn->pn_left->isKind(PNK_IN) ? EmitForIn(cx, bce, pn, top) : EmitNormalFor(cx, bce, pn, top); } @@ -5788,7 +5785,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) UPDATE_LINE_NUMBER_NOTES(cx, bce, pn->pn_pos.begin.lineno); switch (pn->getKind()) { - case TOK_FUNCTION: + case PNK_FUNCTION: { JSFunction *fun; uintN slot; @@ -5807,7 +5804,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) /* * This second pass is needed to emit JSOP_NOP with a source note * for the already-emitted function definition prolog opcode. See - * comments in the TOK_LC case. + * comments in the PNK_LC case. */ JS_ASSERT(pn->isOp(JSOP_NOP)); JS_ASSERT(bce->inFunction()); @@ -5932,7 +5929,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_ARGSBODY: + case PNK_ARGSBODY: { ParseNode *pnlast = pn->last(); for (ParseNode *pn2 = pn->pn_head; pn2 != pnlast; pn2 = pn2->pn_next) { @@ -5949,7 +5946,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_UPVARS: + case PNK_UPVARS: JS_ASSERT(pn->pn_names->count() != 0); bce->roLexdeps = pn->pn_names; ok = EmitTree(cx, bce, pn->pn_tree); @@ -5957,15 +5954,15 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) pn->pn_names.releaseMap(cx); break; - case TOK_IF: + case PNK_IF: ok = EmitIf(cx, bce, pn); break; - case TOK_SWITCH: + case PNK_SWITCH: ok = EmitSwitch(cx, bce, pn); break; - case TOK_WHILE: + case PNK_WHILE: /* * Minimize bytecodes issued for one or more iterations by jumping to * the condition below the body and closing the loop if the condition @@ -6018,7 +6015,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) ok = PopStatementBCE(cx, bce); break; - case TOK_DO: + case PNK_DO: /* Emit an annotated nop so we know to decompile a 'do' keyword. */ noteIndex = NewSrcNote(cx, bce, SRC_WHILE); if (noteIndex < 0 || Emit1(cx, bce, JSOP_NOP) < 0) @@ -6066,11 +6063,11 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) ok = PopStatementBCE(cx, bce); break; - case TOK_FOR: + case PNK_FOR: ok = EmitFor(cx, bce, pn, top); break; - case TOK_BREAK: { + case PNK_BREAK: { stmt = bce->topStmt; atom = pn->pn_atom; @@ -6094,7 +6091,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_CONTINUE: { + case PNK_CONTINUE: { stmt = bce->topStmt; atom = pn->pn_atom; @@ -6123,26 +6120,26 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_WITH: + case PNK_WITH: ok = EmitWith(cx, bce, pn); break; - case TOK_TRY: + case PNK_TRY: if (!EmitTry(cx, bce, pn)) return false; break; - case TOK_CATCH: + case PNK_CATCH: if (!EmitCatch(cx, bce, pn)) return false; break; - case TOK_VAR: + case PNK_VAR: if (!EmitVariables(cx, bce, pn, JS_FALSE, ¬eIndex)) return JS_FALSE; break; - case TOK_RETURN: + case PNK_RETURN: /* Push a return value */ pn2 = pn->pn_kid; if (pn2) { @@ -6179,7 +6176,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #if JS_HAS_GENERATORS - case TOK_YIELD: + case PNK_YIELD: JS_ASSERT(bce->inFunction()); if (pn->pn_kid) { if (!EmitTree(cx, bce, pn->pn_kid)) @@ -6195,7 +6192,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #endif - case TOK_LC: + case PNK_LC: { #if JS_HAS_XML_SUPPORT if (pn->isArity(PN_UNARY)) { @@ -6238,15 +6235,15 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * Assign the destructuring arguments before defining any * functions, see bug 419662. */ - JS_ASSERT(pnchild->isKind(TOK_SEMI)); - JS_ASSERT(pnchild->pn_kid->isKind(TOK_VAR)); + JS_ASSERT(pnchild->isKind(PNK_SEMI)); + JS_ASSERT(pnchild->pn_kid->isKind(PNK_VAR)); if (!EmitTree(cx, bce, pnchild)) return JS_FALSE; pnchild = pnchild->pn_next; } for (pn2 = pnchild; pn2; pn2 = pn2->pn_next) { - if (pn2->isKind(TOK_FUNCTION)) { + if (pn2->isKind(PNK_FUNCTION)) { if (pn2->isOp(JSOP_NOP)) { if (!EmitTree(cx, bce, pn2)) return JS_FALSE; @@ -6274,7 +6271,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_SEQ: + case PNK_SEQ: JS_ASSERT(pn->isArity(PN_LIST)); PushStatement(bce, &stmtInfo, STMT_SEQ, top); for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { @@ -6284,7 +6281,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) ok = PopStatementBCE(cx, bce); break; - case TOK_SEMI: + case PNK_SEMI: pn2 = pn->pn_kid; if (pn2) { /* @@ -6329,10 +6326,10 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } } else { op = wantval ? JSOP_POPV : JSOP_POP; - JS_ASSERT_IF(pn2->isKind(TOK_ASSIGN), pn2->isOp(JSOP_NOP)); + JS_ASSERT_IF(pn2->isKind(PNK_ASSIGN), pn2->isOp(JSOP_NOP)); #if JS_HAS_DESTRUCTURING if (!wantval && - pn2->isKind(TOK_ASSIGN) && + pn2->isKind(PNK_ASSIGN) && !MaybeEmitGroupAssignment(cx, bce, op, pn2, &op)) { return JS_FALSE; } @@ -6346,7 +6343,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) * can't escape directly. */ if (!wantval && - pn2->isKind(TOK_ASSIGN) && + pn2->isKind(PNK_ASSIGN) && pn2->pn_left->isOp(JSOP_SETPROP) && pn2->pn_right->isOp(JSOP_LAMBDA) && pn2->pn_right->pn_funbox->joinable()) { @@ -6361,7 +6358,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_COLON: + case PNK_COLON: /* Emit an annotated nop so we know to decompile a label. */ atom = pn->pn_atom; @@ -6370,9 +6367,9 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; pn2 = pn->expr(); - noteType = (pn2->isKind(TOK_LC) || - (pn2->isKind(TOK_LEXICALSCOPE) && - pn2->expr()->isKind(TOK_LC))) + noteType = (pn2->isKind(PNK_LC) || + (pn2->isKind(PNK_LEXICALSCOPE) && + pn2->expr()->isKind(PNK_LC))) ? SRC_LABELBRACE : SRC_LABEL; noteIndex = NewSrcNote2(cx, bce, noteType, ptrdiff_t(index)); @@ -6396,7 +6393,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_COMMA: + case PNK_COMMA: /* * Emit SRC_PCDELTA notes on each JSOP_POP between comma operands. * These notes help the decompiler bracket the bytecodes generated @@ -6422,23 +6419,23 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_ASSIGN: - case TOK_ADDASSIGN: - case TOK_SUBASSIGN: - case TOK_BITORASSIGN: - case TOK_BITXORASSIGN: - case TOK_BITANDASSIGN: - case TOK_LSHASSIGN: - case TOK_RSHASSIGN: - case TOK_URSHASSIGN: - case TOK_MULASSIGN: - case TOK_DIVASSIGN: - case TOK_MODASSIGN: + case PNK_ASSIGN: + case PNK_ADDASSIGN: + case PNK_SUBASSIGN: + case PNK_BITORASSIGN: + case PNK_BITXORASSIGN: + case PNK_BITANDASSIGN: + case PNK_LSHASSIGN: + case PNK_RSHASSIGN: + case PNK_URSHASSIGN: + case PNK_MULASSIGN: + case PNK_DIVASSIGN: + case PNK_MODASSIGN: if (!EmitAssignment(cx, bce, pn->pn_left, pn->getOp(), pn->pn_right)) return false; break; - case TOK_HOOK: + case PNK_HOOK: /* Emit the condition, then branch if false to the else part. */ if (!EmitTree(cx, bce, pn->pn_kid1)) return JS_FALSE; @@ -6476,8 +6473,8 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; break; - case TOK_OR: - case TOK_AND: + case PNK_OR: + case PNK_AND: /* * JSOP_OR converts the operand on the stack to boolean, and if true, * leaves the original operand value on the stack and jumps; otherwise @@ -6540,29 +6537,29 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_PLUS: - case TOK_MINUS: + case PNK_PLUS: + case PNK_MINUS: if (pn->isArity(PN_UNARY)) goto unary_plusminus; - case TOK_BITOR: - case TOK_BITXOR: - case TOK_BITAND: - case TOK_STRICTEQ: - case TOK_EQ: - case TOK_STRICTNE: - case TOK_NE: - case TOK_LT: - case TOK_LE: - case TOK_GT: - case TOK_GE: - case TOK_IN: - case TOK_INSTANCEOF: - case TOK_LSH: - case TOK_RSH: - case TOK_URSH: - case TOK_STAR: - case TOK_DIV: - case TOK_MOD: + case PNK_BITOR: + case PNK_BITXOR: + case PNK_BITAND: + case PNK_STRICTEQ: + case PNK_EQ: + case PNK_STRICTNE: + case PNK_NE: + case PNK_LT: + case PNK_LE: + case PNK_GT: + case PNK_GE: + case PNK_IN: + case PNK_INSTANCEOF: + case PNK_LSH: + case PNK_RSH: + case PNK_URSH: + case PNK_STAR: + case PNK_DIV: + case PNK_MOD: if (pn->isArity(PN_LIST)) { /* Left-associative operator chain: avoid too much recursion. */ pn2 = pn->pn_head; @@ -6579,7 +6576,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) #if JS_HAS_XML_SUPPORT uintN oldflags; - case TOK_DBLCOLON: + case PNK_DBLCOLON: if (pn->getOp() == JSOP_XMLNAME) { if (!EmitXMLName(cx, pn, JSOP_XMLNAME, bce)) return JS_FALSE; @@ -6615,17 +6612,17 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_THROW: + case PNK_THROW: #if JS_HAS_XML_SUPPORT - case TOK_AT: - case TOK_DEFAULT: + case PNK_AT: + case PNK_DEFAULT: JS_ASSERT(pn->isArity(PN_UNARY)); /* FALL THROUGH */ #endif - case TOK_TYPEOF: - case TOK_VOID: - case TOK_NOT: - case TOK_BITNOT: + case PNK_TYPEOF: + case PNK_VOID: + case PNK_NOT: + case PNK_BITNOT: unary_plusminus: { uintN oldflags; @@ -6641,7 +6638,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) #endif pn2 = pn->pn_kid; - if (op == JSOP_TYPEOF && !pn2->isKind(TOK_NAME)) + if (op == JSOP_TYPEOF && !pn2->isKind(PNK_NAME)) op = JSOP_TYPEOFEXPR; oldflags = bce->flags; @@ -6654,15 +6651,15 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_INC: - case TOK_DEC: + case PNK_INC: + case PNK_DEC: /* Emit lvalue-specialized code for ++/-- operators. */ pn2 = pn->pn_kid; - JS_ASSERT(!pn2->isKind(TOK_RP)); + JS_ASSERT(!pn2->isKind(PNK_RP)); op = pn->getOp(); switch (pn2->getKind()) { default: - JS_ASSERT(pn2->isKind(TOK_NAME)); + JS_ASSERT(pn2->isKind(PNK_NAME)); pn2->setOp(op); if (!BindNameToSlot(cx, bce, pn2)) return JS_FALSE; @@ -6697,15 +6694,15 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } } break; - case TOK_DOT: + case PNK_DOT: if (!EmitPropIncDec(cx, pn2, op, bce)) return JS_FALSE; break; - case TOK_LB: + case PNK_LB: if (!EmitElemIncDec(cx, pn2, op, bce)) return JS_FALSE; break; - case TOK_LP: + case PNK_LP: if (!EmitTree(cx, bce, pn2)) return JS_FALSE; if (NewSrcNote2(cx, bce, SRC_PCBASE, bce->offset() - pn2->pn_offset) < 0) @@ -6725,9 +6722,9 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(!bce->inStrictMode()); JS_ASSERT(pn2->isOp(JSOP_SETXMLNAME)); if (!EmitTree(cx, bce, pn2->pn_kid)) @@ -6741,14 +6738,14 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_DELETE: + case PNK_DELETE: /* * Under ECMA 3, deleting a non-reference returns true -- but alas we * must evaluate the operand if it appears it might have side effects. */ pn2 = pn->pn_kid; switch (pn2->getKind()) { - case TOK_NAME: + case PNK_NAME: if (!BindNameToSlot(cx, bce, pn2)) return JS_FALSE; op = pn2->getOp(); @@ -6760,18 +6757,18 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; } break; - case TOK_DOT: + case PNK_DOT: if (!EmitPropOp(cx, pn2, JSOP_DELPROP, bce, JS_FALSE)) return JS_FALSE; break; #if JS_HAS_XML_SUPPORT - case TOK_DBLDOT: + case PNK_DBLDOT: JS_ASSERT(!bce->inStrictMode()); if (!EmitElemOp(cx, pn2, JSOP_DELDESC, bce)) return JS_FALSE; break; #endif - case TOK_LB: + case PNK_LB: if (!EmitElemOp(cx, pn2, JSOP_DELELEM, bce)) return JS_FALSE; break; @@ -6786,7 +6783,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (!useful) { off = noteIndex = -1; } else { - JS_ASSERT_IF(pn2->isKind(TOK_LP), !(pn2->pn_xflags & PNX_SETCALL)); + JS_ASSERT_IF(pn2->isKind(PNK_LP), !(pn2->pn_xflags & PNX_SETCALL)); if (!EmitTree(cx, bce, pn2)) return JS_FALSE; off = bce->offset(); @@ -6805,7 +6802,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #if JS_HAS_XML_SUPPORT - case TOK_FILTER: + case PNK_FILTER: JS_ASSERT(!bce->inStrictMode()); if (!EmitTree(cx, bce, pn->pn_left)) @@ -6828,7 +6825,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #endif - case TOK_DOT: + case PNK_DOT: /* * Pop a stack operand, convert it to object, get a property named by * this bytecode's immediate-indexed atom operand, and push its value @@ -6838,11 +6835,11 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #if JS_HAS_XML_SUPPORT - case TOK_DBLDOT: + case PNK_DBLDOT: JS_ASSERT(!bce->inStrictMode()); /* FALL THROUGH */ #endif - case TOK_LB: + case PNK_LB: /* * Pop two operands, convert the left one to object and the right one * to property name (atom or tagged int), get the named property, and @@ -6852,10 +6849,10 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) ok = EmitElemOp(cx, pn, pn->getOp(), bce); break; - case TOK_NEW: - case TOK_LP: + case PNK_NEW: + case PNK_LP: { - bool callop = pn->isKind(TOK_LP); + bool callop = pn->isKind(PNK_LP); /* * Emit callable invocation or operator new (constructor call) code. @@ -6874,23 +6871,23 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) */ pn2 = pn->pn_head; switch (pn2->getKind()) { - case TOK_NAME: + case PNK_NAME: if (!EmitNameOp(cx, bce, pn2, callop)) return JS_FALSE; break; - case TOK_DOT: + case PNK_DOT: if (!EmitPropOp(cx, pn2, pn2->getOp(), bce, callop)) return JS_FALSE; break; - case TOK_LB: + case PNK_LB: JS_ASSERT(pn2->isOp(JSOP_GETELEM)); if (!EmitElemOp(cx, pn2, callop ? JSOP_CALLELEM : JSOP_GETELEM, bce)) return JS_FALSE; break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(pn2->isOp(JSOP_XMLNAME)); if (!EmitXMLName(cx, pn2, JSOP_CALLXMLNAME, bce)) return JS_FALSE; @@ -6940,18 +6937,18 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; } - case TOK_LEXICALSCOPE: + case PNK_LEXICALSCOPE: ok = EmitLexicalScope(cx, bce, pn); break; #if JS_HAS_BLOCK_SCOPE - case TOK_LET: + case PNK_LET: if (!EmitLet(cx, bce, pn)) return false; break; #endif /* JS_HAS_BLOCK_SCOPE */ #if JS_HAS_GENERATORS - case TOK_ARRAYPUSH: { + case PNK_ARRAYPUSH: { jsint slot; /* @@ -6969,9 +6966,9 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } #endif - case TOK_RB: + case PNK_RB: #if JS_HAS_GENERATORS - case TOK_ARRAYCOMP: + case PNK_ARRAYCOMP: #endif /* * Emit code for [a, b, c] that is equivalent to constructing a new @@ -6987,15 +6984,15 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) #endif #if JS_HAS_GENERATORS - if (pn->isKind(TOK_ARRAYCOMP)) { + if (pn->isKind(PNK_ARRAYCOMP)) { uintN saveDepth; if (!EmitNewInit(cx, bce, JSProto_Array, pn, sharpnum)) return JS_FALSE; /* - * Pass the new array's stack index to the TOK_ARRAYPUSH case via - * bce->arrayCompDepth, then simply traverse the TOK_FOR node and + * Pass the new array's stack index to the PNK_ARRAYPUSH case via + * bce->arrayCompDepth, then simply traverse the PNK_FOR node and * its kids under pn2 to generate this comprehension. */ JS_ASSERT(bce->stackDepth > 0); @@ -7035,7 +7032,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) for (atomIndex = 0; pn2; atomIndex++, pn2 = pn2->pn_next) { if (!EmitNumberOp(cx, atomIndex, bce)) return JS_FALSE; - if (pn2->isKind(TOK_COMMA) && pn2->isArity(PN_NULLARY)) { + if (pn2->isKind(PNK_COMMA) && pn2->isArity(PN_NULLARY)) { if (Emit1(cx, bce, JSOP_HOLE) < 0) return JS_FALSE; } else { @@ -7061,7 +7058,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) return JS_FALSE; break; - case TOK_RC: { + case PNK_RC: { #if JS_HAS_SHARP_VARS sharpnum = -1; do_emit_object: @@ -7109,7 +7106,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { /* Emit an index for t[2] for later consumption by JSOP_INITELEM. */ pn3 = pn2->pn_left; - if (pn3->isKind(TOK_NUMBER)) { + if (pn3->isKind(PNK_NUMBER)) { if (!EmitNumberOp(cx, pn3->pn_dval, bce)) return JS_FALSE; } @@ -7126,15 +7123,14 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } /* Annotate JSOP_INITELEM so we decompile 2:c and not just c. */ - if (pn3->isKind(TOK_NUMBER)) { + if (pn3->isKind(PNK_NUMBER)) { obj = NULL; if (NewSrcNote(cx, bce, SRC_INITPROP) < 0) return JS_FALSE; if (Emit1(cx, bce, JSOP_INITELEM) < 0) return JS_FALSE; } else { - JS_ASSERT(pn3->isKind(TOK_NAME) || - pn3->isKind(TOK_STRING)); + JS_ASSERT(pn3->isKind(PNK_NAME) || pn3->isKind(PNK_STRING)); jsatomid index; if (!bce->makeAtomIndex(pn3->pn_atom, &index)) return JS_FALSE; @@ -7200,17 +7196,17 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } #if JS_HAS_SHARP_VARS - case TOK_DEFSHARP: + case PNK_DEFSHARP: JS_ASSERT(bce->hasSharps()); sharpnum = pn->pn_num; pn = pn->pn_kid; - if (pn->isKind(TOK_RB)) + if (pn->isKind(PNK_RB)) goto do_emit_array; # if JS_HAS_GENERATORS - if (pn->isKind(TOK_ARRAYCOMP)) + if (pn->isKind(PNK_ARRAYCOMP)) goto do_emit_array; # endif - if (pn->isKind(TOK_RC)) + if (pn->isKind(PNK_RC)) goto do_emit_object; if (!EmitTree(cx, bce, pn)) @@ -7218,13 +7214,13 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) EMIT_UINT16PAIR_IMM_OP(JSOP_DEFSHARP, bce->sharpSlotBase, (jsatomid) sharpnum); break; - case TOK_USESHARP: + case PNK_USESHARP: JS_ASSERT(bce->hasSharps()); EMIT_UINT16PAIR_IMM_OP(JSOP_USESHARP, bce->sharpSlotBase, (jsatomid) pn->pn_num); break; #endif /* JS_HAS_SHARP_VARS */ - case TOK_NAME: + case PNK_NAME: /* * Cope with a left-over function definition that was replaced by a use * of a later function definition of the same name. See FunctionDef and @@ -7237,60 +7233,60 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) break; #if JS_HAS_XML_SUPPORT - case TOK_XMLATTR: - case TOK_XMLSPACE: - case TOK_XMLTEXT: - case TOK_XMLCDATA: - case TOK_XMLCOMMENT: + case PNK_XMLATTR: + case PNK_XMLSPACE: + case PNK_XMLTEXT: + case PNK_XMLCDATA: + case PNK_XMLCOMMENT: JS_ASSERT(!bce->inStrictMode()); /* FALL THROUGH */ #endif - case TOK_STRING: + case PNK_STRING: ok = EmitAtomOp(cx, pn, pn->getOp(), bce); break; - case TOK_NUMBER: + case PNK_NUMBER: ok = EmitNumberOp(cx, pn->pn_dval, bce); break; - case TOK_REGEXP: + case PNK_REGEXP: JS_ASSERT(pn->isOp(JSOP_REGEXP)); ok = EmitIndexOp(cx, JSOP_REGEXP, bce->regexpList.index(pn->pn_objbox), bce); break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: + case PNK_ANYNAME: if (pn->getOp() == JSOP_XMLNAME) { if (!EmitXMLName(cx, pn, JSOP_XMLNAME, bce)) return JS_FALSE; break; } #endif - case TOK_TRUE: - case TOK_FALSE: - case TOK_THIS: - case TOK_NULL: + case PNK_TRUE: + case PNK_FALSE: + case PNK_THIS: + case PNK_NULL: if (Emit1(cx, bce, pn->getOp()) < 0) return JS_FALSE; break; - case TOK_DEBUGGER: + case PNK_DEBUGGER: if (Emit1(cx, bce, JSOP_DEBUGGER) < 0) return JS_FALSE; break; #if JS_HAS_XML_SUPPORT - case TOK_XMLELEM: - case TOK_XMLLIST: + case PNK_XMLELEM: + case PNK_XMLLIST: JS_ASSERT(!bce->inStrictMode()); - JS_ASSERT(pn->isKind(TOK_XMLLIST) || pn->pn_count != 0); + JS_ASSERT(pn->isKind(PNK_XMLLIST) || pn->pn_count != 0); - switch (pn->pn_head ? pn->pn_head->getKind() : TOK_XMLLIST) { - case TOK_XMLETAGO: + switch (pn->pn_head ? pn->pn_head->getKind() : PNK_XMLLIST) { + case PNK_XMLETAGO: JS_ASSERT(0); /* FALL THROUGH */ - case TOK_XMLPTAGC: - case TOK_XMLSTAGO: + case PNK_XMLPTAGC: + case PNK_XMLSTAGO: break; default: if (Emit1(cx, bce, JSOP_STARTXML) < 0) @@ -7298,10 +7294,8 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { - if (pn2->isKind(TOK_LC) && - Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) { + if (pn2->isKind(PNK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) return JS_FALSE; - } if (!EmitTree(cx, bce, pn2)) return JS_FALSE; if (pn2 != pn->pn_head && Emit1(cx, bce, JSOP_ADD) < 0) @@ -7310,7 +7304,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) if (pn->pn_xflags & PNX_XMLROOT) { if (pn->pn_count == 0) { - JS_ASSERT(pn->isKind(TOK_XMLLIST)); + JS_ASSERT(pn->isKind(PNK_XMLLIST)); atom = cx->runtime->atomState.emptyAtom; jsatomid index; if (!bce->makeAtomIndex(atom, &index)) @@ -7326,23 +7320,21 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) #endif break; - case TOK_XMLPTAGC: - case TOK_XMLSTAGO: - case TOK_XMLETAGO: + case PNK_XMLPTAGC: + case PNK_XMLSTAGO: + case PNK_XMLETAGO: if (!EmitXMLTag(cx, bce, pn)) return false; break; - case TOK_XMLNAME: + case PNK_XMLNAME: JS_ASSERT(!bce->inStrictMode()); if (pn->isArity(PN_LIST)) { JS_ASSERT(pn->pn_count != 0); for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { - if (pn2->isKind(TOK_LC) && - Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) { + if (pn2->isKind(PNK_LC) && Emit1(cx, bce, JSOP_STARTXMLEXPR) < 0) return JS_FALSE; - } if (!EmitTree(cx, bce, pn2)) return JS_FALSE; if (pn2 != pn->pn_head && Emit1(cx, bce, JSOP_ADD) < 0) @@ -7356,7 +7348,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn) } break; - case TOK_XMLPI: + case PNK_XMLPI: if (!EmitXMLProcessingInstruction(cx, bce, pn)) return false; break; diff --git a/js/src/frontend/FoldConstants.cpp b/js/src/frontend/FoldConstants.cpp index 317e292edec3..9f1b7fb58ecb 100644 --- a/js/src/frontend/FoldConstants.cpp +++ b/js/src/frontend/FoldConstants.cpp @@ -52,30 +52,25 @@ using namespace js; static ParseNode * -ContainsStmt(ParseNode *pn, TokenKind tt) +ContainsStmt(ParseNode *pn, ParseNodeKind kind) { - ParseNode *pn2, *pnt; - if (!pn) return NULL; - if (pn->isKind(tt)) + if (pn->isKind(kind)) return pn; switch (pn->getArity()) { case PN_LIST: - for (pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { - pnt = ContainsStmt(pn2, tt); - if (pnt) + for (ParseNode *pn2 = pn->pn_head; pn2; pn2 = pn2->pn_next) { + if (ParseNode *pnt = ContainsStmt(pn2, kind)) return pnt; } break; case PN_TERNARY: - pnt = ContainsStmt(pn->pn_kid1, tt); - if (pnt) + if (ParseNode *pnt = ContainsStmt(pn->pn_kid1, kind)) return pnt; - pnt = ContainsStmt(pn->pn_kid2, tt); - if (pnt) + if (ParseNode *pnt = ContainsStmt(pn->pn_kid2, kind)) return pnt; - return ContainsStmt(pn->pn_kid3, tt); + return ContainsStmt(pn->pn_kid3, kind); case PN_BINARY: /* * Limit recursion if pn is a binary expression, which can't contain a @@ -83,18 +78,17 @@ ContainsStmt(ParseNode *pn, TokenKind tt) */ if (!pn->isOp(JSOP_NOP)) return NULL; - pnt = ContainsStmt(pn->pn_left, tt); - if (pnt) + if (ParseNode *pnt = ContainsStmt(pn->pn_left, kind)) return pnt; - return ContainsStmt(pn->pn_right, tt); + return ContainsStmt(pn->pn_right, kind); case PN_UNARY: if (!pn->isOp(JSOP_NOP)) return NULL; - return ContainsStmt(pn->pn_kid, tt); + return ContainsStmt(pn->pn_kid, kind); case PN_NAME: - return ContainsStmt(pn->maybeExpr(), tt); + return ContainsStmt(pn->maybeExpr(), kind); case PN_NAMESET: - return ContainsStmt(pn->pn_tree, tt); + return ContainsStmt(pn->pn_tree, kind); default:; } return NULL; @@ -105,30 +99,30 @@ ContainsStmt(ParseNode *pn, TokenKind tt) * XXX handles only strings and numbers for now */ static JSBool -FoldType(JSContext *cx, ParseNode *pn, TokenKind type) +FoldType(JSContext *cx, ParseNode *pn, ParseNodeKind kind) { - if (!pn->isKind(type)) { - switch (type) { - case TOK_NUMBER: - if (pn->isKind(TOK_STRING)) { + if (!pn->isKind(kind)) { + switch (kind) { + case PNK_NUMBER: + if (pn->isKind(PNK_STRING)) { jsdouble d; if (!ToNumber(cx, StringValue(pn->pn_atom), &d)) return JS_FALSE; pn->pn_dval = d; - pn->setKind(TOK_NUMBER); + pn->setKind(PNK_NUMBER); pn->setOp(JSOP_DOUBLE); } break; - case TOK_STRING: - if (pn->isKind(TOK_NUMBER)) { + case PNK_STRING: + if (pn->isKind(PNK_NUMBER)) { JSString *str = js_NumberToString(cx, pn->pn_dval); if (!str) return JS_FALSE; pn->pn_atom = js_AtomizeString(cx, str); if (!pn->pn_atom) return JS_FALSE; - pn->setKind(TOK_STRING); + pn->setKind(PNK_STRING); pn->setOp(JSOP_STRING); } break; @@ -151,7 +145,7 @@ FoldBinaryNumeric(JSContext *cx, JSOp op, ParseNode *pn1, ParseNode *pn2, jsdouble d, d2; int32 i, j; - JS_ASSERT(pn1->isKind(TOK_NUMBER) && pn2->isKind(TOK_NUMBER)); + JS_ASSERT(pn1->isKind(PNK_NUMBER) && pn2->isKind(PNK_NUMBER)); d = pn1->pn_dval; d2 = pn2->pn_dval; switch (op) { @@ -216,7 +210,7 @@ FoldBinaryNumeric(JSContext *cx, JSOp op, ParseNode *pn1, ParseNode *pn2, tc->freeTree(pn1); if (pn2 != pn) tc->freeTree(pn2); - pn->setKind(TOK_NUMBER); + pn->setKind(PNK_NUMBER); pn->setOp(JSOP_DOUBLE); pn->setArity(PN_NULLARY); pn->pn_dval = d; @@ -228,61 +222,58 @@ FoldBinaryNumeric(JSContext *cx, JSOp op, ParseNode *pn1, ParseNode *pn2, static JSBool FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) { - TokenKind tt; - ParseNode **pnp, *pn1, *pn2; - JSString *accum, *str; - uint32 i, j; - JS_ASSERT(pn->isArity(PN_LIST)); - tt = pn->getKind(); - pnp = &pn->pn_head; - pn1 = *pnp; - accum = NULL; - str = NULL; + ParseNodeKind kind = pn->getKind(); + ParseNode **pnp = &pn->pn_head; + ParseNode *pn1 = *pnp; + JSString *accum = NULL; + JSString *str = NULL; if ((pn->pn_xflags & PNX_CANTFOLD) == 0) { - if (tt == TOK_XMLETAGO) + if (kind == PNK_XMLETAGO) accum = cx->runtime->atomState.etagoAtom; - else if (tt == TOK_XMLSTAGO || tt == TOK_XMLPTAGC) + else if (kind == PNK_XMLSTAGO || kind == PNK_XMLPTAGC) accum = cx->runtime->atomState.stagoAtom; } /* * GC Rooting here is tricky: for most of the loop, |accum| is safe via - * the newborn string root. However, when |pn2->pn_type| is TOK_XMLCDATA, - * TOK_XMLCOMMENT, or TOK_XMLPI it is knocked out of the newborn root. + * the newborn string root. However, when |pn2->getKind()| is PNK_XMLCDATA, + * PNK_XMLCOMMENT, or PNK_XMLPI it is knocked out of the newborn root. * Therefore, we have to add additonal protection from GC nesting under * js_ConcatStrings. */ + ParseNode *pn2; + uint32 i, j; for (pn2 = pn1, i = j = 0; pn2; pn2 = pn2->pn_next, i++) { /* The parser already rejected end-tags with attributes. */ - JS_ASSERT(tt != TOK_XMLETAGO || i == 0); + JS_ASSERT(kind != PNK_XMLETAGO || i == 0); switch (pn2->getKind()) { - case TOK_XMLATTR: + case PNK_XMLATTR: if (!accum) goto cantfold; /* FALL THROUGH */ - case TOK_XMLNAME: - case TOK_XMLSPACE: - case TOK_XMLTEXT: - case TOK_STRING: + case PNK_XMLNAME: + case PNK_XMLSPACE: + case PNK_XMLTEXT: + case PNK_STRING: if (pn2->isArity(PN_LIST)) goto cantfold; str = pn2->pn_atom; break; - case TOK_XMLCDATA: + case PNK_XMLCDATA: str = js_MakeXMLCDATAString(cx, pn2->pn_atom); if (!str) return JS_FALSE; break; - case TOK_XMLCOMMENT: + case PNK_XMLCOMMENT: str = js_MakeXMLCommentString(cx, pn2->pn_atom); if (!str) return JS_FALSE; break; - case TOK_XMLPI: + case PNK_XMLPI: str = js_MakeXMLPIString(cx, pn2->pn_pitarget, pn2->pn_pidata); if (!str) return JS_FALSE; @@ -291,7 +282,7 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) cantfold: default: JS_ASSERT(*pnp == pn1); - if ((tt == TOK_XMLSTAGO || tt == TOK_XMLPTAGC) && + if ((kind == PNK_XMLSTAGO || kind == PNK_XMLPTAGC) && (i & 1) ^ (j & 1)) { #ifdef DEBUG_brendanXXX printf("1: %d, %d => ", i, j); @@ -306,7 +297,7 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) pn1 = tc->freeTree(pn1); --pn->pn_count; } - pn1->setKind(TOK_XMLTEXT); + pn1->setKind(PNK_XMLTEXT); pn1->setOp(JSOP_STRING); pn1->setArity(PN_NULLARY); pn1->pn_atom = js_AtomizeString(cx, accum); @@ -324,7 +315,7 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) if (accum) { { AutoStringRooter tvr(cx, accum); - str = ((tt == TOK_XMLSTAGO || tt == TOK_XMLPTAGC) && i != 0) + str = ((kind == PNK_XMLSTAGO || kind == PNK_XMLPTAGC) && i != 0) ? js_AddAttributePart(cx, i & 1, accum, str) : js_ConcatStrings(cx, accum, str); } @@ -343,9 +334,9 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) if (accum) { str = NULL; if ((pn->pn_xflags & PNX_CANTFOLD) == 0) { - if (tt == TOK_XMLPTAGC) + if (kind == PNK_XMLPTAGC) str = cx->runtime->atomState.ptagcAtom; - else if (tt == TOK_XMLSTAGO || tt == TOK_XMLETAGO) + else if (kind == PNK_XMLSTAGO || kind == PNK_XMLETAGO) str = cx->runtime->atomState.tagcAtom; } if (str) { @@ -359,7 +350,7 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) pn1 = tc->freeTree(pn1); --pn->pn_count; } - pn1->setKind(TOK_XMLTEXT); + pn1->setKind(PNK_XMLTEXT); pn1->setOp(JSOP_STRING); pn1->setArity(PN_NULLARY); pn1->pn_atom = js_AtomizeString(cx, accum); @@ -374,13 +365,13 @@ FoldXMLConstants(JSContext *cx, ParseNode *pn, TreeContext *tc) * Only one node under pn, and it has been folded: move pn1 onto pn * unless pn is an XML root (in which case we need it to tell the code * generator to emit a JSOP_TOXML or JSOP_TOXMLLIST op). If pn is an - * XML root *and* it's a point-tag, rewrite it to TOK_XMLELEM to avoid + * XML root *and* it's a point-tag, rewrite it to PNK_XMLELEM to avoid * extra "<" and "/>" bracketing at runtime. */ if (!(pn->pn_xflags & PNX_XMLROOT)) { pn->become(pn1); - } else if (tt == TOK_XMLPTAGC) { - pn->setKind(TOK_XMLELEM); + } else if (kind == PNK_XMLPTAGC) { + pn->setKind(PNK_XMLELEM); pn->setOp(JSOP_TOXML); } } @@ -412,7 +403,7 @@ Boolish(ParseNode *pn) if (pn->pn_count != 1) return Unknown; ParseNode *pn2 = pn->pn_head; - if (!pn2->isKind(TOK_FUNCTION)) + if (!pn2->isKind(PNK_FUNCTION)) return Unknown; if (!(pn2->pn_funbox->tcflags & TCF_GENEXP_LAMBDA)) return Unknown; @@ -460,11 +451,11 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) case PN_LIST: { /* Propagate inCond through logical connectives. */ - bool cond = inCond && (pn->isKind(TOK_OR) || pn->isKind(TOK_AND)); + bool cond = inCond && (pn->isKind(PNK_OR) || pn->isKind(PNK_AND)); /* Don't fold a parenthesized call expression. See bug 537673. */ pn1 = pn2 = pn->pn_head; - if ((pn->isKind(TOK_LP) || pn->isKind(TOK_NEW)) && pn2->isInParens()) + if ((pn->isKind(PNK_LP) || pn->isKind(PNK_NEW)) && pn2->isInParens()) pn2 = pn2->pn_next; /* Save the list head in pn1 for later use. */ @@ -480,12 +471,12 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pn1 = pn->pn_kid1; pn2 = pn->pn_kid2; pn3 = pn->pn_kid3; - if (pn1 && !FoldConstants(cx, pn1, tc, pn->isKind(TOK_IF))) + if (pn1 && !FoldConstants(cx, pn1, tc, pn->isKind(PNK_IF))) return false; if (pn2) { - if (!FoldConstants(cx, pn2, tc, pn->isKind(TOK_FORHEAD))) + if (!FoldConstants(cx, pn2, tc, pn->isKind(PNK_FORHEAD))) return false; - if (pn->isKind(TOK_FORHEAD) && pn2->isOp(JSOP_TRUE)) { + if (pn->isKind(PNK_FORHEAD) && pn2->isOp(JSOP_TRUE)) { tc->freeTree(pn2); pn->pn_kid2 = NULL; } @@ -499,7 +490,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pn2 = pn->pn_right; /* Propagate inCond through logical connectives. */ - if (pn->isKind(TOK_OR) || pn->isKind(TOK_AND)) { + if (pn->isKind(PNK_OR) || pn->isKind(PNK_AND)) { if (!FoldConstants(cx, pn1, tc, inCond)) return false; if (!FoldConstants(cx, pn2, tc, inCond)) @@ -508,9 +499,9 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) } /* First kid may be null (for default case in switch). */ - if (pn1 && !FoldConstants(cx, pn1, tc, pn->isKind(TOK_WHILE))) + if (pn1 && !FoldConstants(cx, pn1, tc, pn->isKind(PNK_WHILE))) return false; - if (!FoldConstants(cx, pn2, tc, pn->isKind(TOK_DO))) + if (!FoldConstants(cx, pn2, tc, pn->isKind(PNK_DO))) return false; break; @@ -526,7 +517,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) * null. This assumption does not hold true for other unary * expressions. */ - if (pn->isOp(JSOP_TYPEOF) && !pn1->isKind(TOK_NAME)) + if (pn->isOp(JSOP_TYPEOF) && !pn1->isKind(PNK_NAME)) pn->setOp(JSOP_TYPEOFEXPR); if (pn1 && !FoldConstants(cx, pn1, tc, pn->isOp(JSOP_NOT))) @@ -560,26 +551,26 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) } switch (pn->getKind()) { - case TOK_IF: - if (ContainsStmt(pn2, TOK_VAR) || ContainsStmt(pn3, TOK_VAR)) + case PNK_IF: + if (ContainsStmt(pn2, PNK_VAR) || ContainsStmt(pn3, PNK_VAR)) break; /* FALL THROUGH */ - case TOK_HOOK: + case PNK_HOOK: /* Reduce 'if (C) T; else E' into T for true C, E for false. */ switch (pn1->getKind()) { - case TOK_NUMBER: + case PNK_NUMBER: if (pn1->pn_dval == 0 || JSDOUBLE_IS_NaN(pn1->pn_dval)) pn2 = pn3; break; - case TOK_STRING: + case PNK_STRING: if (pn1->pn_atom->length() == 0) pn2 = pn3; break; - case TOK_TRUE: + case PNK_TRUE: break; - case TOK_FALSE: - case TOK_NULL: + case PNK_FALSE: + case PNK_NULL: pn2 = pn3; break; default: @@ -595,15 +586,15 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) if (pn2 && !pn2->isDefn()) pn->become(pn2); - if (!pn2 || (pn->isKind(TOK_SEMI) && !pn->pn_kid)) { + if (!pn2 || (pn->isKind(PNK_SEMI) && !pn->pn_kid)) { /* * False condition and no else, or an empty then-statement was * moved up over pn. Either way, make pn an empty block (not an * empty statement, which does not decompile, even when labeled). - * NB: pn must be a TOK_IF as TOK_HOOK can never have a null kid + * NB: pn must be a PNK_IF as PNK_HOOK can never have a null kid * or an empty statement for a child. */ - pn->setKind(TOK_LC); + pn->setKind(PNK_LC); pn->setArity(PN_LIST); pn->makeEmpty(); } @@ -612,8 +603,8 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) tc->freeTree(pn3); break; - case TOK_OR: - case TOK_AND: + case PNK_OR: + case PNK_AND: if (inCond) { if (pn->isArity(PN_LIST)) { ParseNode **pnp = &pn->pn_head; @@ -624,7 +615,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pnp = &pn1->pn_next; continue; } - if ((t == Truthy) == pn->isKind(TOK_OR)) { + if ((t == Truthy) == pn->isKind(PNK_OR)) { for (pn2 = pn1->pn_next; pn2; pn2 = pn3) { pn3 = pn2->pn_next; tc->freeTree(pn2); @@ -633,7 +624,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pn1->pn_next = NULL; break; } - JS_ASSERT((t == Truthy) == pn->isKind(TOK_AND)); + JS_ASSERT((t == Truthy) == pn->isKind(PNK_AND)); if (pn->pn_count == 1) break; *pnp = pn1->pn_next; @@ -657,11 +648,11 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) } else { Truthiness t = Boolish(pn1); if (t != Unknown) { - if ((t == Truthy) == pn->isKind(TOK_OR)) { + if ((t == Truthy) == pn->isKind(PNK_OR)) { tc->freeTree(pn2); pn->become(pn1); } else { - JS_ASSERT((t == Truthy) == pn->isKind(TOK_AND)); + JS_ASSERT((t == Truthy) == pn->isKind(PNK_AND)); tc->freeTree(pn1); pn->become(pn2); } @@ -670,16 +661,16 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) } break; - case TOK_SUBASSIGN: - case TOK_BITORASSIGN: - case TOK_BITXORASSIGN: - case TOK_BITANDASSIGN: - case TOK_LSHASSIGN: - case TOK_RSHASSIGN: - case TOK_URSHASSIGN: - case TOK_MULASSIGN: - case TOK_DIVASSIGN: - case TOK_MODASSIGN: + case PNK_SUBASSIGN: + case PNK_BITORASSIGN: + case PNK_BITXORASSIGN: + case PNK_BITANDASSIGN: + case PNK_LSHASSIGN: + case PNK_RSHASSIGN: + case PNK_URSHASSIGN: + case PNK_MULASSIGN: + case PNK_DIVASSIGN: + case PNK_MODASSIGN: /* * Compound operators such as *= should be subject to folding, in case * the left-hand side is constant, and so that the decompiler produces @@ -689,10 +680,10 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) */ goto do_binary_op; - case TOK_ADDASSIGN: + case PNK_ADDASSIGN: JS_ASSERT(pn->isOp(JSOP_ADD)); /* FALL THROUGH */ - case TOK_PLUS: + case PNK_PLUS: if (pn->isArity(PN_UNARY)) goto unary_plusminus; if (pn->isArity(PN_LIST)) { @@ -710,10 +701,10 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) /* Ok, we're concatenating: convert non-string constant operands. */ size_t length = 0; for (pn2 = pn1; pn2; pn2 = pn2->pn_next) { - if (!FoldType(cx, pn2, TOK_STRING)) + if (!FoldType(cx, pn2, PNK_STRING)) return false; /* XXX fold only if all operands convert to string */ - if (!pn2->isKind(TOK_STRING)) + if (!pn2->isKind(PNK_STRING)) return true; length += pn2->pn_atom->length(); } @@ -742,7 +733,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pn->pn_atom = js_AtomizeString(cx, str); if (!pn->pn_atom) return false; - pn->setKind(TOK_STRING); + pn->setKind(PNK_STRING); pn->setOp(JSOP_STRING); pn->setArity(PN_NULLARY); break; @@ -750,12 +741,12 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) /* Handle a binary string concatenation. */ JS_ASSERT(pn->isArity(PN_BINARY)); - if (pn1->isKind(TOK_STRING) || pn2->isKind(TOK_STRING)) { + if (pn1->isKind(PNK_STRING) || pn2->isKind(PNK_STRING)) { JSString *left, *right, *str; - if (!FoldType(cx, !pn1->isKind(TOK_STRING) ? pn1 : pn2, TOK_STRING)) + if (!FoldType(cx, !pn1->isKind(PNK_STRING) ? pn1 : pn2, PNK_STRING)) return false; - if (!pn1->isKind(TOK_STRING) || !pn2->isKind(TOK_STRING)) + if (!pn1->isKind(PNK_STRING) || !pn2->isKind(PNK_STRING)) return true; left = pn1->pn_atom; right = pn2->pn_atom; @@ -765,7 +756,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) pn->pn_atom = js_AtomizeString(cx, str); if (!pn->pn_atom) return false; - pn->setKind(TOK_STRING); + pn->setKind(PNK_STRING); pn->setOp(JSOP_STRING); pn->setArity(PN_NULLARY); tc->freeTree(pn1); @@ -776,26 +767,26 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) /* Can't concatenate string literals, let's try numbers. */ goto do_binary_op; - case TOK_MINUS: + case PNK_MINUS: if (pn->isArity(PN_UNARY)) goto unary_plusminus; /* FALL THROUGH */ - case TOK_STAR: - case TOK_LSH: - case TOK_RSH: - case TOK_URSH: - case TOK_DIV: - case TOK_MOD: + case PNK_STAR: + case PNK_LSH: + case PNK_RSH: + case PNK_URSH: + case PNK_DIV: + case PNK_MOD: do_binary_op: if (pn->isArity(PN_LIST)) { JS_ASSERT(pn->pn_count > 2); for (pn2 = pn1; pn2; pn2 = pn2->pn_next) { - if (!FoldType(cx, pn2, TOK_NUMBER)) + if (!FoldType(cx, pn2, PNK_NUMBER)) return false; } for (pn2 = pn1; pn2; pn2 = pn2->pn_next) { /* XXX fold only if all operands convert to number */ - if (!pn2->isKind(TOK_NUMBER)) + if (!pn2->isKind(PNK_NUMBER)) break; } if (!pn2) { @@ -813,23 +804,23 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) } } else { JS_ASSERT(pn->isArity(PN_BINARY)); - if (!FoldType(cx, pn1, TOK_NUMBER) || - !FoldType(cx, pn2, TOK_NUMBER)) { + if (!FoldType(cx, pn1, PNK_NUMBER) || + !FoldType(cx, pn2, PNK_NUMBER)) { return false; } - if (pn1->isKind(TOK_NUMBER) && pn2->isKind(TOK_NUMBER)) { + if (pn1->isKind(PNK_NUMBER) && pn2->isKind(PNK_NUMBER)) { if (!FoldBinaryNumeric(cx, pn->getOp(), pn1, pn2, pn, tc)) return false; } } break; - case TOK_TYPEOF: - case TOK_VOID: - case TOK_NOT: - case TOK_BITNOT: + case PNK_TYPEOF: + case PNK_VOID: + case PNK_NOT: + case PNK_BITNOT: unary_plusminus: - if (pn1->isKind(TOK_NUMBER)) { + if (pn1->isKind(PNK_NUMBER)) { jsdouble d; /* Operate on one numeric constant. */ @@ -848,32 +839,32 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) case JSOP_NOT: if (d == 0 || JSDOUBLE_IS_NaN(d)) { - pn->setKind(TOK_TRUE); + pn->setKind(PNK_TRUE); pn->setOp(JSOP_TRUE); } else { - pn->setKind(TOK_FALSE); + pn->setKind(PNK_FALSE); pn->setOp(JSOP_FALSE); } pn->setArity(PN_NULLARY); /* FALL THROUGH */ default: - /* Return early to dodge the common TOK_NUMBER code. */ + /* Return early to dodge the common PNK_NUMBER code. */ return true; } - pn->setKind(TOK_NUMBER); + pn->setKind(PNK_NUMBER); pn->setOp(JSOP_DOUBLE); pn->setArity(PN_NULLARY); pn->pn_dval = d; tc->freeTree(pn1); - } else if (pn1->isKind(TOK_TRUE) || pn1->isKind(TOK_FALSE)) { + } else if (pn1->isKind(PNK_TRUE) || pn1->isKind(PNK_FALSE)) { if (pn->isOp(JSOP_NOT)) { pn->become(pn1); - if (pn->isKind(TOK_TRUE)) { - pn->setKind(TOK_FALSE); + if (pn->isKind(PNK_TRUE)) { + pn->setKind(PNK_FALSE); pn->setOp(JSOP_FALSE); } else { - pn->setKind(TOK_TRUE); + pn->setKind(PNK_TRUE); pn->setOp(JSOP_TRUE); } tc->freeTree(pn1); @@ -882,21 +873,21 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) break; #if JS_HAS_XML_SUPPORT - case TOK_XMLELEM: - case TOK_XMLLIST: - case TOK_XMLPTAGC: - case TOK_XMLSTAGO: - case TOK_XMLETAGO: - case TOK_XMLNAME: + case PNK_XMLELEM: + case PNK_XMLLIST: + case PNK_XMLPTAGC: + case PNK_XMLSTAGO: + case PNK_XMLETAGO: + case PNK_XMLNAME: if (pn->isArity(PN_LIST)) { - JS_ASSERT(pn->isKind(TOK_XMLLIST) || pn->pn_count != 0); + JS_ASSERT(pn->isKind(PNK_XMLLIST) || pn->pn_count != 0); if (!FoldXMLConstants(cx, pn, tc)) return false; } break; - case TOK_AT: - if (pn1->isKind(TOK_XMLNAME)) { + case PNK_AT: + if (pn1->isKind(PNK_XMLNAME)) { Value v = StringValue(pn1->pn_atom); if (!js_ToAttributeName(cx, &v)) return false; @@ -906,7 +897,7 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) if (!xmlbox) return false; - pn->setKind(TOK_XMLNAME); + pn->setKind(PNK_XMLNAME); pn->setOp(JSOP_OBJECT); pn->setArity(PN_NULLARY); pn->pn_objbox = xmlbox; @@ -929,10 +920,10 @@ js::FoldConstants(JSContext *cx, ParseNode *pn, TreeContext *tc, bool inCond) */ tc->parser->allocator.prepareNodeForMutation(pn); if (t == Truthy) { - pn->setKind(TOK_TRUE); + pn->setKind(PNK_TRUE); pn->setOp(JSOP_TRUE); } else { - pn->setKind(TOK_FALSE); + pn->setKind(PNK_FALSE); pn->setOp(JSOP_FALSE); } pn->setArity(PN_NULLARY); diff --git a/js/src/frontend/ParseNode-inl.h b/js/src/frontend/ParseNode-inl.h index 93fc5f00df31..4de49569f3b4 100644 --- a/js/src/frontend/ParseNode-inl.h +++ b/js/src/frontend/ParseNode-inl.h @@ -50,14 +50,14 @@ inline bool ParseNode::isConstant() { switch (pn_type) { - case TOK_NUMBER: - case TOK_STRING: - case TOK_NULL: - case TOK_FALSE: - case TOK_TRUE: + case PNK_NUMBER: + case PNK_STRING: + case PNK_NULL: + case PNK_FALSE: + case PNK_TRUE: return true; - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: return isOp(JSOP_NEWINIT) && !(pn_xflags & PNX_NONCONST); default: return false; diff --git a/js/src/frontend/ParseNode.cpp b/js/src/frontend/ParseNode.cpp index e7400602593a..ada45e00cedc 100644 --- a/js/src/frontend/ParseNode.cpp +++ b/js/src/frontend/ParseNode.cpp @@ -84,7 +84,7 @@ ParseNode::become(ParseNode *pn2) * If any pointers are pointing to pn2, change them to point to this * instead, since pn2 will be cleared and probably recycled. */ - if (this->isKind(TOK_FUNCTION) && isArity(PN_FUNC)) { + if (this->isKind(PNK_FUNCTION) && isArity(PN_FUNC)) { /* Function node: fix up the pn_funbox->node back-pointer. */ JS_ASSERT(pn_funbox->node == pn2); pn_funbox->node = this; @@ -101,7 +101,7 @@ ParseNode::become(ParseNode *pn2) void ParseNode::clear() { - pn_type = TOK_EOF; + pn_type = PNK_LIMIT; setOp(JSOP_NOP); pn_used = pn_defn = false; pn_arity = PN_NULLARY; @@ -384,20 +384,20 @@ ParseNodeAllocator::allocNode() /* used only by static create methods of subclasses */ ParseNode * -ParseNode::create(ParseNodeArity arity, TreeContext *tc) +ParseNode::create(ParseNodeKind kind, ParseNodeArity arity, TreeContext *tc) { Parser *parser = tc->parser; const Token &tok = parser->tokenStream.currentToken(); - return parser->new_(tok.type, JSOP_NOP, arity, tok.pos); + return parser->new_(kind, JSOP_NOP, arity, tok.pos); } ParseNode * -ParseNode::append(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right) +ParseNode::append(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right) { if (!left || !right) return NULL; - JS_ASSERT(left->isKind(tt) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC)); + JS_ASSERT(left->isKind(kind) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC)); if (left->pn_arity != PN_LIST) { ParseNode *pn1 = left->pn_left, *pn2 = left->pn_right; @@ -405,23 +405,23 @@ ParseNode::append(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right) left->pn_parens = false; left->initList(pn1); left->append(pn2); - if (tt == TOK_PLUS) { - if (pn1->isKind(TOK_STRING)) + if (kind == PNK_PLUS) { + if (pn1->isKind(PNK_STRING)) left->pn_xflags |= PNX_STRCAT; - else if (!pn1->isKind(TOK_NUMBER)) + else if (!pn1->isKind(PNK_NUMBER)) left->pn_xflags |= PNX_CANTFOLD; - if (pn2->isKind(TOK_STRING)) + if (pn2->isKind(PNK_STRING)) left->pn_xflags |= PNX_STRCAT; - else if (!pn2->isKind(TOK_NUMBER)) + else if (!pn2->isKind(PNK_NUMBER)) left->pn_xflags |= PNX_CANTFOLD; } } left->append(right); left->pn_pos.end = right->pn_pos.end; - if (tt == TOK_PLUS) { - if (right->isKind(TOK_STRING)) + if (kind == PNK_PLUS) { + if (right->isKind(PNK_STRING)) left->pn_xflags |= PNX_STRCAT; - else if (!right->isKind(TOK_NUMBER)) + else if (!right->isKind(PNK_NUMBER)) left->pn_xflags |= PNX_CANTFOLD; } @@ -429,7 +429,7 @@ ParseNode::append(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right) } ParseNode * -ParseNode::newBinaryOrAppend(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right, +ParseNode::newBinaryOrAppend(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right, TreeContext *tc) { if (!left || !right) @@ -439,8 +439,8 @@ ParseNode::newBinaryOrAppend(TokenKind tt, JSOp op, ParseNode *left, ParseNode * * Flatten a left-associative (left-heavy) tree of a given operator into * a list, to reduce js_FoldConstants and js_EmitTree recursion. */ - if (left->isKind(tt) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC)) - return append(tt, op, left, right); + if (left->isKind(kind) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC)) + return append(kind, op, left, right); /* * Fold constant addition immediately, to conserve node space and, what's @@ -449,9 +449,9 @@ ParseNode::newBinaryOrAppend(TokenKind tt, JSOp op, ParseNode *left, ParseNode * * generated for expressions such as 1 + 2 + "pt" (which should evaluate * to "3pt", not "12pt"). */ - if (tt == TOK_PLUS && - left->isKind(TOK_NUMBER) && - right->isKind(TOK_NUMBER) && + if (kind == PNK_PLUS && + left->isKind(PNK_NUMBER) && + right->isKind(PNK_NUMBER) && tc->parser->foldConstants) { left->pn_dval += right->pn_dval; @@ -460,13 +460,13 @@ ParseNode::newBinaryOrAppend(TokenKind tt, JSOp op, ParseNode *left, ParseNode * return left; } - return tc->parser->new_(tt, op, left, right); + return tc->parser->new_(kind, op, left, right); } NameNode * -NameNode::create(JSAtom *atom, TreeContext *tc) +NameNode::create(ParseNodeKind kind, JSAtom *atom, TreeContext *tc) { - ParseNode *pn = ParseNode::create(PN_NAME, tc); + ParseNode *pn = ParseNode::create(kind, PN_NAME, tc); if (pn) { pn->pn_atom = atom; ((NameNode *)pn)->initCommon(tc); @@ -619,13 +619,13 @@ js::CloneLeftHandSide(ParseNode *opn, TreeContext *tc) #if JS_HAS_DESTRUCTURING if (opn->isArity(PN_LIST)) { - JS_ASSERT(opn->isKind(TOK_RB) || opn->isKind(TOK_RC)); + JS_ASSERT(opn->isKind(PNK_RB) || opn->isKind(PNK_RC)); pn->makeEmpty(); for (ParseNode *opn2 = opn->pn_head; opn2; opn2 = opn2->pn_next) { ParseNode *pn2; - if (opn->isKind(TOK_RC)) { + if (opn->isKind(PNK_RC)) { JS_ASSERT(opn2->isArity(PN_BINARY)); - JS_ASSERT(opn2->isKind(TOK_COLON)); + JS_ASSERT(opn2->isKind(PNK_COLON)); ParseNode *tag = CloneParseTree(opn2->pn_left, tc); if (!tag) @@ -634,9 +634,9 @@ js::CloneLeftHandSide(ParseNode *opn, TreeContext *tc) if (!target) return NULL; - pn2 = tc->parser->new_(TOK_COLON, JSOP_INITPROP, opn2->pn_pos, tag, target); + pn2 = tc->parser->new_(PNK_COLON, JSOP_INITPROP, opn2->pn_pos, tag, target); } else if (opn2->isArity(PN_NULLARY)) { - JS_ASSERT(opn2->isKind(TOK_COMMA)); + JS_ASSERT(opn2->isKind(PNK_COMMA)); pn2 = CloneParseTree(opn2, tc); } else { pn2 = CloneLeftHandSide(opn2, tc); @@ -652,7 +652,7 @@ js::CloneLeftHandSide(ParseNode *opn, TreeContext *tc) #endif JS_ASSERT(opn->isArity(PN_NAME)); - JS_ASSERT(opn->isKind(TOK_NAME)); + JS_ASSERT(opn->isKind(PNK_NAME)); /* If opn is a definition or use, make pn a use. */ pn->pn_u.name = opn->pn_u.name; diff --git a/js/src/frontend/ParseNode.h b/js/src/frontend/ParseNode.h index b9fa2943adf1..35fc703251da 100644 --- a/js/src/frontend/ParseNode.h +++ b/js/src/frontend/ParseNode.h @@ -53,81 +53,219 @@ namespace js { * not a concrete syntax tree in all respects (for example, || and && are left * associative, but (A && B && C) translates into the right-associated tree * > so that code generation can emit a left-associative branch - * around when A is false). Nodes are labeled by token type, with a - * JSOp secondary label when needed: + * around when A is false). Nodes are labeled by kind, with a + * secondary JSOp label when needed. * + * The long comment after this enum block describes the kinds in detail. + */ +enum ParseNodeKind { + PNK_SEMI, + PNK_COMMA, + PNK_HOOK, + PNK_COLON, + PNK_OR, + PNK_AND, + PNK_BITOR, + PNK_BITXOR, + PNK_BITAND, + PNK_PLUS, + PNK_MINUS, + PNK_STAR, + PNK_DIV, + PNK_MOD, + PNK_INC, + PNK_DEC, + PNK_DOT, + PNK_LB, + PNK_RB, + PNK_LC, + PNK_RC, + PNK_LP, + PNK_RP, + PNK_NAME, + PNK_NUMBER, + PNK_STRING, + PNK_REGEXP, + PNK_TRUE, + PNK_FALSE, + PNK_NULL, + PNK_THIS, + PNK_FUNCTION, + PNK_IF, + PNK_ELSE, + PNK_SWITCH, + PNK_CASE, + PNK_DEFAULT, + PNK_WHILE, + PNK_DO, + PNK_FOR, + PNK_BREAK, + PNK_CONTINUE, + PNK_IN, + PNK_VAR, + PNK_WITH, + PNK_RETURN, + PNK_NEW, + PNK_DELETE, + PNK_DEFSHARP, + PNK_USESHARP, + PNK_TRY, + PNK_CATCH, + PNK_CATCHLIST, + PNK_FINALLY, + PNK_THROW, + PNK_INSTANCEOF, + PNK_DEBUGGER, + PNK_XMLSTAGO, + PNK_XMLETAGO, + PNK_XMLPTAGC, + PNK_XMLTAGC, + PNK_XMLNAME, + PNK_XMLATTR, + PNK_XMLSPACE, + PNK_XMLTEXT, + PNK_XMLCOMMENT, + PNK_XMLCDATA, + PNK_XMLPI, + PNK_AT, + PNK_DBLCOLON, + PNK_ANYNAME, + PNK_DBLDOT, + PNK_FILTER, + PNK_XMLELEM, + PNK_XMLLIST, + PNK_YIELD, + PNK_ARRAYCOMP, + PNK_ARRAYPUSH, + PNK_LEXICALSCOPE, + PNK_LET, + PNK_SEQ, + PNK_FORHEAD, + PNK_ARGSBODY, + PNK_UPVARS, + + /* + * The following parse node kinds occupy contiguous ranges to enable easy + * range-testing. + */ + + /* Equality operators. */ + PNK_STRICTEQ, + PNK_EQ, + PNK_STRICTNE, + PNK_NE, + + /* Unary operators. */ + PNK_TYPEOF, + PNK_VOID, + PNK_NOT, + PNK_BITNOT, + + /* Relational operators (< <= > >=). */ + PNK_LT, + PNK_LE, + PNK_GT, + PNK_GE, + + /* Shift operators (<< >> >>>). */ + PNK_LSH, + PNK_RSH, + PNK_URSH, + + /* Assignment operators (= += -= etc.). */ + PNK_ASSIGN, + PNK_ASSIGNMENT_START = PNK_ASSIGN, + PNK_ADDASSIGN, + PNK_SUBASSIGN, + PNK_BITORASSIGN, + PNK_BITXORASSIGN, + PNK_BITANDASSIGN, + PNK_LSHASSIGN, + PNK_RSHASSIGN, + PNK_URSHASSIGN, + PNK_MULASSIGN, + PNK_DIVASSIGN, + PNK_MODASSIGN, + PNK_ASSIGNMENT_LAST = PNK_MODASSIGN, + + PNK_LIMIT /* domain size */ +}; + +/* * Label Variant Members * ----- ------- ------- * - * TOK_FUNCTION name pn_funbox: ptr to js::FunctionBox holding function + * PNK_FUNCTION name pn_funbox: ptr to js::FunctionBox holding function * object containing arg and var properties. We * create the function object at parse (not emit) * time to specialize arg and var bytecodes early. - * pn_body: TOK_UPVARS if the function's source body - * depends on outer names, else TOK_ARGSBODY - * if formal parameters, else TOK_LC node for - * function body statements, else TOK_RETURN - * for expression closure, else TOK_SEQ for + * pn_body: PNK_UPVARS if the function's source body + * depends on outer names, else PNK_ARGSBODY + * if formal parameters, else PNK_LC node for + * function body statements, else PNK_RETURN + * for expression closure, else PNK_SEQ for * expression closure with destructured * formal parameters * pn_cookie: static level and var index for function * pn_dflags: PND_* definition/use flags (see below) * pn_blockid: block id number - * TOK_ARGSBODY list list of formal parameters followed by TOK_LC node + * PNK_ARGSBODY list list of formal parameters followed by PNK_LC node * for function body statements as final element * pn_count: 1 + number of formal parameters - * TOK_UPVARS nameset pn_names: lexical dependencies (js::Definitions) + * PNK_UPVARS nameset pn_names: lexical dependencies (js::Definitions) * defined in enclosing scopes, or ultimately not * defined (free variables, either global property * references or reference errors). - * pn_tree: TOK_ARGSBODY or TOK_LC node + * pn_tree: PNK_ARGSBODY or PNK_LC node * * - * TOK_LC list pn_head: list of pn_count statements - * TOK_IF ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else or null. + * PNK_LC list pn_head: list of pn_count statements + * PNK_IF ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else or null. * In body of a comprehension or desugared generator - * expression, pn_kid2 is TOK_YIELD, TOK_ARRAYPUSH, - * or (if the push was optimized away) empty TOK_LC. - * TOK_SWITCH binary pn_left: discriminant - * pn_right: list of TOK_CASE nodes, with at most one - * TOK_DEFAULT node, or if there are let bindings + * expression, pn_kid2 is PNK_YIELD, PNK_ARRAYPUSH, + * or (if the push was optimized away) empty PNK_LC. + * PNK_SWITCH binary pn_left: discriminant + * pn_right: list of PNK_CASE nodes, with at most one + * PNK_DEFAULT node, or if there are let bindings * in the top level of the switch body's cases, a - * TOK_LEXICALSCOPE node that contains the list of - * TOK_CASE nodes. - * TOK_CASE, binary pn_left: case expr or null if TOK_DEFAULT - * TOK_DEFAULT pn_right: TOK_LC node for this case's statements + * PNK_LEXICALSCOPE node that contains the list of + * PNK_CASE nodes. + * PNK_CASE, binary pn_left: case expr + * pn_right: PNK_LC node for this case's statements + * PNK_DEFAULT binary pn_left: null + * pn_right: PNK_LC node for this default's statements * pn_val: constant value if lookup or table switch - * TOK_WHILE binary pn_left: cond, pn_right: body - * TOK_DO binary pn_left: body, pn_right: cond - * TOK_FOR binary pn_left: either - * for/in loop: a ternary TOK_IN node with - * pn_kid1: TOK_VAR to left of 'in', or NULL + * PNK_WHILE binary pn_left: cond, pn_right: body + * PNK_DO binary pn_left: body, pn_right: cond + * PNK_FOR binary pn_left: either + * for/in loop: a ternary PNK_IN node with + * pn_kid1: PNK_VAR to left of 'in', or NULL * its pn_xflags may have PNX_POPVAR * and PNX_FORINVAR bits set - * pn_kid2: TOK_NAME or destructuring expr + * pn_kid2: PNK_NAME or destructuring expr * to left of 'in'; if pn_kid1, then this * is a clone of pn_kid1->pn_head * pn_kid3: object expr to right of 'in' - * for(;;) loop: a ternary TOK_RESERVED node with + * for(;;) loop: a ternary PNK_FORHEAD node with * pn_kid1: init expr before first ';' * pn_kid2: cond expr before second ';' * pn_kid3: update expr after second ';' * any kid may be null * pn_right: body - * TOK_THROW unary pn_op: JSOP_THROW, pn_kid: exception - * TOK_TRY ternary pn_kid1: try block - * pn_kid2: null or TOK_RESERVED list of - * TOK_LEXICALSCOPE nodes, each with pn_expr pointing - * to a TOK_CATCH node + * PNK_THROW unary pn_op: JSOP_THROW, pn_kid: exception + * PNK_TRY ternary pn_kid1: try block + * pn_kid2: null or PNK_CATCHLIST list of + * PNK_LEXICALSCOPE nodes, each with pn_expr pointing + * to a PNK_CATCH node * pn_kid3: null or finally block - * TOK_CATCH ternary pn_kid1: TOK_NAME, TOK_RB, or TOK_RC catch var node - * (TOK_RB or TOK_RC if destructuring) + * PNK_CATCH ternary pn_kid1: PNK_NAME, PNK_RB, or PNK_RC catch var node + * (PNK_RB or PNK_RC if destructuring) * pn_kid2: null or the catch guard expression * pn_kid3: catch block statements - * TOK_BREAK name pn_atom: label or null - * TOK_CONTINUE name pn_atom: label or null - * TOK_WITH binary pn_left: head expr, pn_right: body - * TOK_VAR list pn_head: list of TOK_NAME or TOK_ASSIGN nodes + * PNK_BREAK name pn_atom: label or null + * PNK_CONTINUE name pn_atom: label or null + * PNK_WITH binary pn_left: head expr, pn_right: body + * PNK_VAR list pn_head: list of PNK_NAME or PNK_ASSIGN nodes * each name node has either * pn_used: false * pn_atom: variable name @@ -137,142 +275,142 @@ namespace js { * pn_atom: variable name * pn_lexdef: def node * each assignment node has - * pn_left: TOK_NAME with pn_used true and + * pn_left: PNK_NAME with pn_used true and * pn_lexdef (NOT pn_expr) set * pn_right: initializer - * TOK_RETURN unary pn_kid: return expr or null - * TOK_SEMI unary pn_kid: expr or null statement + * PNK_RETURN unary pn_kid: return expr or null + * PNK_SEMI unary pn_kid: expr or null statement * pn_prologue: true if Directive Prologue member * in original source, not introduced via * constant folding or other tree rewriting - * TOK_COLON name pn_atom: label, pn_expr: labeled statement + * PNK_COLON name pn_atom: label, pn_expr: labeled statement * * * All left-associated binary trees of the same type are optimized into lists * to avoid recursion when processing expression chains. - * TOK_COMMA list pn_head: list of pn_count comma-separated exprs - * TOK_ASSIGN binary pn_left: lvalue, pn_right: rvalue - * TOK_ADDASSIGN, binary pn_left: lvalue, pn_right: rvalue - * TOK_SUBASSIGN, pn_op: JSOP_ADD for +=, etc. - * TOK_BITORASSIGN, - * TOK_BITXORASSIGN, - * TOK_BITANDASSIGN, - * TOK_LSHASSIGN, - * TOK_RSHASSIGN, - * TOK_URSHASSIGN, - * TOK_MULASSIGN, - * TOK_DIVASSIGN, - * TOK_MODASSIGN - * TOK_HOOK ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else - * TOK_OR binary pn_left: first in || chain, pn_right: rest of chain - * TOK_AND binary pn_left: first in && chain, pn_right: rest of chain - * TOK_BITOR binary pn_left: left-assoc | expr, pn_right: ^ expr - * TOK_BITXOR binary pn_left: left-assoc ^ expr, pn_right: & expr - * TOK_BITAND binary pn_left: left-assoc & expr, pn_right: EQ expr + * PNK_COMMA list pn_head: list of pn_count comma-separated exprs + * PNK_ASSIGN binary pn_left: lvalue, pn_right: rvalue + * PNK_ADDASSIGN, binary pn_left: lvalue, pn_right: rvalue + * PNK_SUBASSIGN, pn_op: JSOP_ADD for +=, etc. + * PNK_BITORASSIGN, + * PNK_BITXORASSIGN, + * PNK_BITANDASSIGN, + * PNK_LSHASSIGN, + * PNK_RSHASSIGN, + * PNK_URSHASSIGN, + * PNK_MULASSIGN, + * PNK_DIVASSIGN, + * PNK_MODASSIGN + * PNK_HOOK ternary pn_kid1: cond, pn_kid2: then, pn_kid3: else + * PNK_OR binary pn_left: first in || chain, pn_right: rest of chain + * PNK_AND binary pn_left: first in && chain, pn_right: rest of chain + * PNK_BITOR binary pn_left: left-assoc | expr, pn_right: ^ expr + * PNK_BITXOR binary pn_left: left-assoc ^ expr, pn_right: & expr + * PNK_BITAND binary pn_left: left-assoc & expr, pn_right: EQ expr * - * TOK_EQ, binary pn_left: left-assoc EQ expr, pn_right: REL expr - * TOK_NE, - * TOK_STRICTEQ, - * TOK_STRICTNE - * TOK_LT, binary pn_left: left-assoc REL expr, pn_right: SH expr - * TOK_LE, - * TOK_GT, - * TOK_GE - * TOK_LSH, binary pn_left: left-assoc SH expr, pn_right: ADD expr - * TOK_RSH, - * TOK_URSH - * TOK_PLUS, binary pn_left: left-assoc ADD expr, pn_right: MUL expr - * pn_xflags: if a left-associated binary TOK_PLUS + * PNK_EQ, binary pn_left: left-assoc EQ expr, pn_right: REL expr + * PNK_NE, + * PNK_STRICTEQ, + * PNK_STRICTNE + * PNK_LT, binary pn_left: left-assoc REL expr, pn_right: SH expr + * PNK_LE, + * PNK_GT, + * PNK_GE + * PNK_LSH, binary pn_left: left-assoc SH expr, pn_right: ADD expr + * PNK_RSH, + * PNK_URSH + * PNK_PLUS, binary pn_left: left-assoc ADD expr, pn_right: MUL expr + * pn_xflags: if a left-associated binary PNK_PLUS * tree has been flattened into a list (see above * under ), pn_xflags will contain * PNX_STRCAT if at least one list element is a - * string literal (TOK_STRING); if such a list has + * string literal (PNK_STRING); if such a list has * any non-string, non-number term, pn_xflags will * contain PNX_CANTFOLD. * pn_ - * TOK_MINUS pn_op: JSOP_ADD, JSOP_SUB - * TOK_STAR, binary pn_left: left-assoc MUL expr, pn_right: UNARY expr - * TOK_DIV, pn_op: JSOP_MUL, JSOP_DIV, JSOP_MOD - * TOK_MOD - * TOK_TYPEOF, unary pn_kid: UNARY expr - * TOK_VOID, - * TOK_NOT, - * TOK_BITNOT - * TOK_INC, unary pn_kid: MEMBER expr - * TOK_DEC - * TOK_NEW list pn_head: list of ctor, arg1, arg2, ... argN + * PNK_MINUS pn_op: JSOP_ADD, JSOP_SUB + * PNK_STAR, binary pn_left: left-assoc MUL expr, pn_right: UNARY expr + * PNK_DIV, pn_op: JSOP_MUL, JSOP_DIV, JSOP_MOD + * PNK_MOD + * PNK_TYPEOF, unary pn_kid: UNARY expr + * PNK_VOID, + * PNK_NOT, + * PNK_BITNOT + * PNK_INC, unary pn_kid: MEMBER expr + * PNK_DEC + * PNK_NEW list pn_head: list of ctor, arg1, arg2, ... argN * pn_count: 1 + N (where N is number of args) * ctor is a MEMBER expr - * TOK_DELETE unary pn_kid: MEMBER expr - * TOK_DOT, name pn_expr: MEMBER expr to left of . - * TOK_DBLDOT pn_atom: name to right of . - * TOK_LB binary pn_left: MEMBER expr to left of [ + * PNK_DELETE unary pn_kid: MEMBER expr + * PNK_DOT, name pn_expr: MEMBER expr to left of . + * PNK_DBLDOT pn_atom: name to right of . + * PNK_LB binary pn_left: MEMBER expr to left of [ * pn_right: expr between [ and ] - * TOK_LP list pn_head: list of call, arg1, arg2, ... argN + * PNK_LP list pn_head: list of call, arg1, arg2, ... argN * pn_count: 1 + N (where N is number of args) * call is a MEMBER expr naming a callable object - * TOK_RB list pn_head: list of pn_count array element exprs - * [,,] holes are represented by TOK_COMMA nodes + * PNK_RB list pn_head: list of pn_count array element exprs + * [,,] holes are represented by PNK_COMMA nodes * pn_xflags: PN_ENDCOMMA if extra comma at end - * TOK_RC list pn_head: list of pn_count binary TOK_COLON nodes - * TOK_COLON binary key-value pair in object initializer or + * PNK_RC list pn_head: list of pn_count binary PNK_COLON nodes + * PNK_COLON binary key-value pair in object initializer or * destructuring lhs * pn_left: property id, pn_right: value * var {x} = object destructuring shorthand shares - * PN_NAME node for x on left and right of TOK_COLON - * node in TOK_RC's list, has PNX_DESTRUCT flag - * TOK_DEFSHARP unary pn_num: jsint value of n in #n= + * PN_NAME node for x on left and right of PNK_COLON + * node in PNK_RC's list, has PNX_DESTRUCT flag + * PNK_DEFSHARP unary pn_num: jsint value of n in #n= * pn_kid: primary function, paren, name, object or * array literal expressions - * TOK_USESHARP nullary pn_num: jsint value of n in #n# - * TOK_NAME, name pn_atom: name, string, or object atom - * TOK_STRING, pn_op: JSOP_NAME, JSOP_STRING, or JSOP_OBJECT, or + * PNK_USESHARP nullary pn_num: jsint value of n in #n# + * PNK_NAME, name pn_atom: name, string, or object atom + * PNK_STRING, pn_op: JSOP_NAME, JSOP_STRING, or JSOP_OBJECT, or * JSOP_REGEXP - * TOK_REGEXP If JSOP_NAME, pn_op may be JSOP_*ARG or JSOP_*VAR + * PNK_REGEXP If JSOP_NAME, pn_op may be JSOP_*ARG or JSOP_*VAR * with pn_cookie telling (staticLevel, slot) (see * jsscript.h's UPVAR macros) and pn_dflags telling * const-ness and static analysis results - * TOK_NAME name If pn_used, TOK_NAME uses the lexdef member instead + * PNK_NAME name If pn_used, PNK_NAME uses the lexdef member instead * of the expr member it overlays - * TOK_NUMBER dval pn_dval: double value of numeric literal - * TOK_TRUE, nullary pn_op: JSOp bytecode - * TOK_FALSE, - * TOK_NULL, - * TOK_THIS + * PNK_NUMBER dval pn_dval: double value of numeric literal + * PNK_TRUE, nullary pn_op: JSOp bytecode + * PNK_FALSE, + * PNK_NULL, + * PNK_THIS * * - * TOK_DEFAULT name pn_atom: default XML namespace string literal - * TOK_FILTER binary pn_left: container expr, pn_right: filter expr - * TOK_DBLDOT binary pn_left: container expr, pn_right: selector expr - * TOK_ANYNAME nullary pn_op: JSOP_ANYNAME + * PNK_DEFAULT name pn_atom: default XML namespace string literal + * PNK_FILTER binary pn_left: container expr, pn_right: filter expr + * PNK_DBLDOT binary pn_left: container expr, pn_right: selector expr + * PNK_ANYNAME nullary pn_op: JSOP_ANYNAME * pn_atom: cx->runtime->atomState.starAtom - * TOK_AT unary pn_op: JSOP_TOATTRNAME; pn_kid attribute id/expr - * TOK_DBLCOLON binary pn_op: JSOP_QNAME - * pn_left: TOK_ANYNAME or TOK_NAME node - * pn_right: TOK_STRING "*" node, or expr within [] + * PNK_AT unary pn_op: JSOP_TOATTRNAME; pn_kid attribute id/expr + * PNK_DBLCOLON binary pn_op: JSOP_QNAME + * pn_left: PNK_ANYNAME or PNK_NAME node + * pn_right: PNK_STRING "*" node, or expr within [] * name pn_op: JSOP_QNAMECONST - * pn_expr: TOK_ANYNAME or TOK_NAME left operand + * pn_expr: PNK_ANYNAME or PNK_NAME left operand * pn_atom: name on right of :: - * TOK_XMLELEM list XML element node + * PNK_XMLELEM list XML element node * pn_head: start tag, content1, ... contentN, end tag * pn_count: 2 + N where N is number of content nodes * N may be > x.length() if {expr} embedded * After constant folding, these contents may be * concatenated into string nodes. - * TOK_XMLLIST list XML list node + * PNK_XMLLIST list XML list node * pn_head: content1, ... contentN - * TOK_XMLSTAGO, list XML start, end, and point tag contents - * TOK_XMLETAGO, pn_head: tag name or {expr}, ... XML attrs ... - * TOK_XMLPTAGC - * TOK_XMLNAME nullary pn_atom: XML name, with no {expr} embedded - * TOK_XMLNAME list pn_head: tag name or {expr}, ... name or {expr} - * TOK_XMLATTR, nullary pn_atom: attribute value string; pn_op: JSOP_STRING - * TOK_XMLCDATA, - * TOK_XMLCOMMENT - * TOK_XMLPI nullary pn_pitarget: XML processing instruction target + * PNK_XMLSTAGO, list XML start, end, and point tag contents + * PNK_XMLETAGO, pn_head: tag name or {expr}, ... XML attrs ... + * PNK_XMLPTAGC + * PNK_XMLNAME nullary pn_atom: XML name, with no {expr} embedded + * PNK_XMLNAME list pn_head: tag name or {expr}, ... name or {expr} + * PNK_XMLATTR, nullary pn_atom: attribute value string; pn_op: JSOP_STRING + * PNK_XMLCDATA, + * PNK_XMLCOMMENT + * PNK_XMLPI nullary pn_pitarget: XML processing instruction target * pn_pidata: XML PI data, or null if no data - * TOK_XMLTEXT nullary pn_atom: marked-up text, or null if empty string - * TOK_LC unary {expr} in XML tag or content; pn_kid is expr + * PNK_XMLTEXT nullary pn_atom: marked-up text, or null if empty string + * PNK_LC unary {expr} in XML tag or content; pn_kid is expr * * So an XML tag with no {expr} and three attributes is a list with the form: * @@ -287,10 +425,10 @@ namespace js { * ((name1 {expr1}) (name2 {expr2} name3) {expr3}) * * where () bracket a list with elements separated by spaces, and {expr} is a - * TOK_LC unary node with expr as its kid. + * PNK_LC unary node with expr as its kid. * * Thus, the attribute name/value pairs occupy successive odd and even list - * locations, where pn_head is the TOK_XMLNAME node at list location 0. The + * locations, where pn_head is the PNK_XMLNAME node at list location 0. The * parser builds the same sort of structures for elements: * * Hi there!How are you?{x + y} @@ -303,14 +441,14 @@ namespace js { * * Label Variant Members * ----- ------- ------- - * TOK_LEXICALSCOPE name pn_op: JSOP_LEAVEBLOCK or JSOP_LEAVEBLOCKEXPR + * PNK_LEXICALSCOPE name pn_op: JSOP_LEAVEBLOCK or JSOP_LEAVEBLOCKEXPR * pn_objbox: block object in ObjectBox holder * pn_expr: block body - * TOK_ARRAYCOMP list pn_count: 1 + * PNK_ARRAYCOMP list pn_count: 1 * pn_head: list of 1 element, which is block * enclosing for loop(s) and optionally - * if-guarded TOK_ARRAYPUSH - * TOK_ARRAYPUSH unary pn_op: JSOP_ARRAYCOMP + * if-guarded PNK_ARRAYPUSH + * PNK_ARRAYPUSH unary pn_op: JSOP_ARRAYCOMP * pn_kid: array comprehension expression */ enum ParseNodeArity { @@ -328,7 +466,7 @@ struct Definition; struct ParseNode { private: - uint32 pn_type : 16, /* TOK_* type, see frontend/TokenStream.h */ + uint32 pn_type : 16, /* PNK_* type */ pn_op : 8, /* see JSOp enum and jsopcode.tbl */ pn_arity : 5, /* see ParseNodeArity enum */ pn_parens : 1, /* this expr was enclosed in parens */ @@ -336,10 +474,11 @@ struct ParseNode { pn_defn : 1; /* this node is a Definition */ public: - ParseNode(TokenKind type, JSOp op, ParseNodeArity arity) - : pn_type(type), pn_op(op), pn_arity(arity), pn_parens(0), pn_used(0), pn_defn(0), + ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity) + : pn_type(kind), pn_op(op), pn_arity(arity), pn_parens(0), pn_used(0), pn_defn(0), pn_offset(0), pn_next(NULL), pn_link(NULL) { + JS_ASSERT(kind < PNK_LIMIT); pn_pos.begin.index = 0; pn_pos.begin.lineno = 0; pn_pos.end.index = 0; @@ -347,27 +486,51 @@ struct ParseNode { memset(&pn_u, 0, sizeof pn_u); } - ParseNode(TokenKind type, JSOp op, ParseNodeArity arity, const TokenPos &pos) - : pn_type(type), pn_op(op), pn_arity(arity), pn_parens(0), pn_used(0), pn_defn(0), + ParseNode(ParseNodeKind kind, JSOp op, ParseNodeArity arity, const TokenPos &pos) + : pn_type(kind), pn_op(op), pn_arity(arity), pn_parens(0), pn_used(0), pn_defn(0), pn_pos(pos), pn_offset(0), pn_next(NULL), pn_link(NULL) { + JS_ASSERT(kind < PNK_LIMIT); memset(&pn_u, 0, sizeof pn_u); } JSOp getOp() const { return JSOp(pn_op); } void setOp(JSOp op) { pn_op = op; } bool isOp(JSOp op) const { return getOp() == op; } - TokenKind getKind() const { return TokenKind(pn_type); } - void setKind(TokenKind kind) { pn_type = kind; } - bool isKind(TokenKind kind) const { return getKind() == kind; } + + ParseNodeKind getKind() const { + JS_ASSERT(pn_type < PNK_LIMIT); + return ParseNodeKind(pn_type); + } + void setKind(ParseNodeKind kind) { + JS_ASSERT(kind < PNK_LIMIT); + pn_type = kind; + } + bool isKind(ParseNodeKind kind) const { return getKind() == kind; } + ParseNodeArity getArity() const { return ParseNodeArity(pn_arity); } bool isArity(ParseNodeArity a) const { return getArity() == a; } void setArity(ParseNodeArity a) { pn_arity = a; } - bool isEquality() const { return TokenKindIsEquality(getKind()); } - bool isUnaryOp() const { return TokenKindIsUnaryOp(getKind()); } - bool isXMLNameOp() const { return TokenKindIsXML(getKind()); } - bool isAssignment() const { return TokenKindIsAssignment(getKind()); } + bool isXMLNameOp() const { + ParseNodeKind kind = getKind(); + return kind == PNK_ANYNAME || kind == PNK_AT || kind == PNK_DBLCOLON; + } + bool isAssignment() const { + ParseNodeKind kind = getKind(); + return PNK_ASSIGNMENT_START <= kind && kind <= PNK_ASSIGNMENT_LAST; + } + + bool isXMLPropertyIdentifier() const { + ParseNodeKind kind = getKind(); + return kind == PNK_ANYNAME || kind == PNK_AT || kind == PNK_DBLCOLON; + } + + bool isXMLItem() const { + ParseNodeKind kind = getKind(); + return kind == PNK_XMLCOMMENT || kind == PNK_XMLCDATA || kind == PNK_XMLPI || + kind == PNK_XMLELEM || kind == PNK_XMLLIST; + } /* Boolean attributes. */ bool isInParens() const { return pn_parens; } @@ -401,7 +564,7 @@ struct ParseNode { ParseNode *left; ParseNode *right; Value *pval; /* switch case value */ - uintN iflags; /* JSITER_* flags for TOK_FOR node */ + uintN iflags; /* JSITER_* flags for PNK_FOR node */ } binary; struct { /* one kid if unary */ ParseNode *kid; @@ -418,7 +581,7 @@ struct ParseNode { }; union { ParseNode *expr; /* function body, var initializer, or - base object of TOK_DOT */ + base object of PNK_DOT */ Definition *lexdef; /* lexical definition for this use */ }; UpvarCookie cookie; /* upvar cookie with absolute frame @@ -482,7 +645,7 @@ struct ParseNode { pn_next = pn_link = NULL; } - static ParseNode *create(ParseNodeArity arity, TreeContext *tc); + static ParseNode *create(ParseNodeKind kind, ParseNodeArity arity, TreeContext *tc); public: /* @@ -490,7 +653,7 @@ struct ParseNode { * kind and op, and op must be left-associative. */ static ParseNode * - append(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right); + append(ParseNodeKind tt, JSOp op, ParseNode *left, ParseNode *right); /* * Either append right to left, if left meets the conditions necessary to @@ -498,7 +661,8 @@ struct ParseNode { * left. */ static ParseNode * - newBinaryOrAppend(TokenKind tt, JSOp op, ParseNode *left, ParseNode *right, TreeContext *tc); + newBinaryOrAppend(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right, + TreeContext *tc); /* * The pn_expr and lexdef members are arms of an unsafe union. Unless you @@ -542,11 +706,11 @@ struct ParseNode { #define PND_USE2DEF_FLAGS (PND_ASSIGNED | PND_FUNARG | PND_CLOSED) /* PN_LIST pn_xflags bits. */ -#define PNX_STRCAT 0x01 /* TOK_PLUS list has string term */ -#define PNX_CANTFOLD 0x02 /* TOK_PLUS list has unfoldable term */ -#define PNX_POPVAR 0x04 /* TOK_VAR last result needs popping */ -#define PNX_FORINVAR 0x08 /* TOK_VAR is left kid of TOK_IN node, - which is left kid of TOK_FOR */ +#define PNX_STRCAT 0x01 /* PNK_PLUS list has string term */ +#define PNX_CANTFOLD 0x02 /* PNK_PLUS list has unfoldable term */ +#define PNX_POPVAR 0x04 /* PNK_VAR last result needs popping */ +#define PNX_FORINVAR 0x08 /* PNK_VAR is left kid of PNK_IN node, + which is left kid of PNK_FOR */ #define PNX_ENDCOMMA 0x10 /* array literal has comma at end */ #define PNX_XMLROOT 0x20 /* top-most node in XML literal tree */ #define PNX_GROUPINIT 0x40 /* var [a, b] = [c, d]; unit list */ @@ -606,11 +770,11 @@ struct ParseNode { /* True if pn is a parsenode representing a literal constant. */ bool isLiteral() const { - return isKind(TOK_NUMBER) || - isKind(TOK_STRING) || - isKind(TOK_TRUE) || - isKind(TOK_FALSE) || - isKind(TOK_NULL); + return isKind(PNK_NUMBER) || + isKind(PNK_STRING) || + isKind(PNK_TRUE) || + isKind(PNK_FALSE) || + isKind(PNK_NULL); } /* @@ -629,28 +793,28 @@ struct ParseNode { * a directive. */ bool isStringExprStatement() const { - if (getKind() == TOK_SEMI) { + if (getKind() == PNK_SEMI) { JS_ASSERT(pn_arity == PN_UNARY); ParseNode *kid = pn_kid; - return kid && kid->getKind() == TOK_STRING && !kid->pn_parens; + return kid && kid->getKind() == PNK_STRING && !kid->pn_parens; } return false; } /* - * Return true if this node, known to be a string literal, could be the - * string of a directive in a Directive Prologue. Directive strings never - * contain escape sequences or line continuations. + * Return true if this node, known to be an unparenthesized string literal, + * could be the string of a directive in a Directive Prologue. Directive + * strings never contain escape sequences or line continuations. */ bool isEscapeFreeStringLiteral() const { - JS_ASSERT(pn_type == TOK_STRING && !pn_parens); - JSString *str = pn_atom; + JS_ASSERT(isKind(PNK_STRING) && !pn_parens); /* * If the string's length in the source code is its length as a value, * accounting for the quotes, then it must not contain any escape * sequences or line continuations. */ + JSString *str = pn_atom; return (pn_pos.begin.lineno == pn_pos.end.lineno && pn_pos.begin.index + str->length() + 2 == pn_pos.end.index); } @@ -663,13 +827,13 @@ struct ParseNode { * True if this node is a desugared generator expression. */ bool isGeneratorExpr() const { - if (getKind() == TOK_LP) { + if (getKind() == PNK_LP) { ParseNode *callee = this->pn_head; - if (callee->getKind() == TOK_FUNCTION) { - ParseNode *body = (callee->pn_body->getKind() == TOK_UPVARS) + if (callee->getKind() == PNK_FUNCTION) { + ParseNode *body = (callee->pn_body->getKind() == PNK_UPVARS) ? callee->pn_body->pn_tree : callee->pn_body; - if (body->getKind() == TOK_LEXICALSCOPE) + if (body->getKind() == PNK_LEXICALSCOPE) return true; } } @@ -679,10 +843,10 @@ struct ParseNode { ParseNode *generatorExpr() const { JS_ASSERT(isGeneratorExpr()); ParseNode *callee = this->pn_head; - ParseNode *body = callee->pn_body->getKind() == TOK_UPVARS + ParseNode *body = callee->pn_body->getKind() == PNK_UPVARS ? callee->pn_body->pn_tree : callee->pn_body; - JS_ASSERT(body->getKind() == TOK_LEXICALSCOPE); + JS_ASSERT(body->getKind() == PNK_LEXICALSCOPE); return body->pn_expr; } #endif @@ -727,46 +891,46 @@ struct ParseNode { }; struct NullaryNode : public ParseNode { - static inline NullaryNode *create(TreeContext *tc) { - return (NullaryNode *)ParseNode::create(PN_NULLARY, tc); + static inline NullaryNode *create(ParseNodeKind kind, TreeContext *tc) { + return (NullaryNode *)ParseNode::create(kind, PN_NULLARY, tc); } }; struct UnaryNode : public ParseNode { - UnaryNode(TokenKind type, JSOp op, const TokenPos &pos, ParseNode *kid) - : ParseNode(type, op, PN_UNARY, pos) + UnaryNode(ParseNodeKind kind, JSOp op, const TokenPos &pos, ParseNode *kid) + : ParseNode(kind, op, PN_UNARY, pos) { pn_kid = kid; } - static inline UnaryNode *create(TreeContext *tc) { - return (UnaryNode *)ParseNode::create(PN_UNARY, tc); + static inline UnaryNode *create(ParseNodeKind kind, TreeContext *tc) { + return (UnaryNode *)ParseNode::create(kind, PN_UNARY, tc); } }; struct BinaryNode : public ParseNode { - BinaryNode(TokenKind type, JSOp op, const TokenPos &pos, ParseNode *left, ParseNode *right) - : ParseNode(type, op, PN_BINARY, pos) + BinaryNode(ParseNodeKind kind, JSOp op, const TokenPos &pos, ParseNode *left, ParseNode *right) + : ParseNode(kind, op, PN_BINARY, pos) { pn_left = left; pn_right = right; } - BinaryNode(TokenKind type, JSOp op, ParseNode *left, ParseNode *right) - : ParseNode(type, op, PN_BINARY, TokenPos::box(left->pn_pos, right->pn_pos)) + BinaryNode(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right) + : ParseNode(kind, op, PN_BINARY, TokenPos::box(left->pn_pos, right->pn_pos)) { pn_left = left; pn_right = right; } - static inline BinaryNode *create(TreeContext *tc) { - return (BinaryNode *)ParseNode::create(PN_BINARY, tc); + static inline BinaryNode *create(ParseNodeKind kind, TreeContext *tc) { + return (BinaryNode *)ParseNode::create(kind, PN_BINARY, tc); } }; struct TernaryNode : public ParseNode { - TernaryNode(TokenKind type, JSOp op, ParseNode *kid1, ParseNode *kid2, ParseNode *kid3) - : ParseNode(type, op, PN_TERNARY, + TernaryNode(ParseNodeKind kind, JSOp op, ParseNode *kid1, ParseNode *kid2, ParseNode *kid3) + : ParseNode(kind, op, PN_TERNARY, TokenPos::make((kid1 ? kid1 : kid2 ? kid2 : kid3)->pn_pos.begin, (kid3 ? kid3 : kid2 ? kid2 : kid1)->pn_pos.end)) { @@ -775,38 +939,38 @@ struct TernaryNode : public ParseNode { pn_kid3 = kid3; } - static inline TernaryNode *create(TreeContext *tc) { - return (TernaryNode *)ParseNode::create(PN_TERNARY, tc); + static inline TernaryNode *create(ParseNodeKind kind, TreeContext *tc) { + return (TernaryNode *)ParseNode::create(kind, PN_TERNARY, tc); } }; struct ListNode : public ParseNode { - static inline ListNode *create(TreeContext *tc) { - return (ListNode *)ParseNode::create(PN_LIST, tc); + static inline ListNode *create(ParseNodeKind kind, TreeContext *tc) { + return (ListNode *)ParseNode::create(kind, PN_LIST, tc); } }; struct FunctionNode : public ParseNode { - static inline FunctionNode *create(TreeContext *tc) { - return (FunctionNode *)ParseNode::create(PN_FUNC, tc); + static inline FunctionNode *create(ParseNodeKind kind, TreeContext *tc) { + return (FunctionNode *)ParseNode::create(kind, PN_FUNC, tc); } }; struct NameNode : public ParseNode { - static NameNode *create(JSAtom *atom, TreeContext *tc); + static NameNode *create(ParseNodeKind kind, JSAtom *atom, TreeContext *tc); inline void initCommon(TreeContext *tc); }; struct NameSetNode : public ParseNode { - static inline NameSetNode *create(TreeContext *tc) { - return (NameSetNode *)ParseNode::create(PN_NAMESET, tc); + static inline NameSetNode *create(ParseNodeKind kind, TreeContext *tc) { + return (NameSetNode *)ParseNode::create(kind, PN_NAMESET, tc); } }; struct LexicalScopeNode : public ParseNode { - static inline LexicalScopeNode *create(TreeContext *tc) { - return (LexicalScopeNode *)ParseNode::create(PN_NAME, tc); + static inline LexicalScopeNode *create(ParseNodeKind kind, TreeContext *tc) { + return (LexicalScopeNode *)ParseNode::create(kind, PN_NAME, tc); } }; @@ -817,7 +981,7 @@ 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 TOK_VAR list may be a Definition instead of a ParseNode. The pn_defn + * a PNK_VAR list may be a Definition instead of a ParseNode. The pn_defn * bit is set for all Definitions, clear otherwise. * * In an upvars list, defn->resolve() is the outermost definition the @@ -861,7 +1025,7 @@ CloneLeftHandSide(ParseNode *opn, TreeContext *tc); * map x to dn via tc->decls; * pn = dn; * } - * insert pn into its parent TOK_VAR list; + * insert pn into its parent PNK_VAR list; * } else { * pn = allocate a ParseNode for this reference to x; * dn = lookup x in tc's lexical scope chain; @@ -973,9 +1137,9 @@ struct Definition : public ParseNode static const char *kindString(Kind kind); Kind kind() { - if (getKind() == TOK_FUNCTION) + if (getKind() == PNK_FUNCTION) return FUNCTION; - JS_ASSERT(getKind() == TOK_NAME); + JS_ASSERT(getKind() == PNK_NAME); if (isOp(JSOP_NOP)) return UNKNOWN; if (isOp(JSOP_GETARG)) diff --git a/js/src/frontend/Parser.cpp b/js/src/frontend/Parser.cpp index f59d4da26917..a92b317bccb3 100644 --- a/js/src/frontend/Parser.cpp +++ b/js/src/frontend/Parser.cpp @@ -261,7 +261,7 @@ GenerateBlockIdForStmtNode(ParseNode *pn, TreeContext *tc) { JS_ASSERT(tc->topStmt); JS_ASSERT(STMT_MAYBE_SCOPE(tc->topStmt)); - JS_ASSERT(pn->isKind(TOK_LC) || pn->isKind(TOK_LEXICALSCOPE)); + JS_ASSERT(pn->isKind(PNK_LC) || pn->isKind(PNK_LEXICALSCOPE)); if (!GenerateBlockId(tc, tc->topStmt->blockid)) return false; pn->pn_blockid = tc->topStmt->blockid; @@ -321,54 +321,54 @@ HasFinalReturn(ParseNode *pn) uintN rv, rv2, hasDefault; switch (pn->getKind()) { - case TOK_LC: + case PNK_LC: if (!pn->pn_head) return ENDS_IN_OTHER; return HasFinalReturn(pn->last()); - case TOK_IF: + case PNK_IF: if (!pn->pn_kid3) return ENDS_IN_OTHER; return HasFinalReturn(pn->pn_kid2) & HasFinalReturn(pn->pn_kid3); - case TOK_WHILE: + case PNK_WHILE: pn2 = pn->pn_left; - if (pn2->isKind(TOK_TRUE)) + if (pn2->isKind(PNK_TRUE)) return ENDS_IN_RETURN; - if (pn2->isKind(TOK_NUMBER) && pn2->pn_dval) + if (pn2->isKind(PNK_NUMBER) && pn2->pn_dval) return ENDS_IN_RETURN; return ENDS_IN_OTHER; - case TOK_DO: + case PNK_DO: pn2 = pn->pn_right; - if (pn2->isKind(TOK_FALSE)) + if (pn2->isKind(PNK_FALSE)) return HasFinalReturn(pn->pn_left); - if (pn2->isKind(TOK_TRUE)) + if (pn2->isKind(PNK_TRUE)) return ENDS_IN_RETURN; - if (pn2->isKind(TOK_NUMBER)) { + if (pn2->isKind(PNK_NUMBER)) { if (pn2->pn_dval == 0) return HasFinalReturn(pn->pn_left); return ENDS_IN_RETURN; } return ENDS_IN_OTHER; - case TOK_FOR: + case PNK_FOR: pn2 = pn->pn_left; if (pn2->isArity(PN_TERNARY) && !pn2->pn_kid2) return ENDS_IN_RETURN; return ENDS_IN_OTHER; - case TOK_SWITCH: + case PNK_SWITCH: rv = ENDS_IN_RETURN; hasDefault = ENDS_IN_OTHER; pn2 = pn->pn_right; - if (pn2->isKind(TOK_LEXICALSCOPE)) + if (pn2->isKind(PNK_LEXICALSCOPE)) pn2 = pn2->expr(); for (pn2 = pn2->pn_head; rv && pn2; pn2 = pn2->pn_next) { - if (pn2->isKind(TOK_DEFAULT)) + if (pn2->isKind(PNK_DEFAULT)) hasDefault = ENDS_IN_RETURN; pn3 = pn2->pn_right; - JS_ASSERT(pn3->isKind(TOK_LC)); + JS_ASSERT(pn3->isKind(PNK_LC)); if (pn3->pn_head) { rv2 = HasFinalReturn(pn3->last()); if (rv2 == ENDS_IN_OTHER && pn2->pn_next) @@ -381,23 +381,23 @@ HasFinalReturn(ParseNode *pn) rv &= hasDefault; return rv; - case TOK_BREAK: + case PNK_BREAK: return ENDS_IN_BREAK; - case TOK_WITH: + case PNK_WITH: return HasFinalReturn(pn->pn_right); - case TOK_RETURN: + case PNK_RETURN: return ENDS_IN_RETURN; - case TOK_COLON: - case TOK_LEXICALSCOPE: + case PNK_COLON: + case PNK_LEXICALSCOPE: return HasFinalReturn(pn->expr()); - case TOK_THROW: + case PNK_THROW: return ENDS_IN_RETURN; - case TOK_TRY: + case PNK_TRY: /* If we have a finally block that returns, we are done. */ if (pn->pn_kid3) { rv = HasFinalReturn(pn->pn_kid3); @@ -414,11 +414,11 @@ HasFinalReturn(ParseNode *pn) } return rv; - case TOK_CATCH: + case PNK_CATCH: /* Check this catch block's body. */ return HasFinalReturn(pn->pn_kid3); - case TOK_LET: + case PNK_LET: /* Non-binary let statements are let declarations. */ if (!pn->isArity(PN_BINARY)) return ENDS_IN_OTHER; @@ -459,7 +459,7 @@ CheckFinalReturn(JSContext *cx, TreeContext *tc, ParseNode *pn) static bool CheckStrictAssignment(JSContext *cx, TreeContext *tc, ParseNode *lhs) { - if (tc->needStrictChecks() && lhs->isKind(TOK_NAME)) { + if (tc->needStrictChecks() && lhs->isKind(PNK_NAME)) { JSAtom *atom = lhs->pn_atom; JSAtomState *atomState = &cx->runtime->atomState; if (atom == atomState->evalAtom || atom == atomState->argumentsAtom) { @@ -587,7 +587,7 @@ Parser::functionBody() if (tokenStream.currentToken().type == TOK_LC) { pn = statements(); } else { - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_RETURN, tc); if (pn) { pn->pn_kid = assignExpr(); if (!pn->pn_kid) { @@ -599,7 +599,6 @@ Parser::functionBody() JSMSG_BAD_ANON_GENERATOR_RETURN); pn = NULL; } else { - pn->setKind(TOK_RETURN); pn->setOp(JSOP_RETURN); pn->pn_pos.end = pn->pn_kid->pn_pos.end; } @@ -629,11 +628,10 @@ Parser::functionBody() static Definition * MakePlaceholder(ParseNode *pn, TreeContext *tc) { - Definition *dn = (Definition *) NameNode::create(pn->pn_atom, tc); + Definition *dn = (Definition *) NameNode::create(PNK_NAME, pn->pn_atom, tc); if (!dn) return NULL; - dn->setKind(TOK_NAME); dn->setOp(JSOP_NOP); dn->setDefn(true); dn->pn_dflags |= PND_PLACEHOLDER; @@ -724,7 +722,7 @@ MakeAssignment(ParseNode *pn, ParseNode *rhs, TreeContext *tc) pn->pn_link = NULL; } - pn->setKind(TOK_ASSIGN); + pn->setKind(PNK_ASSIGN); pn->setOp(JSOP_NOP); pn->setArity(PN_BINARY); pn->setInParens(false); @@ -757,13 +755,13 @@ MakeDefIntoUse(Definition *dn, ParseNode *pn, JSAtom *atom, TreeContext *tc) } else if (dn->kind() == Definition::FUNCTION) { JS_ASSERT(dn->isOp(JSOP_NOP)); tc->parser->prepareNodeForMutation(dn); - dn->setKind(TOK_NAME); + dn->setKind(PNK_NAME); dn->setArity(PN_NAME); dn->pn_atom = atom; } /* Now make dn no longer a definition, rather a use of pn. */ - JS_ASSERT(dn->isKind(TOK_NAME)); + JS_ASSERT(dn->isKind(PNK_NAME)); JS_ASSERT(dn->isArity(PN_NAME)); JS_ASSERT(dn->pn_atom == atom); @@ -787,33 +785,30 @@ MakeDefIntoUse(Definition *dn, ParseNode *pn, JSAtom *atom, TreeContext *tc) bool js::DefineArg(ParseNode *pn, JSAtom *atom, uintN i, TreeContext *tc) { - ParseNode *argpn, *argsbody; - /* Flag tc so we don't have to lookup arguments on every use. */ if (atom == tc->parser->context->runtime->atomState.argumentsAtom) tc->flags |= TCF_FUN_PARAM_ARGUMENTS; /* * Make an argument definition node, distinguished by being in tc->decls - * but having TOK_NAME type and JSOP_NOP op. Insert it in a TOK_ARGSBODY + * but having PNK_NAME kind and JSOP_NOP op. Insert it in a PNK_ARGSBODY * list node returned via pn->pn_body. */ - argpn = NameNode::create(atom, tc); + ParseNode *argpn = NameNode::create(PNK_NAME, atom, tc); if (!argpn) return false; - JS_ASSERT(argpn->isKind(TOK_NAME) && argpn->isOp(JSOP_NOP)); + JS_ASSERT(argpn->isKind(PNK_NAME) && argpn->isOp(JSOP_NOP)); /* Arguments are initialized by definition. */ argpn->pn_dflags |= PND_INITIALIZED; if (!Define(argpn, atom, tc)) return false; - argsbody = pn->pn_body; + ParseNode *argsbody = pn->pn_body; if (!argsbody) { - argsbody = ListNode::create(tc); + argsbody = ListNode::create(PNK_ARGSBODY, tc); if (!argsbody) return false; - argsbody->setKind(TOK_ARGSBODY); argsbody->setOp(JSOP_NOP); argsbody->makeEmpty(); pn->pn_body = argsbody; @@ -1150,11 +1145,10 @@ LeaveFunction(ParseNode *fn, TreeContext *funtc, PropertyName *funName = NULL, if (funtc->lexdeps->count() - foundCallee != 0) { ParseNode *body = fn->pn_body; - fn->pn_body = NameSetNode::create(tc); + fn->pn_body = NameSetNode::create(PNK_UPVARS, tc); if (!fn->pn_body) return false; - fn->pn_body->setKind(TOK_UPVARS); fn->pn_body->pn_pos = body->pn_pos; if (foundCallee) funtc->lexdeps->remove(funName); @@ -1254,23 +1248,22 @@ Parser::functionArguments(TreeContext &funtc, FunctionBox *funbox, ParseNode **l * anonymous positional parameter into the destructuring * left-hand-side expression and accumulate it in list. */ - ParseNode *rhs = NameNode::create(context->runtime->atomState.emptyAtom, &funtc); + ParseNode *rhs = + NameNode::create(PNK_NAME, context->runtime->atomState.emptyAtom, &funtc); if (!rhs) return false; - rhs->setKind(TOK_NAME); rhs->setOp(JSOP_GETARG); rhs->pn_cookie.set(funtc.staticLevel, slot); rhs->pn_dflags |= PND_BOUND; ParseNode *item = - ParseNode::newBinaryOrAppend(TOK_ASSIGN, JSOP_NOP, lhs, rhs, &funtc); + ParseNode::newBinaryOrAppend(PNK_ASSIGN, JSOP_NOP, lhs, rhs, &funtc); if (!item) return false; if (!list) { - list = ListNode::create(&funtc); + list = ListNode::create(PNK_VAR, &funtc); if (!list) return false; - list->setKind(TOK_VAR); list->makeEmpty(); *listp = list; } @@ -1345,8 +1338,7 @@ Parser::functionDef(PropertyName *funName, FunctionType type, FunctionSyntaxKind JS_ASSERT_IF(kind == Statement, funName); /* Make a TOK_FUNCTION node. */ - tokenStream.mungeCurrentToken(TOK_FUNCTION, JSOP_NOP); - ParseNode *pn = FunctionNode::create(tc); + ParseNode *pn = FunctionNode::create(PNK_FUNCTION, tc); if (!pn) return NULL; pn->pn_body = NULL; @@ -1406,7 +1398,7 @@ Parser::functionDef(PropertyName *funName, FunctionType type, FunctionSyntaxKind if (Definition *fn = tc->lexdeps.lookupDefn(funName)) { JS_ASSERT(fn->isDefn()); - fn->setKind(TOK_FUNCTION); + fn->setKind(PNK_FUNCTION); fn->setArity(PN_FUNC); fn->pn_pos.begin = pn->pn_pos.begin; @@ -1567,28 +1559,26 @@ Parser::functionDef(PropertyName *funName, FunctionType type, FunctionSyntaxKind /* * If there were destructuring formal parameters, prepend the initializing * comma expression that we synthesized to body. If the body is a return - * node, we must make a special TOK_SEQ node, to prepend the destructuring + * node, we must make a special PNK_SEQ node, to prepend the destructuring * code without bracing the decompilation of the function body. */ if (prelude) { if (!body->isArity(PN_LIST)) { ParseNode *block; - block = ListNode::create(outertc); + block = ListNode::create(PNK_SEQ, outertc); if (!block) return NULL; - block->setKind(TOK_SEQ); block->pn_pos = body->pn_pos; block->initList(body); body = block; } - ParseNode *item = UnaryNode::create(outertc); + ParseNode *item = UnaryNode::create(PNK_SEMI, outertc); if (!item) return NULL; - item->setKind(TOK_SEMI); item->pn_pos.begin = item->pn_pos.end = body->pn_pos.begin; item->pn_kid = prelude; item->pn_next = body->pn_head; @@ -1776,15 +1766,14 @@ Parser::recognizeDirectivePrologue(ParseNode *pn, bool *isDirectivePrologueMembe ParseNode * Parser::statements() { - ParseNode *pn, *pn2, *saveBlock; + ParseNode *pn2, *saveBlock; TokenKind tt; JS_CHECK_RECURSION(context, return NULL); - pn = ListNode::create(tc); + ParseNode *pn = ListNode::create(PNK_LC, tc); if (!pn) return NULL; - pn->setKind(TOK_LC); pn->makeEmpty(); pn->pn_blockid = tc->blockid(); saveBlock = tc->blockNode; @@ -1812,7 +1801,7 @@ Parser::statements() if (inDirectivePrologue && !recognizeDirectivePrologue(pn2, &inDirectivePrologue)) return NULL; - if (pn2->isKind(TOK_FUNCTION)) { + if (pn2->isKind(PNK_FUNCTION)) { /* * PNX_FUNCDEFS notifies the emitter that the block contains body- * level function definitions that should be processed before the @@ -1858,8 +1847,8 @@ Parser::condition() MUST_MATCH_TOKEN(TOK_RP, JSMSG_PAREN_AFTER_COND); /* Check for (a = b) and warn about possible (a == b) mistype. */ - JS_ASSERT_IF(pn->isKind(TOK_ASSIGN), pn->isOp(JSOP_NOP)); - if (pn->isKind(TOK_ASSIGN) && + JS_ASSERT_IF(pn->isKind(PNK_ASSIGN), pn->isOp(JSOP_NOP)); + if (pn->isKind(PNK_ASSIGN) && !pn->isInParens() && !reportErrorNumber(NULL, JSREPORT_WARNING | JSREPORT_STRICT, JSMSG_EQUAL_AS_ASSIGN, "")) { @@ -2035,7 +2024,7 @@ DefineGlobal(ParseNode *pn, BytecodeEmitter *bce, PropertyName *name) if (!globalObj->lookupProperty(cx, name, &holder, &prop)) return false; - FunctionBox *funbox = pn->isKind(TOK_FUNCTION) ? pn->pn_funbox : NULL; + FunctionBox *funbox = pn->isKind(PNK_FUNCTION) ? pn->pn_funbox : NULL; GlobalScope::GlobalDef def; if (prop) { @@ -2082,7 +2071,7 @@ DefineGlobal(ParseNode *pn, BytecodeEmitter *bce, PropertyName *name) * hoisted to the top of the script, and the |c = []| will just * overwrite it at runtime. */ - if (pn->isKind(TOK_FUNCTION)) { + if (pn->isKind(PNK_FUNCTION)) { JS_ASSERT(pn->isArity(PN_FUNC)); jsatomid index = p.value(); globalScope->defs[index].funbox = pn->pn_funbox; @@ -2270,7 +2259,7 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, TreeContext *tc) * it and possibly reinitializes its value. Beware that if pn becomes a * use of |mdl.defn()|, and if we have an initializer for this var or * const (typically a const would ;-), then pn must be rewritten into a - * TOK_ASSIGN node. See js::Parser::variables, further below. + * PNK_ASSIGN node. See js::Parser::variables, further below. * * A case such as let (x = 1) { var x = 2; print(x); } is even harder. * There the x definition is hoisted but the x = 2 assignment mutates @@ -2285,7 +2274,7 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, TreeContext *tc) ParseNode *pnu = pn; if (pn->isDefn()) { - pnu = NameNode::create(atom, tc); + pnu = NameNode::create(PNK_NAME, atom, tc); if (!pnu) return JS_FALSE; } @@ -2317,12 +2306,11 @@ BindVarOrConst(JSContext *cx, BindData *data, JSAtom *atom, TreeContext *tc) if (tc->lexdeps->lookup(atom)) { tc->lexdeps->remove(atom); } else { - ParseNode *pn2 = NameNode::create(atom, tc); + ParseNode *pn2 = NameNode::create(PNK_NAME, atom, tc); if (!pn2) return JS_FALSE; /* The token stream may be past the location for pn. */ - pn2->setKind(TOK_NAME); pn2->pn_pos = pn->pn_pos; pn = pn2; } @@ -2354,7 +2342,7 @@ MakeSetCall(JSContext *cx, ParseNode *pn, TreeContext *tc, uintN msg) return false; ParseNode *pn2 = pn->pn_head; - if (pn2->isKind(TOK_FUNCTION) && (pn2->pn_funbox->tcflags & TCF_GENEXP_LAMBDA)) { + if (pn2->isKind(PNK_FUNCTION) && (pn2->pn_funbox->tcflags & TCF_GENEXP_LAMBDA)) { ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, msg); return false; } @@ -2419,7 +2407,7 @@ BindDestructuringVar(JSContext *cx, BindData *data, ParseNode *pn, TreeContext * * simple variable, we must check for assignment to 'arguments' and flag * the enclosing function (if any) as heavyweight. */ - JS_ASSERT(pn->isKind(TOK_NAME)); + JS_ASSERT(pn->isKind(PNK_NAME)); atom = pn->pn_atom; if (atom == cx->runtime->atomState.argumentsAtom) tc->flags |= TCF_FUN_HEAVYWEIGHT; @@ -2468,12 +2456,12 @@ static JSBool BindDestructuringLHS(JSContext *cx, ParseNode *pn, TreeContext *tc) { switch (pn->getKind()) { - case TOK_NAME: + case PNK_NAME: NoteLValue(cx, pn, tc); /* FALL THROUGH */ - case TOK_DOT: - case TOK_LB: + case PNK_DOT: + case PNK_LB: /* * We may be called on a name node that has already been specialized, * in the very weird and ECMA-262-required "for (var [x] = i in o) ..." @@ -2483,15 +2471,15 @@ BindDestructuringLHS(JSContext *cx, ParseNode *pn, TreeContext *tc) pn->setOp(JSOP_SETNAME); break; - case TOK_LP: + case PNK_LP: if (!MakeSetCall(cx, pn, tc, JSMSG_BAD_LEFTSIDE_OF_ASS)) return JS_FALSE; break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(pn->isOp(JSOP_XMLNAME)); pn->setOp(JSOP_BINDXMLNAME); break; @@ -2551,21 +2539,21 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, TreeContext * { bool ok; - if (left->isKind(TOK_ARRAYCOMP)) { + if (left->isKind(PNK_ARRAYCOMP)) { ReportCompileErrorNumber(cx, TS(tc->parser), left, JSREPORT_ERROR, JSMSG_ARRAY_COMP_LEFTSIDE); return false; } - if (left->isKind(TOK_RB)) { + if (left->isKind(PNK_RB)) { for (ParseNode *pn = left->pn_head; pn; pn = pn->pn_next) { /* Nullary comma is an elision; binary comma is an expression.*/ - if (!pn->isKind(TOK_COMMA) || !pn->isArity(PN_NULLARY)) { - if (pn->isKind(TOK_RB) || pn->isKind(TOK_RC)) { + if (!pn->isKind(PNK_COMMA) || !pn->isArity(PN_NULLARY)) { + if (pn->isKind(PNK_RB) || pn->isKind(PNK_RC)) { ok = CheckDestructuring(cx, data, pn, tc); } else { if (data) { - if (!pn->isKind(TOK_NAME)) { + if (!pn->isKind(PNK_NAME)) { ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_NO_VARIABLE_NAME); return false; @@ -2580,15 +2568,15 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, TreeContext * } } } else { - JS_ASSERT(left->isKind(TOK_RC)); + JS_ASSERT(left->isKind(PNK_RC)); for (ParseNode *pair = left->pn_head; pair; pair = pair->pn_next) { - JS_ASSERT(pair->isKind(TOK_COLON)); + JS_ASSERT(pair->isKind(PNK_COLON)); ParseNode *pn = pair->pn_right; - if (pn->isKind(TOK_RB) || pn->isKind(TOK_RC)) { + if (pn->isKind(PNK_RB) || pn->isKind(PNK_RC)) { ok = CheckDestructuring(cx, data, pn, tc); } else if (data) { - if (!pn->isKind(TOK_NAME)) { + if (!pn->isKind(PNK_NAME)) { ReportCompileErrorNumber(cx, TS(tc->parser), pn, JSREPORT_ERROR, JSMSG_NO_VARIABLE_NAME); return false; @@ -2654,23 +2642,23 @@ CheckDestructuring(JSContext *cx, BindData *data, ParseNode *left, TreeContext * static void UndominateInitializers(ParseNode *left, const TokenPtr &end, TreeContext *tc) { - if (left->isKind(TOK_RB)) { + if (left->isKind(PNK_RB)) { for (ParseNode *pn = left->pn_head; pn; pn = pn->pn_next) { /* Nullary comma is an elision; binary comma is an expression.*/ - if (!pn->isKind(TOK_COMMA) || !pn->isArity(PN_NULLARY)) { - if (pn->isKind(TOK_RB) || pn->isKind(TOK_RC)) + if (!pn->isKind(PNK_COMMA) || !pn->isArity(PN_NULLARY)) { + if (pn->isKind(PNK_RB) || pn->isKind(PNK_RC)) UndominateInitializers(pn, end, tc); else pn->pn_pos.end = end; } } } else { - JS_ASSERT(left->isKind(TOK_RC)); + JS_ASSERT(left->isKind(PNK_RC)); for (ParseNode *pair = left->pn_head; pair; pair = pair->pn_next) { - JS_ASSERT(pair->isKind(TOK_COLON)); + JS_ASSERT(pair->isKind(PNK_COLON)); ParseNode *pn = pair->pn_right; - if (pn->isKind(TOK_RB) || pn->isKind(TOK_RC)) + if (pn->isKind(PNK_RB) || pn->isKind(PNK_RC)) UndominateInitializers(pn, end, tc); else pn->pn_pos.end = end; @@ -2681,6 +2669,8 @@ UndominateInitializers(ParseNode *left, const TokenPtr &end, TreeContext *tc) ParseNode * Parser::destructuringExpr(BindData *data, TokenKind tt) { + JS_ASSERT(tokenStream.isCurrentTokenType(tt)); + tc->flags |= TCF_DECL_DESTRUCTURING; ParseNode *pn = primaryExpr(tt, JS_FALSE); tc->flags &= ~TCF_DECL_DESTRUCTURING; @@ -2696,17 +2686,14 @@ Parser::destructuringExpr(BindData *data, TokenKind tt) ParseNode * Parser::returnOrYield(bool useAssignExpr) { - TokenKind tt, tt2; - ParseNode *pn, *pn2; - - tt = tokenStream.currentToken().type; + TokenKind tt = tokenStream.currentToken().type; if (!tc->inFunction()) { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_RETURN_OR_YIELD, (tt == TOK_RETURN) ? js_return_str : js_yield_str); return NULL; } - pn = UnaryNode::create(tc); + ParseNode *pn = UnaryNode::create((tt == TOK_RETURN) ? PNK_RETURN : PNK_YIELD, tc); if (!pn) return NULL; @@ -2726,7 +2713,7 @@ Parser::returnOrYield(bool useAssignExpr) #endif /* This is ugly, but we don't want to require a semicolon. */ - tt2 = tokenStream.peekTokenSameLine(TSF_OPERAND); + TokenKind tt2 = tokenStream.peekTokenSameLine(TSF_OPERAND); if (tt2 == TOK_ERROR) return NULL; @@ -2736,8 +2723,9 @@ Parser::returnOrYield(bool useAssignExpr) (tt2 != tt && tt2 != TOK_RB && tt2 != TOK_RP && tt2 != TOK_COLON && tt2 != TOK_COMMA)) #endif - ) { - pn2 = useAssignExpr ? assignExpr() : expr(); + ) + { + ParseNode *pn2 = useAssignExpr ? assignExpr() : expr(); if (!pn2) return NULL; #if JS_HAS_GENERATORS @@ -2775,7 +2763,7 @@ Parser::returnOrYield(bool useAssignExpr) static ParseNode * PushLexicalScope(JSContext *cx, TokenStream *ts, TreeContext *tc, StmtInfo *stmt) { - ParseNode *pn = LexicalScopeNode::create(tc); + ParseNode *pn = LexicalScopeNode::create(PNK_LEXICALSCOPE, tc); if (!pn) return NULL; @@ -2788,7 +2776,6 @@ PushLexicalScope(JSContext *cx, TokenStream *ts, TreeContext *tc, StmtInfo *stmt return NULL; PushBlockScope(tc, stmt, blockbox, -1); - pn->setKind(TOK_LEXICALSCOPE); pn->setOp(JSOP_LEAVEBLOCK); pn->pn_objbox = blockbox; pn->pn_cookie.makeFree(); @@ -2804,23 +2791,21 @@ PushLexicalScope(JSContext *cx, TokenStream *ts, TreeContext *tc, StmtInfo *stmt ParseNode * Parser::letBlock(JSBool statement) { - ParseNode *pn, *pnblock, *pnlet; - StmtInfo stmtInfo; - JS_ASSERT(tokenStream.currentToken().type == TOK_LET); /* Create the let binary node. */ - pnlet = BinaryNode::create(tc); + ParseNode *pnlet = BinaryNode::create(PNK_LET, tc); if (!pnlet) return NULL; MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_BEFORE_LET); /* This is a let block or expression of the form: let (a, b, c) .... */ - pnblock = PushLexicalScope(context, &tokenStream, tc, &stmtInfo); + StmtInfo stmtInfo; + ParseNode *pnblock = PushLexicalScope(context, &tokenStream, tc, &stmtInfo); if (!pnblock) return NULL; - pn = pnblock; + ParseNode *pn = pnblock; pn->pn_expr = pnlet; pnlet->pn_left = variables(true); @@ -2849,10 +2834,9 @@ Parser::letBlock(JSBool statement) * need to wrap the TOK_LET node in a TOK_SEMI node so that we pop * the return value of the expression. */ - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_SEMI, tc); if (!pn) return NULL; - pn->setKind(TOK_SEMI); pn->pn_num = -1; pn->pn_kid = pnblock; @@ -2924,7 +2908,8 @@ NewBindingNode(JSAtom *atom, TreeContext *tc, bool let = false) } /* Make a new node for this declarator name (or destructuring pattern). */ - pn = NameNode::create(atom, tc); + JS_ASSERT(tc->parser->tokenStream.currentToken().type == TOK_NAME); + pn = NameNode::create(PNK_NAME, atom, tc); if (!pn) return NULL; @@ -2937,10 +2922,8 @@ NewBindingNode(JSAtom *atom, TreeContext *tc, bool let = false) ParseNode * Parser::switchStatement() { - ParseNode *pn5, *saveBlock; - JSBool seenDefault = JS_FALSE; - - ParseNode *pn = BinaryNode::create(tc); + JS_ASSERT(tc->parser->tokenStream.currentToken().type == TOK_SWITCH); + ParseNode *pn = BinaryNode::create(PNK_SWITCH, tc); if (!pn) return NULL; MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_BEFORE_SWITCH); @@ -2961,15 +2944,16 @@ Parser::switchStatement() PushStatement(tc, &stmtInfo, STMT_SWITCH, -1); /* pn2 is a list of case nodes. The default case has pn_left == NULL */ - ParseNode *pn2 = ListNode::create(tc); + ParseNode *pn2 = ListNode::create(PNK_LC, tc); if (!pn2) return NULL; pn2->makeEmpty(); if (!GenerateBlockIdForStmtNode(pn2, tc)) return NULL; - saveBlock = tc->blockNode; + ParseNode *saveBlock = tc->blockNode; tc->blockNode = pn2; + bool seenDefault = false; TokenKind tt; while ((tt = tokenStream.getToken()) != TOK_RC) { ParseNode *pn3; @@ -2979,24 +2963,20 @@ Parser::switchStatement() reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_DEFAULTS); return NULL; } - seenDefault = JS_TRUE; - /* FALL THROUGH */ + seenDefault = true; + pn3 = BinaryNode::create(PNK_DEFAULT, tc); + if (!pn3) + return NULL; + break; case TOK_CASE: { - pn3 = BinaryNode::create(tc); + pn3 = BinaryNode::create(PNK_CASE, tc); if (!pn3) return NULL; - if (tt == TOK_CASE) { - pn3->pn_left = expr(); - if (!pn3->pn_left) - return NULL; - } - pn2->append(pn3); - if (pn2->pn_count == JS_BIT(16)) { - reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_CASES); + pn3->pn_left = expr(); + if (!pn3->pn_left) return NULL; - } break; } @@ -3007,18 +2987,24 @@ Parser::switchStatement() reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_SWITCH); return NULL; } + + pn2->append(pn3); + if (pn2->pn_count == JS_BIT(16)) { + reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_TOO_MANY_CASES); + return NULL; + } + MUST_MATCH_TOKEN(TOK_COLON, JSMSG_COLON_AFTER_CASE); - ParseNode *pn4 = ListNode::create(tc); + ParseNode *pn4 = ListNode::create(PNK_LC, tc); if (!pn4) return NULL; - pn4->setKind(TOK_LC); pn4->makeEmpty(); while ((tt = tokenStream.peekToken(TSF_OPERAND)) != TOK_RC && tt != TOK_CASE && tt != TOK_DEFAULT) { if (tt == TOK_ERROR) return NULL; - pn5 = statement(); + ParseNode *pn5 = statement(); if (!pn5) return NULL; pn4->pn_pos.end = pn5->pn_pos.end; @@ -3052,6 +3038,8 @@ Parser::switchStatement() ParseNode * Parser::forStatement() { + JS_ASSERT(tokenStream.isCurrentTokenType(TOK_FOR)); + ParseNode *pnseq = NULL; #if JS_HAS_BLOCK_SCOPE ParseNode *pnlet = NULL; @@ -3059,7 +3047,7 @@ Parser::forStatement() #endif /* A FOR node is binary, left is loop control and right is the body. */ - ParseNode *pn = BinaryNode::create(tc); + ParseNode *pn = BinaryNode::create(PNK_FOR, tc); if (!pn) return NULL; StmtInfo stmtInfo; @@ -3147,10 +3135,8 @@ Parser::forStatement() * as we've excluded 'in' from being parsed in RelExpr by setting * the TCF_IN_FOR_INIT flag in our TreeContext. */ - ParseNode *pn2, *pn3; - ParseNode *pn4 = TernaryNode::create(tc); - if (!pn4) - return NULL; + TokenPos pos = tokenStream.currentToken().pos; + ParseNode *pn2, *pn3, *pn4; if (pn1 && tokenStream.matchToken(TOK_IN)) { /* * Parse the rest of the for/in head. @@ -3169,28 +3155,29 @@ Parser::forStatement() || (versionNumber() == JSVERSION_1_7 && pn->isOp(JSOP_ITER) && !(pn->pn_iflags & JSITER_FOREACH) && - (pn1->pn_head->isKind(TOK_RC) || - (pn1->pn_head->isKind(TOK_RB) && + (pn1->pn_head->isKind(PNK_RC) || + (pn1->pn_head->isKind(PNK_RB) && pn1->pn_head->pn_count != 2) || - (pn1->pn_head->isKind(TOK_ASSIGN) && - (!pn1->pn_head->pn_left->isKind(TOK_RB) || + (pn1->pn_head->isKind(PNK_ASSIGN) && + (!pn1->pn_head->pn_left->isKind(PNK_RB) || pn1->pn_head->pn_left->pn_count != 2)))) #endif ) - : (!pn1->isKind(TOK_NAME) && - !pn1->isKind(TOK_DOT) && + : (!pn1->isKind(PNK_NAME) && + !pn1->isKind(PNK_DOT) && #if JS_HAS_DESTRUCTURING ((versionNumber() == JSVERSION_1_7 && pn->isOp(JSOP_ITER) && !(pn->pn_iflags & JSITER_FOREACH)) - ? (!pn1->isKind(TOK_RB) || pn1->pn_count != 2) - : (!pn1->isKind(TOK_RB) && !pn1->isKind(TOK_RC))) && + ? (!pn1->isKind(PNK_RB) || pn1->pn_count != 2) + : (!pn1->isKind(PNK_RB) && !pn1->isKind(PNK_RC))) && #endif - !pn1->isKind(TOK_LP) && + !pn1->isKind(PNK_LP) && #if JS_HAS_XML_SUPPORT (!pn1->isXMLNameOp() || !pn1->isOp(JSOP_XMLNAME)) && #endif - !pn1->isKind(TOK_LB))) { + !pn1->isKind(PNK_LB))) + { reportErrorNumber(pn1, JSREPORT_ERROR, JSMSG_BAD_FOR_LEFTSIDE); return NULL; } @@ -3208,11 +3195,12 @@ Parser::forStatement() pn1->pn_xflags |= PNX_FORINVAR; pn2 = pn1->pn_head; - if ((pn2->isKind(TOK_NAME) && pn2->maybeExpr()) + if ((pn2->isKind(PNK_NAME) && pn2->maybeExpr()) #if JS_HAS_DESTRUCTURING - || pn2->isKind(TOK_ASSIGN) + || pn2->isKind(PNK_ASSIGN) #endif - ) { + ) + { /* * Declaration with initializer. * @@ -3227,10 +3215,9 @@ Parser::forStatement() } #endif /* JS_HAS_BLOCK_SCOPE */ - pnseq = ListNode::create(tc); + pnseq = ListNode::create(PNK_SEQ, tc); if (!pnseq) return NULL; - pnseq->setKind(TOK_SEQ); pnseq->pn_pos.begin = pn->pn_pos.begin; dflag = PND_INITIALIZED; @@ -3248,10 +3235,10 @@ Parser::forStatement() pnseq->initList(pn1); #if JS_HAS_DESTRUCTURING - if (pn2->isKind(TOK_ASSIGN)) { + if (pn2->isKind(PNK_ASSIGN)) { pn2 = pn2->pn_left; - JS_ASSERT(pn2->isKind(TOK_RB) || pn2->isKind(TOK_RC) || - pn2->isKind(TOK_NAME)); + JS_ASSERT(pn2->isKind(PNK_RB) || pn2->isKind(PNK_RC) || + pn2->isKind(PNK_NAME)); } #endif pn1 = NULL; @@ -3274,18 +3261,18 @@ Parser::forStatement() } switch (pn2->getKind()) { - case TOK_NAME: + case PNK_NAME: /* Beware 'for (arguments in ...)' with or without a 'var'. */ NoteLValue(context, pn2, tc, dflag); break; #if JS_HAS_DESTRUCTURING - case TOK_ASSIGN: + case PNK_ASSIGN: JS_NOT_REACHED("forStatement TOK_ASSIGN"); break; - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: if (versionNumber() == JSVERSION_1_7) { /* * Destructuring for-in requires [key, value] enumeration @@ -3319,7 +3306,9 @@ Parser::forStatement() tc->topStmt = save; #endif - pn4->setKind(TOK_IN); + pn4 = TernaryNode::create(PNK_IN, tc); + if (!pn4) + return NULL; } else { if (pn->pn_iflags & JSITER_FOREACH) { reportErrorNumber(pn, JSREPORT_ERROR, JSMSG_BAD_FOR_EACH_LOOP); @@ -3349,8 +3338,11 @@ Parser::forStatement() return NULL; } - pn4->setKind(TOK_FORHEAD); + pn4 = TernaryNode::create(PNK_FORHEAD, tc); + if (!pn4) + return NULL; } + pn4->pn_pos = pos; pn4->setOp(JSOP_NOP); pn4->pn_kid1 = pn1; pn4->pn_kid2 = pn2; @@ -3387,7 +3379,7 @@ Parser::forStatement() ParseNode * Parser::tryStatement() { - ParseNode *catchList, *lastCatch; + JS_ASSERT(tokenStream.isCurrentTokenType(TOK_TRY)); /* * try nodes are ternary. @@ -3406,7 +3398,7 @@ Parser::tryStatement() * * finally nodes are TOK_LC statement lists. */ - ParseNode *pn = TernaryNode::create(tc); + ParseNode *pn = TernaryNode::create(PNK_TRY, tc); if (!pn) return NULL; pn->setOp(JSOP_NOP); @@ -3421,13 +3413,13 @@ Parser::tryStatement() MUST_MATCH_TOKEN(TOK_RC, JSMSG_CURLY_AFTER_TRY); PopStatement(tc); - catchList = NULL; + ParseNode *lastCatch; + ParseNode *catchList = NULL; TokenKind tt = tokenStream.getToken(); if (tt == TOK_CATCH) { - catchList = ListNode::create(tc); + catchList = ListNode::create(PNK_CATCHLIST, tc); if (!catchList) return NULL; - catchList->setKind(TOK_RESERVED); catchList->makeEmpty(); lastCatch = NULL; @@ -3457,7 +3449,7 @@ Parser::tryStatement() * where lhs is a name or a destructuring left-hand side. * (the latter is legal only #ifdef JS_HAS_CATCH_GUARD) */ - ParseNode *pn2 = TernaryNode::create(tc); + ParseNode *pn2 = TernaryNode::create(PNK_CATCH, tc); if (!pn2) return NULL; pnblock->pn_expr = pn2; @@ -3553,6 +3545,8 @@ Parser::tryStatement() ParseNode * Parser::withStatement() { + JS_ASSERT(tokenStream.isCurrentTokenType(TOK_WITH)); + /* * In most cases, we want the constructs forbidden in strict mode * code to be a subset of those that JSOPTION_STRICT warns about, and @@ -3566,7 +3560,7 @@ Parser::withStatement() return NULL; } - ParseNode *pn = BinaryNode::create(tc); + ParseNode *pn = BinaryNode::create(PNK_WITH, tc); if (!pn) return NULL; MUST_MATCH_TOKEN(TOK_LP, JSMSG_PAREN_BEFORE_WITH); @@ -3617,7 +3611,7 @@ Parser::letStatement() return pn; /* Let expressions require automatic semicolon insertion. */ - JS_ASSERT(pn->isKind(TOK_SEMI) || pn->isOp(JSOP_LEAVEBLOCKEXPR)); + JS_ASSERT(pn->isKind(PNK_SEMI) || pn->isOp(JSOP_LEAVEBLOCKEXPR)); break; } @@ -3695,15 +3689,14 @@ Parser::letStatement() #ifdef DEBUG ParseNode *tmp = tc->blockNode; - JS_ASSERT(!tmp || !tmp->isKind(TOK_LEXICALSCOPE)); + JS_ASSERT(!tmp || !tmp->isKind(PNK_LEXICALSCOPE)); #endif /* Create a new lexical scope node for these statements. */ - ParseNode *pn1 = LexicalScopeNode::create(tc); + ParseNode *pn1 = LexicalScopeNode::create(PNK_LEXICALSCOPE, tc); if (!pn1) return NULL; - pn1->setKind(TOK_LEXICALSCOPE); pn1->setOp(JSOP_LEAVEBLOCK); pn1->pn_pos = tc->blockNode->pn_pos; pn1->pn_objbox = blockbox; @@ -3732,7 +3725,7 @@ Parser::expressionStatement() return NULL; if (tokenStream.peekToken() == TOK_COLON) { - if (!pn2->isKind(TOK_NAME)) { + if (!pn2->isKind(PNK_NAME)) { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_LABEL); return NULL; } @@ -3756,39 +3749,38 @@ Parser::expressionStatement() return NULL; /* Normalize empty statement to empty block for the decompiler. */ - if (pn->isKind(TOK_SEMI) && !pn->pn_kid) { - pn->setKind(TOK_LC); + if (pn->isKind(PNK_SEMI) && !pn->pn_kid) { + pn->setKind(PNK_LC); pn->setArity(PN_LIST); pn->makeEmpty(); } /* Pop the label, set pn_expr, and return early. */ PopStatement(tc); - pn2->setKind(TOK_COLON); + pn2->setKind(PNK_COLON); pn2->pn_pos.end = pn->pn_pos.end; pn2->pn_expr = pn; return pn2; } - ParseNode *pn = UnaryNode::create(tc); + ParseNode *pn = UnaryNode::create(PNK_SEMI, tc); if (!pn) return NULL; - pn->setKind(TOK_SEMI); pn->pn_pos = pn2->pn_pos; pn->pn_kid = pn2; switch (pn2->getKind()) { - case TOK_LP: + case PNK_LP: /* * Flag lambdas immediately applied as statements as instances of * the JS "module pattern". See CheckForImmediatelyAppliedLambda. */ - if (pn2->pn_head->isKind(TOK_FUNCTION) && + if (pn2->pn_head->isKind(PNK_FUNCTION) && !pn2->pn_head->pn_funbox->node->isFunArg()) { pn2->pn_head->pn_funbox->tcflags |= TCF_FUN_MODULE_PATTERN; } break; - case TOK_ASSIGN: + case PNK_ASSIGN: /* * Keep track of all apparent methods created by assignments such * as this.foo = function (...) {...} in a function that could end @@ -3797,7 +3789,7 @@ Parser::expressionStatement() JS_ASSERT(pn2->isOp(JSOP_NOP)); if (tc->funbox && pn2->pn_left->isOp(JSOP_SETPROP) && - pn2->pn_left->pn_expr->isOp(JSOP_THIS) && + pn2->pn_left->pn_expr->isKind(PNK_THIS) && pn2->pn_right->isOp(JSOP_LAMBDA)) { JS_ASSERT(!pn2->isDefn()); @@ -3836,7 +3828,7 @@ Parser::statement() case TOK_IF: { /* An IF node has three kids: condition, then, and optional else. */ - pn = TernaryNode::create(tc); + pn = TernaryNode::create(PNK_IF, tc); if (!pn) return NULL; ParseNode *pn1 = condition(); @@ -3870,7 +3862,7 @@ Parser::statement() case TOK_WHILE: { - pn = BinaryNode::create(tc); + pn = BinaryNode::create(PNK_WHILE, tc); if (!pn) return NULL; StmtInfo stmtInfo; @@ -3890,7 +3882,7 @@ Parser::statement() case TOK_DO: { - pn = BinaryNode::create(tc); + pn = BinaryNode::create(PNK_DO, tc); if (!pn) return NULL; StmtInfo stmtInfo; @@ -3926,7 +3918,7 @@ Parser::statement() case TOK_THROW: { - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_THROW, tc); if (!pn) return NULL; @@ -3959,7 +3951,7 @@ Parser::statement() case TOK_BREAK: { - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_BREAK, tc); if (!pn) return NULL; if (!MatchLabel(context, &tokenStream, pn)) @@ -3992,7 +3984,7 @@ Parser::statement() case TOK_CONTINUE: { - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_CONTINUE, tc); if (!pn) return NULL; if (!MatchLabel(context, &tokenStream, pn)) @@ -4084,17 +4076,15 @@ Parser::statement() } case TOK_SEMI: - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_SEMI, tc); if (!pn) return NULL; - pn->setKind(TOK_SEMI); return pn; case TOK_DEBUGGER: - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_DEBUGGER, tc); if (!pn) return NULL; - pn->setKind(TOK_DEBUGGER); tc->flags |= TCF_FUN_HEAVYWEIGHT; break; @@ -4104,7 +4094,7 @@ Parser::statement() if (tc->inStrictMode()) return expressionStatement(); - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_DEFAULT, tc); if (!pn) return NULL; if (!tokenStream.matchToken(TOK_NAME) || @@ -4145,21 +4135,16 @@ Parser::statement() ParseNode * Parser::variables(bool inLetHead) { - TokenKind tt; - bool let; - StmtInfo *scopeStmt; - BindData data; - ParseNode *pn, *pn2; - /* * The three options here are: + * - TOK_VAR: We're parsing var declarations. * - TOK_LET: We are parsing a let declaration. * - TOK_LP: We are parsing the head of a let block. - * - Otherwise, we're parsing var declarations. */ - tt = tokenStream.currentToken().type; - let = (tt == TOK_LET || tt == TOK_LP); - JS_ASSERT(let || tt == TOK_VAR); + TokenKind tt = tokenStream.currentToken().type; + JS_ASSERT(tt == TOK_VAR || tt == TOK_LET || tt == TOK_LP); + + bool let = (tt == TOK_LET || tt == TOK_LP); #if JS_HAS_BLOCK_SCOPE bool popScope = (inLetHead || (let && (tc->flags & TCF_IN_FOR_INIT))); @@ -4167,7 +4152,7 @@ Parser::variables(bool inLetHead) #endif /* Make sure that statement set up the tree context correctly. */ - scopeStmt = tc->topScopeStmt; + StmtInfo *scopeStmt = tc->topScopeStmt; if (let) { while (scopeStmt && !(scopeStmt->flags & SIF_SCOPE)) { JS_ASSERT(!STMT_MAYBE_SCOPE(scopeStmt)); @@ -4176,8 +4161,9 @@ Parser::variables(bool inLetHead) JS_ASSERT(scopeStmt); } + BindData data; data.op = let ? JSOP_NOP : tokenStream.currentToken().t_op; - pn = ListNode::create(tc); + ParseNode *pn = ListNode::create(tt == TOK_LET ? PNK_LET : tt == TOK_VAR ? PNK_VAR : PNK_LP, tc); if (!pn) return NULL; pn->setOp(data.op); @@ -4196,6 +4182,7 @@ Parser::variables(bool inLetHead) data.binder = BindVarOrConst; } + ParseNode *pn2; do { tt = tokenStream.getToken(); #if JS_HAS_DESTRUCTURING @@ -4234,7 +4221,7 @@ Parser::variables(bool inLetHead) return NULL; UndominateInitializers(pn2, init->pn_pos.end, tc); - pn2 = ParseNode::newBinaryOrAppend(TOK_ASSIGN, JSOP_NOP, pn2, init, tc); + pn2 = ParseNode::newBinaryOrAppend(PNK_ASSIGN, JSOP_NOP, pn2, init, tc); if (!pn2) return NULL; pn->append(pn2); @@ -4318,7 +4305,7 @@ Parser::expr() { ParseNode *pn = assignExpr(); if (pn && tokenStream.matchToken(TOK_COMMA)) { - ParseNode *pn2 = ListNode::create(tc); + ParseNode *pn2 = ListNode::create(PNK_COMMA, tc); if (!pn2) return NULL; pn2->pn_pos.begin = pn->pn_pos.begin; @@ -4327,7 +4314,7 @@ Parser::expr() do { #if JS_HAS_GENERATORS pn2 = pn->last(); - if (pn2->isKind(TOK_YIELD) && !pn2->isInParens()) { + if (pn2->isKind(PNK_YIELD) && !pn2->isInParens()) { reportErrorNumber(pn2, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str); return NULL; } @@ -4360,7 +4347,6 @@ Parser::expr() BEGIN_EXPR_PARSER(mulExpr1) { - TokenKind tt; ParseNode *pn = unaryExpr(); /* @@ -4368,10 +4354,15 @@ BEGIN_EXPR_PARSER(mulExpr1) * isCurrentTokenType() because unaryExpr() doesn't leave the TokenStream * state one past the end of the unary expression. */ + TokenKind tt; while (pn && ((tt = tokenStream.getToken()) == TOK_STAR || tt == TOK_DIV || tt == TOK_MOD)) { - tt = tokenStream.currentToken().type; + ParseNodeKind kind = (tt == TOK_STAR) + ? PNK_STAR + : (tt == TOK_DIV) + ? PNK_DIV + : PNK_MOD; JSOp op = tokenStream.currentToken().t_op; - pn = ParseNode::newBinaryOrAppend(tt, op, pn, unaryExpr(), tc); + pn = ParseNode::newBinaryOrAppend(kind, op, pn, unaryExpr(), tc); } return pn; } @@ -4383,27 +4374,62 @@ BEGIN_EXPR_PARSER(addExpr1) while (pn && tokenStream.isCurrentTokenType(TOK_PLUS, TOK_MINUS)) { TokenKind tt = tokenStream.currentToken().type; JSOp op = (tt == TOK_PLUS) ? JSOP_ADD : JSOP_SUB; - pn = ParseNode::newBinaryOrAppend(tt, op, pn, mulExpr1n(), tc); + ParseNodeKind kind = (tt == TOK_PLUS) ? PNK_PLUS : PNK_MINUS; + pn = ParseNode::newBinaryOrAppend(kind, op, pn, mulExpr1n(), tc); } return pn; } END_EXPR_PARSER(addExpr1) +inline ParseNodeKind +ShiftTokenToParseNodeKind(const Token &token) +{ + switch (token.type) { + case TOK_LSH: + return PNK_LSH; + case TOK_RSH: + return PNK_RSH; + default: + JS_ASSERT(token.type == TOK_URSH); + return PNK_URSH; + } +} + BEGIN_EXPR_PARSER(shiftExpr1) { ParseNode *left = addExpr1i(); while (left && tokenStream.isCurrentTokenShift()) { - TokenKind tt = tokenStream.currentToken().type; + ParseNodeKind kind = ShiftTokenToParseNodeKind(tokenStream.currentToken()); JSOp op = tokenStream.currentToken().t_op; ParseNode *right = addExpr1n(); if (!right) return NULL; - left = tc->parser->new_(tt, op, left, right); + left = tc->parser->new_(kind, op, left, right); } return left; } END_EXPR_PARSER(shiftExpr1) +inline ParseNodeKind +RelationalTokenToParseNodeKind(const Token &token) +{ + switch (token.type) { + case TOK_IN: + return PNK_IN; + case TOK_INSTANCEOF: + return PNK_INSTANCEOF; + case TOK_LT: + return PNK_LT; + case TOK_LE: + return PNK_LE; + case TOK_GT: + return PNK_GT; + default: + JS_ASSERT(token.type == TOK_GE); + return PNK_GE; + } +} + BEGIN_EXPR_PARSER(relExpr1) { uintN inForInitFlag = tc->flags & TCF_IN_FOR_INIT; @@ -4423,9 +4449,9 @@ BEGIN_EXPR_PARSER(relExpr1) */ (inForInitFlag == 0 && tokenStream.isCurrentTokenType(TOK_IN)) || tokenStream.isCurrentTokenType(TOK_INSTANCEOF))) { - TokenKind tt = tokenStream.currentToken().type; + ParseNodeKind kind = RelationalTokenToParseNodeKind(tokenStream.currentToken()); JSOp op = tokenStream.currentToken().t_op; - pn = ParseNode::newBinaryOrAppend(tt, op, pn, shiftExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(kind, op, pn, shiftExpr1n(), tc); } /* Restore previous state of inForInit flag. */ tc->flags |= inForInitFlag; @@ -4434,16 +4460,32 @@ BEGIN_EXPR_PARSER(relExpr1) } END_EXPR_PARSER(relExpr1) +inline ParseNodeKind +EqualityTokenToParseNodeKind(const Token &token) +{ + switch (token.type) { + case TOK_STRICTEQ: + return PNK_STRICTEQ; + case TOK_EQ: + return PNK_EQ; + case TOK_STRICTNE: + return PNK_STRICTNE; + default: + JS_ASSERT(token.type == TOK_NE); + return PNK_NE; + } +} + BEGIN_EXPR_PARSER(eqExpr1) { ParseNode *left = relExpr1i(); while (left && tokenStream.isCurrentTokenEquality()) { - TokenKind tt = tokenStream.currentToken().type; + ParseNodeKind kind = EqualityTokenToParseNodeKind(tokenStream.currentToken()); JSOp op = tokenStream.currentToken().t_op; ParseNode *right = relExpr1n(); if (!right) return NULL; - left = tc->parser->new_(tt, op, left, right); + left = tc->parser->new_(kind, op, left, right); } return left; } @@ -4453,7 +4495,7 @@ BEGIN_EXPR_PARSER(bitAndExpr1) { ParseNode *pn = eqExpr1i(); while (pn && tokenStream.isCurrentTokenType(TOK_BITAND)) - pn = ParseNode::newBinaryOrAppend(TOK_BITAND, JSOP_BITAND, pn, eqExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(PNK_BITAND, JSOP_BITAND, pn, eqExpr1n(), tc); return pn; } END_EXPR_PARSER(bitAndExpr1) @@ -4462,7 +4504,7 @@ BEGIN_EXPR_PARSER(bitXorExpr1) { ParseNode *pn = bitAndExpr1i(); while (pn && tokenStream.isCurrentTokenType(TOK_BITXOR)) - pn = ParseNode::newBinaryOrAppend(TOK_BITXOR, JSOP_BITXOR, pn, bitAndExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(PNK_BITXOR, JSOP_BITXOR, pn, bitAndExpr1n(), tc); return pn; } END_EXPR_PARSER(bitXorExpr1) @@ -4471,7 +4513,7 @@ BEGIN_EXPR_PARSER(bitOrExpr1) { ParseNode *pn = bitXorExpr1i(); while (pn && tokenStream.isCurrentTokenType(TOK_BITOR)) - pn = ParseNode::newBinaryOrAppend(TOK_BITOR, JSOP_BITOR, pn, bitXorExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(PNK_BITOR, JSOP_BITOR, pn, bitXorExpr1n(), tc); return pn; } END_EXPR_PARSER(bitOrExpr1) @@ -4480,7 +4522,7 @@ BEGIN_EXPR_PARSER(andExpr1) { ParseNode *pn = bitOrExpr1i(); while (pn && tokenStream.isCurrentTokenType(TOK_AND)) - pn = ParseNode::newBinaryOrAppend(TOK_AND, JSOP_AND, pn, bitOrExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(PNK_AND, JSOP_AND, pn, bitOrExpr1n(), tc); return pn; } END_EXPR_PARSER(andExpr1) @@ -4490,7 +4532,7 @@ Parser::orExpr1() { ParseNode *pn = andExpr1i(); while (pn && tokenStream.isCurrentTokenType(TOK_OR)) - pn = ParseNode::newBinaryOrAppend(TOK_OR, JSOP_OR, pn, andExpr1n(), tc); + pn = ParseNode::newBinaryOrAppend(PNK_OR, JSOP_OR, pn, andExpr1n(), tc); return pn; } @@ -4500,7 +4542,7 @@ Parser::condExpr1() ParseNode *pn = orExpr1(); if (pn && tokenStream.isCurrentTokenType(TOK_HOOK)) { ParseNode *pn1 = pn; - pn = TernaryNode::create(tc); + pn = TernaryNode::create(PNK_HOOK, tc); if (!pn) return NULL; @@ -4534,21 +4576,21 @@ bool Parser::setAssignmentLhsOps(ParseNode *pn, JSOp op) { switch (pn->getKind()) { - case TOK_NAME: + case PNK_NAME: if (!CheckStrictAssignment(context, tc, pn)) return false; pn->setOp(pn->isOp(JSOP_GETLOCAL) ? JSOP_SETLOCAL : JSOP_SETNAME); NoteLValue(context, pn, tc); break; - case TOK_DOT: + case PNK_DOT: pn->setOp(JSOP_SETPROP); break; - case TOK_LB: + case PNK_LB: pn->setOp(JSOP_SETELEM); break; #if JS_HAS_DESTRUCTURING - case TOK_RB: - case TOK_RC: + case PNK_RB: + case PNK_RC: if (op != JSOP_NOP) { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_DESTRUCT_ASS); return false; @@ -4557,14 +4599,14 @@ Parser::setAssignmentLhsOps(ParseNode *pn, JSOp op) return false; break; #endif - case TOK_LP: + case PNK_LP: if (!MakeSetCall(context, pn, tc, JSMSG_BAD_LEFTSIDE_OF_ASS)) return false; break; #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: JS_ASSERT(pn->isOp(JSOP_XMLNAME)); pn->setOp(JSOP_SETXMLNAME); break; @@ -4586,25 +4628,39 @@ Parser::assignExpr() return returnOrYield(true); #endif - ParseNode *pn = condExpr1(); - if (!pn) + ParseNode *lhs = condExpr1(); + if (!lhs) return NULL; - if (!tokenStream.isCurrentTokenAssignment()) { + ParseNodeKind kind; + switch (tokenStream.currentToken().type) { + case TOK_ASSIGN: kind = PNK_ASSIGN; break; + case TOK_ADDASSIGN: kind = PNK_ADDASSIGN; break; + case TOK_SUBASSIGN: kind = PNK_SUBASSIGN; break; + case TOK_BITORASSIGN: kind = PNK_BITORASSIGN; break; + case TOK_BITXORASSIGN: kind = PNK_BITXORASSIGN; break; + case TOK_BITANDASSIGN: kind = PNK_BITANDASSIGN; break; + case TOK_LSHASSIGN: kind = PNK_LSHASSIGN; break; + case TOK_RSHASSIGN: kind = PNK_RSHASSIGN; break; + case TOK_URSHASSIGN: kind = PNK_URSHASSIGN; break; + case TOK_MULASSIGN: kind = PNK_MULASSIGN; break; + case TOK_DIVASSIGN: kind = PNK_DIVASSIGN; break; + case TOK_MODASSIGN: kind = PNK_MODASSIGN; break; + default: + JS_ASSERT(!tokenStream.isCurrentTokenAssignment()); tokenStream.ungetToken(); - return pn; + return lhs; } - TokenKind tt = tokenStream.currentToken().type; JSOp op = tokenStream.currentToken().t_op; - if (!setAssignmentLhsOps(pn, op)) + if (!setAssignmentLhsOps(lhs, op)) return NULL; ParseNode *rhs = assignExpr(); if (!rhs) return NULL; - if (pn->isKind(TOK_NAME) && pn->isUsed()) { - Definition *dn = pn->pn_lexdef; + if (lhs->isKind(PNK_NAME) && lhs->isUsed()) { + Definition *dn = lhs->pn_lexdef; /* * If the definition is not flagged as assigned, we must have imputed @@ -4619,22 +4675,22 @@ Parser::assignExpr() } } - return ParseNode::newBinaryOrAppend(tt, op, pn, rhs, tc); + return ParseNode::newBinaryOrAppend(kind, op, lhs, rhs, tc); } static ParseNode * SetLvalKid(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode *pn, ParseNode *kid, const char *name) { - if (!kid->isKind(TOK_NAME) && - !kid->isKind(TOK_DOT) && - (!kid->isKind(TOK_LP) || + if (!kid->isKind(PNK_NAME) && + !kid->isKind(PNK_DOT) && + (!kid->isKind(PNK_LP) || (!kid->isOp(JSOP_CALL) && !kid->isOp(JSOP_EVAL) && !kid->isOp(JSOP_FUNCALL) && !kid->isOp(JSOP_FUNAPPLY))) && #if JS_HAS_XML_SUPPORT (!kid->isXMLNameOp() || !kid->isOp(JSOP_XMLNAME)) && #endif - !kid->isKind(TOK_LB)) + !kid->isKind(PNK_LB)) { ReportCompileErrorNumber(cx, ts, NULL, JSREPORT_ERROR, JSMSG_BAD_OPERAND, name); return NULL; @@ -4657,32 +4713,32 @@ SetIncOpKid(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode *pn, Pars if (!kid) return JS_FALSE; switch (kid->getKind()) { - case TOK_NAME: + case PNK_NAME: op = (tt == TOK_INC) ? (preorder ? JSOP_INCNAME : JSOP_NAMEINC) : (preorder ? JSOP_DECNAME : JSOP_NAMEDEC); NoteLValue(cx, kid, tc); break; - case TOK_DOT: + case PNK_DOT: op = (tt == TOK_INC) ? (preorder ? JSOP_INCPROP : JSOP_PROPINC) : (preorder ? JSOP_DECPROP : JSOP_PROPDEC); break; - case TOK_LP: + case PNK_LP: if (!MakeSetCall(cx, kid, tc, JSMSG_BAD_INCOP_OPERAND)) return JS_FALSE; /* FALL THROUGH */ #if JS_HAS_XML_SUPPORT - case TOK_ANYNAME: - case TOK_AT: - case TOK_DBLCOLON: + case PNK_ANYNAME: + case PNK_AT: + case PNK_DBLCOLON: if (kid->isOp(JSOP_XMLNAME)) kid->setOp(JSOP_SETXMLNAME); /* FALL THROUGH */ #endif - case TOK_LB: + case PNK_LB: op = (tt == TOK_INC) ? (preorder ? JSOP_INCELEM : JSOP_ELEMINC) : (preorder ? JSOP_DECELEM : JSOP_ELEMDEC); @@ -4696,6 +4752,16 @@ SetIncOpKid(JSContext *cx, TokenStream *ts, TreeContext *tc, ParseNode *pn, Pars return JS_TRUE; } +ParseNode * +Parser::unaryOpExpr(ParseNodeKind kind, JSOp op) +{ + TokenPtr begin = tokenStream.currentToken().pos.begin; + ParseNode *kid = unaryExpr(); + if (!kid) + return NULL; + return new_(kind, op, TokenPos::make(begin, kid->pn_pos.end), kid); +} + ParseNode * Parser::unaryExpr() { @@ -4703,29 +4769,23 @@ Parser::unaryExpr() JS_CHECK_RECURSION(context, return NULL); - TokenKind tt = tokenStream.getToken(TSF_OPERAND); - switch (tt) { + switch (TokenKind tt = tokenStream.getToken(TSF_OPERAND)) { case TOK_TYPEOF: + return unaryOpExpr(PNK_TYPEOF, JSOP_TYPEOF); case TOK_VOID: + return unaryOpExpr(PNK_VOID, JSOP_VOID); case TOK_NOT: + return unaryOpExpr(PNK_NOT, JSOP_NOT); case TOK_BITNOT: + return unaryOpExpr(PNK_BITNOT, JSOP_BITNOT); case TOK_PLUS: + return unaryOpExpr(PNK_PLUS, JSOP_POS); case TOK_MINUS: - pn = UnaryNode::create(tc); - if (!pn) - return NULL; - pn->setKind(tt); - pn->setOp(tokenStream.currentToken().t_op); - pn2 = unaryExpr(); - if (!pn2) - return NULL; - pn->pn_pos.end = pn2->pn_pos.end; - pn->pn_kid = pn2; - break; + return unaryOpExpr(PNK_MINUS, JSOP_NEG); case TOK_INC: case TOK_DEC: - pn = UnaryNode::create(tc); + pn = UnaryNode::create((tt == TOK_INC) ? PNK_INC : PNK_DEC, tc); if (!pn) return NULL; pn2 = memberExpr(JS_TRUE); @@ -4738,7 +4798,7 @@ Parser::unaryExpr() case TOK_DELETE: { - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_DELETE, tc); if (!pn) return NULL; pn2 = unaryExpr(); @@ -4754,7 +4814,7 @@ Parser::unaryExpr() if (foldConstants && !FoldConstants(context, pn2, tc)) return NULL; switch (pn2->getKind()) { - case TOK_LP: + case PNK_LP: if (!(pn2->pn_xflags & PNX_SETCALL)) { /* * Call MakeSetCall to check for errors, but clear PNX_SETCALL @@ -4765,7 +4825,7 @@ Parser::unaryExpr() pn2->pn_xflags &= ~PNX_SETCALL; } break; - case TOK_NAME: + case PNK_NAME: if (!ReportStrictModeError(context, &tokenStream, tc, pn, JSMSG_DEPRECATED_DELETE_OPERAND)) { return NULL; @@ -4795,7 +4855,7 @@ Parser::unaryExpr() tt = tokenStream.peekTokenSameLine(TSF_OPERAND); if (tt == TOK_INC || tt == TOK_DEC) { (void) tokenStream.getToken(); - pn2 = UnaryNode::create(tc); + pn2 = UnaryNode::create((tt == TOK_INC) ? PNK_INC : PNK_DEC, tc); if (!pn2) return NULL; if (!SetIncOpKid(context, &tokenStream, tc, pn2, pn, tt, JS_FALSE)) @@ -5158,11 +5218,11 @@ CompExprTransplanter::transplant(ParseNode *pn) * * Return null on failure, else return the top-most parse node for the array * comprehension or generator expression, with a unary node as the body of the - * (possibly nested) for-loop, initialized by |type, op, kid|. + * (possibly nested) for-loop, initialized by |kind, op, kid|. */ ParseNode * Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, - TokenKind type, JSOp op) + ParseNodeKind kind, JSOp op) { uintN adjust; ParseNode *pn, *pn2, *pn3, **pnp; @@ -5172,7 +5232,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, JS_ASSERT(tokenStream.currentToken().type == TOK_FOR); - if (type == TOK_SEMI) { + if (kind == PNK_SEMI) { /* * Generator expression desugars to an immediately applied lambda that * yields the next value from a for-in loop (possibly nested, and with @@ -5183,7 +5243,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, return NULL; adjust = pn->pn_blockid - blockid; } else { - JS_ASSERT(type == TOK_ARRAYPUSH); + JS_ASSERT(kind == PNK_ARRAYPUSH); /* * Make a parse-node and literal object representing the block scope of @@ -5212,7 +5272,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, pnp = &pn->pn_expr; - CompExprTransplanter transplanter(kid, tc, type == TOK_SEMI, adjust); + CompExprTransplanter transplanter(kid, tc, kind == PNK_SEMI, adjust); transplanter.transplant(kid); data.pn = NULL; @@ -5226,7 +5286,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, * index to count each block-local let-variable on the left-hand side * of the IN. */ - pn2 = BinaryNode::create(tc); + pn2 = BinaryNode::create(PNK_FOR, tc); if (!pn2) return NULL; @@ -5303,7 +5363,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, if (versionNumber() == JSVERSION_1_7) { /* Destructuring requires [key, value] enumeration in JS1.7. */ - if (!pn3->isKind(TOK_RB) || pn3->pn_count != 2) { + if (!pn3->isKind(PNK_RB) || pn3->pn_count != 2) { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_FOR_LEFTSIDE); return NULL; } @@ -5329,11 +5389,10 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, * Synthesize a declaration. Every definition must appear in the parse * tree in order for ComprehensionTranslator to work. */ - ParseNode *vars = ListNode::create(tc); + ParseNode *vars = ListNode::create(PNK_VAR, tc); if (!vars) return NULL; vars->setOp(JSOP_NOP); - vars->setKind(TOK_VAR); vars->pn_pos = pn3->pn_pos; vars->makeEmpty(); vars->append(pn3); @@ -5344,7 +5403,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, if (!pn3) return NULL; - pn2->pn_left = new_(TOK_IN, JSOP_NOP, vars, pn3, pn4); + pn2->pn_left = new_(PNK_IN, JSOP_NOP, vars, pn3, pn4); if (!pn2->pn_left) return NULL; *pnp = pn2; @@ -5352,7 +5411,7 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, } while (tokenStream.matchToken(TOK_FOR)); if (tokenStream.matchToken(TOK_IF)) { - pn2 = TernaryNode::create(tc); + pn2 = TernaryNode::create(PNK_IF, tc); if (!pn2) return NULL; pn2->pn_kid1 = condition(); @@ -5362,10 +5421,9 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, pnp = &pn2->pn_kid2; } - pn2 = UnaryNode::create(tc); + pn2 = UnaryNode::create(kind, tc); if (!pn2) return NULL; - pn2->setKind(type); pn2->setOp(op); pn2->pn_kid = kid; *pnp = pn2; @@ -5394,11 +5452,12 @@ Parser::comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, ParseNode * Parser::generatorExpr(ParseNode *kid) { + JS_ASSERT(tokenStream.isCurrentTokenType(TOK_FOR)); + /* Create a |yield| node for |kid|. */ - ParseNode *pn = UnaryNode::create(tc); + ParseNode *pn = UnaryNode::create(PNK_YIELD, tc); if (!pn) return NULL; - pn->setKind(TOK_YIELD); pn->setOp(JSOP_YIELD); pn->setInParens(true); pn->pn_pos = kid->pn_pos; @@ -5406,10 +5465,9 @@ Parser::generatorExpr(ParseNode *kid) pn->pn_hidden = true; /* Make a new node for the desugared generator function. */ - ParseNode *genfn = FunctionNode::create(tc); + ParseNode *genfn = FunctionNode::create(PNK_FUNCTION, tc); if (!genfn) return NULL; - genfn->setKind(TOK_FUNCTION); genfn->setOp(JSOP_LAMBDA); JS_ASSERT(!genfn->pn_body); genfn->pn_dflags = PND_FUNARG; @@ -5466,10 +5524,9 @@ Parser::generatorExpr(ParseNode *kid) * Our result is a call expression that invokes the anonymous generator * function object. */ - ParseNode *result = ListNode::create(tc); + ParseNode *result = ListNode::create(PNK_LP, tc); if (!result) return NULL; - result->setKind(TOK_LP); result->setOp(JSOP_CALL); result->pn_pos.begin = genfn->pn_pos.begin; result->initList(genfn); @@ -5498,7 +5555,7 @@ Parser::argumentList(ParseNode *listNode) guard.endBody(); #if JS_HAS_GENERATORS - if (argNode->isKind(TOK_YIELD) && + if (argNode->isKind(PNK_YIELD) && !argNode->isInParens() && tokenStream.peekToken() == TOK_COMMA) { reportErrorNumber(argNode, JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX, js_yield_str); @@ -5539,7 +5596,7 @@ Parser::argumentList(ParseNode *listNode) static ParseNode * CheckForImmediatelyAppliedLambda(ParseNode *pn) { - if (pn->isKind(TOK_FUNCTION)) { + if (pn->isKind(PNK_FUNCTION)) { JS_ASSERT(pn->isArity(PN_FUNC)); FunctionBox *funbox = pn->pn_funbox; @@ -5560,7 +5617,7 @@ Parser::memberExpr(JSBool allowCallSyntax) /* Check for new expression first. */ TokenKind tt = tokenStream.getToken(TSF_OPERAND); if (tt == TOK_NEW) { - pn = ListNode::create(tc); + pn = ListNode::create(PNK_NEW, tc); if (!pn) return NULL; pn2 = memberExpr(JS_FALSE); @@ -5593,7 +5650,7 @@ Parser::memberExpr(JSBool allowCallSyntax) while ((tt = tokenStream.getToken()) > TOK_EOF) { if (tt == TOK_DOT) { - pn2 = NameNode::create(NULL, tc); + pn2 = NameNode::create(PNK_DOT, NULL, tc); if (!pn2) return NULL; @@ -5623,21 +5680,21 @@ Parser::memberExpr(JSBool allowCallSyntax) } /* Check both tt and pn_type, to distinguish |x.(y)| and |x.y::z| from |x.y|. */ - if (tt == TOK_NAME && pn3->isKind(TOK_NAME)) { + if (tt == TOK_NAME && pn3->isKind(PNK_NAME)) { pn2->setOp(JSOP_GETPROP); pn2->pn_expr = pn; pn2->pn_atom = pn3->pn_atom; freeTree(pn3); } else { if (tt == TOK_LP) { - pn2->setKind(TOK_FILTER); + pn2->setKind(PNK_FILTER); pn2->setOp(JSOP_FILTER); /* A filtering predicate is like a with statement. */ tc->flags |= TCF_FUN_HEAVYWEIGHT; - } else if (TokenKindIsXML(pn3->getKind())) { + } else if (pn3->isXMLPropertyIdentifier()) { JS_ASSERT(!tc->inStrictMode()); - pn2->setKind(TOK_LB); + pn2->setKind(PNK_LB); pn2->setOp(JSOP_GETELEM); } else { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT); @@ -5662,19 +5719,18 @@ Parser::memberExpr(JSBool allowCallSyntax) return NULL; } - pn2 = BinaryNode::create(tc); + pn2 = BinaryNode::create(PNK_DBLDOT, tc); if (!pn2) return NULL; tt = tokenStream.getToken(TSF_OPERAND | TSF_KEYWORD_IS_NAME); pn3 = primaryExpr(tt, JS_TRUE); if (!pn3) return NULL; - tt = pn3->getKind(); - if (tt == TOK_NAME && !pn3->isInParens()) { - pn3->setKind(TOK_STRING); + if (pn3->isKind(PNK_NAME) && !pn3->isInParens()) { + pn3->setKind(PNK_STRING); pn3->setArity(PN_NULLARY); pn3->setOp(JSOP_QNAMEPART); - } else if (!TokenKindIsXML(tt)) { + } else if (!pn3->isXMLPropertyIdentifier()) { reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_NAME_AFTER_DOT); return NULL; } @@ -5685,7 +5741,7 @@ Parser::memberExpr(JSBool allowCallSyntax) pn2->pn_pos.end = tokenStream.currentToken().pos.end; #endif } else if (tt == TOK_LB) { - pn2 = BinaryNode::create(tc); + pn2 = BinaryNode::create(PNK_LB, tc); if (!pn2) return NULL; pn3 = expr(); @@ -5704,18 +5760,18 @@ Parser::memberExpr(JSBool allowCallSyntax) * instead of a string. */ do { - if (pn3->isKind(TOK_STRING)) { + if (pn3->isKind(PNK_STRING)) { jsuint index; if (!js_IdIsIndex(ATOM_TO_JSID(pn3->pn_atom), &index)) { - pn2->setKind(TOK_DOT); + pn2->setKind(PNK_DOT); pn2->setOp(JSOP_GETPROP); pn2->setArity(PN_NAME); pn2->pn_expr = pn; pn2->pn_atom = pn3->pn_atom; break; } - pn3->setKind(TOK_NUMBER); + pn3->setKind(PNK_NUMBER); pn3->setOp(JSOP_DOUBLE); pn3->pn_dval = index; } @@ -5724,7 +5780,7 @@ Parser::memberExpr(JSBool allowCallSyntax) pn2->pn_right = pn3; } while (0); } else if (allowCallSyntax && tt == TOK_LP) { - pn2 = ListNode::create(tc); + pn2 = ListNode::create(PNK_LP, tc); if (!pn2) return NULL; pn2->setOp(JSOP_CALL); @@ -5863,24 +5919,24 @@ Parser::propertySelector() { JS_ASSERT(!tc->inStrictMode()); - DebugOnly tp = &tokenStream.currentToken(); - JS_ASSERT(tp->type == TOK_STAR || tp->type == TOK_NAME); - - ParseNode *pn = NullaryNode::create(tc); - if (!pn) - return NULL; - if (pn->isKind(TOK_STAR)) { - pn->setKind(TOK_ANYNAME); - pn->setOp(JSOP_ANYNAME); - pn->pn_atom = context->runtime->atomState.starAtom; + ParseNode *selector; + if (tokenStream.isCurrentTokenType(TOK_STAR)) { + selector = NullaryNode::create(PNK_ANYNAME, tc); + if (!selector) + return NULL; + selector->setOp(JSOP_ANYNAME); + selector->pn_atom = context->runtime->atomState.starAtom; } else { - JS_ASSERT(pn->isKind(TOK_NAME)); - pn->setOp(JSOP_QNAMEPART); - pn->setArity(PN_NAME); - pn->pn_atom = tokenStream.currentToken().name(); - pn->pn_cookie.makeFree(); + JS_ASSERT(tokenStream.isCurrentTokenType(TOK_NAME)); + selector = NullaryNode::create(PNK_NAME, tc); + if (!selector) + return NULL; + selector->setOp(JSOP_QNAMEPART); + selector->setArity(PN_NAME); + selector->pn_atom = tokenStream.currentToken().name(); + selector->pn_cookie.makeFree(); } - return pn; + return selector; } ParseNode * @@ -5888,11 +5944,8 @@ Parser::qualifiedSuffix(ParseNode *pn) { JS_ASSERT(!tc->inStrictMode()); - ParseNode *pn2, *pn3; - TokenKind tt; - JS_ASSERT(tokenStream.currentToken().type == TOK_DBLCOLON); - pn2 = NameNode::create(NULL, tc); + ParseNode *pn2 = NameNode::create(PNK_DBLCOLON, NULL, tc); if (!pn2) return NULL; @@ -5900,7 +5953,7 @@ Parser::qualifiedSuffix(ParseNode *pn) if (pn->isOp(JSOP_QNAMEPART)) pn->setOp(JSOP_NAME); - tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); + TokenKind tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); if (tt == TOK_STAR || tt == TOK_NAME) { /* Inline and specialize propertySelector for JSOP_QNAMECONST. */ pn2->setOp(JSOP_QNAMECONST); @@ -5917,7 +5970,7 @@ Parser::qualifiedSuffix(ParseNode *pn) reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_SYNTAX_ERROR); return NULL; } - pn3 = endBracketedExpr(); + ParseNode *pn3 = endBracketedExpr(); if (!pn3) return NULL; @@ -5935,9 +5988,6 @@ Parser::qualifiedIdentifier() { JS_ASSERT(!tc->inStrictMode()); - DebugOnly tp = &tokenStream.currentToken(); - JS_ASSERT(tp->type == TOK_STAR || tp->type == TOK_NAME); - ParseNode *pn = propertySelector(); if (!pn) return NULL; @@ -5954,15 +6004,14 @@ Parser::attributeIdentifier() { JS_ASSERT(!tc->inStrictMode()); - ParseNode *pn, *pn2; - TokenKind tt; - JS_ASSERT(tokenStream.currentToken().type == TOK_AT); - pn = UnaryNode::create(tc); + ParseNode *pn = UnaryNode::create(PNK_AT, tc); if (!pn) return NULL; pn->setOp(JSOP_TOATTRNAME); - tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); + + ParseNode *pn2; + TokenKind tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); if (tt == TOK_STAR || tt == TOK_NAME) { pn2 = qualifiedIdentifier(); } else if (tt == TOK_LB) { @@ -5985,10 +6034,8 @@ Parser::xmlExpr(JSBool inTag) { JS_ASSERT(!tc->inStrictMode()); - ParseNode *pn, *pn2; - JS_ASSERT(tokenStream.currentToken().type == TOK_LC); - pn = UnaryNode::create(tc); + ParseNode *pn = UnaryNode::create(PNK_LC, tc); if (!pn) return NULL; @@ -6000,7 +6047,7 @@ Parser::xmlExpr(JSBool inTag) */ bool oldflag = tokenStream.isXMLTagMode(); tokenStream.setXMLTagMode(false); - pn2 = expr(); + ParseNode *pn2 = expr(); if (!pn2) return NULL; @@ -6011,29 +6058,16 @@ Parser::xmlExpr(JSBool inTag) return pn; } -/* - * Make a terminal node for one of TOK_XMLNAME, TOK_XMLATTR, TOK_XMLSPACE, - * TOK_XMLTEXT, TOK_XMLCDATA, TOK_XMLCOMMENT, or TOK_XMLPI. When converting - * parse tree to XML, we preserve a TOK_XMLSPACE node only if it's the sole - * child of a container tag. - */ ParseNode * -Parser::xmlAtomNode() +Parser::atomNode(ParseNodeKind kind, JSOp op) { - JS_ASSERT(!tc->inStrictMode()); - - ParseNode *pn = NullaryNode::create(tc); - if (!pn) + ParseNode *node = NullaryNode::create(kind, tc); + if (!node) return NULL; + node->setOp(op); const Token &tok = tokenStream.currentToken(); - pn->setOp(tok.t_op); - if (tok.type == TOK_XMLPI) { - pn->pn_pitarget = tok.xmlPITarget(); - pn->pn_pidata = tok.xmlPIData(); - } else { - pn->pn_atom = tok.atom(); - } - return pn; + node->pn_atom = tok.atom(); + return node; } /* @@ -6045,8 +6079,8 @@ Parser::xmlAtomNode() * * Return a PN_LIST, PN_UNARY, or PN_NULLARY according as XMLNameExpr produces * a list of names and/or expressions, a single expression, or a single name. - * If PN_LIST or PN_NULLARY, pn_type will be TOK_XMLNAME; if PN_UNARY, pn_type - * will be TOK_LC. + * If PN_LIST or PN_NULLARY, getKind() will be PNK_XMLNAME. Otherwise if + * PN_UNARY, getKind() will be PNK_LC. */ ParseNode * Parser::xmlNameExpr() @@ -6065,7 +6099,8 @@ Parser::xmlNameExpr() return NULL; } else { JS_ASSERT(tt == TOK_XMLNAME); - pn2 = xmlAtomNode(); + JS_ASSERT(tokenStream.currentToken().t_op == JSOP_STRING); + pn2 = atomNode(PNK_XMLNAME, JSOP_STRING); if (!pn2) return NULL; } @@ -6074,10 +6109,9 @@ Parser::xmlNameExpr() pn = pn2; } else { if (!list) { - list = ListNode::create(tc); + list = ListNode::create(PNK_XMLNAME, tc); if (!list) return NULL; - list->setKind(TOK_XMLNAME); list->pn_pos.begin = pn->pn_pos.begin; list->initList(pn); list->pn_xflags = PNX_CANTFOLD; @@ -6098,7 +6132,7 @@ Parser::xmlNameExpr() */ #define XML_FOLDABLE(pn) ((pn)->isArity(PN_LIST) \ ? ((pn)->pn_xflags & PNX_CANTFOLD) == 0 \ - : !(pn)->isKind(TOK_LC)) + : !(pn)->isKind(PNK_LC)) /* * Parse the productions: @@ -6112,13 +6146,13 @@ Parser::xmlNameExpr() * produces a list of name and attribute values and/or braced expressions, a * single expression, or a single name. * - * If PN_LIST or PN_NULLARY, pn_type will be TOK_XMLNAME for the case where - * XMLTagContent: XMLNameExpr. If pn_type is not TOK_XMLNAME but pn_arity is - * PN_LIST, pn_type will be tagtype. If PN_UNARY, pn_type will be TOK_LC and - * we parsed exactly one expression. + * If PN_LIST or PN_NULLARY, getKind() will be PNK_XMLNAME for the case where + * XMLTagContent: XMLNameExpr. If getKind() is not PNK_XMLNAME but getArity() + * is PN_LIST, getKind() will be tagkind. If PN_UNARY, getKind() will be + * PNK_LC and we parsed exactly one expression. */ ParseNode * -Parser::xmlTagContent(TokenKind tagtype, JSAtom **namep) +Parser::xmlTagContent(ParseNodeKind tagkind, JSAtom **namep) { JS_ASSERT(!tc->inStrictMode()); @@ -6142,10 +6176,9 @@ Parser::xmlTagContent(TokenKind tagtype, JSAtom **namep) if (!pn2) return NULL; if (!list) { - list = ListNode::create(tc); + list = ListNode::create(tagkind, tc); if (!list) return NULL; - list->setKind(tagtype); list->pn_pos.begin = pn->pn_pos.begin; list->initList(pn); pn = list; @@ -6160,7 +6193,8 @@ Parser::xmlTagContent(TokenKind tagtype, JSAtom **namep) tt = tokenStream.getToken(); if (tt == TOK_XMLATTR) { - pn2 = xmlAtomNode(); + JS_ASSERT(tokenStream.currentToken().t_op == JSOP_STRING); + pn2 = atomNode(PNK_XMLATTR, JSOP_STRING); } else if (tt == TOK_LC) { pn2 = xmlExpr(JS_TRUE); pn->pn_xflags |= PNX_CANTFOLD; @@ -6205,9 +6239,11 @@ Parser::xmlElementContent(ParseNode *pn) JSAtom *textAtom = tokenStream.currentToken().atom(); if (textAtom) { /* Non-zero-length XML text scanned. */ - ParseNode *pn2 = xmlAtomNode(); + JS_ASSERT(tokenStream.currentToken().t_op == JSOP_STRING); + ParseNode *pn2 = atomNode(tt == TOK_XMLSPACE ? PNK_XMLSPACE : PNK_XMLTEXT, + JSOP_STRING); if (!pn2) - return JS_FALSE; + return false; pn->pn_pos.end = pn2->pn_pos.end; pn->append(pn2); } @@ -6220,20 +6256,30 @@ Parser::xmlElementContent(ParseNode *pn) ParseNode *pn2; if (tt == TOK_LC) { pn2 = xmlExpr(JS_FALSE); + if (!pn2) + return false; pn->pn_xflags |= PNX_CANTFOLD; } else if (tt == TOK_XMLSTAGO) { pn2 = xmlElementOrList(JS_FALSE); - if (pn2) { - pn2->pn_xflags &= ~PNX_XMLROOT; - pn->pn_xflags |= pn2->pn_xflags; - } + if (!pn2) + return false; + pn2->pn_xflags &= ~PNX_XMLROOT; + pn->pn_xflags |= pn2->pn_xflags; + } else if (tt == TOK_XMLPI) { + pn2 = NullaryNode::create(PNK_XMLPI, tc); + if (!pn2) + return false; + const Token &tok = tokenStream.currentToken(); + pn2->setOp(tok.t_op); + pn2->pn_pitarget = tok.xmlPITarget(); + pn2->pn_pidata = tok.xmlPIData(); } else { - JS_ASSERT(tt == TOK_XMLCDATA || tt == TOK_XMLCOMMENT || - tt == TOK_XMLPI); - pn2 = xmlAtomNode(); + JS_ASSERT(tt == TOK_XMLCDATA || tt == TOK_XMLCOMMENT); + pn2 = atomNode(tt == TOK_XMLCDATA ? PNK_XMLCDATA : PNK_XMLCOMMENT, + tokenStream.currentToken().t_op); + if (!pn2) + return false; } - if (!pn2) - return JS_FALSE; pn->pn_pos.end = pn2->pn_pos.end; pn->append(pn2); } @@ -6258,7 +6304,7 @@ Parser::xmlElementOrList(JSBool allowList) JS_CHECK_RECURSION(context, return NULL); JS_ASSERT(tokenStream.currentToken().type == TOK_XMLSTAGO); - pn = ListNode::create(tc); + pn = ListNode::create(PNK_XMLSTAGO, tc); if (!pn) return NULL; @@ -6271,7 +6317,7 @@ Parser::xmlElementOrList(JSBool allowList) /* * XMLElement. Append the tag and its contents, if any, to pn. */ - pn2 = xmlTagContent(TOK_XMLSTAGO, &startAtom); + pn2 = xmlTagContent(PNK_XMLSTAGO, &startAtom); if (!pn2) return NULL; tokenStream.matchToken(TOK_XMLSPACE); @@ -6279,18 +6325,17 @@ Parser::xmlElementOrList(JSBool allowList) tt = tokenStream.getToken(); if (tt == TOK_XMLPTAGC) { /* Point tag (/>): recycle pn if pn2 is a list of tag contents. */ - if (pn2->isKind(TOK_XMLSTAGO)) { + if (pn2->isKind(PNK_XMLSTAGO)) { pn->makeEmpty(); freeTree(pn); pn = pn2; } else { - JS_ASSERT(pn2->isKind(TOK_XMLNAME) || - pn2->isKind(TOK_LC)); + JS_ASSERT(pn2->isKind(PNK_XMLNAME) || pn2->isKind(PNK_LC)); pn->initList(pn2); if (!XML_FOLDABLE(pn2)) pn->pn_xflags |= PNX_CANTFOLD; } - pn->setKind(TOK_XMLPTAGC); + pn->setKind(PNK_XMLPTAGC); pn->pn_xflags |= PNX_XMLROOT; } else { /* We had better have a tag-close (>) at this point. */ @@ -6301,18 +6346,18 @@ Parser::xmlElementOrList(JSBool allowList) pn2->pn_pos.end = tokenStream.currentToken().pos.end; /* Make sure pn2 is a TOK_XMLSTAGO list containing tag contents. */ - if (!pn2->isKind(TOK_XMLSTAGO)) { + if (!pn2->isKind(PNK_XMLSTAGO)) { pn->initList(pn2); if (!XML_FOLDABLE(pn2)) pn->pn_xflags |= PNX_CANTFOLD; pn2 = pn; - pn = ListNode::create(tc); + pn = ListNode::create(PNK_XMLTAGC, tc); if (!pn) return NULL; } /* Now make pn a nominal-root TOK_XMLELEM list containing pn2. */ - pn->setKind(TOK_XMLELEM); + pn->setKind(PNK_XMLELEM); pn->pn_pos.begin = pn2->pn_pos.begin; pn->initList(pn2); if (!XML_FOLDABLE(pn2)) @@ -6331,10 +6376,10 @@ Parser::xmlElementOrList(JSBool allowList) } /* Parse end tag; check mismatch at compile-time if we can. */ - pn2 = xmlTagContent(TOK_XMLETAGO, &endAtom); + pn2 = xmlTagContent(PNK_XMLETAGO, &endAtom); if (!pn2) return NULL; - if (pn2->isKind(TOK_XMLETAGO)) { + if (pn2->isKind(PNK_XMLETAGO)) { /* Oops, end tag has attributes! */ reportErrorNumber(NULL, JSREPORT_ERROR, JSMSG_BAD_XML_TAG_SYNTAX); return NULL; @@ -6347,11 +6392,10 @@ Parser::xmlElementOrList(JSBool allowList) } /* Make a TOK_XMLETAGO list with pn2 as its single child. */ - JS_ASSERT(pn2->isKind(TOK_XMLNAME) || pn2->isKind(TOK_LC)); - list = ListNode::create(tc); + JS_ASSERT(pn2->isKind(PNK_XMLNAME) || pn2->isKind(PNK_LC)); + list = ListNode::create(PNK_XMLETAGO, tc); if (!list) return NULL; - list->setKind(TOK_XMLETAGO); list->initList(pn2); pn->append(list); if (!XML_FOLDABLE(pn2)) { @@ -6367,7 +6411,7 @@ Parser::xmlElementOrList(JSBool allowList) pn->setOp(JSOP_TOXML); } else if (allowList && tt == TOK_XMLTAGC) { /* XMLList Initialiser. */ - pn->setKind(TOK_XMLLIST); + pn->setKind(PNK_XMLLIST); pn->setOp(JSOP_TOXMLLIST); pn->makeEmpty(); pn->pn_xflags |= PNX_XMLROOT; @@ -6469,9 +6513,21 @@ BlockIdInScope(uintN blockid, TreeContext *tc) } #endif +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; @@ -6481,10 +6537,9 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) case TOK_FUNCTION: #if JS_HAS_XML_SUPPORT if (!tc->inStrictMode() && tokenStream.matchToken(TOK_DBLCOLON, TSF_KEYWORD_IS_NAME)) { - pn2 = NullaryNode::create(tc); + pn2 = NullaryNode::create(PNK_FUNCTION, tc); if (!pn2) return NULL; - pn2->setKind(TOK_FUNCTION); pn = qualifiedSuffix(pn2); if (!pn) return NULL; @@ -6501,10 +6556,9 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) JSBool matched; jsuint index; - pn = ListNode::create(tc); + pn = ListNode::create(PNK_RB, tc); if (!pn) return NULL; - pn->setKind(TOK_RB); pn->setOp(JSOP_NEWINIT); pn->makeEmpty(); @@ -6529,7 +6583,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) if (tt == TOK_COMMA) { /* So CURRENT_TOKEN gets TOK_COMMA and not TOK_LB. */ tokenStream.matchToken(TOK_COMMA); - pn2 = NullaryNode::create(tc); + pn2 = NullaryNode::create(PNK_COMMA, tc); pn->pn_xflags |= PNX_HOLEY | PNX_NONCONST; } else { pn2 = assignExpr(); @@ -6593,7 +6647,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) ParseNode *pnexp, *pntop; /* Relabel pn as an array comprehension node. */ - pn->setKind(TOK_ARRAYCOMP); + pn->setKind(PNK_ARRAYCOMP); /* * Remove the comprehension expression from pn's linked list @@ -6607,7 +6661,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) *pn->pn_tail = NULL; pntop = comprehensionTail(pnexp, pn->pn_blockid, false, - TOK_ARRAYPUSH, JSOP_ARRAYPUSH); + PNK_ARRAYPUSH, JSOP_ARRAYPUSH); if (!pntop) return NULL; pn->append(pntop); @@ -6636,10 +6690,9 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) VALUE = 0x4 | GET | SET }; - pn = ListNode::create(tc); + pn = ListNode::create(PNK_RC, tc); if (!pn) return NULL; - pn->setKind(TOK_RC); pn->setOp(JSOP_NEWINIT); pn->makeEmpty(); @@ -6648,7 +6701,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); switch (tt) { case TOK_NUMBER: - pn3 = NullaryNode::create(tc); + pn3 = NullaryNode::create(PNK_NUMBER, tc); if (!pn3) return NULL; pn3->pn_dval = tokenStream.currentToken().number(); @@ -6658,23 +6711,31 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) case TOK_NAME: { atom = tokenStream.currentToken().name(); - if (atom == context->runtime->atomState.getAtom) + if (atom == context->runtime->atomState.getAtom) { op = JSOP_GETTER; - else if (atom == context->runtime->atomState.setAtom) + } else if (atom == context->runtime->atomState.setAtom) { op = JSOP_SETTER; - else - goto property_name; + } else { + pn3 = NullaryNode::create(PNK_NAME, tc); + if (!pn3) + return NULL; + pn3->pn_atom = atom; + break; + } tt = tokenStream.getToken(TSF_KEYWORD_IS_NAME); - if (tt == TOK_NAME || tt == TOK_STRING) { - atom = (tt == TOK_NAME) - ? tokenStream.currentToken().name() - : tokenStream.currentToken().atom(); - pn3 = NameNode::create(atom, tc); + if (tt == TOK_NAME) { + atom = tokenStream.currentToken().name(); + pn3 = NameNode::create(PNK_NAME, atom, tc); + if (!pn3) + return NULL; + } else if (tt == TOK_STRING) { + atom = tokenStream.currentToken().atom(); + pn3 = NameNode::create(PNK_STRING, atom, tc); if (!pn3) return NULL; } else if (tt == TOK_NUMBER) { - pn3 = NullaryNode::create(tc); + pn3 = NullaryNode::create(PNK_NUMBER, tc); if (!pn3) return NULL; pn3->pn_dval = tokenStream.currentToken().number(); @@ -6682,20 +6743,23 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) return NULL; } else { tokenStream.ungetToken(); - goto property_name; + pn3 = NullaryNode::create(PNK_NAME, tc); + if (!pn3) + return NULL; + pn3->pn_atom = atom; + break; } pn->pn_xflags |= PNX_NONCONST; /* NB: Getter function in { get x(){} } is unnamed. */ pn2 = functionDef(NULL, op == JSOP_GETTER ? Getter : Setter, Expression); - pn2 = ParseNode::newBinaryOrAppend(TOK_COLON, op, pn3, pn2, tc); + pn2 = ParseNode::newBinaryOrAppend(PNK_COLON, op, pn3, pn2, tc); goto skip; } case TOK_STRING: atom = tokenStream.currentToken().atom(); - property_name: - pn3 = NullaryNode::create(tc); + pn3 = NullaryNode::create(PNK_STRING, tc); if (!pn3) return NULL; pn3->pn_atom = atom; @@ -6739,14 +6803,14 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) return NULL; pn->pn_xflags |= PNX_DESTRUCT | PNX_NONCONST; pnval = pn3; - if (pnval->isKind(TOK_NAME)) { + if (pnval->isKind(PNK_NAME)) { pnval->setArity(PN_NAME); ((NameNode *)pnval)->initCommon(tc); } #endif } - pn2 = ParseNode::newBinaryOrAppend(TOK_COLON, op, pn3, pnval, tc); + pn2 = ParseNode::newBinaryOrAppend(PNK_COLON, op, pn3, pnval, tc); skip: if (!pn2) return NULL; @@ -6822,7 +6886,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) #if JS_HAS_SHARP_VARS case TOK_DEFSHARP: - pn = UnaryNode::create(tc); + pn = UnaryNode::create(PNK_DEFSHARP, tc); if (!pn) return NULL; pn->pn_num = tokenStream.currentToken().sharpNumber(); @@ -6830,14 +6894,14 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) pn->pn_kid = primaryExpr(tt, JS_FALSE); if (!pn->pn_kid) return NULL; - if (pn->pn_kid->isKind(TOK_USESHARP) || - pn->pn_kid->isKind(TOK_DEFSHARP) || - pn->pn_kid->isKind(TOK_STRING) || - pn->pn_kid->isKind(TOK_NUMBER) || - pn->pn_kid->isKind(TOK_TRUE) || - pn->pn_kid->isKind(TOK_FALSE) || - pn->pn_kid->isKind(TOK_NULL) || - pn->pn_kid->isKind(TOK_THIS)) + if (pn->pn_kid->isKind(PNK_USESHARP) || + pn->pn_kid->isKind(PNK_DEFSHARP) || + pn->pn_kid->isKind(PNK_STRING) || + pn->pn_kid->isKind(PNK_NUMBER) || + pn->pn_kid->isKind(PNK_TRUE) || + pn->pn_kid->isKind(PNK_FALSE) || + pn->pn_kid->isKind(PNK_NULL) || + pn->pn_kid->isKind(PNK_THIS)) { reportErrorNumber(pn->pn_kid, JSREPORT_ERROR, JSMSG_BAD_SHARP_VAR_DEF); return NULL; @@ -6848,7 +6912,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) case TOK_USESHARP: /* Check for forward/dangling references at runtime, to allow eval. */ - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_USESHARP, tc); if (!pn) return NULL; if (!tc->ensureSharpSlots()) @@ -6892,22 +6956,29 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) #if JS_HAS_XML_SUPPORT case TOK_XMLCDATA: - case TOK_XMLCOMMENT: JS_ASSERT(!tc->inStrictMode()); - /* FALL THROUGH */ -#endif - case TOK_STRING: - pn = NullaryNode::create(tc); + pn = atomNode(PNK_XMLCDATA, JSOP_XMLCDATA); + if (!pn) + return NULL; + break; + + case TOK_XMLCOMMENT: + JS_ASSERT(!tc->inStrictMode()); + pn = atomNode(PNK_XMLCOMMENT, JSOP_XMLCOMMENT); + if (!pn) + return NULL; + break; +#endif + case TOK_STRING: + pn = atomNode(PNK_STRING, JSOP_STRING); if (!pn) return NULL; - pn->pn_atom = tokenStream.currentToken().atom(); - pn->setOp(tokenStream.currentToken().t_op); break; #if JS_HAS_XML_SUPPORT case TOK_XMLPI: JS_ASSERT(!tc->inStrictMode()); - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_XMLPI, tc); if (!pn) return NULL; pn->pn_pitarget = tokenStream.currentToken().xmlPITarget(); @@ -6916,7 +6987,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) #endif case TOK_NAME: - pn = NameNode::create(tokenStream.currentToken().name(), tc); + pn = NameNode::create(PNK_NAME, tokenStream.currentToken().name(), tc); if (!pn) return NULL; JS_ASSERT(tokenStream.currentToken().t_op == JSOP_NAME); @@ -7039,7 +7110,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) } pn->setArity(PN_NULLARY); - pn->setKind(TOK_FUNCTION); + pn->setKind(PNK_FUNCTION); } } pn = qualifiedSuffix(pn); @@ -7051,7 +7122,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) case TOK_REGEXP: { - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_REGEXP, tc); if (!pn) return NULL; @@ -7083,7 +7154,7 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) } case TOK_NUMBER: - pn = NullaryNode::create(tc); + pn = NullaryNode::create(PNK_NUMBER, tc); if (!pn) return NULL; pn->setOp(JSOP_DOUBLE); @@ -7091,14 +7162,13 @@ Parser::primaryExpr(TokenKind tt, JSBool afterDot) break; case TOK_TRUE: + return PrimaryExprNode(PNK_TRUE, JSOP_TRUE, tc); case TOK_FALSE: + return PrimaryExprNode(PNK_FALSE, JSOP_FALSE, tc); case TOK_THIS: + return PrimaryExprNode(PNK_THIS, JSOP_THIS, tc); case TOK_NULL: - pn = NullaryNode::create(tc); - if (!pn) - return NULL; - pn->setOp(tokenStream.currentToken().t_op); - break; + return PrimaryExprNode(PNK_NULL, JSOP_NULL, tc); case TOK_ERROR: /* The scanner or one of its subroutines reported the error. */ @@ -7134,8 +7204,8 @@ Parser::parenExpr(JSBool *genexp) if (tokenStream.matchToken(TOK_FOR)) { if (!guard.checkValidBody(pn)) return NULL; - JS_ASSERT(!pn->isKind(TOK_YIELD)); - if (pn->isKind(TOK_COMMA) && !pn->isInParens()) { + JS_ASSERT(!pn->isKind(PNK_YIELD)); + if (pn->isKind(PNK_COMMA) && !pn->isInParens()) { reportErrorNumber(pn->last(), JSREPORT_ERROR, JSMSG_BAD_GENERATOR_SYNTAX, js_generator_str); return NULL; diff --git a/js/src/frontend/Parser.h b/js/src/frontend/Parser.h index 17f11e387c45..6ff7f3f9ced2 100644 --- a/js/src/frontend/Parser.h +++ b/js/src/frontend/Parser.h @@ -141,6 +141,12 @@ struct Parser : private AutoGCRooter return allocator.allocNode(); } + /* + * Create a parse node with the given kind and op using the current token's + * atom. + */ + ParseNode *atomNode(ParseNodeKind kind, JSOp op); + public: ParseNode *freeTree(ParseNode *pn) { return allocator.freeTree(pn); } void prepareNodeForMutation(ParseNode *pn) { return allocator.prepareNodeForMutation(pn); } @@ -218,9 +224,11 @@ struct Parser : private AutoGCRooter ParseNode *functionDef(PropertyName *name, FunctionType type, FunctionSyntaxKind kind); + ParseNode *unaryOpExpr(ParseNodeKind kind, JSOp op); + ParseNode *condition(); ParseNode *comprehensionTail(ParseNode *kid, uintN blockid, bool isGenexp, - TokenKind type = TOK_SEMI, JSOp op = JSOP_NOP); + ParseNodeKind kind = PNK_SEMI, JSOp op = JSOP_NOP); ParseNode *generatorExpr(ParseNode *kid); JSBool argumentList(ParseNode *listNode); ParseNode *bracketedExpr(); @@ -236,9 +244,8 @@ struct Parser : private AutoGCRooter ParseNode *qualifiedIdentifier(); ParseNode *attributeIdentifier(); ParseNode *xmlExpr(JSBool inTag); - ParseNode *xmlAtomNode(); ParseNode *xmlNameExpr(); - ParseNode *xmlTagContent(TokenKind tagtype, JSAtom **namep); + ParseNode *xmlTagContent(ParseNodeKind tagkind, JSAtom **namep); JSBool xmlElementContent(ParseNode *pn); ParseNode *xmlElementOrList(JSBool allowList); ParseNode *xmlElementOrListRoot(JSBool allowList); diff --git a/js/src/frontend/SemanticAnalysis.cpp b/js/src/frontend/SemanticAnalysis.cpp index 79984e40148a..f75164e1d7c5 100644 --- a/js/src/frontend/SemanticAnalysis.cpp +++ b/js/src/frontend/SemanticAnalysis.cpp @@ -194,7 +194,7 @@ FindFunArgs(FunctionBox *funbox, int level, FunctionBoxQueue *queue) uintN skipmin = UpvarCookie::FREE_LEVEL; ParseNode *pn = fn->pn_body; - if (pn->isKind(TOK_UPVARS)) { + if (pn->isKind(PNK_UPVARS)) { AtomDefnMapPtr &upvars = pn->pn_names; JS_ASSERT(upvars->count() != 0); @@ -273,7 +273,7 @@ MarkFunArgs(JSContext *cx, FunctionBox *funbox, uint32 functionCount) JS_ASSERT(fn->isFunArg()); ParseNode *pn = fn->pn_body; - if (pn->isKind(TOK_UPVARS)) { + if (pn->isKind(PNK_UPVARS)) { AtomDefnMapPtr upvars = pn->pn_names; JS_ASSERT(!upvars->empty()); @@ -528,11 +528,11 @@ ConsiderUnbranding(FunctionBox *funbox) #if JS_HAS_EXPR_CLOSURES { ParseNode *pn2 = funbox->node->pn_body; - if (pn2->isKind(TOK_UPVARS)) + if (pn2->isKind(PNK_UPVARS)) pn2 = pn2->pn_tree; - if (pn2->isKind(TOK_ARGSBODY)) + if (pn2->isKind(PNK_ARGSBODY)) pn2 = pn2->last(); - if (!pn2->isKind(TOK_LC)) + if (!pn2->isKind(PNK_LC)) returnsExpr = true; } #endif @@ -585,7 +585,7 @@ SetFunctionKinds(FunctionBox *funbox, uint32 *tcflags, bool isDirectEval) bool hasUpvars = false; bool canFlatten = true; - if (pn->isKind(TOK_UPVARS)) { + if (pn->isKind(PNK_UPVARS)) { AtomDefnMapPtr upvars = pn->pn_names; JS_ASSERT(!upvars->empty()); @@ -630,13 +630,13 @@ SetFunctionKinds(FunctionBox *funbox, uint32 *tcflags, bool isDirectEval) fn->setOp(JSOP_LAMBDA_FC); break; default: - /* js_EmitTree's case TOK_FUNCTION: will select op. */ + /* js::frontend::EmitTree's PNK_FUNCTION case sets op. */ JS_ASSERT(fn->isOp(JSOP_NOP)); } } } - if (fun->kind() == JSFUN_INTERPRETED && pn->isKind(TOK_UPVARS)) { + if (fun->kind() == JSFUN_INTERPRETED && pn->isKind(PNK_UPVARS)) { /* * One or more upvars cannot be safely snapshot into a flat * closure's non-reserved slot (see JSOP_GETFCSLOT), so we loop diff --git a/js/src/frontend/TokenStream.cpp b/js/src/frontend/TokenStream.cpp index c2a309f28348..743269d03415 100644 --- a/js/src/frontend/TokenStream.cpp +++ b/js/src/frontend/TokenStream.cpp @@ -2282,14 +2282,8 @@ TokenKindToString(TokenKind tt) case TOK_XMLELEM: return "TOK_XMLELEM"; case TOK_XMLLIST: return "TOK_XMLLIST"; case TOK_YIELD: return "TOK_YIELD"; - case TOK_ARRAYCOMP: return "TOK_ARRAYCOMP"; - case TOK_ARRAYPUSH: return "TOK_ARRAYPUSH"; case TOK_LEXICALSCOPE: return "TOK_LEXICALSCOPE"; case TOK_LET: return "TOK_LET"; - case TOK_SEQ: return "TOK_SEQ"; - case TOK_FORHEAD: return "TOK_FORHEAD"; - case TOK_ARGSBODY: return "TOK_ARGSBODY"; - case TOK_UPVARS: return "TOK_UPVARS"; case TOK_RESERVED: return "TOK_RESERVED"; case TOK_STRICT_RESERVED: return "TOK_STRICT_RESERVED"; case TOK_STRICTEQ: return "TOK_STRICTEQ"; diff --git a/js/src/frontend/TokenStream.h b/js/src/frontend/TokenStream.h index 5745501f56c1..a47917dcf205 100644 --- a/js/src/frontend/TokenStream.h +++ b/js/src/frontend/TokenStream.h @@ -136,17 +136,8 @@ enum TokenKind { TOK_XMLELEM, /* XML element node type (no token) */ TOK_XMLLIST, /* XML list node type (no token) */ TOK_YIELD, /* yield from generator function */ - TOK_ARRAYCOMP, /* array comprehension initialiser */ - TOK_ARRAYPUSH, /* array push within comprehension */ TOK_LEXICALSCOPE, /* block scope AST node label */ TOK_LET, /* let keyword */ - TOK_SEQ, /* synthetic sequence of statements, not a - block */ - TOK_FORHEAD, /* head of for(;;)-style loop */ - TOK_ARGSBODY, /* formal args in list + body at end */ - TOK_UPVARS, /* lexical dependencies as JSAtomDefnMap of - definitions paired with a parse tree full - of uses of those names */ TOK_RESERVED, /* reserved keywords */ TOK_STRICT_RESERVED, /* reserved keywords in strict mode */ @@ -163,13 +154,11 @@ enum TokenKind { TOK_NE, TOK_EQUALITY_LAST = TOK_NE, - /* Unary operation tokens, per TokenKindIsUnaryOp */ + /* Unary operation tokens */ TOK_TYPEOF, - TOK_UNARYOP_START = TOK_TYPEOF, TOK_VOID, TOK_NOT, TOK_BITNOT, - TOK_UNARYOP_LAST = TOK_BITNOT, /* Relational ops (< <= > >=), per TokenKindIsRelational */ TOK_LT, @@ -201,7 +190,6 @@ enum TokenKind { TOK_DIVASSIGN, TOK_MODASSIGN, TOK_ASSIGNMENT_LAST = TOK_MODASSIGN, - TOK_LIMIT /* domain size */ }; @@ -212,12 +200,6 @@ TokenKindIsEquality(TokenKind tt) return TOK_EQUALITY_START <= tt && tt <= TOK_EQUALITY_LAST; } -inline bool -TokenKindIsUnaryOp(TokenKind tt) -{ - return TOK_UNARYOP_START <= tt && tt <= TOK_UNARYOP_LAST; -} - inline bool TokenKindIsXML(TokenKind tt) { @@ -242,13 +224,6 @@ TokenKindIsAssignment(TokenKind tt) return TOK_ASSIGNMENT_START <= tt && tt <= TOK_ASSIGNMENT_LAST; } -inline bool -TreeTypeIsXML(TokenKind tt) -{ - return tt == TOK_XMLCOMMENT || tt == TOK_XMLCDATA || tt == TOK_XMLPI || - tt == TOK_XMLELEM || tt == TOK_XMLLIST; -} - inline bool TokenKindIsDecl(TokenKind tt) { @@ -542,10 +517,6 @@ class TokenStream return TokenKindIsEquality(currentToken().type); } - bool isCurrentTokenUnaryOp() const { - return TokenKindIsUnaryOp(currentToken().type); - } - bool isCurrentTokenRelational() const { return TokenKindIsRelational(currentToken().type); } diff --git a/js/src/jsreflect.cpp b/js/src/jsreflect.cpp index 81f4198c9da8..c4af2c568d76 100644 --- a/js/src/jsreflect.cpp +++ b/js/src/jsreflect.cpp @@ -1607,8 +1607,8 @@ class ASTSerializer return StringValue(atom ? atom : cx->runtime->atomState.emptyAtom); } - BinaryOperator binop(TokenKind tk, JSOp op); - UnaryOperator unop(TokenKind tk, JSOp op); + BinaryOperator binop(ParseNodeKind kind, JSOp op); + UnaryOperator unop(ParseNodeKind kind, JSOp op); AssignmentOperator aop(JSOp op); bool statements(ParseNode *pn, NodeVector &elts); @@ -1730,9 +1730,9 @@ ASTSerializer::aop(JSOp op) } UnaryOperator -ASTSerializer::unop(TokenKind tk, JSOp op) +ASTSerializer::unop(ParseNodeKind kind, JSOp op) { - if (tk == TOK_DELETE) + if (kind == PNK_DELETE) return UNOP_DELETE; switch (op) { @@ -1755,52 +1755,52 @@ ASTSerializer::unop(TokenKind tk, JSOp op) } BinaryOperator -ASTSerializer::binop(TokenKind tk, JSOp op) +ASTSerializer::binop(ParseNodeKind kind, JSOp op) { - switch (tk) { - case TOK_LSH: + switch (kind) { + case PNK_LSH: return BINOP_LSH; - case TOK_RSH: + case PNK_RSH: return BINOP_RSH; - case TOK_URSH: + case PNK_URSH: return BINOP_URSH; - case TOK_LT: + case PNK_LT: return BINOP_LT; - case TOK_LE: + case PNK_LE: return BINOP_LE; - case TOK_GT: + case PNK_GT: return BINOP_GT; - case TOK_GE: + case PNK_GE: return BINOP_GE; - case TOK_EQ: + case PNK_EQ: return BINOP_EQ; - case TOK_NE: + case PNK_NE: return BINOP_NE; - case TOK_STRICTEQ: + case PNK_STRICTEQ: return BINOP_STRICTEQ; - case TOK_STRICTNE: + case PNK_STRICTNE: return BINOP_STRICTNE; - case TOK_PLUS: + case PNK_PLUS: return BINOP_PLUS; - case TOK_MINUS: + case PNK_MINUS: return BINOP_MINUS; - case TOK_STAR: + case PNK_STAR: return BINOP_STAR; - case TOK_DIV: + case PNK_DIV: return BINOP_DIV; - case TOK_MOD: + case PNK_MOD: return BINOP_MOD; - case TOK_BITOR: + case PNK_BITOR: return BINOP_BITOR; - case TOK_BITXOR: + case PNK_BITXOR: return BINOP_BITXOR; - case TOK_BITAND: + case PNK_BITAND: return BINOP_BITAND; - case TOK_IN: + case PNK_IN: return BINOP_IN; - case TOK_INSTANCEOF: + case PNK_INSTANCEOF: return BINOP_INSTANCEOF; - case TOK_DBLDOT: + case PNK_DBLDOT: return BINOP_DBLDOT; default: return BINOP_ERR; @@ -1810,7 +1810,7 @@ ASTSerializer::binop(TokenKind tk, JSOp op) bool ASTSerializer::statements(ParseNode *pn, NodeVector &elts) { - JS_ASSERT(pn->isKind(TOK_LC) && pn->isArity(PN_LIST)); + JS_ASSERT(pn->isKind(PNK_LC) && pn->isArity(PN_LIST)); if (!elts.reserve(pn->pn_count)) return false; @@ -1860,7 +1860,7 @@ ASTSerializer::xmls(ParseNode *pn, NodeVector &elts) bool ASTSerializer::blockStatement(ParseNode *pn, Value *dst) { - JS_ASSERT(pn->isKind(TOK_LC)); + JS_ASSERT(pn->isKind(PNK_LC)); NodeVector stmts(cx); return statements(pn, stmts) && @@ -1887,17 +1887,17 @@ ASTSerializer::sourceElement(ParseNode *pn, Value *dst) bool ASTSerializer::declaration(ParseNode *pn, Value *dst) { - JS_ASSERT(pn->isKind(TOK_FUNCTION) || pn->isKind(TOK_VAR) || pn->isKind(TOK_LET)); + JS_ASSERT(pn->isKind(PNK_FUNCTION) || pn->isKind(PNK_VAR) || pn->isKind(PNK_LET)); switch (pn->getKind()) { - case TOK_FUNCTION: + case PNK_FUNCTION: return function(pn, AST_FUNC_DECL, dst); - case TOK_VAR: + case PNK_VAR: return variableDeclaration(pn, false, dst); default: - JS_ASSERT(pn->isKind(TOK_LET)); + JS_ASSERT(pn->isKind(PNK_LET)); return variableDeclaration(pn, true, dst); } } @@ -1905,7 +1905,7 @@ ASTSerializer::declaration(ParseNode *pn, Value *dst) bool ASTSerializer::variableDeclaration(ParseNode *pn, bool let, Value *dst) { - JS_ASSERT(let ? pn->isKind(TOK_LET) : pn->isKind(TOK_VAR)); + JS_ASSERT(let ? pn->isKind(PNK_LET) : pn->isKind(PNK_VAR)); /* Later updated to VARDECL_CONST if we find a PND_CONST declarator. */ VarDeclKind kind = let ? VARDECL_LET : VARDECL_VAR; @@ -1936,17 +1936,17 @@ ASTSerializer::variableDeclaration(ParseNode *pn, bool let, Value *dst) bool ASTSerializer::variableDeclarator(ParseNode *pn, VarDeclKind *pkind, Value *dst) { - /* A destructuring declarator is always a TOK_ASSIGN. */ - JS_ASSERT(pn->isKind(TOK_NAME) || pn->isKind(TOK_ASSIGN)); + /* A destructuring declarator is always a PNK_ASSIGN. */ + JS_ASSERT(pn->isKind(PNK_NAME) || pn->isKind(PNK_ASSIGN)); ParseNode *pnleft; ParseNode *pnright; - if (pn->isKind(TOK_NAME)) { + if (pn->isKind(PNK_NAME)) { pnleft = pn; pnright = pn->isUsed() ? NULL : pn->pn_expr; } else { - JS_ASSERT(pn->isKind(TOK_ASSIGN)); + JS_ASSERT(pn->isKind(PNK_ASSIGN)); pnleft = pn->pn_left; pnright = pn->pn_right; } @@ -2002,7 +2002,7 @@ ASTSerializer::switchStatement(ParseNode *pn, Value *dst) ParseNode *listNode; bool lexical; - if (pn->pn_right->isKind(TOK_LEXICALSCOPE)) { + if (pn->pn_right->isKind(PNK_LEXICALSCOPE)) { listNode = pn->pn_right->pn_expr; lexical = true; } else { @@ -2071,9 +2071,9 @@ ASTSerializer::forInit(ParseNode *pn, Value *dst) return true; } - return pn->isKind(TOK_VAR) + return pn->isKind(PNK_VAR) ? variableDeclaration(pn, false, dst) - : pn->isKind(TOK_LET) + : pn->isKind(PNK_LET) ? variableDeclaration(pn, true, dst) : expression(pn, dst); } @@ -2083,16 +2083,16 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) { JS_CHECK_RECURSION(cx, return false); switch (pn->getKind()) { - case TOK_FUNCTION: - case TOK_VAR: - case TOK_LET: + case PNK_FUNCTION: + case PNK_VAR: + case PNK_LET: return declaration(pn, dst); - case TOK_NAME: + case PNK_NAME: LOCAL_ASSERT(pn->isUsed()); return statement(pn->pn_lexdef, dst); - case TOK_SEMI: + case PNK_SEMI: if (pn->pn_kid) { Value expr; return expression(pn->pn_kid, &expr) && @@ -2100,9 +2100,9 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) } return builder.emptyStatement(&pn->pn_pos, dst); - case TOK_LEXICALSCOPE: + case PNK_LEXICALSCOPE: pn = pn->pn_expr; - if (pn->isKind(TOK_LET)) { + if (pn->isKind(PNK_LET)) { NodeVector dtors(cx); Value stmt; @@ -2111,14 +2111,14 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) builder.letStatement(dtors, stmt, &pn->pn_pos, dst); } - if (!pn->isKind(TOK_LC)) + if (!pn->isKind(PNK_LC)) return statement(pn, dst); /* FALL THROUGH */ - case TOK_LC: + case PNK_LC: return blockStatement(pn, dst); - case TOK_IF: + case PNK_IF: { Value test, cons, alt; @@ -2128,25 +2128,25 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) builder.ifStatement(test, cons, alt, &pn->pn_pos, dst); } - case TOK_SWITCH: + case PNK_SWITCH: return switchStatement(pn, dst); - case TOK_TRY: + case PNK_TRY: return tryStatement(pn, dst); - case TOK_WITH: - case TOK_WHILE: + case PNK_WITH: + case PNK_WHILE: { Value expr, stmt; return expression(pn->pn_left, &expr) && statement(pn->pn_right, &stmt) && - (pn->isKind(TOK_WITH) + (pn->isKind(PNK_WITH) ? builder.withStatement(expr, stmt, &pn->pn_pos, dst) : builder.whileStatement(expr, stmt, &pn->pn_pos, dst)); } - case TOK_DO: + case PNK_DO: { Value stmt, test; @@ -2155,7 +2155,7 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) builder.doWhileStatement(stmt, test, &pn->pn_pos, dst); } - case TOK_FOR: + case PNK_FOR: { ParseNode *head = pn->pn_left; @@ -2165,13 +2165,13 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) bool isForEach = pn->pn_iflags & JSITER_FOREACH; - if (head->isKind(TOK_IN)) { + if (head->isKind(PNK_IN)) { Value var, expr; return (!head->pn_kid1 ? pattern(head->pn_kid2, NULL, &var) : variableDeclaration(head->pn_kid1, - head->pn_kid1->isKind(TOK_LET), + head->pn_kid1->isKind(PNK_LET), &var)) && expression(head->pn_kid3, &expr) && builder.forInStatement(var, expr, stmt, isForEach, &pn->pn_pos, dst); @@ -2186,21 +2186,21 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) } /* Synthesized by the parser when a for-in loop contains a variable initializer. */ - case TOK_SEQ: + case PNK_SEQ: { LOCAL_ASSERT(pn->pn_count == 2); ParseNode *prelude = pn->pn_head; ParseNode *loop = prelude->pn_next; - LOCAL_ASSERT(prelude->isKind(TOK_VAR) && loop->isKind(TOK_FOR)); + LOCAL_ASSERT(prelude->isKind(PNK_VAR) && loop->isKind(PNK_FOR)); Value var; if (!variableDeclaration(prelude, false, &var)) return false; ParseNode *head = loop->pn_left; - JS_ASSERT(head->isKind(TOK_IN)); + JS_ASSERT(head->isKind(PNK_IN)); bool isForEach = loop->pn_iflags & JSITER_FOREACH; @@ -2211,18 +2211,18 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) builder.forInStatement(var, expr, stmt, isForEach, &pn->pn_pos, dst); } - case TOK_BREAK: - case TOK_CONTINUE: + case PNK_BREAK: + case PNK_CONTINUE: { Value label; return optIdentifier(pn->pn_atom, NULL, &label) && - (pn->isKind(TOK_BREAK) + (pn->isKind(PNK_BREAK) ? builder.breakStatement(label, &pn->pn_pos, dst) : builder.continueStatement(label, &pn->pn_pos, dst)); } - case TOK_COLON: + case PNK_COLON: { Value label, stmt; @@ -2231,22 +2231,22 @@ ASTSerializer::statement(ParseNode *pn, Value *dst) builder.labeledStatement(label, stmt, &pn->pn_pos, dst); } - case TOK_THROW: - case TOK_RETURN: + case PNK_THROW: + case PNK_RETURN: { Value arg; return optExpression(pn->pn_kid, &arg) && - (pn->isKind(TOK_THROW) + (pn->isKind(PNK_THROW) ? builder.throwStatement(arg, &pn->pn_pos, dst) : builder.returnStatement(arg, &pn->pn_pos, dst)); } - case TOK_DEBUGGER: + case PNK_DEBUGGER: return builder.debuggerStatement(&pn->pn_pos, dst); #if JS_HAS_XML_SUPPORT - case TOK_DEFAULT: + case PNK_DEFAULT: { LOCAL_ASSERT(pn->isArity(PN_UNARY)); @@ -2268,9 +2268,9 @@ ASTSerializer::leftAssociate(ParseNode *pn, Value *dst) JS_ASSERT(pn->isArity(PN_LIST)); JS_ASSERT(pn->pn_count >= 1); - TokenKind tk = pn->getKind(); - bool lor = tk == TOK_OR; - bool logop = lor || (tk == TOK_AND); + ParseNodeKind kind = pn->getKind(); + bool lor = kind == PNK_OR; + bool logop = lor || (kind == PNK_AND); ParseNode *head = pn->pn_head; Value left; @@ -2306,7 +2306,7 @@ ASTSerializer::comprehensionBlock(ParseNode *pn, Value *dst) ParseNode *in = pn->pn_left; - LOCAL_ASSERT(in && in->isKind(TOK_IN)); + LOCAL_ASSERT(in && in->isKind(PNK_IN)); bool isForEach = pn->pn_iflags & JSITER_FOREACH; @@ -2319,12 +2319,12 @@ ASTSerializer::comprehensionBlock(ParseNode *pn, Value *dst) bool ASTSerializer::comprehension(ParseNode *pn, Value *dst) { - LOCAL_ASSERT(pn->isKind(TOK_FOR)); + LOCAL_ASSERT(pn->isKind(PNK_FOR)); NodeVector blocks(cx); ParseNode *next = pn; - while (next->isKind(TOK_FOR)) { + while (next->isKind(PNK_FOR)) { Value block; if (!comprehensionBlock(next, &block) || !blocks.append(block)) return false; @@ -2333,17 +2333,17 @@ ASTSerializer::comprehension(ParseNode *pn, Value *dst) Value filter = MagicValue(JS_SERIALIZE_NO_NODE); - if (next->isKind(TOK_IF)) { + if (next->isKind(PNK_IF)) { if (!optExpression(next->pn_kid1, &filter)) return false; next = next->pn_kid2; - } else if (next->isKind(TOK_LC) && next->pn_count == 0) { + } else if (next->isKind(PNK_LC) && next->pn_count == 0) { /* FoldConstants optimized away the push. */ NodeVector empty(cx); return builder.arrayExpression(empty, &pn->pn_pos, dst); } - LOCAL_ASSERT(next->isKind(TOK_ARRAYPUSH)); + LOCAL_ASSERT(next->isKind(PNK_ARRAYPUSH)); Value body; @@ -2354,12 +2354,12 @@ ASTSerializer::comprehension(ParseNode *pn, Value *dst) bool ASTSerializer::generatorExpression(ParseNode *pn, Value *dst) { - LOCAL_ASSERT(pn->isKind(TOK_FOR)); + LOCAL_ASSERT(pn->isKind(PNK_FOR)); NodeVector blocks(cx); ParseNode *next = pn; - while (next->isKind(TOK_FOR)) { + while (next->isKind(PNK_FOR)) { Value block; if (!comprehensionBlock(next, &block) || !blocks.append(block)) return false; @@ -2368,14 +2368,14 @@ ASTSerializer::generatorExpression(ParseNode *pn, Value *dst) Value filter = MagicValue(JS_SERIALIZE_NO_NODE); - if (next->isKind(TOK_IF)) { + if (next->isKind(PNK_IF)) { if (!optExpression(next->pn_kid1, &filter)) return false; next = next->pn_kid2; } - LOCAL_ASSERT(next->isKind(TOK_SEMI) && - next->pn_kid->isKind(TOK_YIELD) && + LOCAL_ASSERT(next->isKind(PNK_SEMI) && + next->pn_kid->isKind(PNK_YIELD) && next->pn_kid->pn_kid); Value body; @@ -2389,17 +2389,17 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) { JS_CHECK_RECURSION(cx, return false); switch (pn->getKind()) { - case TOK_FUNCTION: + case PNK_FUNCTION: return function(pn, AST_FUNC_EXPR, dst); - case TOK_COMMA: + case PNK_COMMA: { NodeVector exprs(cx); return expressions(pn, exprs) && builder.sequenceExpression(exprs, &pn->pn_pos, dst); } - case TOK_HOOK: + case PNK_HOOK: { Value test, cons, alt; @@ -2409,22 +2409,22 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.conditionalExpression(test, cons, alt, &pn->pn_pos, dst); } - case TOK_OR: - case TOK_AND: + case PNK_OR: + case PNK_AND: { if (pn->isArity(PN_BINARY)) { Value left, right; return expression(pn->pn_left, &left) && expression(pn->pn_right, &right) && - builder.logicalExpression(pn->isKind(TOK_OR), left, right, &pn->pn_pos, dst); + builder.logicalExpression(pn->isKind(PNK_OR), left, right, &pn->pn_pos, dst); } return leftAssociate(pn, dst); } - case TOK_INC: - case TOK_DEC: + case PNK_INC: + case PNK_DEC: { - bool incr = pn->isKind(TOK_INC); + bool incr = pn->isKind(PNK_INC); bool prefix = pn->getOp() >= JSOP_INCNAME && pn->getOp() <= JSOP_DECELEM; Value expr; @@ -2432,18 +2432,18 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.updateExpression(expr, incr, prefix, &pn->pn_pos, dst); } - case TOK_ASSIGN: - case TOK_ADDASSIGN: - case TOK_SUBASSIGN: - case TOK_BITORASSIGN: - case TOK_BITXORASSIGN: - case TOK_BITANDASSIGN: - case TOK_LSHASSIGN: - case TOK_RSHASSIGN: - case TOK_URSHASSIGN: - case TOK_MULASSIGN: - case TOK_DIVASSIGN: - case TOK_MODASSIGN: + case PNK_ASSIGN: + case PNK_ADDASSIGN: + case PNK_SUBASSIGN: + case PNK_BITORASSIGN: + case PNK_BITXORASSIGN: + case PNK_BITANDASSIGN: + case PNK_LSHASSIGN: + case PNK_RSHASSIGN: + case PNK_URSHASSIGN: + case PNK_MULASSIGN: + case PNK_DIVASSIGN: + case PNK_MODASSIGN: { AssignmentOperator op = aop(pn->getOp()); LOCAL_ASSERT(op > AOP_ERR && op < AOP_LIMIT); @@ -2454,31 +2454,31 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.assignmentExpression(op, lhs, rhs, &pn->pn_pos, dst); } - case TOK_PLUS: - case TOK_MINUS: + case PNK_PLUS: + case PNK_MINUS: if (pn->isArity(PN_UNARY)) goto unary_plusminus; /* FALL THROUGH */ - case TOK_STRICTEQ: - case TOK_EQ: - case TOK_STRICTNE: - case TOK_NE: - case TOK_LT: - case TOK_LE: - case TOK_GT: - case TOK_GE: - case TOK_LSH: - case TOK_RSH: - case TOK_URSH: - case TOK_STAR: - case TOK_DIV: - case TOK_MOD: - case TOK_BITOR: - case TOK_BITXOR: - case TOK_BITAND: - case TOK_IN: - case TOK_INSTANCEOF: - case TOK_DBLDOT: + case PNK_STRICTEQ: + case PNK_EQ: + case PNK_STRICTNE: + case PNK_NE: + case PNK_LT: + case PNK_LE: + case PNK_GT: + case PNK_GE: + case PNK_LSH: + case PNK_RSH: + case PNK_URSH: + case PNK_STAR: + case PNK_DIV: + case PNK_MOD: + case PNK_BITOR: + case PNK_BITXOR: + case PNK_BITAND: + case PNK_IN: + case PNK_INSTANCEOF: + case PNK_DBLDOT: if (pn->isArity(PN_BINARY)) { BinaryOperator op = binop(pn->getKind(), pn->getOp()); LOCAL_ASSERT(op > BINOP_ERR && op < BINOP_LIMIT); @@ -2490,11 +2490,11 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) } return leftAssociate(pn, dst); - case TOK_DELETE: - case TOK_TYPEOF: - case TOK_VOID: - case TOK_NOT: - case TOK_BITNOT: + case PNK_DELETE: + case PNK_TYPEOF: + case PNK_VOID: + case PNK_NOT: + case PNK_BITNOT: unary_plusminus: { UnaryOperator op = unop(pn->getKind(), pn->getOp()); LOCAL_ASSERT(op > UNOP_ERR && op < UNOP_LIMIT); @@ -2504,8 +2504,8 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.unaryExpression(op, expr, &pn->pn_pos, dst); } - case TOK_NEW: - case TOK_LP: + case PNK_NEW: + case PNK_LP: { #ifdef JS_HAS_GENERATOR_EXPRS if (pn->isGeneratorExpr()) @@ -2529,12 +2529,12 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) args.infallibleAppend(arg); } - return pn->isKind(TOK_NEW) + return pn->isKind(PNK_NEW) ? builder.newExpression(callee, args, &pn->pn_pos, dst) : builder.callExpression(callee, args, &pn->pn_pos, dst); } - case TOK_DOT: + case PNK_DOT: { Value expr, id; return expression(pn->pn_expr, &expr) && @@ -2542,7 +2542,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.memberExpression(false, expr, id, &pn->pn_pos, dst); } - case TOK_LB: + case PNK_LB: { Value left, right; return expression(pn->pn_left, &left) && @@ -2550,14 +2550,14 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.memberExpression(true, left, right, &pn->pn_pos, dst); } - case TOK_RB: + case PNK_RB: { NodeVector elts(cx); if (!elts.reserve(pn->pn_count)) return false; for (ParseNode *next = pn->pn_head; next; next = next->pn_next) { - if (next->isKind(TOK_COMMA)) { + if (next->isKind(PNK_COMMA)) { elts.infallibleAppend(MagicValue(JS_SERIALIZE_NO_NODE)); } else { Value expr; @@ -2570,7 +2570,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) return builder.arrayExpression(elts, &pn->pn_pos, dst); } - case TOK_RC: + case PNK_RC: { /* The parser notes any uninitialized properties by setting the PNX_DESTRUCT flag. */ if (pn->pn_xflags & PNX_DESTRUCT) { @@ -2591,45 +2591,45 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) return builder.objectExpression(elts, &pn->pn_pos, dst); } - case TOK_NAME: + case PNK_NAME: return identifier(pn, dst); - case TOK_THIS: + case PNK_THIS: return builder.thisExpression(&pn->pn_pos, dst); - case TOK_STRING: - case TOK_REGEXP: - case TOK_NUMBER: - case TOK_TRUE: - case TOK_FALSE: - case TOK_NULL: + case PNK_STRING: + case PNK_REGEXP: + case PNK_NUMBER: + case PNK_TRUE: + case PNK_FALSE: + case PNK_NULL: return literal(pn, dst); - case TOK_YIELD: + case PNK_YIELD: { Value arg; return optExpression(pn->pn_kid, &arg) && builder.yieldExpression(arg, &pn->pn_pos, dst); } - case TOK_DEFSHARP: + case PNK_DEFSHARP: { Value expr; return expression(pn->pn_kid, &expr) && builder.graphExpression(pn->pn_num, expr, &pn->pn_pos, dst); } - case TOK_USESHARP: + case PNK_USESHARP: return builder.graphIndexExpression(pn->pn_num, &pn->pn_pos, dst); - case TOK_ARRAYCOMP: + case PNK_ARRAYCOMP: /* NB: it's no longer the case that pn_count could be 2. */ LOCAL_ASSERT(pn->pn_count == 1); - LOCAL_ASSERT(pn->pn_head->isKind(TOK_LEXICALSCOPE)); + LOCAL_ASSERT(pn->pn_head->isKind(PNK_LEXICALSCOPE)); return comprehension(pn->pn_head->pn_expr, dst); - case TOK_LEXICALSCOPE: + case PNK_LEXICALSCOPE: { pn = pn->pn_expr; @@ -2642,7 +2642,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) } #ifdef JS_HAS_XML_SUPPORT - case TOK_ANYNAME: + case PNK_ANYNAME: if (pn->isOp(JSOP_XMLNAME) || pn->isOp(JSOP_SETXMLNAME) || pn->isOp(JSOP_BINDXMLNAME)) @@ -2651,7 +2651,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) } return builder.xmlAnyName(&pn->pn_pos, dst); - case TOK_DBLCOLON: + case PNK_DBLCOLON: { if (pn->isOp(JSOP_XMLNAME) || pn->isOp(JSOP_SETXMLNAME) || @@ -2680,7 +2680,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) return false; } - if (pnleft->isKind(TOK_FUNCTION)) + if (pnleft->isKind(PNK_FUNCTION)) return builder.xmlFunctionQualifiedIdentifier(right, computed, &pn->pn_pos, dst); Value left; @@ -2688,7 +2688,7 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) builder.xmlQualifiedIdentifier(left, right, computed, &pn->pn_pos, dst); } - case TOK_AT: + case PNK_AT: { if (pn->isOp(JSOP_XMLNAME) || pn->isOp(JSOP_SETXMLNAME) || @@ -2699,14 +2699,14 @@ ASTSerializer::expression(ParseNode *pn, Value *dst) Value expr; ParseNode *kid = pn->pn_kid; - bool computed = ((!kid->isKind(TOK_NAME) || !kid->isOp(JSOP_QNAMEPART)) && - !kid->isKind(TOK_DBLCOLON) && - !kid->isKind(TOK_ANYNAME)); + bool computed = ((!kid->isKind(PNK_NAME) || !kid->isOp(JSOP_QNAMEPART)) && + !kid->isKind(PNK_DBLCOLON) && + !kid->isKind(PNK_ANYNAME)); return expression(kid, &expr) && builder.xmlAttributeSelector(expr, computed, &pn->pn_pos, dst); } - case TOK_FILTER: + case PNK_FILTER: { Value left, right; return expression(pn->pn_left, &left) && @@ -2730,14 +2730,14 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) JS_CHECK_RECURSION(cx, return false); switch (pn->getKind()) { #ifdef JS_HAS_XML_SUPPORT - case TOK_LC: + case PNK_LC: { Value expr; return expression(pn->pn_kid, &expr) && builder.xmlEscapeExpression(expr, &pn->pn_pos, dst); } - case TOK_XMLELEM: + case PNK_XMLELEM: { NodeVector elts(cx); if (!xmls(pn, elts)) @@ -2745,7 +2745,7 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) return builder.xmlElement(elts, &pn->pn_pos, dst); } - case TOK_XMLLIST: + case PNK_XMLLIST: { NodeVector elts(cx); if (!xmls(pn, elts)) @@ -2753,7 +2753,7 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) return builder.xmlList(elts, &pn->pn_pos, dst); } - case TOK_XMLSTAGO: + case PNK_XMLSTAGO: { NodeVector elts(cx); if (!xmls(pn, elts)) @@ -2761,7 +2761,7 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) return builder.xmlStartTag(elts, &pn->pn_pos, dst); } - case TOK_XMLETAGO: + case PNK_XMLETAGO: { NodeVector elts(cx); if (!xmls(pn, elts)) @@ -2769,7 +2769,7 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) return builder.xmlEndTag(elts, &pn->pn_pos, dst); } - case TOK_XMLPTAGC: + case PNK_XMLPTAGC: { NodeVector elts(cx); if (!xmls(pn, elts)) @@ -2777,11 +2777,11 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) return builder.xmlPointTag(elts, &pn->pn_pos, dst); } - case TOK_XMLTEXT: - case TOK_XMLSPACE: + case PNK_XMLTEXT: + case PNK_XMLSPACE: return builder.xmlText(atomContents(pn->pn_atom), &pn->pn_pos, dst); - case TOK_XMLNAME: + case PNK_XMLNAME: if (pn->isArity(PN_NULLARY)) return builder.xmlName(atomContents(pn->pn_atom), &pn->pn_pos, dst); @@ -2793,16 +2793,16 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) builder.xmlName(elts, &pn->pn_pos, dst); } - case TOK_XMLATTR: + case PNK_XMLATTR: return builder.xmlAttribute(atomContents(pn->pn_atom), &pn->pn_pos, dst); - case TOK_XMLCDATA: + case PNK_XMLCDATA: return builder.xmlCdata(atomContents(pn->pn_atom), &pn->pn_pos, dst); - case TOK_XMLCOMMENT: + case PNK_XMLCOMMENT: return builder.xmlComment(atomContents(pn->pn_atom), &pn->pn_pos, dst); - case TOK_XMLPI: + case PNK_XMLPI: if (!pn->pn_pidata) return builder.xmlPI(atomContents(pn->pn_pitarget), &pn->pn_pos, dst); else @@ -2820,10 +2820,10 @@ ASTSerializer::xml(ParseNode *pn, Value *dst) bool ASTSerializer::propertyName(ParseNode *pn, Value *dst) { - if (pn->isKind(TOK_NAME)) + if (pn->isKind(PNK_NAME)) return identifier(pn, dst); - LOCAL_ASSERT(pn->isKind(TOK_STRING) || pn->isKind(TOK_NUMBER)); + LOCAL_ASSERT(pn->isKind(PNK_STRING) || pn->isKind(PNK_NUMBER)); return literal(pn, dst); } @@ -2860,11 +2860,11 @@ ASTSerializer::literal(ParseNode *pn, Value *dst) { Value val; switch (pn->getKind()) { - case TOK_STRING: + case PNK_STRING: val.setString(pn->pn_atom); break; - case TOK_REGEXP: + case PNK_REGEXP: { JSObject *re1 = pn->pn_objbox ? pn->pn_objbox->object : NULL; LOCAL_ASSERT(re1 && re1->isRegExp()); @@ -2881,19 +2881,19 @@ ASTSerializer::literal(ParseNode *pn, Value *dst) break; } - case TOK_NUMBER: + case PNK_NUMBER: val.setNumber(pn->pn_dval); break; - case TOK_NULL: + case PNK_NULL: val.setNull(); break; - case TOK_TRUE: + case PNK_TRUE: val.setBoolean(true); break; - case TOK_FALSE: + case PNK_FALSE: val.setBoolean(false); break; @@ -2907,14 +2907,14 @@ ASTSerializer::literal(ParseNode *pn, Value *dst) bool ASTSerializer::arrayPattern(ParseNode *pn, VarDeclKind *pkind, Value *dst) { - JS_ASSERT(pn->isKind(TOK_RB)); + JS_ASSERT(pn->isKind(PNK_RB)); NodeVector elts(cx); if (!elts.reserve(pn->pn_count)) return false; for (ParseNode *next = pn->pn_head; next; next = next->pn_next) { - if (next->isKind(TOK_COMMA)) { + if (next->isKind(PNK_COMMA)) { elts.infallibleAppend(MagicValue(JS_SERIALIZE_NO_NODE)); } else { Value patt; @@ -2930,7 +2930,7 @@ ASTSerializer::arrayPattern(ParseNode *pn, VarDeclKind *pkind, Value *dst) bool ASTSerializer::objectPattern(ParseNode *pn, VarDeclKind *pkind, Value *dst) { - JS_ASSERT(pn->isKind(TOK_RC)); + JS_ASSERT(pn->isKind(PNK_RC)); NodeVector elts(cx); if (!elts.reserve(pn->pn_count)) @@ -2957,13 +2957,13 @@ ASTSerializer::pattern(ParseNode *pn, VarDeclKind *pkind, Value *dst) { JS_CHECK_RECURSION(cx, return false); switch (pn->getKind()) { - case TOK_RC: + case PNK_RC: return objectPattern(pn, pkind, dst); - case TOK_RB: + case PNK_RB: return arrayPattern(pn, pkind, dst); - case TOK_NAME: + case PNK_NAME: if (pkind && (pn->pn_dflags & PND_CONST)) *pkind = VARDECL_CONST; /* FALL THROUGH */ @@ -3013,7 +3013,7 @@ ASTSerializer::function(ParseNode *pn, ASTType type, Value *dst) NodeVector args(cx); - ParseNode *argsAndBody = pn->pn_body->isKind(TOK_UPVARS) + ParseNode *argsAndBody = pn->pn_body->isKind(PNK_UPVARS) ? pn->pn_body->pn_tree : pn->pn_body; @@ -3029,7 +3029,7 @@ ASTSerializer::functionArgsAndBody(ParseNode *pn, NodeVector &args, Value *body) ParseNode *pnbody; /* Extract the args and body separately. */ - if (pn->isKind(TOK_ARGSBODY)) { + if (pn->isKind(PNK_ARGSBODY)) { pnargs = pn; pnbody = pn->last(); } else { @@ -3042,30 +3042,30 @@ ASTSerializer::functionArgsAndBody(ParseNode *pn, NodeVector &args, Value *body) /* Extract the destructuring assignments. */ if (pnbody->isArity(PN_LIST) && (pnbody->pn_xflags & PNX_DESTRUCT)) { ParseNode *head = pnbody->pn_head; - LOCAL_ASSERT(head && head->isKind(TOK_SEMI)); + LOCAL_ASSERT(head && head->isKind(PNK_SEMI)); pndestruct = head->pn_kid; - LOCAL_ASSERT(pndestruct && pndestruct->isKind(TOK_VAR)); + LOCAL_ASSERT(pndestruct && pndestruct->isKind(PNK_VAR)); } else { pndestruct = NULL; } /* Serialize the arguments and body. */ switch (pnbody->getKind()) { - case TOK_RETURN: /* expression closure, no destructured args */ + case PNK_RETURN: /* expression closure, no destructured args */ return functionArgs(pn, pnargs, NULL, pnbody, args) && expression(pnbody->pn_kid, body); - case TOK_SEQ: /* expression closure with destructured args */ + case PNK_SEQ: /* expression closure with destructured args */ { ParseNode *pnstart = pnbody->pn_head->pn_next; - LOCAL_ASSERT(pnstart && pnstart->isKind(TOK_RETURN)); + LOCAL_ASSERT(pnstart && pnstart->isKind(PNK_RETURN)); return functionArgs(pn, pnargs, pndestruct, pnbody, args) && expression(pnstart->pn_kid, body); } - case TOK_LC: /* statement closure */ + case PNK_LC: /* statement closure */ { ParseNode *pnstart = (pnbody->pn_xflags & PNX_DESTRUCT) ? pnbody->pn_head->pn_next diff --git a/js/src/jsxml.cpp b/js/src/jsxml.cpp index c98735055478..bb69cbef9d22 100644 --- a/js/src/jsxml.cpp +++ b/js/src/jsxml.cpp @@ -1313,7 +1313,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla if (!js_EnterLocalRootScope(cx)) return NULL; switch (pn->getKind()) { - case TOK_XMLELEM: + case PNK_XMLELEM: length = inScopeNSes->length; pn2 = pn->pn_head; xml = ParseNodeToXML(parser, pn2, inScopeNSes, flags); @@ -1330,12 +1330,12 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla while ((pn2 = pn2->pn_next) != NULL) { if (!pn2->pn_next) { /* Don't append the end tag! */ - JS_ASSERT(pn2->isKind(TOK_XMLETAGO)); + JS_ASSERT(pn2->isKind(PNK_XMLETAGO)); break; } if ((flags & XSF_IGNORE_WHITESPACE) && - n > 1 && pn2->isKind(TOK_XMLSPACE)) { + n > 1 && pn2->isKind(PNK_XMLSPACE)) { --n; continue; } @@ -1370,7 +1370,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla XMLARRAY_TRUNCATE(cx, inScopeNSes, length); break; - case TOK_XMLLIST: + case PNK_XMLLIST: xml = js_NewXML(cx, JSXML_CLASS_LIST); if (!xml) goto fail; @@ -1386,7 +1386,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla * condition this on an XML.ignoreWhitespace setting when the list * constructor is XMLList (note XML/XMLList unification hazard). */ - if (pn2->isKind(TOK_XMLSPACE)) { + if (pn2->isKind(PNK_XMLSPACE)) { --n; continue; } @@ -1408,11 +1408,11 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla xml->xml_kids.trim(); break; - case TOK_XMLSTAGO: - case TOK_XMLPTAGC: + case PNK_XMLSTAGO: + case PNK_XMLPTAGC: length = inScopeNSes->length; pn2 = pn->pn_head; - JS_ASSERT(pn2->isKind(TOK_XMLNAME)); + JS_ASSERT(pn2->isKind(PNK_XMLNAME)); if (pn2->isArity(PN_LIST)) goto syntax; @@ -1429,7 +1429,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla size_t length; const jschar *chars; - if (!pn2->isKind(TOK_XMLNAME) || !pn2->isArity(PN_NULLARY)) + if (!pn2->isKind(PNK_XMLNAME) || !pn2->isArity(PN_NULLARY)) goto syntax; /* Enforce "Well-formedness constraint: Unique Att Spec". */ @@ -1449,7 +1449,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla JSAtom *atom = pn2->pn_atom; pn2 = pn2->pn_next; JS_ASSERT(pn2); - if (!pn2->isKind(TOK_XMLATTR)) + if (!pn2->isKind(PNK_XMLATTR)) goto syntax; chars = atom->chars(); @@ -1546,7 +1546,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla pn2 = pn2->pn_next; JS_ASSERT(pn2); - JS_ASSERT(pn2->isKind(TOK_XMLATTR)); + JS_ASSERT(pn2->isKind(PNK_XMLATTR)); attr = js_NewXML(cx, JSXML_CLASS_ATTRIBUTE); if (!attr) @@ -1559,22 +1559,22 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla } /* Point tag closes its own namespace scope. */ - if (pn->isKind(TOK_XMLPTAGC)) + if (pn->isKind(PNK_XMLPTAGC)) XMLARRAY_TRUNCATE(cx, inScopeNSes, length); break; - case TOK_XMLSPACE: - case TOK_XMLTEXT: - case TOK_XMLCDATA: - case TOK_XMLCOMMENT: - case TOK_XMLPI: + case PNK_XMLSPACE: + case PNK_XMLTEXT: + case PNK_XMLCDATA: + case PNK_XMLCOMMENT: + case PNK_XMLPI: str = pn->pn_atom; qn = NULL; - if (pn->isKind(TOK_XMLCOMMENT)) { + if (pn->isKind(PNK_XMLCOMMENT)) { if (flags & XSF_IGNORE_COMMENTS) goto skip_child; xml_class = JSXML_CLASS_COMMENT; - } else if (pn->isKind(TOK_XMLPI)) { + } else if (pn->isKind(PNK_XMLPI)) { if (IS_XML(str)) { Value v = StringValue(str); JSAutoByteString bytes; @@ -1603,7 +1603,7 @@ ParseNodeToXML(Parser *parser, ParseNode *pn, JSXMLArray *inScopeNSes, uintN fla if (!xml) goto fail; xml->name = qn; - if (pn->isKind(TOK_XMLSPACE)) + if (pn->isKind(PNK_XMLSPACE)) xml->xml_flags |= XMLF_WHITESPACE_TEXT; xml->xml_value = str; break;