From: Argyrios Kyrtzidis Date: Fri, 22 Apr 2016 07:21:16 +0000 (+0000) Subject: [index] Add SymbolSubKinds for ObjC IB annotations. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9a54e817f1647da0bc9b16c691bc4388a4a99e12;p=clang [index] Add SymbolSubKinds for ObjC IB annotations. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@267118 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Index/IndexSymbol.h b/include/clang/Index/IndexSymbol.h index bd19771a18..b0bc93e464 100644 --- a/include/clang/Index/IndexSymbol.h +++ b/include/clang/Index/IndexSymbol.h @@ -64,8 +64,10 @@ enum class SymbolSubKind : uint8_t { TemplatePartialSpecialization = 1 << 1, TemplateSpecialization = 1 << 2, UnitTest = 1 << 3, + IBAnnotated = 1 << 4, + IBOutletCollection = 1 << 5, }; -static const unsigned SymbolSubKindBitNum = 4; +static const unsigned SymbolSubKindBitNum = 6; typedef unsigned SymbolSubKindSet; /// Set of roles that are attributed to symbol occurrences. diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index ba83d0cdef..13a8452300 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -40,6 +40,15 @@ static bool isUnitTest(const ObjCMethodDecl *D) { return isUnitTestCase(D->getClassInterface()); } +static void checkForIBOutlets(const Decl *D, SymbolSubKindSet &SubKindSet) { + if (D->hasAttr()) { + SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; + } else if (D->hasAttr()) { + SubKindSet |= (unsigned)SymbolSubKind::IBAnnotated; + SubKindSet |= (unsigned)SymbolSubKind::IBOutletCollection; + } +} + SymbolInfo index::getSymbolInfo(const Decl *D) { assert(D); SymbolInfo Info; @@ -135,14 +144,18 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Lang = SymbolLanguage::ObjC; if (isUnitTest(cast(D))) Info.SubKinds |= (unsigned)SymbolSubKind::UnitTest; + if (D->hasAttr()) + Info.SubKinds |= (unsigned)SymbolSubKind::IBAnnotated; break; case Decl::ObjCProperty: Info.Kind = SymbolKind::InstanceProperty; Info.Lang = SymbolLanguage::ObjC; + checkForIBOutlets(D, Info.SubKinds); break; case Decl::ObjCIvar: Info.Kind = SymbolKind::Field; Info.Lang = SymbolLanguage::ObjC; + checkForIBOutlets(D, Info.SubKinds); break; case Decl::Namespace: Info.Kind = SymbolKind::Namespace; @@ -347,6 +360,8 @@ void index::applyForEachSymbolSubKind(SymbolSubKindSet SubKinds, APPLY_FOR_SUBKIND(TemplatePartialSpecialization); APPLY_FOR_SUBKIND(TemplateSpecialization); APPLY_FOR_SUBKIND(UnitTest); + APPLY_FOR_SUBKIND(IBAnnotated); + APPLY_FOR_SUBKIND(IBOutletCollection); #undef APPLY_FOR_SUBKIND } @@ -363,6 +378,8 @@ void index::printSymbolSubKinds(SymbolSubKindSet SubKinds, raw_ostream &OS) { case SymbolSubKind::TemplatePartialSpecialization: OS << "TPS"; break; case SymbolSubKind::TemplateSpecialization: OS << "TS"; break; case SymbolSubKind::UnitTest: OS << "test"; break; + case SymbolSubKind::IBAnnotated: OS << "IB"; break; + case SymbolSubKind::IBOutletCollection: OS << "IBColl"; break; } }); } diff --git a/test/Index/Core/index-subkinds.m b/test/Index/Core/index-subkinds.m index a78e1235a3..e668d84ffa 100644 --- a/test/Index/Core/index-subkinds.m +++ b/test/Index/Core/index-subkinds.m @@ -34,3 +34,15 @@ // CHECK: [[@LINE+1]]:1 | instance-method(test)/ObjC | testInCat | c:objc(cs)MyTestCase(im)testInCat | -[MyTestCase(cat) testInCat] | Def,Dyn,RelChild | rel: 1 - (void)testInCat {} @end + + +@class NSButton; +@interface IBCls +// CHECK: [[@LINE+2]]:34 | instance-method/ObjC | prop | c:objc(cs)IBCls(im)prop | -[IBCls prop] | Decl,Dyn,RelChild | rel: 1 +// CHECK: [[@LINE+1]]:34 | instance-property(IB)/ObjC | prop | c:objc(cs)IBCls(py)prop | | Decl,RelChild | rel: 1 +@property (readonly) IBOutlet id prop; +// CHECK: [[@LINE+1]]:54 | instance-property(IB,IBColl)/ObjC | propColl | c:objc(cs)IBCls(py)propColl | | Decl,RelChild | rel: 1 +@property (readonly) IBOutletCollection(NSButton) id propColl; +// CHECK: [[@LINE+1]]:1 | instance-method(IB)/ObjC | doIt | c:objc(cs)IBCls(im)doIt | -[IBCls doIt] | Decl,Dyn,RelChild | rel: 1 +-(IBAction)doIt; +@end