From 1e8f9cd0c087fd7f52abacefe8d049639bbe6d09 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sun, 26 Aug 2018 06:27:23 +0000 Subject: [PATCH] [index] Introduce 'ProtocolInterface' as part of SymbolPropertySet This is useful to directly infer that a method or property is from a protocol interface at the point of the symbol occurrences. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@340696 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Index/IndexSymbol.h | 6 ++++-- lib/Index/IndexSymbol.cpp | 5 +++++ test/Index/Core/external-source-symbol-attr.m | 2 +- test/Index/Core/index-source.m | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/clang/Index/IndexSymbol.h b/include/clang/Index/IndexSymbol.h index 068796141d..8aaaa69545 100644 --- a/include/clang/Index/IndexSymbol.h +++ b/include/clang/Index/IndexSymbol.h @@ -75,7 +75,7 @@ enum class SymbolSubKind : uint8_t { UsingValue, }; -typedef uint8_t SymbolPropertySet; +typedef uint16_t SymbolPropertySet; /// Set of properties that provide additional info about a symbol. enum class SymbolProperty : SymbolPropertySet { Generic = 1 << 0, @@ -86,8 +86,10 @@ enum class SymbolProperty : SymbolPropertySet { IBOutletCollection = 1 << 5, GKInspectable = 1 << 6, Local = 1 << 7, + /// Symbol is part of a protocol interface. + ProtocolInterface = 1 << 8, }; -static const unsigned SymbolPropertyBitNum = 8; +static const unsigned SymbolPropertyBitNum = 9; /// Set of roles that are attributed to symbol occurrences. /// diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 03b55ffe8a..1cdc0984f7 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -96,6 +96,9 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { if (isFunctionLocalSymbol(D)) { Info.Properties |= (SymbolPropertySet)SymbolProperty::Local; } + if (isa(D->getDeclContext())) { + Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface; + } if (const TagDecl *TD = dyn_cast(D)) { switch (TD->getTagKind()) { @@ -519,6 +522,7 @@ void index::applyForEachSymbolProperty(SymbolPropertySet Props, APPLY_FOR_PROPERTY(IBOutletCollection); APPLY_FOR_PROPERTY(GKInspectable); APPLY_FOR_PROPERTY(Local); + APPLY_FOR_PROPERTY(ProtocolInterface); #undef APPLY_FOR_PROPERTY } @@ -539,6 +543,7 @@ void index::printSymbolProperties(SymbolPropertySet Props, raw_ostream &OS) { case SymbolProperty::IBOutletCollection: OS << "IBColl"; break; case SymbolProperty::GKInspectable: OS << "GKI"; break; case SymbolProperty::Local: OS << "local"; break; + case SymbolProperty::ProtocolInterface: OS << "protocol"; break; } }); } diff --git a/test/Index/Core/external-source-symbol-attr.m b/test/Index/Core/external-source-symbol-attr.m index cdc5296697..41bb7a264a 100644 --- a/test/Index/Core/external-source-symbol-attr.m +++ b/test/Index/Core/external-source-symbol-attr.m @@ -87,7 +87,7 @@ void test2(I3 *i3, id prot2, SomeEnum some) { [i3 meth2]; // CHECK: [[@LINE-1]]:7 | instance-method/Swift | meth2 | c:@CM@modname@objc(cs)I3(im)meth2 | [prot2 meth]; - // CHECK: [[@LINE-1]]:10 | instance-method/Swift | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | + // CHECK: [[@LINE-1]]:10 | instance-method(protocol)/Swift | meth | c:@M@modname@objc(pl)ExtProt2(im)meth | some = SomeEnumFirst; // CHECK: [[@LINE-1]]:10 | enumerator/Swift | SomeEnumFirst | c:@M@modname@E@SomeEnum@SomeEnumFirst | } diff --git a/test/Index/Core/index-source.m b/test/Index/Core/index-source.m index c319be63ab..ed616dbc9a 100644 --- a/test/Index/Core/index-source.m +++ b/test/Index/Core/index-source.m @@ -474,12 +474,12 @@ void testImplicitProperties(ImplicitProperties *c) { @end @protocol Prot3 // CHECK: [[@LINE]]:11 | protocol/ObjC | Prot3 | [[PROT3_USR:.*]] | | Decl | --(void)meth; +-(void)meth; // CHECK: [[@LINE]]:8 | instance-method(protocol)/ObjC | meth | [[PROT3_meth_USR:.*]] | -[Prot3 meth] | Decl,Dyn,RelChild | @end void test_rec1() { id o1; - [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method/ObjC | meth | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3 + [o1 meth]; // CHECK: [[@LINE]]:7 | instance-method(protocol)/ObjC | meth | [[PROT3_meth_USR]] | {{.*}} | Ref,Call,Dyn,RelRec,RelCall,RelCont | rel: 3 // CHECK-NEXT: RelCall,RelCont | test_rec1 | // CHECK-NEXT: RelRec | Prot3 | [[PROT3_USR]] // CHECK-NEXT: RelRec | Prot1 | [[PROT1_USR]] -- 2.40.0