summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2018-11-15 15:06:11 +0000
committerSam McCall <sam.mccall@gmail.com>2018-11-15 15:06:11 +0000
commit35f3da1925f4f5ba5830108db44f053f917b7d55 (patch)
tree5a7e890047bfc7c6b7d319f09acc97f5467b8e7a /clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
parente98ec77a95a9045e47d13c9f5f0df7d912997026 (diff)
downloadbcm5719-llvm-35f3da1925f4f5ba5830108db44f053f917b7d55.tar.gz
bcm5719-llvm-35f3da1925f4f5ba5830108db44f053f917b7d55.zip
[clang-tidy] Update checks to play nicely with limited traversal scope added in r346847
Summary: (See D54204 for original review) Reviewers: hokein Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D54579 llvm-svn: 346961
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index 9420c6c3b87..3cb26532c83 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -507,8 +507,16 @@ void SimplifyBooleanExprCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
ChainedConditionalAssignment);
}
+// This is a silly hack to let us run a RecursiveASTVisitor on the Context.
+// We want to match exactly one node in the AST, doesn't matter which.
+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 +564,10 @@ void SimplifyBooleanExprCheck::check(const MatchFinder::MatchResult &Result) {
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
+ assert(MatchedOnce);
+ Visitor(this, Result).TraverseAST(*Result.Context);
+ }
}
void SimplifyBooleanExprCheck::issueDiag(
OpenPOWER on IntegriCloud