зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1123906 - Get rid of static create() methods on ParseNode subclasses. Use constructors instead. r=efaust.
--HG-- extra : rebase_source : 91d848876481c3052f6e6acb74cda892d37bbca7
This commit is contained in:
Родитель
a775a5666a
Коммит
068d7b1ffa
|
@ -520,7 +520,10 @@ class FullParseHandler
|
|||
ParseNode *catchName, ParseNode *catchGuard, ParseNode *catchBody);
|
||||
|
||||
inline void setLastFunctionArgumentDefault(ParseNode *funcpn, ParseNode *pn);
|
||||
inline ParseNode *newFunctionDefinition();
|
||||
|
||||
ParseNode *newFunctionDefinition() {
|
||||
return new_<CodeNode>(pos());
|
||||
}
|
||||
void setFunctionBody(ParseNode *pn, ParseNode *kid) {
|
||||
pn->pn_body = kid;
|
||||
}
|
||||
|
@ -532,8 +535,12 @@ class FullParseHandler
|
|||
pn->pn_body->append(argpn);
|
||||
}
|
||||
|
||||
inline ParseNode *newLexicalScope(ObjectBox *blockbox);
|
||||
inline void setLexicalScopeBody(ParseNode *block, ParseNode *body);
|
||||
ParseNode *newLexicalScope(ObjectBox *blockBox) {
|
||||
return new_<LexicalScopeNode>(blockBox, pos());
|
||||
}
|
||||
void setLexicalScopeBody(ParseNode *block, ParseNode *body) {
|
||||
block->pn_expr = body;
|
||||
}
|
||||
|
||||
bool isOperationWithoutParens(ParseNode *pn, ParseNodeKind kind) {
|
||||
return pn->isKind(kind) && !pn->isInParens();
|
||||
|
@ -564,18 +571,15 @@ class FullParseHandler
|
|||
return pn->pn_pos;
|
||||
}
|
||||
|
||||
ParseNode *newList(ParseNodeKind kind, ParseNode *kid = nullptr, JSOp op = JSOP_NOP) {
|
||||
ParseNode *pn = ListNode::create(kind, this);
|
||||
if (!pn)
|
||||
return nullptr;
|
||||
pn->setOp(op);
|
||||
pn->makeEmpty();
|
||||
if (kid) {
|
||||
pn->pn_pos.begin = kid->pn_pos.begin;
|
||||
pn->append(kid);
|
||||
}
|
||||
return pn;
|
||||
ParseNode *newList(ParseNodeKind kind, JSOp op = JSOP_NOP) {
|
||||
return new_<ListNode>(kind, op, pos());
|
||||
}
|
||||
|
||||
/* New list with one initial child node. kid must be non-null. */
|
||||
ParseNode *newList(ParseNodeKind kind, ParseNode *kid, JSOp op = JSOP_NOP) {
|
||||
return new_<ListNode>(kind, op, kid);
|
||||
}
|
||||
|
||||
void addList(ParseNode *pn, ParseNode *kid) {
|
||||
pn->append(kid);
|
||||
}
|
||||
|
@ -717,38 +721,6 @@ FullParseHandler::setLastFunctionArgumentDefault(ParseNode *funcpn, ParseNode *d
|
|||
arg->pn_expr = defaultValue;
|
||||
}
|
||||
|
||||
inline ParseNode *
|
||||
FullParseHandler::newFunctionDefinition()
|
||||
{
|
||||
ParseNode *pn = CodeNode::create(PNK_FUNCTION, this);
|
||||
if (!pn)
|
||||
return nullptr;
|
||||
pn->pn_body = nullptr;
|
||||
pn->pn_funbox = nullptr;
|
||||
pn->pn_cookie.makeFree();
|
||||
pn->pn_dflags = 0;
|
||||
return pn;
|
||||
}
|
||||
|
||||
inline ParseNode *
|
||||
FullParseHandler::newLexicalScope(ObjectBox *blockbox)
|
||||
{
|
||||
ParseNode *pn = LexicalScopeNode::create(PNK_LEXICALSCOPE, this);
|
||||
if (!pn)
|
||||
return nullptr;
|
||||
|
||||
pn->pn_objbox = blockbox;
|
||||
pn->pn_cookie.makeFree();
|
||||
pn->pn_dflags = 0;
|
||||
return pn;
|
||||
}
|
||||
|
||||
inline void
|
||||
FullParseHandler::setLexicalScopeBody(ParseNode *block, ParseNode *kid)
|
||||
{
|
||||
block->pn_expr = kid;
|
||||
}
|
||||
|
||||
inline bool
|
||||
FullParseHandler::finishInitializerAssignment(ParseNode *pn, ParseNode *init, JSOp op)
|
||||
{
|
||||
|
|
|
@ -244,15 +244,6 @@ ParseNodeAllocator::allocNode()
|
|||
return p;
|
||||
}
|
||||
|
||||
/* used only by static create methods of subclasses */
|
||||
|
||||
ParseNode *
|
||||
ParseNode::create(ParseNodeKind kind, ParseNodeArity arity, FullParseHandler *handler)
|
||||
{
|
||||
const Token &tok = handler->currentToken();
|
||||
return handler->new_<ParseNode>(kind, JSOP_NOP, arity, tok.pos);
|
||||
}
|
||||
|
||||
ParseNode *
|
||||
ParseNode::append(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right,
|
||||
FullParseHandler *handler)
|
||||
|
|
|
@ -638,8 +638,6 @@ class ParseNode
|
|||
pn_next = pn_link = nullptr;
|
||||
}
|
||||
|
||||
static ParseNode *create(ParseNodeKind kind, ParseNodeArity arity, FullParseHandler *handler);
|
||||
|
||||
public:
|
||||
/*
|
||||
* Append right to left, forming a list node. |left| must have the given
|
||||
|
@ -922,10 +920,6 @@ struct UnaryNode : public ParseNode
|
|||
pn_kid = kid;
|
||||
}
|
||||
|
||||
static inline UnaryNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (UnaryNode *) ParseNode::create(kind, PN_UNARY, handler);
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
return node.isArity(PN_UNARY);
|
||||
}
|
||||
|
@ -951,10 +945,6 @@ struct BinaryNode : public ParseNode
|
|||
pn_right = right;
|
||||
}
|
||||
|
||||
static inline BinaryNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (BinaryNode *) ParseNode::create(kind, PN_BINARY, handler);
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
return node.isArity(PN_BINARY);
|
||||
}
|
||||
|
@ -975,10 +965,6 @@ struct BinaryObjNode : public ParseNode
|
|||
pn_binary_obj = objbox;
|
||||
}
|
||||
|
||||
static inline BinaryObjNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (BinaryObjNode *) ParseNode::create(kind, PN_BINARY_OBJ, handler);
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
return node.isArity(PN_BINARY_OBJ);
|
||||
}
|
||||
|
@ -1009,10 +995,6 @@ struct TernaryNode : public ParseNode
|
|||
pn_kid3 = kid3;
|
||||
}
|
||||
|
||||
static inline TernaryNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (TernaryNode *) ParseNode::create(kind, PN_TERNARY, handler);
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
return node.isArity(PN_TERNARY);
|
||||
}
|
||||
|
@ -1030,16 +1012,18 @@ struct ListNode : public ParseNode
|
|||
makeEmpty();
|
||||
}
|
||||
|
||||
ListNode(ParseNodeKind kind, JSOp op, const TokenPos &pos)
|
||||
: ParseNode(kind, op, PN_LIST, pos)
|
||||
{
|
||||
makeEmpty();
|
||||
}
|
||||
|
||||
ListNode(ParseNodeKind kind, JSOp op, ParseNode *kid)
|
||||
: ParseNode(kind, op, PN_LIST, kid->pn_pos)
|
||||
{
|
||||
initList(kid);
|
||||
}
|
||||
|
||||
static inline ListNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (ListNode *) ParseNode::create(kind, PN_LIST, handler);
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
return node.isArity(PN_LIST);
|
||||
}
|
||||
|
@ -1051,8 +1035,13 @@ struct ListNode : public ParseNode
|
|||
|
||||
struct CodeNode : public ParseNode
|
||||
{
|
||||
static inline CodeNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (CodeNode *) ParseNode::create(kind, PN_CODE, handler);
|
||||
explicit CodeNode(const TokenPos &pos)
|
||||
: ParseNode(PNK_FUNCTION, JSOP_NOP, PN_CODE, pos)
|
||||
{
|
||||
MOZ_ASSERT(!pn_body);
|
||||
MOZ_ASSERT(!pn_funbox);
|
||||
MOZ_ASSERT(pn_dflags == 0);
|
||||
pn_cookie.makeFree();
|
||||
}
|
||||
|
||||
static bool test(const ParseNode &node) {
|
||||
|
@ -1089,8 +1078,22 @@ struct NameNode : public ParseNode
|
|||
|
||||
struct LexicalScopeNode : public ParseNode
|
||||
{
|
||||
static inline LexicalScopeNode *create(ParseNodeKind kind, FullParseHandler *handler) {
|
||||
return (LexicalScopeNode *) ParseNode::create(kind, PN_NAME, handler);
|
||||
LexicalScopeNode(ObjectBox *blockBox, const TokenPos &pos)
|
||||
: ParseNode(PNK_LEXICALSCOPE, JSOP_NOP, PN_NAME, pos)
|
||||
{
|
||||
MOZ_ASSERT(!pn_expr);
|
||||
MOZ_ASSERT(pn_dflags == 0);
|
||||
MOZ_ASSERT(pn_blockid == 0);
|
||||
pn_objbox = blockBox;
|
||||
pn_cookie.makeFree();
|
||||
}
|
||||
|
||||
LexicalScopeNode(ObjectBox *blockBox, ParseNode *blockNode)
|
||||
: ParseNode(PNK_LEXICALSCOPE, JSOP_NOP, PN_NAME, blockNode->pn_pos)
|
||||
{
|
||||
pn_objbox = blockBox;
|
||||
pn_expr = blockNode;
|
||||
pn_blockid = blockNode->pn_blockid;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -828,11 +828,9 @@ Parser<FullParseHandler>::standaloneFunctionBody(HandleFunction fun, const AutoN
|
|||
if (!fn)
|
||||
return null();
|
||||
|
||||
ParseNode *argsbody = ListNode::create(PNK_ARGSBODY, &handler);
|
||||
ParseNode *argsbody = handler.newList(PNK_ARGSBODY);
|
||||
if (!argsbody)
|
||||
return null();
|
||||
argsbody->setOp(JSOP_NOP);
|
||||
argsbody->makeEmpty();
|
||||
fn->pn_body = argsbody;
|
||||
|
||||
FunctionBox *funbox = newFunctionBox(fn, fun, /* outerpc = */ nullptr, inheritedDirectives,
|
||||
|
@ -2243,21 +2241,18 @@ Parser<FullParseHandler>::finishFunctionDefinition(ParseNode *pn, FunctionBox *f
|
|||
if (!body->isArity(PN_LIST)) {
|
||||
ParseNode *block;
|
||||
|
||||
block = ListNode::create(PNK_SEQ, &handler);
|
||||
block = handler.newList(PNK_SEQ, body);
|
||||
if (!block)
|
||||
return false;
|
||||
block->pn_pos = body->pn_pos;
|
||||
block->initList(body);
|
||||
|
||||
body = block;
|
||||
}
|
||||
|
||||
ParseNode *item = UnaryNode::create(PNK_SEMI, &handler);
|
||||
ParseNode *item = handler.new_<UnaryNode>(PNK_SEMI, JSOP_NOP,
|
||||
TokenPos(body->pn_pos.begin, body->pn_pos.begin),
|
||||
prelude);
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
item->pn_pos.begin = item->pn_pos.end = body->pn_pos.begin;
|
||||
item->pn_kid = prelude;
|
||||
item->pn_next = body->pn_head;
|
||||
body->pn_head = item;
|
||||
if (body->pn_tail == &body->pn_head)
|
||||
|
@ -3825,7 +3820,7 @@ Parser<ParseHandler>::variables(ParseNodeKind kind, bool *psimple,
|
|||
else if (kind == PNK_GLOBALCONST)
|
||||
op = JSOP_DEFCONST;
|
||||
|
||||
Node pn = handler.newList(kind, null(), op);
|
||||
Node pn = handler.newList(kind, op);
|
||||
if (!pn)
|
||||
return null();
|
||||
|
||||
|
@ -4086,14 +4081,9 @@ Parser<FullParseHandler>::lexicalDeclaration(bool isConst)
|
|||
#endif
|
||||
|
||||
/* Create a new lexical scope node for these statements. */
|
||||
ParseNode *pn1 = LexicalScopeNode::create(PNK_LEXICALSCOPE, &handler);
|
||||
ParseNode *pn1 = handler.new_<LexicalScopeNode>(blockbox, pc->blockNode);
|
||||
if (!pn1)
|
||||
return null();
|
||||
|
||||
pn1->pn_pos = pc->blockNode->pn_pos;
|
||||
pn1->pn_objbox = blockbox;
|
||||
pn1->pn_expr = pc->blockNode;
|
||||
pn1->pn_blockid = pc->blockNode->pn_blockid;
|
||||
pc->blockNode = pn1;
|
||||
}
|
||||
|
||||
|
@ -6744,7 +6734,7 @@ Parser<FullParseHandler>::legacyComprehensionTail(ParseNode *bodyExpr, unsigned
|
|||
}
|
||||
|
||||
unsigned adjust;
|
||||
ParseNode *pn, *pn2, *pn3, **pnp;
|
||||
ParseNode *pn, *pn3, **pnp;
|
||||
StmtInfoPC stmtInfo(context);
|
||||
BindData<FullParseHandler> data(context);
|
||||
TokenKind tt;
|
||||
|
@ -6811,11 +6801,11 @@ Parser<FullParseHandler>::legacyComprehensionTail(ParseNode *bodyExpr, unsigned
|
|||
* index to count each block-local let-variable on the left-hand side
|
||||
* of the in/of.
|
||||
*/
|
||||
pn2 = BinaryNode::create(PNK_FOR, &handler);
|
||||
ParseNode *pn2 = handler.new_<BinaryNode>(PNK_FOR, JSOP_ITER, pos(),
|
||||
nullptr, nullptr);
|
||||
if (!pn2)
|
||||
return null();
|
||||
|
||||
pn2->setOp(JSOP_ITER);
|
||||
pn2->pn_iflags = JSITER_ENUMERATE;
|
||||
if (allowsForEachIn()) {
|
||||
bool matched;
|
||||
|
@ -6935,13 +6925,9 @@ Parser<FullParseHandler>::legacyComprehensionTail(ParseNode *bodyExpr, unsigned
|
|||
* These are lets to tell the bytecode emitter to emit initialization
|
||||
* code for the temporal dead zone.
|
||||
*/
|
||||
ParseNode *lets = ListNode::create(PNK_LET, &handler);
|
||||
ParseNode *lets = handler.newList(PNK_LET, pn3);
|
||||
if (!lets)
|
||||
return null();
|
||||
lets->setOp(JSOP_NOP);
|
||||
lets->pn_pos = pn3->pn_pos;
|
||||
lets->makeEmpty();
|
||||
lets->append(pn3);
|
||||
lets->pn_xflags |= PNX_POPVAR;
|
||||
|
||||
/* Definitions can't be passed directly to EmitAssignment as lhs. */
|
||||
|
@ -6966,14 +6952,15 @@ Parser<FullParseHandler>::legacyComprehensionTail(ParseNode *bodyExpr, unsigned
|
|||
if (!tokenStream.matchToken(&matched, TOK_IF))
|
||||
return null();
|
||||
if (matched) {
|
||||
pn2 = TernaryNode::create(PNK_IF, &handler);
|
||||
if (!pn2)
|
||||
ParseNode *cond = condition();
|
||||
if (!cond)
|
||||
return null();
|
||||
pn2->pn_kid1 = condition();
|
||||
if (!pn2->pn_kid1)
|
||||
ParseNode *ifNode = handler.new_<TernaryNode>(PNK_IF, JSOP_NOP, cond, nullptr, nullptr,
|
||||
cond->pn_pos);
|
||||
if (!ifNode)
|
||||
return null();
|
||||
*pnp = pn2;
|
||||
pnp = &pn2->pn_kid2;
|
||||
*pnp = ifNode;
|
||||
pnp = &ifNode->pn_kid2;
|
||||
}
|
||||
|
||||
ParseNode *bodyStmt;
|
||||
|
@ -7183,22 +7170,14 @@ Parser<FullParseHandler>::legacyGeneratorExpr(ParseNode *expr)
|
|||
{
|
||||
MOZ_ASSERT(tokenStream.isCurrentTokenType(TOK_FOR));
|
||||
|
||||
/* Make a new node for the desugared generator function. */
|
||||
// Make a new node for the desugared generator function.
|
||||
ParseNode *genfn = generatorComprehensionLambda(LegacyGenerator, expr->pn_pos.begin, expr);
|
||||
if (!genfn)
|
||||
return null();
|
||||
|
||||
/*
|
||||
* Our result is a call expression that invokes the anonymous generator
|
||||
* function object.
|
||||
*/
|
||||
ParseNode *result = ListNode::create(PNK_GENEXP, &handler);
|
||||
if (!result)
|
||||
return null();
|
||||
result->setOp(JSOP_CALL);
|
||||
result->pn_pos.begin = genfn->pn_pos.begin;
|
||||
result->initList(genfn);
|
||||
return result;
|
||||
// Our result is a call expression that invokes the anonymous generator
|
||||
// function object.
|
||||
return handler.newList(PNK_GENEXP, genfn, JSOP_CALL);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
@ -7256,7 +7235,7 @@ Parser<ParseHandler>::comprehensionFor(GeneratorKind comprehensionKind)
|
|||
Node lhs = newName(name);
|
||||
if (!lhs)
|
||||
return null();
|
||||
Node decls = handler.newList(PNK_LET, lhs, JSOP_NOP);
|
||||
Node decls = handler.newList(PNK_LET, lhs);
|
||||
if (!decls)
|
||||
return null();
|
||||
data.pn = lhs;
|
||||
|
@ -7538,7 +7517,7 @@ Parser<ParseHandler>::memberExpr(TokenKind tt, bool allowCallSyntax, InvokedPred
|
|||
|
||||
/* Check for new expression first. */
|
||||
if (tt == TOK_NEW) {
|
||||
lhs = handler.newList(PNK_NEW, null(), JSOP_NEW);
|
||||
lhs = handler.newList(PNK_NEW, JSOP_NEW);
|
||||
if (!lhs)
|
||||
return null();
|
||||
|
||||
|
@ -7600,11 +7579,7 @@ Parser<ParseHandler>::memberExpr(TokenKind tt, bool allowCallSyntax, InvokedPred
|
|||
tt == TOK_NO_SUBS_TEMPLATE)
|
||||
{
|
||||
JSOp op = JSOP_CALL;
|
||||
if (tt == TOK_LP)
|
||||
nextMember = handler.newList(PNK_CALL, null(), JSOP_CALL);
|
||||
else
|
||||
nextMember = handler.newList(PNK_TAGGED_TEMPLATE, null(), JSOP_CALL);
|
||||
|
||||
nextMember = handler.newList(tt == TOK_LP ? PNK_CALL : PNK_TAGGED_TEMPLATE, JSOP_CALL);
|
||||
if (!nextMember)
|
||||
return null();
|
||||
|
||||
|
|
|
@ -216,7 +216,10 @@ class SyntaxParseHandler
|
|||
return tokenStream.currentToken().pos;
|
||||
}
|
||||
|
||||
Node newList(ParseNodeKind kind, Node kid = NodeGeneric, JSOp op = JSOP_NOP) {
|
||||
Node newList(ParseNodeKind kind, JSOp op = JSOP_NOP) {
|
||||
return NodeGeneric;
|
||||
}
|
||||
Node newList(ParseNodeKind kind, Node kid, JSOp op = JSOP_NOP) {
|
||||
return NodeGeneric;
|
||||
}
|
||||
void addList(Node pn, Node kid) {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче