[cfe-commits] r116907 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaLookup.cpp test/FixIt/typo.cpp test/FixIt/typo.m test/SemaObjC/super.m test/SemaObjC/synth-provisional-ivars.m

Douglas Gregor dgregor at apple.com
Tue Oct 19 20:06:35 PDT 2010


Author: dgregor
Date: Tue Oct 19 22:06:34 2010
New Revision: 116907

URL: http://llvm.org/viewvc/llvm-project?rev=116907&view=rev
Log:
Fix handling of property and ivar lookup in typo correction; the two
kinds of lookup into Objective-C classes were tangled together, a
situation that was compounded by automatically synthesized ivars.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/FixIt/typo.cpp
    cfe/trunk/test/FixIt/typo.m
    cfe/trunk/test/SemaObjC/super.m
    cfe/trunk/test/SemaObjC/synth-provisional-ivars.m

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Tue Oct 19 22:06:34 2010
@@ -1310,6 +1310,10 @@
     CTC_CXXCasts,
     /// \brief A member lookup context.
     CTC_MemberLookup,
+    /// \brief An Objective-C ivar lookup context (e.g., self->ivar).
+    CTC_ObjCIvarLookup,
+    /// \brief An Objective-C property lookup context (e.g., self.prop).
+    CTC_ObjCPropertyLookup,
     /// \brief The receiver of an Objective-C message send within an
     /// Objective-C method where 'super' is a valid keyword.
     CTC_ObjCMessageReceiver

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Oct 19 22:06:34 2010
@@ -3231,7 +3231,9 @@
         // Attempt to correct for typos in ivar names.
         LookupResult Res(*this, R.getLookupName(), R.getNameLoc(),
                          LookupMemberName);
-        if (CorrectTypo(Res, 0, 0, IDecl, false, CTC_MemberLookup) &&
+        if (CorrectTypo(Res, 0, 0, IDecl, false, 
+                        IsArrow? CTC_ObjCIvarLookup
+                               : CTC_ObjCPropertyLookup) &&
             (IV = Res.getAsSingle<ObjCIvarDecl>())) {
           Diag(R.getNameLoc(),
                diag::err_typecheck_member_reference_ivar_suggest)

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Oct 19 22:06:34 2010
@@ -2785,6 +2785,57 @@
   BestResults[Keyword] = true;
 }
 
+/// \brief Perform name lookup for a possible result for typo correction.
+static void LookupPotentialTypoResult(Sema &SemaRef,
+                                      LookupResult &Res,
+                                      IdentifierInfo *Name,
+                                      Scope *S, CXXScopeSpec *SS,
+                                      DeclContext *MemberContext,
+                                      bool EnteringContext,
+                                      Sema::CorrectTypoContext CTC) {
+  Res.suppressDiagnostics();
+  Res.clear();
+  Res.setLookupName(Name);
+  if (MemberContext) {    
+    if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(MemberContext)) {
+      if (CTC == Sema::CTC_ObjCIvarLookup) {
+        if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) {
+          Res.addDecl(Ivar);
+          Res.resolveKind();
+          return;
+        }
+      }
+      
+      if (ObjCPropertyDecl *Prop = Class->FindPropertyDeclaration(Name)) {
+        Res.addDecl(Prop);
+        Res.resolveKind();
+        return;
+      }
+    }
+        
+    SemaRef.LookupQualifiedName(Res, MemberContext);
+    return;
+  }
+  
+  SemaRef.LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false, 
+                           EnteringContext);
+  
+  // Fake ivar lookup; this should really be part of
+  // LookupParsedName.
+  if (ObjCMethodDecl *Method = SemaRef.getCurMethodDecl()) {
+    if (Method->isInstanceMethod() && Method->getClassInterface() &&
+        (Res.empty() || 
+         (Res.isSingleResult() &&
+          Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) {
+       if (ObjCIvarDecl *IV 
+             = Method->getClassInterface()->lookupInstanceVariable(Name)) {
+         Res.addDecl(IV);
+         Res.resolveKind();
+       }
+     }
+  }
+}
+
 /// \brief Try to "correct" a typo in the source code by finding
 /// visible declarations whose names are similar to the name that was
 /// present in the source code.
@@ -2946,10 +2997,17 @@
       WantCXXNamedCasts = true;
       break;
       
+    case CTC_ObjCPropertyLookup:
+      // FIXME: Add "isa"?
+      break;
+      
     case CTC_MemberLookup:
       if (getLangOptions().CPlusPlus)
         Consumer.addKeywordResult(Context, "template");
       break;
+      
+    case CTC_ObjCIvarLookup:
+      break;
   }
 
   if (WantTypeSpecifiers) {
@@ -3104,33 +3162,8 @@
     
     // Perform name lookup on this name.
     IdentifierInfo *Name = &Context.Idents.get(I->getKey());
-    Res.suppressDiagnostics();
-    Res.clear();
-    Res.setLookupName(Name);
-    if (MemberContext)
-      LookupQualifiedName(Res, MemberContext);
-    else {
-      LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false, 
-                       EnteringContext);
-
-      // Fake ivar lookup; this should really be part of
-      // LookupParsedName.
-      if (ObjCMethodDecl *Method = getCurMethodDecl()) {
-        if (Method->isInstanceMethod() && Method->getClassInterface() &&
-            (Res.empty() || 
-             (Res.isSingleResult() &&
-              Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) {
-          ObjCInterfaceDecl *ClassDeclared = 0;
-          if (ObjCIvarDecl *IV 
-                = Method->getClassInterface()->lookupInstanceVariable(Name, 
-                                                               ClassDeclared)) {
-            Res.clear();
-            Res.addDecl(IV);
-            Res.resolveKind();
-          }
-        }
-      }
-    }
+    LookupPotentialTypoResult(*this, Res, Name, S, SS, MemberContext, 
+                              EnteringContext, CTC);
     
     switch (Res.getResultKind()) {
     case LookupResult::NotFound:
@@ -3152,7 +3185,7 @@
     case LookupResult::FoundOverloaded:
     case LookupResult::FoundUnresolvedValue:
       ++I;
-      LastLookupWasAccepted = false;
+      LastLookupWasAccepted = true;
       break;
     }
     
@@ -3172,39 +3205,14 @@
       Res.clear();
     } else if (!LastLookupWasAccepted) {
       // Perform name lookup on this name.
-      Res.suppressDiagnostics();
-      Res.clear();
-      Res.setLookupName(Name);
-      if (MemberContext)
-        LookupQualifiedName(Res, MemberContext);
-      else {
-        LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false, 
-                         EnteringContext);
-
-        // Fake ivar lookup; this should really be part of
-        // LookupParsedName.
-        if (ObjCMethodDecl *Method = getCurMethodDecl()) {
-          if (Method->isInstanceMethod() && Method->getClassInterface() &&
-              (Res.empty() || 
-               (Res.isSingleResult() &&
-                Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) {
-            ObjCInterfaceDecl *ClassDeclared = 0;
-            if (ObjCIvarDecl *IV 
-                = Method->getClassInterface()->lookupInstanceVariable(Name, 
-                                                              ClassDeclared)) {
-              Res.clear();
-              Res.addDecl(IV);
-              Res.resolveKind();
-            }
-          }
-        }
-      }
+      LookupPotentialTypoResult(*this, Res, Name, S, SS, MemberContext, 
+                                EnteringContext, CTC);
     }
 
     // Record the correction for unqualified lookup.
     if (IsUnqualifiedLookup)
       UnqualifiedTyposCorrected[Typo] 
-        = std::make_pair(Consumer.begin()->getKey(), Consumer.begin()->second);
+        = std::make_pair(Name->getName(), Consumer.begin()->second);
       
     return &Context.Idents.get(Consumer.begin()->getKey());  
   }
@@ -3218,7 +3226,7 @@
     // Record the correction for unqualified lookup.
     if (IsUnqualifiedLookup)
       UnqualifiedTyposCorrected[Typo]
-        = std::make_pair(Consumer.begin()->getKey(), Consumer.begin()->second);
+        = std::make_pair("super", Consumer.begin()->second);
     
     return &Context.Idents.get("super");
   }

