]> granicus.if.org Git - clang/commitdiff
[index] Introduce 'ProtocolInterface' as part of SymbolPropertySet
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 26 Aug 2018 06:27:23 +0000 (06:27 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sun, 26 Aug 2018 06:27:23 +0000 (06:27 +0000)
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
lib/Index/IndexSymbol.cpp
test/Index/Core/external-source-symbol-attr.m
test/Index/Core/index-source.m

index 068796141df8bcf0e9ed28c69bfba3ebde1da4dc..8aaaa695456c402910cd5f063dde7b640498431d 100644 (file)
@@ -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.
 ///
index 03b55ffe8a4ecbf3964b8b2be1cf5b0563732aac..1cdc0984f780bcc099d304087a19d97603612413 100644 (file)
@@ -96,6 +96,9 @@ SymbolInfo index::getSymbolInfo(const Decl *D) {
   if (isFunctionLocalSymbol(D)) {
     Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
   }
+  if (isa<ObjCProtocolDecl>(D->getDeclContext())) {
+    Info.Properties |= (SymbolPropertySet)SymbolProperty::ProtocolInterface;
+  }
 
   if (const TagDecl *TD = dyn_cast<TagDecl>(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;
     }
   });
 }
index cdc52966977d17ea2aab3c843b9e682a87086ce0..41bb7a264ab3edf654c4898bd9fa452fb35ab63e 100644 (file)
@@ -87,7 +87,7 @@ void test2(I3 *i3, id<ExtProt2> 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 |
 }
index c319be63ab9eeed5db40f81b73b91bf93d0dfed3..ed616dbc9ae6e86c861dc1319357d779804ac2c5 100644 (file)
@@ -474,12 +474,12 @@ void testImplicitProperties(ImplicitProperties *c) {
 @end
 
 @protocol Prot3 // CHECK: [[@LINE]]:11 | protocol/ObjC | Prot3 | [[PROT3_USR:.*]] | <no-cgname> | 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<Prot3, Prot1> 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]]