Bug 784608 (part 6) - Rename some parsing and emitting variables. r=luke.

--HG--
extra : rebase_source : c21e322bb37172ca45ddac032a851465545fd2b8
This commit is contained in:
Nicholas Nethercote 2012-08-22 23:16:05 -07:00
parent fdc6f399fd
commit 230074bf69
5 changed files with 63 additions and 62 deletions

View File

@ -121,7 +121,7 @@ BytecodeEmitter::BytecodeEmitter(BytecodeEmitter *parent, Parser *parser, Shared
constList(sc->context),
typesetCount(0),
hasSingletons(false),
inForInit(false),
emittingForInit(false),
hasGlobalScope(hasGlobalScope),
selfHostingMode(selfHostingMode)
{
@ -1302,7 +1302,7 @@ BindNameToSlot(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
* Don't generate upvars on the left side of a for loop. See
* bug 470758.
*/
if (bce->inForInit)
if (bce->emittingForInit)
return true;
/*
@ -1819,11 +1819,11 @@ EmitXMLName(JSContext *cx, ParseNode *pn, JSOp op, BytecodeEmitter *bce)
JS_ASSERT(op == JSOP_XMLNAME || op == JSOP_CALLXMLNAME);
ParseNode *pn2 = pn->pn_kid;
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
if (!EmitTree(cx, bce, pn2))
return false;
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
if (NewSrcNote2(cx, bce, SRC_PCBASE, bce->offset() - pn2->pn_offset) < 0)
return false;
@ -3409,11 +3409,11 @@ EmitVariables(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, VarEmitOption
return false;
}
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
if (!EmitTree(cx, bce, pn3))
return false;
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
} else if (letNotes) {
/* JSOP_ENTERLETx expects at least 1 slot to have been pushed. */
if (Emit1(cx, bce, JSOP_UNDEFINED) < 0)
@ -4563,10 +4563,10 @@ EmitForIn(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
if (pn1) {
ParseNode *decl = letDecl ? pn1->pn_expr : pn1;
JS_ASSERT(decl->isKind(PNK_VAR) || decl->isKind(PNK_LET));
bce->inForInit = true;
bce->emittingForInit = true;
if (!EmitVariables(cx, bce, decl, DefineVars))
return false;
bce->inForInit = false;
bce->emittingForInit = false;
}
/* Compile the object expression to the right of 'in'. */
@ -4708,7 +4708,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
/* No initializer: emit an annotated nop for the decompiler. */
op = JSOP_NOP;
} else {
bce->inForInit = true;
bce->emittingForInit = true;
#if JS_HAS_DESTRUCTURING
if (pn3->isKind(PNK_ASSIGN)) {
JS_ASSERT(pn3->isOp(JSOP_NOP));
@ -4733,7 +4733,7 @@ EmitNormalFor(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
op = JSOP_NOP;
}
}
bce->inForInit = false;
bce->emittingForInit = false;
}
/*
@ -5400,13 +5400,13 @@ EmitCallOrNew(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
ParseNode *receiver = pn2->pn_next;
if (!EmitTree(cx, bce, receiver))
return false;
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
for (ParseNode *argpn = receiver->pn_next; argpn != funNode; argpn = argpn->pn_next) {
if (!EmitTree(cx, bce, argpn))
return false;
}
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
argc -= 2;
emitArgs = false;
break;
@ -5446,13 +5446,13 @@ EmitCallOrNew(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn, ptrdiff_t top)
* JSOP_NEW bytecode with a two-byte immediate telling how many args
* were pushed on the operand stack.
*/
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
for (ParseNode *pn3 = pn2->pn_next; pn3; pn3 = pn3->pn_next) {
if (!EmitTree(cx, bce, pn3))
return false;
}
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
}
if (NewSrcNote2(cx, bce, SRC_PCBASE, bce->offset() - top) < 0)
return false;
@ -5967,12 +5967,12 @@ EmitUnary(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
if (op == JSOP_TYPEOF && !pn2->isKind(PNK_NAME))
op = JSOP_TYPEOFEXPR;
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
if (!EmitTree(cx, bce, pn2))
return false;
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
return Emit1(cx, bce, op) >= 0;
}
@ -6366,10 +6366,10 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
/*
* Binary :: has a right operand that brackets arbitrary code,
* possibly including a let (a = b) ... expression. We must clear
* inForInit to avoid mis-compiling such beasts.
* emittingForInit to avoid mis-compiling such beasts.
*/
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
#endif
/* Binary operators that evaluate both operands unconditionally. */
@ -6378,7 +6378,7 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
if (!EmitTree(cx, bce, pn->pn_right))
return false;
#if JS_HAS_XML_SUPPORT
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
#endif
if (Emit1(cx, bce, pn->getOp()) < 0)
return false;
@ -6393,11 +6393,11 @@ frontend::EmitTree(JSContext *cx, BytecodeEmitter *bce, ParseNode *pn)
} else {
JSOp op = pn->getOp();
JS_ASSERT(op == JSOP_BINDXMLNAME || op == JSOP_SETXMLNAME);
bool oldInForInit = bce->inForInit;
bce->inForInit = false;
bool oldEmittingForInit = bce->emittingForInit;
bce->emittingForInit = false;
if (!EmitTree(cx, bce, pn->pn_kid))
return false;
bce->inForInit = oldInForInit;
bce->emittingForInit = oldEmittingForInit;
if (Emit1(cx, bce, op) < 0)
return false;
}

View File

@ -112,7 +112,7 @@ struct BytecodeEmitter
bool hasSingletons:1; /* script contains singleton initializer JSOP_OBJECT */
bool inForInit:1; /* emitting init expr of for; exclude 'in' */
bool emittingForInit:1; /* true while emitting init expr of for; exclude 'in' */
const bool hasGlobalScope:1; /* frontend::CompileScript's scope chain is the
global object */

View File

@ -48,9 +48,9 @@ ParseContext::ParseContext(Parser *prs, SharedContext *sc, unsigned staticLevel,
parent(prs->pc),
innermostWith(NULL),
funcStmts(NULL),
hasReturnExpr(false),
hasReturnVoid(false),
inForInit(false),
funHasReturnExpr(false),
funHasReturnVoid(false),
parsingForInit(false),
inDeclDestructuring(false)
{
prs->pc = this;

View File

@ -700,7 +700,7 @@ Parser::functionBody(FunctionBodyType type)
PushStatementPC(pc, &stmtInfo, STMT_BLOCK);
stmtInfo.isFunctionBodyBlock = true;
JS_ASSERT(!pc->hasReturnExpr && !pc->hasReturnVoid);
JS_ASSERT(!pc->funHasReturnExpr && !pc->funHasReturnVoid);
ParseNode *pn;
if (type == StatementListBody) {
@ -739,7 +739,7 @@ Parser::functionBody(FunctionBodyType type)
FinishPopStatement(pc);
/* Check for falling off the end of a function that returns a value. */
if (context->hasStrictOption() && pc->hasReturnExpr &&
if (context->hasStrictOption() && pc->funHasReturnExpr &&
!CheckFinalReturn(context, this, pn))
{
pn = NULL;
@ -2559,24 +2559,24 @@ Parser::returnOrYield(bool useAssignExpr)
#if JS_HAS_GENERATORS
if (tt == TOK_RETURN)
#endif
pc->hasReturnExpr = true;
pc->funHasReturnExpr = true;
pn->pn_pos.end = pn2->pn_pos.end;
pn->pn_kid = pn2;
} else {
#if JS_HAS_GENERATORS
if (tt == TOK_RETURN)
#endif
pc->hasReturnVoid = true;
pc->funHasReturnVoid = true;
}
if (pc->hasReturnExpr && pc->sc->funIsGenerator()) {
if (pc->funHasReturnExpr && pc->sc->funIsGenerator()) {
/* As in Python (see PEP-255), disallow return v; in generators. */
ReportBadReturn(context, this, pn, &Parser::reportError, JSMSG_BAD_GENERATOR_RETURN,
JSMSG_BAD_ANON_GENERATOR_RETURN);
return NULL;
}
if (context->hasStrictOption() && pc->hasReturnExpr && pc->hasReturnVoid &&
if (context->hasStrictOption() && pc->funHasReturnExpr && pc->funHasReturnVoid &&
!ReportBadReturn(context, this, pn, &Parser::reportStrictWarning,
JSMSG_NO_RETURN_VALUE, JSMSG_ANON_NO_RETURN_VALUE))
{
@ -2964,7 +2964,7 @@ Parser::forStatement()
/*
* Set pn1 to a var list or an initializing expression.
*
* Set the inForInit flag during parsing of the first clause
* Set the parsingForInit flag during parsing of the first clause
* of the for statement. This flag will be used by the RelExpr
* production; if it is set, then the 'in' keyword will not be
* recognized as an operator, leaving it available to be parsed as
@ -2974,7 +2974,7 @@ Parser::forStatement()
* expressions involving an 'in' operator are illegal in the init
* clause of an ordinary for loop.
*/
pc->inForInit = true;
pc->parsingForInit = true;
if (tt == TOK_VAR || tt == TOK_CONST) {
forDecl = true;
tokenStream.consumeKnownToken(tt);
@ -2997,7 +2997,7 @@ Parser::forStatement()
else {
pn1 = expr();
}
pc->inForInit = false;
pc->parsingForInit = false;
if (!pn1)
return NULL;
}
@ -3015,7 +3015,7 @@ Parser::forStatement()
* We can be sure that it's a for/in loop if there's still an 'in'
* keyword here, even if JavaScript recognizes 'in' as an operator,
* as we've excluded 'in' from being parsed in RelExpr by setting
* pc->inForInit.
* pc->parsingForInit.
*/
ParseNode *forHead; /* initialized by both branches. */
StmtInfoPC letStmt(context); /* used if blockObj != NULL. */
@ -4075,7 +4075,7 @@ Parser::variables(ParseNodeKind kind, StaticBlockObject *blockObj, VarContext va
if (!CheckDestructuring(context, &data, pn2, this))
return NULL;
bool ignored;
if (pc->inForInit && matchInOrOf(&ignored)) {
if (pc->parsingForInit && matchInOrOf(&ignored)) {
tokenStream.ungetToken();
pn->append(pn2);
continue;
@ -4281,8 +4281,8 @@ BEGIN_EXPR_PARSER(relExpr1)
* Uses of the in operator in shiftExprs are always unambiguous,
* so unset the flag that prohibits recognizing it.
*/
bool oldInForInit = pc->inForInit;
pc->inForInit = false;
bool oldParsingForInit = pc->parsingForInit;
pc->parsingForInit = false;
ParseNode *pn = shiftExpr1i();
while (pn &&
@ -4291,14 +4291,14 @@ BEGIN_EXPR_PARSER(relExpr1)
* Recognize the 'in' token as an operator only if we're not
* currently in the init expr of a for loop.
*/
(oldInForInit == 0 && tokenStream.isCurrentTokenType(TOK_IN)) ||
(oldParsingForInit == 0 && tokenStream.isCurrentTokenType(TOK_IN)) ||
tokenStream.isCurrentTokenType(TOK_INSTANCEOF))) {
ParseNodeKind kind = RelationalTokenToParseNodeKind(tokenStream.currentToken());
JSOp op = tokenStream.currentToken().t_op;
pn = ParseNode::newBinaryOrAppend(kind, op, pn, shiftExpr1n(), this);
}
/* Restore previous state of inForInit flag. */
pc->inForInit |= oldInForInit;
/* Restore previous state of parsingForInit flag. */
pc->parsingForInit |= oldParsingForInit;
return pn;
}
@ -4392,10 +4392,10 @@ Parser::condExpr1()
* where it's unambiguous, even if we might be parsing the init of a
* for statement.
*/
bool oldInForInit = pc->inForInit;
pc->inForInit = false;
bool oldParsingForInit = pc->parsingForInit;
pc->parsingForInit = false;
ParseNode *thenExpr = assignExpr();
pc->inForInit = oldInForInit;
pc->parsingForInit = oldParsingForInit;
if (!thenExpr)
return NULL;
@ -4810,7 +4810,7 @@ GenexpGuard::maybeNoteGenerator(ParseNode *pn)
parser->reportError(NULL, JSMSG_BAD_RETURN_OR_YIELD, js_yield_str);
return false;
}
if (pc->hasReturnExpr) {
if (pc->funHasReturnExpr) {
/* At the time we saw the yield, we might not have set funIsGenerator yet. */
ReportBadReturn(pc->sc->context, parser, pn, &Parser::reportError,
JSMSG_BAD_GENERATOR_RETURN, JSMSG_BAD_ANON_GENERATOR_RETURN);
@ -5696,10 +5696,10 @@ Parser::bracketedExpr()
* where it's unambiguous, even if we might be parsing the init of a
* for statement.
*/
bool oldInForInit = pc->inForInit;
pc->inForInit = false;
bool oldParsingForInit = pc->parsingForInit;
pc->parsingForInit = false;
ParseNode *pn = expr();
pc->inForInit = oldInForInit;
pc->parsingForInit = oldParsingForInit;
return pn;
}

View File

@ -180,14 +180,15 @@ struct ParseContext /* tree context for semantic checks */
that will alias any top-level bindings with
the same name. */
/*
* Flags that are set for a short time during parsing to indicate context
* or the presence of a code feature.
*/
bool hasReturnExpr:1; /* function has 'return <expr>;' */
bool hasReturnVoid:1; /* function has 'return;' */
// The following flags are set when a particular code feature is detected
// in a function.
bool funHasReturnExpr:1; /* function has 'return <expr>;' */
bool funHasReturnVoid:1; /* function has 'return;' */
bool inForInit:1; /* parsing init expr of for; exclude 'in' */
// The following flags are set when parsing enters a particular region of
// source code, and cleared when that region is exited.
bool parsingForInit:1; /* true while parsing init expr of for;
exclude 'in' */
// Set when parsing a declaration-like destructuring pattern. This flag
// causes PrimaryExpr to create PN_NAME parse nodes for variable references