r241561 - [libclang] Implement proper code-completion in an ObjC type parameter position.
Douglas Gregor
dgregor at apple.com
Mon Jul 6 23:20:36 PDT 2015
Author: dgregor
Date: Tue Jul 7 01:20:36 2015
New Revision: 241561
URL: http://llvm.org/viewvc/llvm-project?rev=241561&view=rev
Log:
[libclang] Implement proper code-completion in an ObjC type parameter position.
rdar://19670303
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/test/Index/complete-parameterized-classes.m
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=241561&r1=241560&r2=241561&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jul 7 01:20:36 2015
@@ -1942,6 +1942,10 @@ public:
Optional<ArrayRef<QualType>>
getObjCSubstitutions(const DeclContext *dc) const;
+ /// Determines if this is an ObjC interface type that may accept type
+ /// parameters.
+ bool acceptsObjCTypeParams() const;
+
const char *getTypeClassName() const;
QualType getCanonicalTypeInternal() const {
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=241561&r1=241560&r2=241561&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Jul 7 01:20:36 2015
@@ -1339,6 +1339,17 @@ Optional<ArrayRef<QualType>> Type::getOb
return objectType->getTypeArgs();
}
+bool Type::acceptsObjCTypeParams() const {
+ if (auto *IfaceT = getAsObjCInterfaceType()) {
+ if (auto *ID = IfaceT->getInterface()) {
+ if (ID->getTypeParamList())
+ return true;
+ }
+ }
+
+ return false;
+}
+
void ObjCObjectType::computeSuperClassTypeSlow() const {
// Retrieve the class declaration for this type. If there isn't one
// (e.g., this is some variant of "id" or "Class"), then there is no
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=241561&r1=241560&r2=241561&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Jul 7 01:20:36 2015
@@ -1658,8 +1658,13 @@ void Parser::parseObjCTypeArgsOrProtocol
identifierLocs[i]));
}
- Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs.data(),
- identifierLocPairs.size());
+ QualType BaseT = Actions.GetTypeFromParser(baseType);
+ if (!BaseT.isNull() && BaseT->acceptsObjCTypeParams()) {
+ Actions.CodeCompleteOrdinaryName(getCurScope(), Sema::PCC_Type);
+ } else {
+ Actions.CodeCompleteObjCProtocolReferences(identifierLocPairs.data(),
+ identifierLocPairs.size());
+ }
cutOffParsing();
return;
}
Modified: cfe/trunk/test/Index/complete-parameterized-classes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/complete-parameterized-classes.m?rev=241561&r1=241560&r2=241561&view=diff
==============================================================================
--- cfe/trunk/test/Index/complete-parameterized-classes.m (original)
+++ cfe/trunk/test/Index/complete-parameterized-classes.m Tue Jul 7 01:20:36 2015
@@ -37,6 +37,11 @@ void test2(Test *obj) {
-(id)getit:(id)val {}
@end
+void test3() {
+ Test<> t;
+ NSObject<> n;
+}
+
// RUN: c-index-test -code-completion-at=%s:25:8 %s | FileCheck -check-prefix=CHECK-CC0 %s
// CHECK-CC0: ObjCInstanceMethodDecl:{ResultType void}{TypedText apply2:}{Placeholder ^(MyClsA *, MyClsB *)block} (35)
// CHECK-CC0: ObjCInstanceMethodDecl:{ResultType void}{TypedText apply:}{Placeholder ^(MyClsA *, MyClsB *)block} (35)
@@ -64,3 +69,11 @@ void test2(Test *obj) {
// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text void}{RightParen )}{TypedText apply}{TypedText :}{LeftParen (}{Text void (^)(id, NSObject *)}{RightParen )}{Text block} (40)
// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text NSObject *}{RightParen )}{TypedText getit}{TypedText :}{LeftParen (}{Text id}{RightParen )}{Text val} (40)
// CHECK-CC6: ObjCInstanceMethodDecl:{LeftParen (}{Text id}{RightParen )}{TypedText prop} (40)
+
+// RUN: c-index-test -code-completion-at=%s:41:8 %s | FileCheck -check-prefix=CHECK-CC7 %s
+// CHECK-CC7: ObjCInterfaceDecl:{TypedText MyClsA}
+// RUN: c-index-test -code-completion-at=%s:42:12 %s > %t.out
+// RUN: FileCheck -input-file=%t.out -check-prefix=CHECK-CC8 %s
+// RUN: FileCheck -input-file=%t.out -check-prefix=CHECK-CC9 %s
+// CHECK-CC8: ObjCProtocolDecl:{TypedText NSObject}
+// CHECK-CC9-NOT: ObjCInterfaceDecl:{TypedText MyClsA}
More information about the cfe-commits
mailing list