r202529 - When completing Objective-C instance method invocations, perform a contextual conversion to an Objective-C pointer type of the target expression if needed. This fixes code completion of method invocations where the target is a smart pointer that has an explicit conversion operator to an Objective-C type.
Anders Carlsson
andersca at mac.com
Fri Feb 28 11:07:22 PST 2014
Author: andersca
Date: Fri Feb 28 13:07:22 2014
New Revision: 202529
URL: http://llvm.org/viewvc/llvm-project?rev=202529&view=rev
Log:
When completing Objective-C instance method invocations, perform a contextual conversion to an Objective-C pointer type of the target expression if needed. This fixes code completion of method invocations where the target is a smart pointer that has an explicit conversion operator to an Objective-C type.
Added:
cfe/trunk/test/CodeCompletion/objc-message.mm
Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=202529&r1=202528&r2=202529&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Fri Feb 28 13:07:22 2014
@@ -5529,7 +5529,7 @@ void Sema::CodeCompleteObjCInstanceMessa
// 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 (ReceiverType->isObjCIdType() || ReceiverType->isObjCClassType()) {
if (ObjCInterfaceDecl *IFace = GetAssumedMessageSendExprType(RecExpr)) {
if (ReceiverType->isObjCClassType())
return CodeCompleteObjCClassMessage(S,
@@ -5540,6 +5540,13 @@ void Sema::CodeCompleteObjCInstanceMessa
ReceiverType = Context.getObjCObjectPointerType(
Context.getObjCInterfaceType(IFace));
}
+ } else if (RecExpr && getLangOpts().CPlusPlus) {
+ ExprResult Conv = PerformContextuallyConvertToObjCPointer(RecExpr);
+ if (Conv.isUsable()) {
+ RecExpr = Conv.take();
+ ReceiverType = RecExpr->getType();
+ }
+ }
// Build the set of methods we can see.
ResultBuilder Results(*this, CodeCompleter->getAllocator(),
Added: cfe/trunk/test/CodeCompletion/objc-message.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeCompletion/objc-message.mm?rev=202529&view=auto
==============================================================================
--- cfe/trunk/test/CodeCompletion/objc-message.mm (added)
+++ cfe/trunk/test/CodeCompletion/objc-message.mm Fri Feb 28 13:07:22 2014
@@ -0,0 +1,46 @@
+// Note: the run lines follow their respective tests, since line/column
+// matter in this test.
+
+ at protocol FooTestProtocol
++ protocolClassMethod;
+- protocolInstanceMethod;
+ at end
+ at interface Foo <FooTestProtocol> {
+ void *isa;
+}
++ (int)classMethod1:a withKeyword:b;
++ (void)classMethod2;
++ new;
+- instanceMethod1;
+ at end
+
+ at interface Foo (FooTestCategory)
++ categoryClassMethod;
+- categoryInstanceMethod;
+ at end
+
+template<typename T> struct RetainPtr {
+ template <typename U> struct RemovePointer { typedef U Type; };
+ template <typename U> struct RemovePointer<U*> { typedef U Type; };
+
+ typedef typename RemovePointer<T>::Type* PtrType;
+
+ explicit operator PtrType() const;
+};
+
+void func(const RetainPtr<Foo>& ptr)
+{
+ [ptr instanceMethod1];
+}
+
+void func(const RetainPtr<id <FooTestProtocol>>& ptr)
+{
+ [ptr instanceMethod1];
+}
+
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-at=%s:33:7 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+// CHECK-CC1: categoryInstanceMethod : [#id#]categoryInstanceMethod
+// CHECK-CC1: instanceMethod1 : [#id#]instanceMethod1
+// CHECK-CC1: protocolInstanceMethod : [#id#]protocolInstanceMethod
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -code-completion-at=%s:38:7 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
+// CHECK-CC2: protocolInstanceMethod : [#id#]protocolInstanceMethod
More information about the cfe-commits
mailing list