[cfe-commits] r151805 - /cfe/trunk/lib/Parse/ParseExpr.cpp

Richard Smith richard-llvm at metafoo.co.uk
Wed Feb 29 23:10:06 PST 2012


Author: rsmith
Date: Thu Mar  1 01:10:06 2012
New Revision: 151805

URL: http://llvm.org/viewvc/llvm-project?rev=151805&view=rev
Log:
Avoid examining the AST from the parser, and simplify somewhat.

Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=151805&r1=151804&r2=151805&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Thu Mar  1 01:10:06 2012
@@ -282,12 +282,6 @@
     Token OpToken = Tok;
     ConsumeToken();
 
-    if (!LHS.isInvalid() && isa<InitListExpr>(LHS.get())) {
-      Diag(OpToken, diag::err_init_list_bin_op)
-        << /*LHS*/0 << PP.getSpelling(OpToken) << LHS.get()->getSourceRange();
-      LHS = ExprError();
-    }
-
     // Special case handling for the ternary operator.
     ExprResult TernaryMiddle(true);
     if (NextTokPrec == prec::Conditional) {
@@ -363,9 +357,11 @@
     // parse as if we were allowed braced-init-lists everywhere, and check that
     // they only appear on the RHS of assignments later.
     ExprResult RHS;
-    if (getLang().CPlusPlus0x && Tok.is(tok::l_brace))
+    bool RHSIsInitList = false;
+    if (getLang().CPlusPlus0x && Tok.is(tok::l_brace)) {
       RHS = ParseBraceInitializer();
-    else if (getLang().CPlusPlus && NextTokPrec <= prec::Conditional)
+      RHSIsInitList = true;
+    } else if (getLang().CPlusPlus && NextTokPrec <= prec::Conditional)
       RHS = ParseAssignmentExpression();
     else
       RHS = ParseCastExpression(false);
@@ -387,10 +383,10 @@
     // more tightly with RHS than we do, evaluate it completely first.
     if (ThisPrec < NextTokPrec ||
         (ThisPrec == NextTokPrec && isRightAssoc)) {
-      if (!LHS.isInvalid() && isa<InitListExpr>(LHS.get())) {
-        Diag(OpToken, diag::err_init_list_bin_op)
-          << /*LHS*/0 << PP.getSpelling(OpToken) << LHS.get()->getSourceRange();
-        LHS = ExprError();
+      if (!RHS.isInvalid() && RHSIsInitList) {
+        Diag(Tok, diag::err_init_list_bin_op)
+          << /*LHS*/0 << PP.getSpelling(Tok) << Actions.getExprRange(RHS.get());
+        RHS = ExprError();
       }
       // 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
@@ -399,6 +395,7 @@
       // The function takes ownership of the RHS.
       RHS = ParseRHSOfBinaryExpression(RHS, 
                             static_cast<prec::Level>(ThisPrec + !isRightAssoc));
+      RHSIsInitList = false;
 
       if (RHS.isInvalid())
         LHS = ExprError();
@@ -408,13 +405,14 @@
     }
     assert(NextTokPrec <= ThisPrec && "Recursion didn't work!");
 
-    if (!RHS.isInvalid() && isa<InitListExpr>(RHS.get())) {
+    if (!RHS.isInvalid() && RHSIsInitList) {
       if (ThisPrec == prec::Assignment) {
         Diag(OpToken, diag::warn_cxx98_compat_generalized_initializer_lists)
-          << RHS.get()->getSourceRange();
+          << Actions.getExprRange(RHS.get());
       } else {
         Diag(OpToken, diag::err_init_list_bin_op)
-          << /*RHS*/1 << PP.getSpelling(OpToken) << RHS.get()->getSourceRange();
+          << /*RHS*/1 << PP.getSpelling(OpToken)
+          << Actions.getExprRange(RHS.get());
         LHS = ExprError();
       }
     }





More information about the cfe-commits mailing list