[PATCH] D54579: [clang-tidy] Update checks to play nicely with limited traversal scope added in r346847
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 15 06:26:48 PST 2018
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added subscribers: cfe-commits, xazax.hun.
(See https://reviews.llvm.org/D54204 for original review)
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D54579
Files:
clang-tidy/misc/UnusedParametersCheck.cpp
clang-tidy/modernize/LoopConvertCheck.cpp
clang-tidy/modernize/LoopConvertUtils.h
clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tidy/readability/SimplifyBooleanExprCheck.h
Index: clang-tidy/readability/SimplifyBooleanExprCheck.h
===================================================================
--- clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -79,6 +79,7 @@
SourceLocation Loc, StringRef Description,
SourceRange ReplacementRange, StringRef Replacement);
+ bool MatchedOnce = false;
const bool ChainedConditionalReturn;
const bool ChainedConditionalAssignment;
};
Index: clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===================================================================
--- clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -507,8 +507,15 @@
ChainedConditionalAssignment);
}
+// This is a silly hack to let us run a RecursiveASTVisitor on the Context.
+AST_MATCHER_P(Decl, matchOnce, bool *, Matched) {
+ if (*Matched)
+ return false;
+ return *Matched = true;
+}
+
void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(translationUnitDecl().bind("top"), this);
+ Finder->addMatcher(matchOnce(&MatchedOnce), this);
matchBoolCondition(Finder, true, ConditionThenStmtId);
matchBoolCondition(Finder, false, ConditionElseStmtId);
@@ -556,8 +563,8 @@
else if (const auto *Compound =
Result.Nodes.getNodeAs<CompoundStmt>(CompoundNotBoolId))
replaceCompoundReturnWithCondition(Result, Compound, true);
- else if (const auto TU = Result.Nodes.getNodeAs<Decl>("top"))
- Visitor(this, Result).TraverseDecl(const_cast<Decl*>(TU));
+ else // MatchOnce matcher
+ Visitor(this, Result).TraverseAST(*Result.Context);
}
void SimplifyBooleanExprCheck::issueDiag(
Index: clang-tidy/modernize/LoopConvertUtils.h
===================================================================
--- clang-tidy/modernize/LoopConvertUtils.h
+++ clang-tidy/modernize/LoopConvertUtils.h
@@ -59,9 +59,9 @@
/// \brief Run the analysis on the TranslationUnitDecl.
///
/// In case we're running this analysis multiple times, don't repeat the work.
- void gatherAncestors(const clang::TranslationUnitDecl *T) {
+ void gatherAncestors(ASTContext &Ctx) {
if (StmtAncestors.empty())
- TraverseDecl(const_cast<clang::TranslationUnitDecl *>(T));
+ TraverseAST(Ctx);
}
/// Accessor for StmtAncestors.
Index: clang-tidy/modernize/LoopConvertCheck.cpp
===================================================================
--- clang-tidy/modernize/LoopConvertCheck.cpp
+++ clang-tidy/modernize/LoopConvertCheck.cpp
@@ -899,7 +899,7 @@
// variable declared inside the loop outside of it.
// FIXME: Determine when the external dependency isn't an expression converted
// by another loop.
- TUInfo->getParentFinder().gatherAncestors(Context->getTranslationUnitDecl());
+ TUInfo->getParentFinder().gatherAncestors(*Context);
DependencyFinderASTVisitor DependencyFinder(
&TUInfo->getParentFinder().getStmtToParentStmtMap(),
&TUInfo->getParentFinder().getDeclToParentStmtMap(),
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===================================================================
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -74,7 +74,7 @@
class UnusedParametersCheck::IndexerVisitor
: public RecursiveASTVisitor<IndexerVisitor> {
public:
- IndexerVisitor(TranslationUnitDecl *Top) { TraverseDecl(Top); }
+ IndexerVisitor(ASTContext &Ctx) { TraverseAST(Ctx); }
const std::unordered_set<const CallExpr *> &
getFnCalls(const FunctionDecl *Fn) {
@@ -136,8 +136,7 @@
auto MyDiag = diag(Param->getLocation(), "parameter %0 is unused") << Param;
if (!Indexer) {
- Indexer = llvm::make_unique<IndexerVisitor>(
- Result.Context->getTranslationUnitDecl());
+ Indexer = llvm::make_unique<IndexerVisitor>(*Result.Context);
}
// Comment out parameter name for non-local functions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54579.174200.patch
Type: text/x-patch
Size: 4013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181115/df4d1524/attachment-0001.bin>
More information about the cfe-commits
mailing list