Modified: cfe/trunk/test/FixIt/typo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.cpp?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.cpp (original)
+++ cfe/trunk/test/FixIt/typo.cpp Tue Oct 19 22:06:34 2010
@@ -2,9 +2,7 @@
 // RUN: cp %s %t
 // RUN: %clang_cc1 -fsyntax-only -fixit -x c++ %t || true
 // RUN: %clang_cc1 -fsyntax-only -pedantic -Werror -x c++ %t
-//
-// FIXME: Disabled while we investigate failure.
-// REQUIRES: disabled
+
 namespace std {
   template<typename T> class basic_string { // expected-note 2{{'basic_string' declared here}}
   public:

Modified: cfe/trunk/test/FixIt/typo.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.m?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.m (original)
+++ cfe/trunk/test/FixIt/typo.m Tue Oct 19 22:06:34 2010
@@ -2,9 +2,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -x objective-c -E -P %s -o %t
 // RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fixit %t  || true
 // RUN: %clang_cc1 -x objective-c -fsyntax-only -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -pedantic -Werror %t
-//
-// FIXME: Disabled while we investigate failure.
-// REQUIRES: disabled
 
 @interface NSString // expected-note{{'NSString' declared here}}
 + (int)method:(int)x;

Modified: cfe/trunk/test/SemaObjC/super.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super.m?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super.m (original)
+++ cfe/trunk/test/SemaObjC/super.m Tue Oct 19 22:06:34 2010
@@ -54,7 +54,7 @@
   [super m]; // expected-warning{{receiver type 'int' is not 'id'}} \
                 expected-warning {{method '-m' not found (return type defaults to 'id')}}
 }
-void f1(id puper) {
+void f1(id puper) {  // expected-note {{'puper' declared here}}
   [super m]; // expected-error{{use of undeclared identifier 'super'}}
 }
 

Modified: cfe/trunk/test/SemaObjC/synth-provisional-ivars.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/synth-provisional-ivars.m?rev=116907&r1=116906&r2=116907&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/synth-provisional-ivars.m (original)
+++ cfe/trunk/test/SemaObjC/synth-provisional-ivars.m Tue Oct 19 22:06:34 2010
@@ -18,7 +18,7 @@
 @end
 
 @implementation I
-- (int) Meth { return PROP; } // expected-note{{'PROP' declared here}}
+- (int) Meth { return PROP; } // expected-note 2{{'PROP' declared here}}
 
 @dynamic PROP1;
 - (int) Meth1 { return PROP1; }  // expected-error {{use of undeclared identifier 'PROP1'}}





More information about the cfe-commits mailing list