forked from OSchip/llvm-project
Finish code completion for Objective-C message sends
llvm-svn: 89168
This commit is contained in:
parent
4797e58d6b
commit
a3329fa05e
|
@ -1704,24 +1704,42 @@ void Sema::CodeCompleteObjCInstanceMessage(Scope *S, ExprTy *Receiver) {
|
|||
return;
|
||||
}
|
||||
|
||||
const ObjCObjectPointerType* OCOPT
|
||||
= ReceiverType->getAs<ObjCObjectPointerType>();
|
||||
if (!OCOPT)
|
||||
return;
|
||||
|
||||
// FIXME: handle 'id', 'Class', and qualified types.
|
||||
|
||||
// Build the set of methods we can see.
|
||||
ResultBuilder Results(*this);
|
||||
Results.EnterNewScope();
|
||||
|
||||
ObjCInterfaceDecl *CDecl = OCOPT->getInterfaceDecl();
|
||||
if (!CDecl)
|
||||
return;
|
||||
|
||||
AddObjCMethods(CDecl, true, CurContext, Results);
|
||||
// Handle messages to Class. This really isn't a message to an instance
|
||||
// method, so we treat it the same way we would treat a message send to a
|
||||
// class method.
|
||||
if (ReceiverType->isObjCClassType() ||
|
||||
ReceiverType->isObjCQualifiedClassType()) {
|
||||
if (ObjCMethodDecl *CurMethod = getCurMethodDecl()) {
|
||||
if (ObjCInterfaceDecl *ClassDecl = CurMethod->getClassInterface())
|
||||
AddObjCMethods(ClassDecl, false, CurContext, Results);
|
||||
}
|
||||
}
|
||||
// Handle messages to a qualified ID ("id<foo>").
|
||||
else if (const ObjCObjectPointerType *QualID
|
||||
= ReceiverType->getAsObjCQualifiedIdType()) {
|
||||
// Search protocols for instance methods.
|
||||
for (ObjCObjectPointerType::qual_iterator I = QualID->qual_begin(),
|
||||
E = QualID->qual_end();
|
||||
I != E; ++I)
|
||||
AddObjCMethods(*I, true, CurContext, Results);
|
||||
}
|
||||
// Handle messages to a pointer to interface type.
|
||||
else if (const ObjCObjectPointerType *IFacePtr
|
||||
= ReceiverType->getAsObjCInterfacePointerType()) {
|
||||
// Search the class, its superclasses, etc., for instance methods.
|
||||
AddObjCMethods(IFacePtr->getInterfaceDecl(), true, CurContext, Results);
|
||||
|
||||
// Search protocols for instance methods.
|
||||
for (ObjCObjectPointerType::qual_iterator I = IFacePtr->qual_begin(),
|
||||
E = IFacePtr->qual_end();
|
||||
I != E; ++I)
|
||||
AddObjCMethods(*I, true, CurContext, Results);
|
||||
}
|
||||
|
||||
Results.ExitScope();
|
||||
|
||||
// This also suppresses remaining diagnostics.
|
||||
HandleCodeCompleteResults(this, CodeCompleter, Results.data(),Results.size());
|
||||
}
|
||||
|
|
|
@ -74,6 +74,14 @@ void test_super_var(MySubClass *super) {
|
|||
[super MyInstMethod: super second:super];
|
||||
}
|
||||
|
||||
@protocol FooTestProtocol2
|
||||
- (int)secondProtocolInstanceMethod;
|
||||
@end
|
||||
|
||||
void test_qual_id(id<FooTestProtocol,FooTestProtocol2> ptr) {
|
||||
[ptr protocolInstanceMethod:1];
|
||||
}
|
||||
|
||||
// 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)a}{Text withKeyword:}{Placeholder (int)b}
|
||||
|
@ -93,4 +101,7 @@ void test_super_var(MySubClass *super) {
|
|||
// RUN: c-index-test -code-completion-at=%s:74:9 %s | FileCheck -check-prefix=CHECK-CC5 %s
|
||||
// CHECK-CC5: ObjCInstanceMethodDecl:{TypedText MyInstMethod:}{Placeholder (id)x}{Text second:}{Placeholder (id)y}
|
||||
// CHECK-CC5: ObjCInstanceMethodDecl:{TypedText MySubInstMethod}
|
||||
// RUN: c-index-test -code-completion-at=%s:82:8 %s | FileCheck -check-prefix=CHECK-CC6 %s
|
||||
// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText protocolInstanceMethod:}{Placeholder (int)value}
|
||||
// CHECK-CC6: ObjCInstanceMethodDecl:{TypedText secondProtocolInstanceMethod}
|
||||
|
||||
|
|
Loading…
Reference in New Issue