[cfe-commits] r104023 - in /cfe/trunk: lib/Sema/SemaLookup.cpp test/FixIt/typo.m

Douglas Gregor dgregor at apple.com
Tue May 18 09:30:22 PDT 2010


Author: dgregor
Date: Tue May 18 11:30:22 2010
New Revision: 104023

URL: http://llvm.org/viewvc/llvm-project?rev=104023&view=rev
Log:
Give a slight edge to the context-sensitive keyword 'super' over
non-function-local declarations with names similar to what the user
typed. For example, this allows us to correct 'supper' to 'super' in
an Objective-C message send, even though the C function 'isupper' has
the same edit distance.


Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/test/FixIt/typo.m

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=104023&r1=104022&r2=104023&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue May 18 11:30:22 2010
@@ -2684,7 +2684,7 @@
       Consumer.addKeywordResult(Context, "typeof");
   }
   
-  if (WantCXXNamedCasts) {
+  if (WantCXXNamedCasts && getLangOptions().CPlusPlus) {
     Consumer.addKeywordResult(Context, "const_cast");
     Consumer.addKeywordResult(Context, "dynamic_cast");
     Consumer.addKeywordResult(Context, "reinterpret_cast");
@@ -2814,6 +2814,25 @@
         BestIvarOrPropertyDecl = 0;
         FoundIvarOrPropertyDecl = false;
         Consumer.clear_decls();
+      } else if (CTC == CTC_ObjCMessageReceiver &&
+                 (*Consumer.keyword_begin())->isStr("super")) {
+        // In an Objective-C message send, give the "super" keyword a slight
+        // edge over entities not in function or method scope.
+        for (TypoCorrectionConsumer::iterator I = Consumer.begin(), 
+                                           IEnd = Consumer.end();
+             I != IEnd; ++I) {
+          if ((*I)->getDeclName() == BestName) {
+            if ((*I)->getDeclContext()->isFunctionOrMethod())
+              return DeclarationName();
+          }
+        }
+        
+        // Everything found was outside a function or method; the 'super'
+        // keyword takes precedence.
+        BestIvarOrPropertyDecl = 0;
+        FoundIvarOrPropertyDecl = false;
+        Consumer.clear_decls();        
+        BestName = *Consumer.keyword_begin();
       } else {
         // Name collision; we will not correct typos.
         return DeclarationName();

Modified: cfe/trunk/test/FixIt/typo.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/typo.m?rev=104023&r1=104022&r2=104023&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/typo.m (original)
+++ cfe/trunk/test/FixIt/typo.m Tue May 18 11:30:22 2010
@@ -111,7 +111,6 @@
   
 @end
 
-#ifdef NON_FIXITS
 double *isupper(int);
 
 @interface Sub2 : Super
@@ -120,10 +119,9 @@
 
 @implementation Sub2
 - (int)method2 {
-  return [supper method2]; // expected-error{{use of undeclared identifier 'supper'}}
+  return [supper method2]; // expected-error{{unknown receiver 'supper'; did you mean 'super'?}}
 }
 @end
-#endif
 
 @interface Ivar
 @end
@@ -138,7 +136,7 @@
 @end
 
 @implementation User
- at synthesize ivar;
+ at synthesize ivar; // expected-error{{synthesized property 'ivar' must either be named the same as a compatible ivar or must explicitly name an ivar}}
 
 - (void)method {
   // Test that we don't correct 'ivar' to 'Ivar'  e





More information about the cfe-commits mailing list