[cfe-commits] r114225 - in /cfe/trunk: lib/Parse/ParseExpr.cpp test/FixIt/fixit-unrecoverable.cpp test/Index/complete-recovery.m test/SemaCXX/destructor.cpp test/SemaCXX/elaborated-type-specifier.cpp test/SemaObjC/crash-label.m test/SemaTemplate/dependent-base-classes.cpp

Douglas Gregor dgregor at apple.com
Fri Sep 17 15:25:06 PDT 2010


Author: dgregor
Date: Fri Sep 17 17:25:06 2010
New Revision: 114225

URL: http://llvm.org/viewvc/llvm-project?rev=114225&view=rev
Log:
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement. 

The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given

  x = p->y

if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.


Modified:
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/test/FixIt/fixit-unrecoverable.cpp
    cfe/trunk/test/Index/complete-recovery.m
    cfe/trunk/test/SemaCXX/destructor.cpp
    cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp
    cfe/trunk/test/SemaObjC/crash-label.m
    cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Sep 17 17:25:06 2010
@@ -177,8 +177,6 @@
 ///
 ExprResult Parser::ParseExpression() {
   ExprResult LHS(ParseAssignmentExpression());
-  if (LHS.isInvalid()) return move(LHS);
-
   return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
@@ -190,8 +188,6 @@
 ExprResult
 Parser::ParseExpressionWithLeadingAt(SourceLocation AtLoc) {
   ExprResult LHS(ParseObjCAtExpression(AtLoc));
-  if (LHS.isInvalid()) return move(LHS);
-
   return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
@@ -206,14 +202,13 @@
     ExtensionRAIIObject O(Diags);
 
     LHS = ParseCastExpression(false);
-    if (LHS.isInvalid()) return move(LHS);
   }
 
-  LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
-                             LHS.take());
-  if (LHS.isInvalid()) return move(LHS);
+  if (!LHS.isInvalid())
+    LHS = Actions.ActOnUnaryOp(getCurScope(), ExtLoc, tok::kw___extension__,
+                               LHS.take());
 
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Comma);
+  return ParseRHSOfBinaryExpression(move(LHS), prec::Comma);
 }
 
 /// ParseAssignmentExpression - Parse an expr that doesn't include commas.
@@ -228,9 +223,7 @@
     return ParseThrowExpression();
 
   ExprResult LHS(ParseCastExpression(false));
-  if (LHS.isInvalid()) return move(LHS);
-
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Assignment);
+  return ParseRHSOfBinaryExpression(move(LHS), prec::Assignment);
 }
 
 /// ParseAssignmentExprWithObjCMessageExprStart - Parse an assignment expression
@@ -251,8 +244,7 @@
                                      ReceiverType, ReceiverExpr);
   if (R.isInvalid()) return move(R);
   R = ParsePostfixExpressionSuffix(R.take());
-  if (R.isInvalid()) return move(R);
-  return ParseRHSOfBinaryExpression(R.take(), prec::Assignment);
+  return ParseRHSOfBinaryExpression(R, prec::Assignment);
 }
 
 
@@ -264,9 +256,7 @@
                                                Sema::Unevaluated);
 
   ExprResult LHS(ParseCastExpression(false));
-  if (LHS.isInvalid()) return move(LHS);
-
-  return ParseRHSOfBinaryExpression(LHS.take(), prec::Conditional);
+  return ParseRHSOfBinaryExpression(LHS, prec::Conditional);
 }
 
 /// ParseRHSOfBinaryExpression - Parse a binary expression that starts with
@@ -362,9 +352,10 @@
       RHS = ParseAssignmentExpression();
     else
       RHS = ParseCastExpression(false);
-    if (RHS.isInvalid())
-      return move(RHS);
 
+    if (RHS.isInvalid())
+      LHS = ExprError();
+    
     // Remember the precedence of this operator and get the precedence of the
     // operator immediately to the right of the RHS.
     prec::Level ThisPrec = NextTokPrec;
@@ -384,10 +375,11 @@
       // 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.
       // The function takes ownership of the RHS.
-      RHS = ParseRHSOfBinaryExpression(RHS.get(), 
+      RHS = ParseRHSOfBinaryExpression(RHS, 
                             static_cast<prec::Level>(ThisPrec + !isRightAssoc));
+
       if (RHS.isInvalid())
-        return move(RHS);
+        LHS = ExprError();
 
       NextTokPrec = getBinOpPrecedence(Tok.getKind(), GreaterThanIsOperator,
                                        getLang().CPlusPlus0x);
@@ -426,9 +418,9 @@
                                                      ParsedType TypeOfCast) {
   bool NotCastExpr;
   ExprResult Res = ParseCastExpression(isUnaryExpression,
-                                             isAddressOfOperand,
-                                             NotCastExpr,
-                                             TypeOfCast);
+                                       isAddressOfOperand,
+                                       NotCastExpr,
+                                       TypeOfCast);
   if (NotCastExpr)
     Diag(Tok, diag::err_expected_expression);
   return move(Res);

