@@ -182,22 +182,22 @@ class NodeFinder : ASTWalker {
182
182
DeclContextStack.push_back (newDC);
183
183
}
184
184
185
- if (D->getLoc () != LocToResolve) {
185
+ auto *VD = dyn_cast<ValueDecl>(D);
186
+ if (!VD)
186
187
return Action::Continue ();
187
- }
188
188
189
- if (auto VD = dyn_cast<ValueDecl>(D)) {
190
- // FIXME: ParamDecls might be closure parameters that can have ambiguous
191
- // types. The current infrastructure of just asking for the VD's type
192
- // doesn't work here. We need to inspect the constraints system solution.
193
- if (VD->hasName () && !isa<ParamDecl>(D)) {
194
- assert (Result == nullptr );
195
- Result = std::make_unique<NodeFinderDeclResult>(VD);
196
- return Action::Stop ();
197
- }
198
- }
189
+ // FIXME: ParamDecls might be closure parameters that can have ambiguous
190
+ // types. The current infrastructure of just asking for the VD's type
191
+ // doesn't work here. We need to inspect the constraints system solution.
192
+ if (isa<ParamDecl>(VD))
193
+ return Action::Continue ();
199
194
200
- return Action::Continue ();
195
+ if (!VD->hasName () || VD->getNameLoc () != LocToResolve)
196
+ return Action::Continue ();
197
+
198
+ assert (Result == nullptr );
199
+ Result = std::make_unique<NodeFinderDeclResult>(VD);
200
+ return Action::Stop ();
201
201
}
202
202
203
203
PostWalkAction walkToDeclPost (Decl *D) override {
@@ -208,6 +208,23 @@ class NodeFinder : ASTWalker {
208
208
return Action::Continue ();
209
209
}
210
210
211
+ // / Retrieve the name location for an expression that supports cursor info.
212
+ DeclNameLoc getExprNameLoc (Expr *E) {
213
+ if (auto *DRE = dyn_cast<DeclRefExpr>(E))
214
+ return DRE->getNameLoc ();
215
+
216
+ if (auto *UDRE = dyn_cast<UnresolvedDeclRefExpr>(E))
217
+ return UDRE->getNameLoc ();
218
+
219
+ if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(E))
220
+ return ODRE->getNameLoc ();
221
+
222
+ if (auto *UDE = dyn_cast<UnresolvedDotExpr>(E))
223
+ return UDE->getNameLoc ();
224
+
225
+ return DeclNameLoc ();
226
+ }
227
+
211
228
PreWalkResult<Expr *> walkToExprPre (Expr *E) override {
212
229
if (auto closure = dyn_cast<ClosureExpr>(E)) {
213
230
DeclContextStack.push_back (closure);
@@ -224,25 +241,13 @@ class NodeFinder : ASTWalker {
224
241
}
225
242
}
226
243
227
- if (E-> getLoc () != LocToResolve) {
244
+ if (getExprNameLoc (E). getBaseNameLoc () != LocToResolve)
228
245
return Action::Continue (E);
229
- }
230
246
231
- switch (E->getKind ()) {
232
- case ExprKind::DeclRef:
233
- case ExprKind::UnresolvedDot:
234
- case ExprKind::UnresolvedDeclRef:
235
- case ExprKind::OverloadedDeclRef: {
236
- assert (Result == nullptr );
237
- Result =
238
- std::make_unique<NodeFinderExprResult>(E, getCurrentDeclContext ());
239
- return Action::Stop ();
240
- }
241
- default :
242
- break ;
243
- }
244
-
245
- return Action::Continue (E);
247
+ assert (Result == nullptr );
248
+ Result =
249
+ std::make_unique<NodeFinderExprResult>(E, getCurrentDeclContext ());
250
+ return Action::Stop ();
246
251
}
247
252
248
253
PostWalkResult<Expr *> walkToExprPost (Expr *E) override {
0 commit comments