Skip to content

Commit 1b1320b

Browse files
committed
[index] Thread through SymbolRoleSet as a generalization of "bool isRef"
As a first step toward having more detailed "role" information, thread through a SymbolRole bitset. For now it just contains the existing ref vs. definition status.
1 parent ce1a99a commit 1b1320b

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

include/swift/Index/IndexDataConsumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class IndexDataConsumer {
3535
virtual bool startSourceEntity(const IndexSymbol &symbol) = 0;
3636
virtual bool recordRelatedEntity(const IndexSymbol &symbol) = 0;
3737
virtual bool finishSourceEntity(SymbolKind kind, SymbolSubKind subKind,
38-
bool isRef) = 0;
38+
SymbolRoleSet roles) = 0;
3939
};
4040

4141
} // end namespace index

include/swift/Index/IndexSymbol.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define SWIFT_INDEX_INDEXSYMBOL_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "clang/Index/IndexSymbol.h"
1718
#include "llvm/ADT/SmallString.h"
1819

1920
namespace swift {
@@ -73,13 +74,16 @@ enum class SymbolSubKind {
7374
ExtensionOfProtocol,
7475
};
7576

77+
using SymbolRole = clang::index::SymbolRole;
78+
using SymbolRoleSet = clang::index::SymbolRoleSet;
79+
7680
struct IndexSymbol {
7781
enum TypeKind { Base, FuncDecl, CallReference };
7882
TypeKind entityType = Base;
7983

8084
SymbolKind kind;
8185
SymbolSubKind subKind = SymbolSubKind::None;
82-
bool isRef;
86+
SymbolRoleSet roles = SymbolRoleSet(0);
8387
// The following strings are guaranteed to live at least as long as the
8488
// current indexing action.
8589
StringRef name;

lib/Index/Index.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
8686
Decl *D;
8787
SymbolKind Kind;
8888
SymbolSubKind SubKind;
89-
bool IsRef;
89+
SymbolRoleSet Roles;
9090
};
9191
SmallVector<Entity, 6> EntitiesStack;
9292
SmallVector<Expr *, 8> ExprStack;
@@ -269,7 +269,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
269269
Entity CurrEnt = EntitiesStack.pop_back_val();
270270
assert(CurrEnt.Kind != SymbolKind::Unknown);
271271
if (!IdxConsumer.finishSourceEntity(CurrEnt.Kind, CurrEnt.SubKind,
272-
CurrEnt.IsRef)) {
272+
CurrEnt.Roles)) {
273273
Cancelled = true;
274274
return false;
275275
}
@@ -502,7 +502,7 @@ bool IndexSwiftASTWalker::startEntity(ValueDecl *D, const IndexSymbol &Info) {
502502
return false;
503503
}
504504

505-
EntitiesStack.push_back({D, Info.kind, Info.subKind, Info.isRef});
505+
EntitiesStack.push_back({D, Info.kind, Info.subKind, Info.roles});
506506
return true;
507507
}
508508

@@ -582,7 +582,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
582582
Cancelled = true;
583583
return false;
584584
}
585-
if (!IdxConsumer.finishSourceEntity(Info.kind, Info.subKind, Info.isRef)) {
585+
if (!IdxConsumer.finishSourceEntity(Info.kind, Info.subKind, Info.roles)) {
586586
Cancelled = true;
587587
return false;
588588
}
@@ -653,7 +653,7 @@ bool IndexSwiftASTWalker::reportExtension(ExtensionDecl *D) {
653653
if (Cancelled)
654654
return false;
655655

656-
EntitiesStack.push_back({D, Info.kind, Info.subKind, Info.isRef});
656+
EntitiesStack.push_back({D, Info.kind, Info.subKind, Info.roles});
657657
return true;
658658
}
659659

@@ -769,7 +769,10 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
769769
Info.subKind = getSubKindForAccessor(cast<FuncDecl>(D)->getAccessorKind());
770770
// Cannot be extension, which is not a ValueDecl.
771771

772-
Info.isRef = IsRef;
772+
if (IsRef)
773+
Info.roles |= (unsigned)SymbolRole::Reference;
774+
else
775+
Info.roles |= (unsigned)SymbolRole::Definition;
773776

774777
if (getNameAndUSR(D, Info.name, Info.USR))
775778
return true;

tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,18 @@ class SKIndexDataConsumer : public IndexDataConsumer {
8484
}
8585

8686
bool finishSourceEntity(SymbolKind kind, SymbolSubKind subKind,
87-
bool isRef) override {
87+
SymbolRoleSet roles) override {
88+
bool isRef = roles & (unsigned)SymbolRole::Reference;
8889
auto UID = SwiftLangSupport::getUIDForSymbol(kind, subKind, isRef);
8990
return impl.finishSourceEntity(UID);
9091
}
9192

9293
template <typename F>
9394
bool withEntityInfo(const IndexSymbol &symbol, F func) {
9495
auto initEntity = [](EntityInfo &info, const IndexSymbol &symbol) {
96+
bool isRef = symbol.roles & (unsigned)SymbolRole::Reference;
9597
info.Kind = SwiftLangSupport::getUIDForSymbol(symbol.kind, symbol.subKind,
96-
symbol.isRef);
98+
isRef);
9799
info.Name = symbol.name;
98100
info.USR = symbol.USR;
99101
info.Group = symbol.group;

tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ using namespace swift;
3939
using namespace swift::ide;
4040
using swift::index::SymbolKind;
4141
using swift::index::SymbolSubKind;
42+
using swift::index::SymbolRole;
43+
using swift::index::SymbolRoleSet;
4244

4345
static UIdent KindDeclFunctionFree("source.lang.swift.decl.function.free");
4446
static UIdent KindRefFunctionFree("source.lang.swift.ref.function.free");

0 commit comments

Comments
 (0)