Skip to content

Commit 8c45e20

Browse files
author
Nathan Hawes
committed
[indexer] Add relations to IndexSymbol add a -print-indexed-symbols option to swift-ide-test for testing
1 parent 7f582c4 commit 8c45e20

File tree

7 files changed

+549
-183
lines changed

7 files changed

+549
-183
lines changed

include/swift/Index/IndexDataConsumer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class IndexDataConsumer {
2222
virtual void anchor();
2323

2424
public:
25+
enum Action {Skip, Abort, Continue};
26+
2527
virtual ~IndexDataConsumer() {}
2628

2729
virtual void failed(StringRef error) = 0;
@@ -32,8 +34,7 @@ class IndexDataConsumer {
3234
virtual bool startDependency(SymbolKind kind, StringRef name, StringRef path,
3335
bool isSystem, StringRef hash) = 0;
3436
virtual bool finishDependency(SymbolKind kind) = 0;
35-
virtual bool startSourceEntity(const IndexSymbol &symbol) = 0;
36-
virtual bool recordRelatedEntity(const IndexSymbol &symbol) = 0;
37+
virtual Action startSourceEntity(const IndexSymbol &symbol) = 0;
3738
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKindSet subKinds,
3839
SymbolRoleSet roles) = 0;
3940

include/swift/Index/IndexSymbol.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,38 @@ inline SymbolSubKindSet &operator|=(SymbolSubKindSet &SKSet, SymbolSubKind SK) {
9292
using SymbolRole = clang::index::SymbolRole;
9393
using SymbolRoleSet = clang::index::SymbolRoleSet;
9494

95-
struct IndexSymbol {
95+
struct IndexRelation {
9696
const ValueDecl *decl;
9797
SymbolKind kind;
9898
SymbolSubKindSet subKinds = SymbolSubKindSet(0);
9999
SymbolRoleSet roles = SymbolRoleSet(0);
100+
100101
// The following strings are guaranteed to live at least as long as the
101102
// current indexing action.
102103
StringRef name;
103104
StringRef USR; // USR may be safely compared by pointer.
104105
StringRef group;
105-
StringRef receiverUSR;
106+
107+
IndexRelation(SymbolRoleSet Roles, const ValueDecl *Sym, SymbolKind Kind, SymbolSubKindSet SubKinds, StringRef Name, StringRef USR)
108+
: decl(Sym), kind(Kind), subKinds(SubKinds), roles(Roles), name(Name), USR(USR) {}
109+
110+
IndexRelation() = default;
111+
};
112+
113+
struct IndexSymbol : IndexRelation {
114+
SmallVector<IndexRelation, 3> Relations;
106115
unsigned line = 0;
107116
unsigned column = 0;
108117

109118
IndexSymbol() = default;
119+
120+
StringRef getReceiverUSR() const {
121+
for(auto Relation: Relations) {
122+
if (Relation.roles & (SymbolRoleSet) SymbolRole::RelationReceivedBy)
123+
return Relation.USR;
124+
}
125+
return StringRef();
126+
}
110127
};
111128

112129
SymbolKind getSymbolKindForDecl(const Decl *D);

0 commit comments

Comments
 (0)