@@ -62,6 +62,8 @@ class SemaAnnotator : public ASTWalker {
62
62
bool passModulePathElements (ArrayRef<ImportDecl::AccessPathElement> Path,
63
63
const clang::Module *ClangMod);
64
64
65
+ bool passReference (ValueDecl *D, Type Ty, SourceLoc Loc, SourceRange Range,
66
+ ReferenceMetaData Data);
65
67
bool passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data);
66
68
bool passReference (ModuleEntity Mod, std::pair<Identifier, SourceLoc> IdLoc);
67
69
@@ -324,6 +326,32 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
324
326
return { false , nullptr };
325
327
return { false , E };
326
328
329
+ } else if (auto *KPE = dyn_cast<KeyPathExpr>(E)) {
330
+ for (auto &component : KPE->getComponents ()) {
331
+ switch (component.getKind ()) {
332
+ case KeyPathExpr::Component::Kind::Property:
333
+ case KeyPathExpr::Component::Kind::Subscript: {
334
+ auto *decl = component.getDeclRef ().getDecl ();
335
+ auto loc = component.getLoc ();
336
+ SourceRange range (loc, loc);
337
+ passReference (decl, component.getComponentType (), loc, range,
338
+ ReferenceMetaData (
339
+ (isa<SubscriptDecl>(decl)
340
+ ? SemaReferenceKind::SubscriptRef
341
+ : SemaReferenceKind::DeclMemberRef),
342
+ OpAccess));
343
+ break ;
344
+ }
345
+
346
+ case KeyPathExpr::Component::Kind::Invalid:
347
+ case KeyPathExpr::Component::Kind::UnresolvedProperty:
348
+ case KeyPathExpr::Component::Kind::UnresolvedSubscript:
349
+ case KeyPathExpr::Component::Kind::OptionalChain:
350
+ case KeyPathExpr::Component::Kind::OptionalWrap:
351
+ case KeyPathExpr::Component::Kind::OptionalForce:
352
+ break ;
353
+ }
354
+ }
327
355
} else if (auto *BinE = dyn_cast<BinaryExpr>(E)) {
328
356
// Visit in source order.
329
357
if (!BinE->getArg ()->getElement (0 )->walk (*this ))
@@ -459,31 +487,37 @@ bool SemaAnnotator::passSubscriptReference(ValueDecl *D, SourceLoc Loc,
459
487
460
488
bool SemaAnnotator::
461
489
passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data) {
490
+ return passReference (D, Ty, Loc.getBaseNameLoc (), Loc.getSourceRange (), Data);
491
+ }
492
+
493
+ bool SemaAnnotator::
494
+ passReference (ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range,
495
+ ReferenceMetaData Data) {
462
496
TypeDecl *CtorTyRef = nullptr ;
463
497
ExtensionDecl *ExtDecl = nullptr ;
464
498
465
499
if (auto *TD = dyn_cast<TypeDecl>(D)) {
466
- if (!CtorRefs.empty () && Loc .isValid ()) {
500
+ if (!CtorRefs.empty () && BaseNameLoc .isValid ()) {
467
501
Expr *Fn = CtorRefs.back ()->getFn ();
468
- if (Fn->getLoc () == Loc. getBaseNameLoc () ) {
502
+ if (Fn->getLoc () == BaseNameLoc ) {
469
503
D = extractDecl (Fn);
470
504
CtorTyRef = TD;
471
505
}
472
506
}
473
507
474
- if (!ExtDecls.empty () && Loc .isValid ()) {
508
+ if (!ExtDecls.empty () && BaseNameLoc .isValid ()) {
475
509
auto ExtTyLoc = ExtDecls.back ()->getExtendedTypeLoc ().getLoc ();
476
- if (ExtTyLoc.isValid () && ExtTyLoc == Loc. getBaseNameLoc () ) {
510
+ if (ExtTyLoc.isValid () && ExtTyLoc == BaseNameLoc ) {
477
511
ExtDecl = ExtDecls.back ();
478
512
}
479
513
}
480
514
}
481
515
482
- CharSourceRange Range =
516
+ CharSourceRange CharRange =
483
517
Lexer::getCharSourceRangeFromSourceRange (D->getASTContext ().SourceMgr ,
484
- Loc. getSourceRange () );
485
- bool Continue = SEWalker.visitDeclReference (D, Range , CtorTyRef, ExtDecl, Ty ,
486
- Data);
518
+ Range );
519
+ bool Continue = SEWalker.visitDeclReference (D, CharRange , CtorTyRef, ExtDecl,
520
+ Ty, Data);
487
521
if (!Continue)
488
522
Cancelled = true ;
489
523
return Continue;
0 commit comments