Modified: cfe/trunk/test/FixIt/fixit-unrecoverable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-unrecoverable.cpp?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit-unrecoverable.cpp (original)
+++ cfe/trunk/test/FixIt/fixit-unrecoverable.cpp Fri Sep 17 17:25:06 2010
@@ -6,6 +6,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
 float f(int y) {
-  return static_cst<float>(y); // expected-error{{use of undeclared identifier 'static_cst'; did you mean 'static_cast'?}}
+  return static_cst<float>(y); // expected-error{{use of undeclared identifier 'static_cst'; did you mean 'static_cast'?}} \
+  // expected-error{{for function-style cast or type construction}}
 }
 

Modified: cfe/trunk/test/Index/complete-recovery.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-recovery.m?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-recovery.m (original)
+++ cfe/trunk/test/Index/complete-recovery.m Fri Sep 17 17:25:06 2010
@@ -7,7 +7,9 @@
 @implementation A
 - (void)method:(int)x {
   A *a = [A method:1];
-  blarg * blah = wibble
+  blarg * blah = wibble;
+  A *a2;
+  z = [a2 method:1];
 }
 @end
 
@@ -23,3 +25,5 @@
 // CHECK-CC2: NotImplemented:{TypedText _Bool}
 // CHECK-CC2: VarDecl:{ResultType A *}{TypedText a}
 // CHECK-CC2: NotImplemented:{TypedText sizeof}{LeftParen (}{Placeholder expression-or-type}{RightParen )}
+// RUN: c-index-test -code-completion-at=%s:12:11 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s
+// CHECK-CC3: ObjCInstanceMethodDecl:{ResultType void}{TypedText method:}{Placeholder (int)} (17)

Modified: cfe/trunk/test/SemaCXX/destructor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/destructor.cpp?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/destructor.cpp (original)
+++ cfe/trunk/test/SemaCXX/destructor.cpp Fri Sep 17 17:25:06 2010
@@ -67,7 +67,7 @@
 namespace PR6421 {
   class T; // expected-note{{forward declaration}}
 
-  class QGenericArgument
+  class QGenericArgument // expected-note{{declared here}}
   {
     template<typename U>
     void foo(T t) // expected-error{{variable has incomplete type}}
@@ -76,7 +76,8 @@
     void disconnect()
     {
       T* t;
-      bob<QGenericArgument>(t); // expected-error{{undeclared identifier 'bob'}}
+      bob<QGenericArgument>(t); // expected-error{{undeclared identifier 'bob'}} \
+      // expected-error{{does not refer to a value}}
     }
   };
 }

Modified: cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp (original)
+++ cfe/trunk/test/SemaCXX/elaborated-type-specifier.cpp Fri Sep 17 17:25:06 2010
@@ -35,7 +35,8 @@
 }
 
 void test_S5_scope() {
-  S4 *s4; // expected-error{{use of undeclared identifier 'S4'}}
+  S4 *s4; // expected-error{{use of undeclared identifier 'S4'}} \
+  // expected-error{{use of undeclared identifier 's4'}}
 }
 
 int test_funcparam_scope(struct S5 * s5) {

Modified: cfe/trunk/test/SemaObjC/crash-label.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/crash-label.m?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/crash-label.m (original)
+++ cfe/trunk/test/SemaObjC/crash-label.m Fri Sep 17 17:25:06 2010
@@ -7,4 +7,4 @@
 - (NSDictionary *) _setupKernelStandardMode:(NSString *)source { // expected-error 2 {{expected a type}} \
 expected-error {{missing context for method declaration}} \
 expected-note{{to match this '{'}}
-  Exit:   if(_ciKernel && !success ) { // expected-error {{use of undeclared identifier}} // expected-error 2 {{expected}} expected-note{{to match this '{'}}
+  Exit:   if(_ciKernel && !success ) { // expected-error {{use of undeclared identifier}} // expected-error 2 {{expected}} expected-note{{to match this '{'}} expected-error{{use of undeclared identifier 'success'}}

Modified: cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp?rev=114225&r1=114224&r2=114225&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/dependent-base-classes.cpp Fri Sep 17 17:25:06 2010
@@ -105,7 +105,9 @@
     void f0(const X & k)
     {
       this->template f1<int>()(k); // expected-error{{'f1' following the 'template' keyword does not refer to a template}} \
-      // FIXME: expected-error{{unqualified-id}}
+      // FIXME: expected-error{{unqualified-id}} \
+      // expected-error{{function-style cast or type construction}} \
+      // expected-error{{expected expression}}
     }
   };
 }





More information about the cfe-commits mailing list