Skip to content

Commit 1ef1e2f

Browse files
committed
[Index] Apply RelationContainedBy role to references contained by VarDecl.
This reverts commit abf6a30.
1 parent 17f1cf9 commit 1ef1e2f

File tree

9 files changed

+701
-116
lines changed

9 files changed

+701
-116
lines changed

include/swift/IDE/SourceEntityWalker.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ class SourceEntityWalker {
8888
/// false, the remaining traversal is terminated and returns failure.
8989
virtual bool walkToDeclPost(Decl *D) { return true; }
9090

91+
/// This method is called in AST order, unlike \c walkToDecl* which are called
92+
/// in source order. It is guaranteed to be called in balance with its
93+
/// counterpart \c endBalancedASTOrderDeclVisit.
94+
virtual void beginBalancedASTOrderDeclVisit(Decl *D){};
95+
96+
/// This method is called after declaration visitation in AST order.
97+
virtual void endBalancedASTOrderDeclVisit(Decl *D){};
98+
9199
/// This method is called when first visiting a statement, before walking into
92100
/// its children. If it returns false, the subtree is skipped.
93101
virtual bool walkToStmtPre(Stmt *S) { return true; }
@@ -112,6 +120,15 @@ class SourceEntityWalker {
112120
/// returns false, the remaining traversal is terminated and returns failure.
113121
virtual bool walkToPatternPost(Pattern *P) { return true; }
114122

123+
/// This method is called when first visiting a type representation, before
124+
/// walking into its children. If it returns false, the subtree is skipped.
125+
virtual bool walkToTypeReprPre(TypeRepr *T) { return true; }
126+
127+
/// This method is called after visiting the children of a type
128+
/// representation. If it returns false, the remaining traversal is terminated
129+
/// and returns failure.
130+
virtual bool walkToTypeReprPost(TypeRepr *T) { return true; }
131+
115132
/// This method is called when a ValueDecl is referenced in source. If it
116133
/// returns false, the remaining traversal is terminated and returns failure.
117134
///

lib/IDE/SourceEntityWalker.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ class SemaAnnotator : public ASTWalker {
5555
return SEWalker.shouldWalkIntoGenericParams();
5656
}
5757
bool walkToDeclPre(Decl *D) override;
58+
bool walkToDeclPreProper(Decl *D);
5859
std::pair<bool, Expr *> walkToExprPre(Expr *E) override;
5960
bool walkToTypeReprPre(TypeRepr *T) override;
6061

6162
bool walkToDeclPost(Decl *D) override;
63+
bool walkToDeclPostProper(Decl *D);
6264
Expr *walkToExprPost(Expr *E) override;
6365
bool walkToTypeReprPost(TypeRepr *T) override;
6466

@@ -118,6 +120,21 @@ bool SemaAnnotator::walkToDeclPre(Decl *D) {
118120
return isa<PatternBindingDecl>(D);
119121
}
120122

123+
SEWalker.beginBalancedASTOrderDeclVisit(D);
124+
bool Continue = walkToDeclPreProper(D);
125+
126+
if (!Continue) {
127+
// To satisfy the contract of balanced calls to
128+
// begin/endBalancedASTOrderDeclVisit, we must call
129+
// endBalancedASTOrderDeclVisit here if walkToDeclPost isn't going to be
130+
// called.
131+
SEWalker.endBalancedASTOrderDeclVisit(D);
132+
}
133+
134+
return Continue;
135+
}
136+
137+
bool SemaAnnotator::walkToDeclPreProper(Decl *D) {
121138
if (!handleCustomAttributes(D)) {
122139
Cancelled = true;
123140
return false;
@@ -203,6 +220,12 @@ bool SemaAnnotator::walkToDeclPre(Decl *D) {
203220
}
204221

205222
bool SemaAnnotator::walkToDeclPost(Decl *D) {
223+
bool Continue = walkToDeclPostProper(D);
224+
SEWalker.endBalancedASTOrderDeclVisit(D);
225+
return Continue;
226+
}
227+
228+
bool SemaAnnotator::walkToDeclPostProper(Decl *D) {
206229
if (isDone())
207230
return false;
208231

@@ -580,6 +603,12 @@ bool SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
580603
if (isDone())
581604
return false;
582605

606+
bool Continue = SEWalker.walkToTypeReprPre(T);
607+
if (!Continue) {
608+
Cancelled = true;
609+
return false;
610+
}
611+
583612
if (auto IdT = dyn_cast<ComponentIdentTypeRepr>(T)) {
584613
if (ValueDecl *VD = IdT->getBoundDecl()) {
585614
if (auto *ModD = dyn_cast<ModuleDecl>(VD)) {
@@ -591,11 +620,19 @@ bool SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
591620
ReferenceMetaData(SemaReferenceKind::TypeRef, None));
592621
}
593622
}
623+
594624
return true;
595625
}
596626

597627
bool SemaAnnotator::walkToTypeReprPost(TypeRepr *T) {
598-
return !isDone();
628+
if (isDone()) {
629+
return false;
630+
}
631+
632+
bool Continue = SEWalker.walkToTypeReprPost(T);
633+
if (!Continue)
634+
Cancelled = true;
635+
return Continue;
599636
}
600637

601638
std::pair<bool, Pattern *> SemaAnnotator::walkToPatternPre(Pattern *P) {

0 commit comments

Comments
 (0)