Skip to content

Commit

Permalink
[index] Introduce 'ProtocolInterface' as part of SymbolPropertySet
Browse files Browse the repository at this point in the history
This is useful to directly infer that a method or property is from a protocol interface
at the point of the symbol occurrences.

llvm-svn: 340696
  • Loading branch information
akyrtzi committed Aug 26, 2018
1 parent 4240ecb commit 7c3a12f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions clang/include/clang/Index/IndexSymbol.h
Expand Up @@ -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,
Expand All @@ -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.
///
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Index/IndexSymbol.cpp
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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;
}
});
}
2 changes: 1 addition & 1 deletion clang/test/Index/Core/external-source-symbol-attr.m
Expand Up @@ -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 |
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Index/Core/index-source.m
Expand Up @@ -474,12 +474,12 @@ - (void)test: (int)x :(int)y { // CHECK: [[@LINE]]:9 | instance-method/ObjC | te
@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]]
Expand Down

0 comments on commit 7c3a12f

Please sign in to comment.