Skip to content

Commit cc777e5

Browse files
committed
[Index] Call updateInfo while constructing index symbols
This will allow us to inspect the updated symbol info to decided whether we should report access levels for a declaration.
1 parent ca0491a commit cc777e5

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

lib/Index/Index.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,12 +1108,19 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
11081108
/// Whether the given decl should be marked implicit in the index data.
11091109
bool hasImplicitRole(Decl *D);
11101110

1111-
bool initIndexSymbol(ValueDecl *D, SourceLoc Loc, bool IsRef,
1112-
IndexSymbol &Info);
1111+
bool initIndexSymbol(
1112+
ValueDecl *D, SourceLoc Loc, bool IsRef, IndexSymbol &Info,
1113+
llvm::function_ref<bool(IndexSymbol &)> updateInfo = [](IndexSymbol &) {
1114+
return false;
1115+
});
11131116
bool initIndexSymbol(ExtensionDecl *D, ValueDecl *ExtendedD, SourceLoc Loc,
11141117
IndexSymbol &Info);
11151118
bool initFuncDeclIndexSymbol(FuncDecl *D, IndexSymbol &Info);
1116-
bool initFuncRefIndexSymbol(ValueDecl *D, SourceLoc Loc, IndexSymbol &Info);
1119+
bool initFuncRefIndexSymbol(
1120+
ValueDecl *D, SourceLoc Loc, IndexSymbol &Info,
1121+
llvm::function_ref<bool(IndexSymbol &)> updateInfo = [](IndexSymbol &) {
1122+
return false;
1123+
});
11171124
bool initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D, SourceLoc Loc,
11181125
IndexSymbol &Info,
11191126
std::optional<AccessKind> AccKind);
@@ -1663,22 +1670,18 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
16631670
// AbstractStorageDecl.
16641671
assert(getParentDecl() == D);
16651672
auto PreviousTop = EntitiesStack.pop_back_val();
1666-
bool initFailed = initFuncRefIndexSymbol(D, Loc, Info);
1673+
bool initFailed = initFuncRefIndexSymbol(D, Loc, Info, updateInfo);
16671674
EntitiesStack.push_back(PreviousTop);
16681675

16691676
if (initFailed)
16701677
return true; // continue walking.
1671-
if (updateInfo(Info))
1672-
return true;
16731678

16741679
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles))
16751680
Cancelled = true;
16761681
} else {
16771682
IndexSymbol Info;
1678-
if (initIndexSymbol(D, Loc, IsRef, Info))
1683+
if (initIndexSymbol(D, Loc, IsRef, Info, updateInfo))
16791684
return true; // continue walking.
1680-
if (updateInfo(Info))
1681-
return true;
16821685
if (addRelation(Info, (SymbolRoleSet)SymbolRole::RelationAccessorOf |
16831686
(SymbolRoleSet)SymbolRole::RelationChildOf , D))
16841687
return true;
@@ -1929,8 +1932,9 @@ bool IndexSwiftASTWalker::hasImplicitRole(Decl *D) {
19291932
return false;
19301933
}
19311934

1932-
bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
1933-
bool IsRef, IndexSymbol &Info) {
1935+
bool IndexSwiftASTWalker::initIndexSymbol(
1936+
ValueDecl *D, SourceLoc Loc, bool IsRef, IndexSymbol &Info,
1937+
llvm::function_ref<bool(IndexSymbol &)> updateInfo) {
19341938
assert(D);
19351939

19361940
auto MappedLoc = getMappedLocation(Loc);
@@ -1970,6 +1974,10 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
19701974
Info.roles |= (unsigned)SymbolRole::Implicit;
19711975
}
19721976

1977+
if (updateInfo(Info)) {
1978+
return true;
1979+
}
1980+
19731981
return false;
19741982
}
19751983

@@ -2036,10 +2044,11 @@ bool IndexSwiftASTWalker::initFuncDeclIndexSymbol(FuncDecl *D,
20362044
return false;
20372045
}
20382046

2039-
bool IndexSwiftASTWalker::initFuncRefIndexSymbol(ValueDecl *D, SourceLoc Loc,
2040-
IndexSymbol &Info) {
2047+
bool IndexSwiftASTWalker::initFuncRefIndexSymbol(
2048+
ValueDecl *D, SourceLoc Loc, IndexSymbol &Info,
2049+
llvm::function_ref<bool(IndexSymbol &)> updateInfo) {
20412050

2042-
if (initIndexSymbol(D, Loc, /*IsRef=*/true, Info))
2051+
if (initIndexSymbol(D, Loc, /*IsRef=*/true, Info, updateInfo))
20432052
return true;
20442053

20452054
if (!isa<AbstractStorageDecl>(D) && !ide::isBeingCalled(ExprStack))

0 commit comments

Comments
 (0)