SourceEntityWalker: Add a parameter to visitDeclReference() describing the kind of the reference under visit. NFC

This commit is contained in:
Xi Ge
2016-12-20 14:29:12 -08:00
parent dbefa60605
commit 14f968a5ed
10 changed files with 66 additions and 33 deletions

View File

@@ -60,7 +60,7 @@ private:
bool passModulePathElements(ArrayRef<ImportDecl::AccessPathElement> Path,
const clang::Module *ClangMod);
bool passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc);
bool passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, SemaReferenceKind Kind);
bool passReference(ModuleEntity Mod, std::pair<Identifier, SourceLoc> IdLoc);
bool passSubscriptReference(ValueDecl *D, SourceLoc Loc, bool IsOpenBracket);
@@ -211,7 +211,8 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
std::make_pair(module->getName(), E->getLoc())))
return { false, nullptr };
} else if (!passReference(DRE->getDecl(), DRE->getType(),
DRE->getNameLoc())) {
DRE->getNameLoc(),
SemaReferenceKind::DeclRef)) {
return { false, nullptr };
}
} else if (MemberRefExpr *MRE = dyn_cast<MemberRefExpr>(E)) {
@@ -219,7 +220,7 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
if (!MRE->getBase()->walk(*this))
return { false, nullptr };
if (!passReference(MRE->getMember().getDecl(), MRE->getType(),
MRE->getNameLoc()))
MRE->getNameLoc(), SemaReferenceKind::DeclMemberRef))
return { false, nullptr };
// We already visited the children.
@@ -229,7 +230,8 @@ std::pair<bool, Expr *> SemaAnnotator::walkToExprPre(Expr *E) {
} else if (auto OtherCtorE = dyn_cast<OtherConstructorDeclRefExpr>(E)) {
if (!passReference(OtherCtorE->getDecl(), OtherCtorE->getType(),
OtherCtorE->getConstructorLoc()))
OtherCtorE->getConstructorLoc(),
SemaReferenceKind::DeclConstructorRef))
return { false, nullptr };
} else if (SubscriptExpr *SE = dyn_cast<SubscriptExpr>(E)) {
@@ -293,7 +295,8 @@ bool SemaAnnotator::walkToTypeReprPre(TypeRepr *T) {
return passReference(ModD, std::make_pair(IdT->getIdentifier(),
IdT->getIdLoc()));
return passReference(VD, Type(), DeclNameLoc(IdT->getIdLoc()));
return passReference(VD, Type(), DeclNameLoc(IdT->getIdLoc()),
SemaReferenceKind::TypeRef);
}
}
return true;
@@ -323,7 +326,8 @@ std::pair<bool, Pattern *> SemaAnnotator::walkToPatternPre(Pattern *P) {
if (!Element)
return { true, P };
Type T = EP->hasType() ? EP->getType() : Type();
return { passReference(Element, T, DeclNameLoc(EP->getLoc())), P };
return { passReference(Element, T, DeclNameLoc(EP->getLoc()),
SemaReferenceKind::EnumElementRef), P };
}
auto *TP = dyn_cast<TypedPattern>(P);
@@ -353,7 +357,8 @@ bool SemaAnnotator::handleImports(ImportDecl *Import) {
auto Decls = Import->getDecls();
if (Decls.size() == 1) {
// FIXME: ImportDecl should store a DeclNameLoc.
if (!passReference(Decls.front(), Type(), DeclNameLoc(Import->getEndLoc())))
if (!passReference(Decls.front(), Type(), DeclNameLoc(Import->getEndLoc()),
SemaReferenceKind::DeclRef))
return false;
}
@@ -385,7 +390,8 @@ bool SemaAnnotator::passSubscriptReference(ValueDecl *D, SourceLoc Loc,
return Continue;
}
bool SemaAnnotator::passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc) {
bool SemaAnnotator::
passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, SemaReferenceKind Kind) {
TypeDecl *CtorTyRef = nullptr;
if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
@@ -401,7 +407,7 @@ bool SemaAnnotator::passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc) {
CharSourceRange Range =
Lexer::getCharSourceRangeFromSourceRange(D->getASTContext().SourceMgr,
Loc.getSourceRange());
bool Continue = SEWalker.visitDeclReference(D, Range, CtorTyRef, Ty);
bool Continue = SEWalker.visitDeclReference(D, Range, CtorTyRef, Ty, Kind);
if (!Continue)
Cancelled = true;
return Continue;
@@ -475,7 +481,8 @@ bool SourceEntityWalker::walk(DeclContext *DC) {
}
bool SourceEntityWalker::visitDeclReference(ValueDecl *D, CharSourceRange Range,
TypeDecl *CtorTyRef, Type T) {
TypeDecl *CtorTyRef, Type T,
SemaReferenceKind Kind) {
return true;
}
@@ -485,7 +492,8 @@ bool SourceEntityWalker::visitSubscriptReference(ValueDecl *D,
// Most of the clients treat subscript reference the same way as a
// regular reference when called on the open bracket and
// ignore the closing one.
return IsOpenBracket ? visitDeclReference(D, Range, nullptr, Type()) : true;
return IsOpenBracket ? visitDeclReference(D, Range, nullptr, Type(),
SemaReferenceKind::SubscriptRef) : true;
}
bool SourceEntityWalker::visitCallArgName(Identifier Name,