summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2018-12-20 13:50:04 +0000
committerAlexander Kornienko <alexfh@google.com>2018-12-20 13:50:04 +0000
commit14706b9687ac3dff2e7493b8663f5350d6855617 (patch)
treed307e4acd2a8bbc9c3acaa00abb22f3fc1a63491
parent5f31de229fb3a9fdef9e0ace8a1330909f7347c1 (diff)
downloadbcm5719-llvm-14706b9687ac3dff2e7493b8663f5350d6855617.tar.gz
bcm5719-llvm-14706b9687ac3dff2e7493b8663f5350d6855617.zip
[clang-tidy] Use translationUnitDecl() instead of a custom matcher.
llvm-svn: 349758
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp22
-rw-r--r--clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h1
2 files changed, 5 insertions, 18 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
index b565a5fe0ad..51e8c4c894c 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -319,8 +319,6 @@ bool containsDiscardedTokens(const MatchFinder::MatchResult &Result,
} // namespace
class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor<Visitor> {
- using Base = RecursiveASTVisitor<Visitor>;
-
public:
Visitor(SimplifyBooleanExprCheck *Check,
const MatchFinder::MatchResult &Result)
@@ -507,16 +505,8 @@ 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(matchOnce(&MatchedOnce), this);
+ Finder->addMatcher(translationUnitDecl().bind("top"), this);
matchBoolCondition(Finder, true, ConditionThenStmtId);
matchBoolCondition(Finder, false, ConditionElseStmtId);
@@ -535,8 +525,10 @@ void SimplifyBooleanExprCheck::registerMatchers(MatchFinder *Finder) {
}
void SimplifyBooleanExprCheck::check(const MatchFinder::MatchResult &Result) {
- if (const CXXBoolLiteralExpr *TrueConditionRemoved =
- getBoolLiteral(Result, ConditionThenStmtId))
+ if (const auto *TU = Result.Nodes.getNodeAs<TranslationUnitDecl>("top"))
+ Visitor(this, Result).TraverseAST(*Result.Context);
+ else if (const CXXBoolLiteralExpr *TrueConditionRemoved =
+ getBoolLiteral(Result, ConditionThenStmtId))
replaceWithThenStatement(Result, TrueConditionRemoved);
else if (const CXXBoolLiteralExpr *FalseConditionRemoved =
getBoolLiteral(Result, ConditionElseStmtId))
@@ -564,10 +556,6 @@ void SimplifyBooleanExprCheck::check(const MatchFinder::MatchResult &Result) {
else if (const auto *Compound =
Result.Nodes.getNodeAs<CompoundStmt>(CompoundNotBoolId))
replaceCompoundReturnWithCondition(Result, Compound, true);
- else { // MatchOnce matcher
- assert(MatchedOnce);
- Visitor(this, Result).TraverseAST(*Result.Context);
- }
}
void SimplifyBooleanExprCheck::issueDiag(
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
index 14ac82de635..af47453f251 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.h
@@ -79,7 +79,6 @@ private:
SourceLocation Loc, StringRef Description,
SourceRange ReplacementRange, StringRef Replacement);
- bool MatchedOnce = false;
const bool ChainedConditionalReturn;
const bool ChainedConditionalAssignment;
};
OpenPOWER on IntegriCloud