[cfe-commits] r114255 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Parse/ParseExpr.cpp lib/Sema/SemaCodeComplete.cpp test/Index/complete-recovery.m test/SemaCXX/copy-assignment.cpp

Douglas Gregor dgregor at apple.com
Fri Sep 17 18:28:11 PDT 2010


Author: dgregor
Date: Fri Sep 17 20:28:11 2010
New Revision: 114255

URL: http://llvm.org/viewvc/llvm-project?rev=114255&view=rev
Log:
Continue parsing more postfix expressions, even after semantic
errors. Improves code completion in yet another case.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-recovery.m
    cfe/trunk/test/SemaCXX/copy-assignment.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=114255&r1=114254&r2=114255&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Sep 17 20:28:11 2010
@@ -4313,7 +4313,7 @@
   void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
                                        SourceLocation OpLoc,
                                        bool IsArrow);
-  void CodeCompletePostfixExpression(Scope *S, Expr *LHS);
+  void CodeCompletePostfixExpression(Scope *S, ExprResult LHS);
   void CodeCompleteTag(Scope *S, unsigned TagSpec);
   void CodeCompleteTypeQualifiers(DeclSpec &DS);
   void CodeCompleteCase(Scope *S);

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=114255&r1=114254&r2=114255&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Fri Sep 17 20:28:11 2010
@@ -242,8 +242,7 @@
   ExprResult R
     = ParseObjCMessageExpressionBody(LBracLoc, SuperLoc,
                                      ReceiverType, ReceiverExpr);
-  if (R.isInvalid()) return move(R);
-  R = ParsePostfixExpressionSuffix(R.take());
+  R = ParsePostfixExpressionSuffix(R);
   return ParseRHSOfBinaryExpression(R, prec::Assignment);
 }
 
@@ -576,8 +575,6 @@
 
       Res = ParseParenExpression(ParenExprType, false/*stopIfCastExr*/,
                                  TypeOfCast, CastTy, RParenLoc);
-      if (Res.isInvalid()) 
-        return move(Res);
     }
 
     switch (ParenExprType) {
@@ -1012,8 +1009,7 @@
   }
 
   // These can be followed by postfix-expr pieces.
-  if (Res.isInvalid()) return move(Res);
-  return ParsePostfixExpressionSuffix(Res.get());
+  return ParsePostfixExpressionSuffix(Res);
 }
 
 /// ParsePostfixExpressionSuffix - Once the leading part of a postfix-expression
@@ -1045,7 +1041,7 @@
       if (InMessageExpression)
         return move(LHS);
         
-      Actions.CodeCompletePostfixExpression(getCurScope(), LHS.take());
+      Actions.CodeCompletePostfixExpression(getCurScope(), LHS);
       ConsumeCodeCompletionToken();
       LHS = ExprError();
       break;
@@ -1099,12 +1095,7 @@
       CommaLocsTy CommaLocs;
 
       Loc = ConsumeParen();
-
-      if (LHS.isInvalid()) {
-        SkipUntil(tok::r_paren);
-        return ExprError();
-      }
-
+      
       if (Tok.is(tok::code_completion)) {
         Actions.CodeCompleteCall(getCurScope(), LHS.get(), 0, 0);
         ConsumeCodeCompletionToken();
@@ -1114,24 +1105,25 @@
         if (ParseExpressionList(ArgExprs, CommaLocs, &Sema::CodeCompleteCall,
                                 LHS.get())) {
           SkipUntil(tok::r_paren);
-          return ExprError();
+          LHS = ExprError();
         }
       }
 
       // Match the ')'.
-      if (Tok.isNot(tok::r_paren)) {
+      if (LHS.isInvalid()) {
+        SkipUntil(tok::r_paren);
+      } else if (Tok.isNot(tok::r_paren)) {
         MatchRHSPunctuation(tok::r_paren, Loc);
-        return ExprError();
-      }
-
-      if (!LHS.isInvalid()) {
-        assert((ArgExprs.size() == 0 || ArgExprs.size()-1 == CommaLocs.size())&&
+        LHS = ExprError();
+      } else {
+        assert((ArgExprs.size() == 0 || 
+                ArgExprs.size()-1 == CommaLocs.size())&&
                "Unexpected number of commas!");
         LHS = Actions.ActOnCallExpr(getCurScope(), LHS.take(), Loc,
                                     move_arg(ArgExprs), Tok.getLocation());
+        ConsumeParen();
       }
 
-      ConsumeParen();
       break;
     }
     case tok::arrow:
@@ -1183,7 +1175,7 @@
                              /*AllowConstructorName=*/false, 
                              ObjectType,
                              Name))
