[llvm-branch-commits] [cfe-branch] r118573 - in /cfe/branches/Apple/whitney: lib/Sema/SemaCodeComplete.cpp test/Index/complete-objc-message.m

Daniel Dunbar daniel at zuster.org
Tue Nov 9 09:32:36 PST 2010


Author: ddunbar
Date: Tue Nov  9 11:32:36 2010
New Revision: 118573

URL: http://llvm.org/viewvc/llvm-project?rev=118573&view=rev
Log:
Merge r118443:
--
Author: Douglas Gregor <dgregor at apple.com>
Date:   Mon Nov 8 21:12:30 2010 +0000

    If an instance method messages is sending to an expression of type Class,
    and we statically can compute a bound on the actual type (e.g.,
    because it's a send to the the magic "class" instance method), code
    complete as if we were performing a class message send to that class.

Modified:
    cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
    cfe/branches/Apple/whitney/test/Index/complete-objc-message.m

Modified: cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp?rev=118573&r1=118572&r2=118573&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/branches/Apple/whitney/lib/Sema/SemaCodeComplete.cpp Tue Nov  9 11:32:36 2010
@@ -4695,6 +4695,21 @@
                                             Context.getObjCInterfaceType(Super))
                                  : Context.getObjCIdType();
   
+  // If we're messaging an expression with type "id" or "Class", check
+  // whether we know something special about the receiver that allows
+  // us to assume a more-specific receiver type.
+  if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType())
+    if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr)) {
+      if (ReceiverType->isObjCClassType())
+        return CodeCompleteObjCClassMessage(S, 
+                       ParsedType::make(Context.getObjCInterfaceType(IFace)),
+                                            SelIdents, NumSelIdents,
+                                            AtArgumentExpression, Super);
+
+      ReceiverType = Context.getObjCObjectPointerType(
+                                          Context.getObjCInterfaceType(IFace));
+    }
+
   // Build the set of methods we can see.
   ResultBuilder Results(*this, CodeCompletionContext::CCC_Other);
   Results.EnterNewScope();
@@ -4712,14 +4727,6 @@
   // others.
   if (ObjCMethodDecl *CurMethod = getCurMethodDecl())
     Results.setPreferredSelector(CurMethod->getSelector());
-
-  // If we're messaging an expression with type "id" or "Class", check
-  // whether we know something special about the receiver that allows
-  // us to assume a more-specific receiver type.
-  if (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType())
-    if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr))
-      ReceiverType = Context.getObjCObjectPointerType(
-                                          Context.getObjCInterfaceType(IFace));
   
   // Keep track of the selectors we've already added.
   VisitedSelectorSet Selectors;

Modified: cfe/branches/Apple/whitney/test/Index/complete-objc-message.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/test/Index/complete-objc-message.m?rev=118573&r1=118572&r2=118573&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/test/Index/complete-objc-message.m (original)
+++ cfe/branches/Apple/whitney/test/Index/complete-objc-message.m Tue Nov  9 11:32:36 2010
@@ -150,6 +150,27 @@
   [c method2];
 };
 
+ at protocol P
+- (Class)class;
+ at end
+
+ at interface A () <P>
+ at end
+
+ at interface A ()
++ (void)class_method3;
+ at end
+
+ at interface A (Cat)
++ (void)class_method4;
+ at end
+
+ at implementation A
+- (void)method5:(A*)a {
+  [[self class] class_method4];
+}
+ at end
+
 // RUN: c-index-test -code-completion-at=%s:23:19 %s | FileCheck -check-prefix=CHECK-CC1 %s
 // CHECK-CC1: {TypedText categoryClassMethod}
 // CHECK-CC1: {TypedText classMethod1:}{Placeholder (id)}{HorizontalSpace  }{TypedText withKeyword:}{Placeholder (int)}
@@ -256,6 +277,10 @@
 // CHECK-REDUNDANT-NOT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method2}
 // CHECK-REDUNDANT: ObjCInstanceMethodDecl:{ResultType void}{TypedText method3} (35)
 
+// RUN: c-index-test -code-completion-at=%s:170:16 %s | FileCheck -check-prefix=CHECK-CLASS-RESULT %s
+// CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method3} (35)
+// CHECK-CLASS-RESULT: ObjCClassMethodDecl:{ResultType void}{TypedText class_method4} (35)
+
 // Test code completion with a missing opening bracket:
 // RUN: c-index-test -code-completion-at=%s:135:5 %s | FileCheck -check-prefix=CHECK-CCI %s
 // RUN: c-index-test -code-completion-at=%s:139:7 %s | FileCheck -check-prefix=CHECK-CC7 %s
@@ -268,3 +293,4 @@
 // RUN: c-index-test -code-completion-at=%s:141:14 %s | FileCheck -check-prefix=CHECK-CCC %s
 // RUN: c-index-test -code-completion-at=%s:141:23 %s | FileCheck -check-prefix=CHECK-CCD %s
 // RUN: c-index-test -code-completion-at=%s:141:30 %s | FileCheck -check-prefix=CHECK-CCE %s
+





More information about the llvm-branch-commits mailing list