r173903 - The instance methods of the root class of an Objective-C hieararchy

Douglas Gregor dgregor at apple.com
Tue Jan 29 22:58:39 PST 2013


Author: dgregor
Date: Wed Jan 30 00:58:39 2013
New Revision: 173903

URL: http://llvm.org/viewvc/llvm-project?rev=173903&view=rev
Log:
The instance methods of the root class of an Objective-C hieararchy
can be messaged via the metaclass. Provide code completions for this
case. Fixes <rdar://problem/12560296>.

Modified:
    cfe/trunk/lib/Sema/SemaCodeComplete.cpp
    cfe/trunk/test/Index/complete-objc-message.m
    cfe/trunk/test/Index/complete-super.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=173903&r1=173902&r2=173903&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Wed Jan 30 00:58:39 2013
@@ -4769,10 +4769,15 @@ static void AddObjCMethods(ObjCContainer
                            bool InOriginalClass = true) {
   typedef CodeCompletionResult Result;
   Container = getContainerDef(Container);
+  ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container);
+  bool isRootClass = IFace && !IFace->getSuperClass();
   for (ObjCContainerDecl::method_iterator M = Container->meth_begin(),
                                        MEnd = Container->meth_end();
        M != MEnd; ++M) {
-    if (M->isInstanceMethod() == WantInstanceMethods) {
+    // The instance methods on the root class can be messaged via the
+    // metaclass.
+    if (M->isInstanceMethod() == WantInstanceMethods ||
+        (isRootClass && !WantInstanceMethods)) {
       // Check whether the selector identifiers we've been given are a 
       // subset of the identifiers for this particular method.
       if (!isAcceptableObjCMethod(*M, WantKind, SelIdents, NumSelIdents,
@@ -4805,7 +4810,6 @@ static void AddObjCMethods(ObjCContainer
     }
   }
   
-  ObjCInterfaceDecl *IFace = dyn_cast<ObjCInterfaceDecl>(Container);
   if (!IFace || !IFace->hasDefinition())
     return;
   

Modified: cfe/trunk/test/Index/complete-objc-message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-objc-message.m?rev=173903&r1=173902&r2=173903&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-objc-message.m (original)
+++ cfe/trunk/test/Index/complete-objc-message.m Wed Jan 30 00:58:39 2013
@@ -193,6 +193,7 @@ void test_DO(DO *d, A* a) {
 // CHECK-CC1: {TypedText categoryClassMethod} (35)
 // CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace  }{TypedText withKeyword:}{Placeholder (int)} (35)
 // CHECK-CC1: {TypedText classMethod2} (35)
+// CHECK-CC1: {TypedText instanceMethod1} (35)
 // CHECK-CC1: {TypedText new} (35)
 // CHECK-CC1: {TypedText protocolClassMethod} (37)
 // CHECK-CC1: Completion contexts:

Modified: cfe/trunk/test/Index/complete-super.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-super.m?rev=173903&r1=173902&r2=173903&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-super.m (original)
+++ cfe/trunk/test/Index/complete-super.m Wed Jan 30 00:58:39 2013
@@ -53,8 +53,7 @@ typedef int Bool;
 // CHECK-ADD-ADD: ObjCInstanceMethodDecl:{ResultType void}{TypedText last} (35)
 
 // RUN: c-index-test -code-completion-at=%s:24:10 %s | FileCheck -check-prefix=CHECK-SELECTOR-SELECTOR %s
-// CHECK-SELECTOR-SELECTOR-NOT: x
-// CHECK-SELECTOR-SELECTOR: ObjCClassMethodDecl:{ResultType void}{TypedText last} (35)
+// CHECK-SELECTOR-SELECTOR: ObjCInstanceMethodDecl:{ResultType void}{TypedText last} (35)
 // CHECK-SELECTOR-SELECTOR: ObjCClassMethodDecl:{ResultType void}{TypedText select:}{Placeholder condition}{HorizontalSpace  }{Text first:}{Placeholder a}{HorizontalSpace  }{Text second:}{Placeholder b} (20)
 
 // Check "super" completion at the second identifier





More information about the cfe-commits mailing list