Bug 883434 - Give TokenPos a real constructor. r=ejpbruel.

--HG--
extra : rebase_source : 4820e91d38810d03dff3c0bddaea104f53e7c12c
This commit is contained in:
Jason Orendorff 2013-06-21 08:18:01 -05:00
Родитель c94220111d
Коммит e64c4e8fd7
5 изменённых файлов: 27 добавлений и 36 удалений

Просмотреть файл

@ -163,7 +163,7 @@ class FullParseHandler
}
ParseNode *newUnary(ParseNodeKind kind, JSOp op, uint32_t begin, ParseNode *kid) {
TokenPos pos = {begin, kid ? kid->pn_pos.end : begin + 1};
TokenPos pos(begin, kid ? kid->pn_pos.end : begin + 1);
return new_<UnaryNode>(kind, op, pos, kid);
}
@ -176,7 +176,7 @@ class FullParseHandler
}
ParseNode *newBinary(ParseNodeKind kind, ParseNode *left, ParseNode *right,
JSOp op = JSOP_NOP) {
TokenPos pos = TokenPos::make(left->pn_pos.begin, right->pn_pos.end);
TokenPos pos(left->pn_pos.begin, right->pn_pos.end);
return new_<BinaryNode>(kind, op, pos, left, right);
}
ParseNode *newBinaryOrAppend(ParseNodeKind kind, ParseNode *left, ParseNode *right,
@ -225,7 +225,7 @@ class FullParseHandler
ParseNode *newExprStatement(ParseNode *expr, uint32_t end) {
JS_ASSERT(expr->pn_pos.end <= end);
return new_<UnaryNode>(PNK_SEMI, JSOP_NOP, TokenPos::make(expr->pn_pos.begin, end), expr);
return new_<UnaryNode>(PNK_SEMI, JSOP_NOP, TokenPos(expr->pn_pos.begin, end), expr);
}
ParseNode *newIfStatement(uint32_t begin, ParseNode *cond, ParseNode *thenBranch,
@ -243,7 +243,7 @@ class FullParseHandler
}
ParseNode *newWhileStatement(uint32_t begin, ParseNode *cond, ParseNode *body) {
TokenPos pos = TokenPos::make(begin, body->pn_pos.end);
TokenPos pos(begin, body->pn_pos.end);
return new_<BinaryNode>(PNK_WHILE, JSOP_NOP, pos, cond, body);
}
@ -252,7 +252,7 @@ class FullParseHandler
{
/* A FOR node is binary, left is loop control and right is the body. */
JSOp op = forHead->isKind(PNK_FORIN) ? JSOP_ITER : JSOP_NOP;
BinaryNode *pn = new_<BinaryNode>(PNK_FOR, op, TokenPos::make(begin, body->pn_pos.end),
BinaryNode *pn = new_<BinaryNode>(PNK_FOR, op, TokenPos(begin, body->pn_pos.end),
forHead, body);
if (!pn)
return null();
@ -268,12 +268,12 @@ class FullParseHandler
}
ParseNode *newSwitchStatement(uint32_t begin, ParseNode *discriminant, ParseNode *caseList) {
TokenPos pos = TokenPos::make(begin, caseList->pn_pos.end);
TokenPos pos(begin, caseList->pn_pos.end);
return new_<BinaryNode>(PNK_SWITCH, JSOP_NOP, pos, discriminant, caseList);
}
ParseNode *newCaseOrDefault(uint32_t begin, ParseNode *expr, ParseNode *body) {
TokenPos pos = TokenPos::make(begin, body->pn_pos.end);
TokenPos pos(begin, body->pn_pos.end);
return new_<BinaryNode>(expr ? PNK_CASE : PNK_DEFAULT, JSOP_NOP, pos, expr, body);
}
@ -291,8 +291,7 @@ class FullParseHandler
}
ParseNode *newWithStatement(uint32_t begin, ParseNode *expr, ParseNode *body) {
return new_<BinaryNode>(PNK_WITH, JSOP_NOP, TokenPos::make(begin, body->pn_pos.end),
expr, body);
return new_<BinaryNode>(PNK_WITH, JSOP_NOP, TokenPos(begin, body->pn_pos.end), expr, body);
}
ParseNode *newLabeledStatement(PropertyName *label, ParseNode *stmt, uint32_t begin) {
@ -306,8 +305,7 @@ class FullParseHandler
ParseNode *newTryStatement(uint32_t begin, ParseNode *body, ParseNode *catchList,
ParseNode *finallyBlock) {
TokenPos pos = TokenPos::make(begin,
(finallyBlock ? finallyBlock : catchList)->pn_pos.end);
TokenPos pos(begin, (finallyBlock ? finallyBlock : catchList)->pn_pos.end);
return new_<TernaryNode>(PNK_TRY, JSOP_NOP, body, catchList, finallyBlock, pos);
}

Просмотреть файл

@ -432,11 +432,9 @@ struct ParseNode
public:
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)
pn_pos(0, 0), pn_offset(0), pn_next(NULL), pn_link(NULL)
{
JS_ASSERT(kind < PNK_LIMIT);
pn_pos.begin = 0;
pn_pos.end = 0;
memset(&pn_u, 0, sizeof pn_u);
}
@ -895,8 +893,8 @@ struct TernaryNode : public ParseNode
{
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))
TokenPos((kid1 ? kid1 : kid2 ? kid2 : kid3)->pn_pos.begin,
(kid3 ? kid3 : kid2 ? kid2 : kid1)->pn_pos.end))
{
pn_kid1 = kid1;
pn_kid2 = kid2;
@ -1006,7 +1004,7 @@ class LabeledStatement : public ParseNode
{
public:
LabeledStatement(PropertyName *label, ParseNode *stmt, uint32_t begin)
: ParseNode(PNK_LABEL, JSOP_NOP, PN_NAME, TokenPos::make(begin, stmt->pn_pos.end))
: ParseNode(PNK_LABEL, JSOP_NOP, PN_NAME, TokenPos(begin, stmt->pn_pos.end))
{
pn_atom = label;
pn_expr = stmt;
@ -1095,7 +1093,7 @@ class ConditionalExpression : public ParseNode
public:
ConditionalExpression(ParseNode *condition, ParseNode *thenExpr, ParseNode *elseExpr)
: ParseNode(PNK_CONDITIONAL, JSOP_NOP, PN_TERNARY,
TokenPos::make(condition->pn_pos.begin, elseExpr->pn_pos.end))
TokenPos(condition->pn_pos.begin, elseExpr->pn_pos.end))
{
JS_ASSERT(condition);
JS_ASSERT(thenExpr);
@ -1168,7 +1166,7 @@ class PropertyAccess : public ParseNode
{
public:
PropertyAccess(ParseNode *lhs, PropertyName *name, uint32_t begin, uint32_t end)
: ParseNode(PNK_DOT, JSOP_GETPROP, PN_NAME, TokenPos::make(begin, end))
: ParseNode(PNK_DOT, JSOP_GETPROP, PN_NAME, TokenPos(begin, end))
{
JS_ASSERT(lhs != NULL);
JS_ASSERT(name != NULL);
@ -1195,7 +1193,7 @@ class PropertyByValue : public ParseNode
{
public:
PropertyByValue(ParseNode *lhs, ParseNode *propExpr, uint32_t begin, uint32_t end)
: ParseNode(PNK_ELEM, JSOP_GETELEM, PN_BINARY, TokenPos::make(begin, end))
: ParseNode(PNK_ELEM, JSOP_GETELEM, PN_BINARY, TokenPos(begin, end))
{
pn_u.binary.left = lhs;
pn_u.binary.right = propExpr;

Просмотреть файл

@ -3667,7 +3667,7 @@ Parser<ParseHandler>::doWhileStatement()
(void) tokenStream.matchToken(TOK_SEMI);
}
return handler.newDoWhileStatement(body, cond, TokenPos::make(begin, pos().end));
return handler.newDoWhileStatement(body, cond, TokenPos(begin, pos().end));
}
template <typename ParseHandler>
@ -4045,7 +4045,7 @@ Parser<FullParseHandler>::forStatement()
MUST_MATCH_TOKEN(TOK_RP, JSMSG_PAREN_AFTER_FOR_CTRL);
TokenPos headPos = TokenPos::make(begin, pos().end);
TokenPos headPos(begin, pos().end);
ParseNode *forHead = handler.newForHead(isForInOrOf, pn1, pn2, pn3, headPos);
if (!forHead)
return null();
@ -4341,7 +4341,7 @@ Parser<ParseHandler>::continueStatement()
if (!MatchOrInsertSemicolon(context, &tokenStream))
return null();
return handler.newContinueStatement(label, TokenPos::make(begin, pos().end));
return handler.newContinueStatement(label, TokenPos(begin, pos().end));
}
template <typename ParseHandler>
@ -4378,7 +4378,7 @@ Parser<ParseHandler>::breakStatement()
if (!MatchOrInsertSemicolon(context, &tokenStream))
return null();
return handler.newBreakStatement(label, TokenPos::make(begin, pos().end));
return handler.newBreakStatement(label, TokenPos(begin, pos().end));
}
template <typename ParseHandler>
@ -4446,7 +4446,7 @@ Parser<ParseHandler>::returnStatementOrYieldExpression()
Node pn = isYield
? handler.newUnary(PNK_YIELD, JSOP_YIELD, begin, exprNode)
: handler.newReturnStatement(exprNode, TokenPos::make(begin, pos().end));
: handler.newReturnStatement(exprNode, TokenPos(begin, pos().end));
if (!pn)
return null();
@ -4515,8 +4515,7 @@ Parser<FullParseHandler>::withStatement()
for (AtomDefnRange r = pc->lexdeps->all(); !r.empty(); r.popFront()) {
DefinitionNode defn = r.front().value().get<FullParseHandler>();
DefinitionNode lexdep = handler.resolve(defn);
handler.deoptimizeUsesWithin(lexdep,
TokenPos::make(begin, pos().begin));
handler.deoptimizeUsesWithin(lexdep, TokenPos(begin, pos().begin));
}
return handler.newWithStatement(begin, objectExpr, innerBlock);
@ -4582,7 +4581,7 @@ Parser<ParseHandler>::throwStatement()
if (!MatchOrInsertSemicolon(context, &tokenStream))
return null();
return handler.newThrowStatement(throwExpr, TokenPos::make(begin, pos().end));
return handler.newThrowStatement(throwExpr, TokenPos(begin, pos().end));
}
template <typename ParseHandler>

Просмотреть файл

@ -198,19 +198,15 @@ struct TokenPos {
uint32_t begin; /* offset of the token's first char */
uint32_t end; /* offset of 1 past the token's last char */
static TokenPos make(uint32_t begin, uint32_t end) {
JS_ASSERT(begin <= end);
TokenPos pos = {begin, end};
return pos;
}
TokenPos() {}
TokenPos(uint32_t begin, uint32_t end) : begin(begin), end(end) {}
/* Return a TokenPos that covers left, right, and anything in between. */
static TokenPos box(const TokenPos &left, const TokenPos &right) {
JS_ASSERT(left.begin <= left.end);
JS_ASSERT(left.end <= right.begin);
JS_ASSERT(right.begin <= right.end);
TokenPos pos = {left.begin, right.end};
return pos;
return TokenPos(left.begin, right.end);
}
bool operator==(const TokenPos& bpos) const {

Просмотреть файл

@ -2201,7 +2201,7 @@ ASTSerializer::leftAssociate(ParseNode *pn, MutableHandleValue dst)
if (!expression(next, &right))
return false;
TokenPos subpos = {pn->pn_pos.begin, next->pn_pos.end};
TokenPos subpos(pn->pn_pos.begin, next->pn_pos.end);
if (logop) {
if (!builder.logicalExpression(lor, left, right, &subpos, &left))