@@ -60,7 +60,7 @@ class SemaAnnotator : public ASTWalker {
6060 bool passModulePathElements (ArrayRef<ImportDecl::AccessPathElement> Path,
6161 const clang::Module *ClangMod);
6262
63- bool passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc);
63+ bool passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc, SemaReferenceKind Kind );
6464 bool passReference (ModuleEntity Mod, std::pair<Identifier, SourceLoc> IdLoc);
6565
6666 bool passSubscriptReference (ValueDecl *D, SourceLoc Loc, bool IsOpenBracket);
@@ -211,15 +211,16 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
211211 std::make_pair (module ->getName (), E->getLoc ())))
212212 return { false , nullptr };
213213 } else if (!passReference (DRE->getDecl (), DRE->getType (),
214- DRE->getNameLoc ())) {
214+ DRE->getNameLoc (),
215+ SemaReferenceKind::DeclRef)) {
215216 return { false , nullptr };
216217 }
217218 } else if (MemberRefExpr *MRE = dyn_cast<MemberRefExpr>(E)) {
218219 // Visit in source order.
219220 if (!MRE->getBase ()->walk (*this ))
220221 return { false , nullptr };
221222 if (!passReference (MRE->getMember ().getDecl (), MRE->getType (),
222- MRE->getNameLoc ()))
223+ MRE->getNameLoc (), SemaReferenceKind::DeclMemberRef ))
223224 return { false , nullptr };
224225
225226 // We already visited the children.
@@ -229,7 +230,8 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
229230
230231 } else if (auto OtherCtorE = dyn_cast<OtherConstructorDeclRefExpr>(E)) {
231232 if (!passReference (OtherCtorE->getDecl (), OtherCtorE->getType (),
232- OtherCtorE->getConstructorLoc ()))
233+ OtherCtorE->getConstructorLoc (),
234+ SemaReferenceKind::DeclConstructorRef))
233235 return { false , nullptr };
234236
235237 } else if (SubscriptExpr *SE = dyn_cast<SubscriptExpr>(E)) {
@@ -293,7 +295,8 @@ bool SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
293295 return passReference (ModD, std::make_pair (IdT->getIdentifier (),
294296 IdT->getIdLoc ()));
295297
296- return passReference (VD, Type (), DeclNameLoc (IdT->getIdLoc ()));
298+ return passReference (VD, Type (), DeclNameLoc (IdT->getIdLoc ()),
299+ SemaReferenceKind::TypeRef);
297300 }
298301 }
299302 return true ;
@@ -323,7 +326,8 @@ std::pair<bool, Pattern *> SemaAnnotator::walkToPatternPre(Pattern *P) {
323326 if (!Element)
324327 return { true , P };
325328 Type T = EP->hasType () ? EP->getType () : Type ();
326- return { passReference (Element, T, DeclNameLoc (EP->getLoc ())), P };
329+ return { passReference (Element, T, DeclNameLoc (EP->getLoc ()),
330+ SemaReferenceKind::EnumElementRef), P };
327331 }
328332
329333 auto *TP = dyn_cast<TypedPattern>(P);
@@ -353,7 +357,8 @@ bool SemaAnnotator::handleImports(ImportDecl *Import) {
353357 auto Decls = Import->getDecls ();
354358 if (Decls.size () == 1 ) {
355359 // FIXME: ImportDecl should store a DeclNameLoc.
356- if (!passReference (Decls.front (), Type (), DeclNameLoc (Import->getEndLoc ())))
360+ if (!passReference (Decls.front (), Type (), DeclNameLoc (Import->getEndLoc ()),
361+ SemaReferenceKind::DeclRef))
357362 return false ;
358363 }
359364
@@ -385,7 +390,8 @@ bool SemaAnnotator::passSubscriptReference(ValueDecl *D, SourceLoc Loc,
385390 return Continue;
386391}
387392
388- bool SemaAnnotator::passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc) {
393+ bool SemaAnnotator::
394+ passReference (ValueDecl *D, Type Ty, DeclNameLoc Loc, SemaReferenceKind Kind) {
389395 TypeDecl *CtorTyRef = nullptr ;
390396
391397 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
@@ -401,7 +407,7 @@ bool SemaAnnotator::passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc) {
401407 CharSourceRange Range =
402408 Lexer::getCharSourceRangeFromSourceRange (D->getASTContext ().SourceMgr ,
403409 Loc.getSourceRange ());
404- bool Continue = SEWalker.visitDeclReference (D, Range, CtorTyRef, Ty);
410+ bool Continue = SEWalker.visitDeclReference (D, Range, CtorTyRef, Ty, Kind );
405411 if (!Continue)
406412 Cancelled = true ;
407413 return Continue;
@@ -475,7 +481,8 @@ bool SourceEntityWalker::walk(DeclContext *DC) {
475481}
476482
477483bool SourceEntityWalker::visitDeclReference (ValueDecl *D, CharSourceRange Range,
478- TypeDecl *CtorTyRef, Type T) {
484+ TypeDecl *CtorTyRef, Type T,
485+ SemaReferenceKind Kind) {
479486 return true ;
480487}
481488
@@ -485,7 +492,8 @@ bool SourceEntityWalker::visitSubscriptReference(ValueDecl *D,
485492 // Most of the clients treat subscript reference the same way as a
486493 // regular reference when called on the open bracket and
487494 // ignore the closing one.
488- return IsOpenBracket ? visitDeclReference (D, Range, nullptr , Type ()) : true ;
495+ return IsOpenBracket ? visitDeclReference (D, Range, nullptr , Type (),
496+ SemaReferenceKind::SubscriptRef) : true ;
489497}
490498
491499bool SourceEntityWalker::visitCallArgName (Identifier Name,
0 commit comments