forked from OSchip/llvm-project
Fix parsing of assignment expressions and handling of right-associative
things. llvm-svn: 38881
This commit is contained in:
parent
96c3deb53d
commit
89d53752f5
|
@ -253,15 +253,19 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, unsigned MinPrec) {
|
|||
unsigned ThisPrec = NextTokPrec;
|
||||
NextTokPrec = getBinOpPrecedence(Tok.getKind());
|
||||
|
||||
// FIXME: ASSIGNMENT IS RIGHT ASSOCIATIVE.
|
||||
// FIXME: do we want to handle assignment here??
|
||||
bool isRightAssoc = OpToken.getKind() == tok::question;
|
||||
// Assignment and conditional expressions are right-associative.
|
||||
bool isRightAssoc = NextTokPrec == prec::Conditional ||
|
||||
NextTokPrec == prec::Assignment;
|
||||
|
||||
// Get the precedence of the operator to the right of the RHS. If it binds
|
||||
// more tightly with RHS than we do, evaluate it completely first.
|
||||
if (ThisPrec < NextTokPrec ||
|
||||
(ThisPrec == NextTokPrec && isRightAssoc)) {
|
||||
RHS = ParseRHSOfBinaryExpression(RHS, ThisPrec+1);
|
||||
// If this is left-associative, only parse things on the RHS that bind
|
||||
// more tightly than the current operator. If it is left-associative, it
|
||||
// is okay, to bind exactly as tightly. For example, compile A=B=C=D as
|
||||
// A=(B=(C=D)), where each paren is a level of recursion here.
|
||||
RHS = ParseRHSOfBinaryExpression(RHS, ThisPrec + !isRightAssoc);
|
||||
if (RHS.isInvalid) return RHS;
|
||||
|
||||
NextTokPrec = getBinOpPrecedence(Tok.getKind());
|
||||
|
|
|
@ -62,3 +62,7 @@ void test6() {
|
|||
int test7(int a, int b) {
|
||||
return a ? a,b : a;
|
||||
}
|
||||
|
||||
int test8(int a, int b) {
|
||||
return a = b = c;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue