Author: alexfh Date: Thu Dec 20 05:50:04 2018 New Revision: 349758 URL: http://llvm.org/viewvc/llvm-project?rev=349758&view=rev Log: [clang-tidy] Use translationUnitDecl() instead of a custom matcher.
Modified: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h Modified: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=349758&r1=349757&r2=349758&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp Thu Dec 20 05:50:04 2018 @@ -319,8 +319,6 @@ bool containsDiscardedTokens(const Match } // 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::storeOpti 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::registerM } 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(con 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( Modified: clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h?rev=349758&r1=349757&r2=349758&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h (original) +++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h Thu Dec 20 05:50:04 2018 @@ -79,7 +79,6 @@ private: SourceLocation Loc, StringRef Description, SourceRange ReplacementRange, StringRef Replacement); - bool MatchedOnce = false; const bool ChainedConditionalReturn; const bool ChainedConditionalAssignment; }; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits