@@ -922,6 +922,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
922922 }
923923 bool reportPseudoAccessor (AbstractStorageDecl *D, AccessorKind AccKind,
924924 bool IsRef, SourceLoc Loc);
925+ bool reportIsDynamicRef (ValueDecl *D, IndexSymbol &Info);
925926
926927 bool finishCurrentEntity () {
927928 Entity CurrEnt = EntitiesStack.pop_back_val ();
@@ -1336,24 +1337,6 @@ bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet
13361337 return true ;
13371338}
13381339
1339- static bool isDynamicVarAccessorOrFunc (ValueDecl *D, SymbolInfo symInfo) {
1340- if (auto NTD = D->getDeclContext ()->getSelfNominalTypeDecl ()) {
1341- bool isClassOrProtocol = isa<ClassDecl>(NTD) || isa<ProtocolDecl>(NTD);
1342- bool isInternalAccessor =
1343- symInfo.SubKind == SymbolSubKind::SwiftAccessorWillSet ||
1344- symInfo.SubKind == SymbolSubKind::SwiftAccessorDidSet ||
1345- symInfo.SubKind == SymbolSubKind::SwiftAccessorAddressor ||
1346- symInfo.SubKind == SymbolSubKind::SwiftAccessorMutableAddressor;
1347- if (isClassOrProtocol &&
1348- symInfo.Kind != SymbolKind::StaticMethod &&
1349- !isInternalAccessor &&
1350- !D->isFinal ()) {
1351- return true ;
1352- }
1353- }
1354- return false ;
1355- }
1356-
13571340bool IndexSwiftASTWalker::reportPseudoAccessor (AbstractStorageDecl *D,
13581341 AccessorKind AccKind, bool IsRef,
13591342 SourceLoc Loc) {
@@ -1377,7 +1360,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
13771360 Info.symInfo .SubKind = getSubKindForAccessor (AccKind);
13781361 Info.roles |= (SymbolRoleSet)SymbolRole::Implicit;
13791362 Info.group = " " ;
1380- if (isDynamicVarAccessorOrFunc (D, Info. symInfo )) {
1363+ if (ide::isDeclOverridable (D )) {
13811364 Info.roles |= (SymbolRoleSet)SymbolRole::Dynamic;
13821365 }
13831366 return false ;
@@ -1569,6 +1552,27 @@ bool IndexSwiftASTWalker::reportRef(ValueDecl *D, SourceLoc Loc,
15691552 return finishCurrentEntity ();
15701553}
15711554
1555+ bool IndexSwiftASTWalker::reportIsDynamicRef (ValueDecl *D, IndexSymbol &Info) {
1556+ Expr *BaseE = ide::getBase (ExprStack);
1557+ if (!BaseE)
1558+ return false ;
1559+
1560+ if (!ide::isDynamicRef (BaseE, D))
1561+ return false ;
1562+
1563+ Info.roles |= (unsigned )SymbolRole::Dynamic;
1564+
1565+ SmallVector<NominalTypeDecl *, 1 > Types;
1566+ ide::getReceiverType (BaseE, Types);
1567+ for (auto *ReceiverTy : Types) {
1568+ if (addRelation (Info, (SymbolRoleSet) SymbolRole::RelationReceivedBy,
1569+ ReceiverTy))
1570+ return true ;
1571+ }
1572+
1573+ return false ;
1574+ }
1575+
15721576bool IndexSwiftASTWalker::reportImplicitConformance (ValueDecl *witness, ValueDecl *requirement,
15731577 Decl *container) {
15741578 if (!shouldIndex (witness, /* IsRef=*/ true ))
@@ -1658,7 +1662,7 @@ bool IndexSwiftASTWalker::initFuncDeclIndexSymbol(FuncDecl *D,
16581662 if (initIndexSymbol (D, D->getLoc (/* SerializedOK*/ false ), /* IsRef=*/ false , Info))
16591663 return true ;
16601664
1661- if (isDynamicVarAccessorOrFunc (D, Info. symInfo )) {
1665+ if (ide::isDeclOverridable (D )) {
16621666 Info.roles |= (SymbolRoleSet)SymbolRole::Dynamic;
16631667 }
16641668
@@ -1702,20 +1706,9 @@ bool IndexSwiftASTWalker::initFuncRefIndexSymbol(ValueDecl *D, SourceLoc Loc,
17021706 return true ;
17031707 }
17041708
1705- Expr *BaseE = ide::getBase (ExprStack);
1706- if (!BaseE)
1707- return false ;
1708-
1709- if (ide::isDynamicCall (BaseE, D))
1710- Info.roles |= (unsigned )SymbolRole::Dynamic;
1709+ if (reportIsDynamicRef (D, Info))
1710+ return true ;
17111711
1712- SmallVector<NominalTypeDecl *, 1 > Types;
1713- ide::getReceiverType (BaseE, Types);
1714- for (auto *ReceiverTy : Types) {
1715- if (addRelation (Info, (SymbolRoleSet) SymbolRole::RelationReceivedBy,
1716- ReceiverTy))
1717- return true ;
1718- }
17191712 return false ;
17201713}
17211714
@@ -1740,6 +1733,9 @@ bool IndexSwiftASTWalker::initVarRefIndexSymbols(Expr *CurrentE, ValueDecl *D,
17401733 Info.roles |= (unsigned )SymbolRole::Write;
17411734 }
17421735
1736+ if (reportIsDynamicRef (D, Info))
1737+ return true ;
1738+
17431739 return false ;
17441740}
17451741
0 commit comments