mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 630213 - ASTSerializer::leftAssociate right-associates. r=dherman.
--HG-- extra : rebase_source : 18bbf8f963f4c76b1fe6d4e7acc9aa6b33381b73
This commit is contained in:
parent
45e8859924
commit
84d99790b9
@ -2320,53 +2320,34 @@ ASTSerializer::leftAssociate(JSParseNode *pn, Value *dst)
|
||||
const size_t len = pn->pn_count;
|
||||
JS_ASSERT(len >= 1);
|
||||
|
||||
if (len == 1)
|
||||
return expression(pn->pn_head, dst);
|
||||
|
||||
JS_ASSERT(len >= 2);
|
||||
|
||||
Vector<JSParseNode *, 8> list(cx);
|
||||
if (!list.reserve(len))
|
||||
return false;
|
||||
|
||||
for (JSParseNode *next = pn->pn_head; next; next = next->pn_next) {
|
||||
JS_ALWAYS_TRUE(list.append(next)); /* space check above */
|
||||
}
|
||||
|
||||
TokenKind tk = PN_TYPE(pn);
|
||||
|
||||
bool lor = tk == TOK_OR;
|
||||
bool logop = lor || (tk == TOK_AND);
|
||||
|
||||
Value right;
|
||||
|
||||
if (!expression(list[len - 1], &right))
|
||||
return false;
|
||||
|
||||
size_t i = len - 2;
|
||||
|
||||
do {
|
||||
JSParseNode *next = list[i];
|
||||
|
||||
JSParseNode *head = pn->pn_head;
|
||||
Value left;
|
||||
if (!expression(next, &left))
|
||||
if (!expression(head, &left))
|
||||
return false;
|
||||
for (JSParseNode *next = head->pn_next; next; next = next->pn_next) {
|
||||
Value right;
|
||||
if (!expression(next, &right))
|
||||
return false;
|
||||
|
||||
TokenPos subpos = { next->pn_pos.begin, pn->pn_pos.end };
|
||||
TokenPos subpos = { pn->pn_pos.begin, next->pn_pos.end };
|
||||
|
||||
if (logop) {
|
||||
if (!builder.logicalExpression(lor, left, right, &subpos, &right))
|
||||
if (!builder.logicalExpression(lor, left, right, &subpos, &left))
|
||||
return false;
|
||||
} else {
|
||||
BinaryOperator op = binop(PN_TYPE(pn), PN_OP(pn));
|
||||
LOCAL_ASSERT(op > BINOP_ERR && op < BINOP_LIMIT);
|
||||
|
||||
if (!builder.binaryExpression(op, left, right, &subpos, &right))
|
||||
if (!builder.binaryExpression(op, left, right, &subpos, &left))
|
||||
return false;
|
||||
}
|
||||
} while (i-- != 0);
|
||||
}
|
||||
|
||||
*dst = right;
|
||||
*dst = left;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -251,8 +251,9 @@ assertExpr("(x << y)", binExpr("<<", ident("x"), ident("y")));
|
||||
assertExpr("(x >> y)", binExpr(">>", ident("x"), ident("y")));
|
||||
assertExpr("(x >>> y)", binExpr(">>>", ident("x"), ident("y")));
|
||||
assertExpr("(x + y)", binExpr("+", ident("x"), ident("y")));
|
||||
assertExpr("(w + x + y + z)", binExpr("+", ident("w"), binExpr("+", ident("x", binExpr("+", ident("y"), ident("z"))))))
|
||||
assertExpr("(w + x + y + z)", binExpr("+", binExpr("+", binExpr("+", ident("w"), ident("x")), ident("y")), ident("z")));
|
||||
assertExpr("(x - y)", binExpr("-", ident("x"), ident("y")));
|
||||
assertExpr("(w - x - y - z)", binExpr("-", binExpr("-", binExpr("-", ident("w"), ident("x")), ident("y")), ident("z")));
|
||||
assertExpr("(x * y)", binExpr("*", ident("x"), ident("y")));
|
||||
assertExpr("(x / y)", binExpr("/", ident("x"), ident("y")));
|
||||
assertExpr("(x % y)", binExpr("%", ident("x"), ident("y")));
|
||||
@ -275,7 +276,7 @@ assertExpr("(x ^= y)", aExpr("^=", ident("x"), ident("y")));
|
||||
assertExpr("(x &= y)", aExpr("&=", ident("x"), ident("y")));
|
||||
assertExpr("(x || y)", logExpr("||", ident("x"), ident("y")));
|
||||
assertExpr("(x && y)", logExpr("&&", ident("x"), ident("y")));
|
||||
assertExpr("(w || x || y || z)", logExpr("||", ident("w"), logExpr("||", ident("x", logExpr("||", ident("y"), ident("z"))))))
|
||||
assertExpr("(w || x || y || z)", logExpr("||", logExpr("||", logExpr("||", ident("w"), ident("x")), ident("y")), ident("z")))
|
||||
assertExpr("(x ? y : z)", condExpr(ident("x"), ident("y"), ident("z")));
|
||||
assertExpr("(x,y)", seqExpr([ident("x"),ident("y")]))
|
||||
assertExpr("(x,y,z)", seqExpr([ident("x"),ident("y"),ident("z")]))
|
||||
|
Loading…
Reference in New Issue
Block a user