-        return ExprError();
+        LHS = ExprError();
       
       if (!LHS.isInvalid())
         LHS = Actions.ActOnMemberAccessExpr(getCurScope(), LHS.take(), OpLoc, 
@@ -1363,21 +1355,18 @@
   default: assert(0 && "Not a builtin primary expression!");
   case tok::kw___builtin_va_arg: {
     ExprResult Expr(ParseAssignmentExpression());
-    if (Expr.isInvalid()) {
-      SkipUntil(tok::r_paren);
-      return ExprError();
-    }
 
     if (ExpectAndConsume(tok::comma, diag::err_expected_comma, "",tok::r_paren))
-      return ExprError();
+      Expr = ExprError();
 
     TypeResult Ty = ParseTypeName();
 
     if (Tok.isNot(tok::r_paren)) {
       Diag(Tok, diag::err_expected_rparen);
-      return ExprError();
+      Expr = ExprError();
     }
-    if (Ty.isInvalid())
+
+    if (Expr.isInvalid() || Ty.isInvalid())
       Res = ExprError();
     else
       Res = Actions.ActOnVAArg(StartLoc, Expr.take(), Ty.get(), ConsumeParen());

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=114255&r1=114254&r2=114255&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Sep 17 20:28:11 2010
@@ -2757,9 +2757,11 @@
                             Results.data(),Results.size());
 }
 
-void Sema::CodeCompletePostfixExpression(Scope *S, Expr *E) {
-  if (getLangOptions().ObjC1)
-    CodeCompleteObjCInstanceMessage(S, E, 0, 0, false);
+void Sema::CodeCompletePostfixExpression(Scope *S, ExprResult E) {
+  if (E.isInvalid())
+    CodeCompleteOrdinaryName(S, PCC_RecoveryInFunction);
+  else if (getLangOptions().ObjC1)
+    CodeCompleteObjCInstanceMessage(S, E.take(), 0, 0, false);
 }
 
 static void AddObjCProperties(ObjCContainerDecl *Container, 

Modified: cfe/trunk/test/Index/complete-recovery.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-recovery.m?rev=114255&r1=114254&r2=114255&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-recovery.m (original)
+++ cfe/trunk/test/Index/complete-recovery.m Fri Sep 17 20:28:11 2010
@@ -11,6 +11,7 @@
   A *a2;
   z = [a2 method:1];
   blah ? blech : [a2 method:1];
+  (a * a2)([a2 method:1]);
 }
 @end
 
@@ -29,3 +30,4 @@
 // 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)
 // RUN: c-index-test -code-completion-at=%s:13:22 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s
+// RUN: c-index-test -code-completion-at=%s:14:16 -Xclang -code-completion-patterns %s | FileCheck -check-prefix=CHECK-CC3 %s

Modified: cfe/trunk/test/SemaCXX/copy-assignment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/copy-assignment.cpp?rev=114255&r1=114254&r2=114255&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/copy-assignment.cpp (original)
+++ cfe/trunk/test/SemaCXX/copy-assignment.cpp Fri Sep 17 20:28:11 2010
@@ -99,13 +99,15 @@
 
 // <rdar://problem/8315440>: Don't crash
 // FIXME: the recovery here is really bad.
-namespace test1 {
-  template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}}
-    A(UndeclaredType n) : X(n) {} // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{undeclared identifier 'n'}} expected-error {{expected ';' at end}} expected-error {{field has incomplete type}}
+namespace test1 { // expected-note{{to match this '{'}}
+  template<typename T> class A : public unknown::X { // expected-error {{undeclared identifier 'unknown'}} expected-error {{expected class name}} \
+    // expected-note{{template parameter is declared here}}
+    A(UndeclaredType n) : X(n) {} // expected-error{{expected ')'}} expected-note{{to match this '('}} \
+    // expected-error{{use of undeclared identifier 'n'}}
   };
-  template<typename T> class B : public A<T>     {
+  template<typename T> class B : public A<T>     { // expected-error{{declaration of 'T' shadows template parameter}}
     virtual void foo() {}
   };
-  extern template class A<char>; // expected-note {{in instantiation}} expected-note {{not complete}}
-  extern template class B<char>;
-}
+  extern template class A<char>; // expected-error{{expected member name or ';' after declaration specifiers}}
+  extern template class B<char>; // expected-error{{expected member name or ';' after declaration specifiers}}
+} // expected-error{{expected ';' after class}} // expected-error{{expected '}'}}





More information about the cfe-commits mailing list