Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 1 | //===--- SimplifyBooleanExpr.h clang-tidy -----------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H |
| 11 | #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H |
| 12 | |
| 13 | #include "../ClangTidy.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace readability { |
| 18 | |
Alexander Kornienko | f8ed0a8 | 2015-08-27 18:01:58 +0000 | [diff] [blame] | 19 | /// Looks for boolean expressions involving boolean constants and simplifies |
| 20 | /// them to use the appropriate boolean expression directly. |
Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 21 | /// |
Aaron Ballman | f034a8c | 2016-02-12 15:09:05 +0000 | [diff] [blame] | 22 | /// For the user-facing documentation see: |
| 23 | /// http://clang.llvm.org/extra/clang-tidy/checks/readability-simplify-boolean-expr.html |
Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 24 | class SimplifyBooleanExprCheck : public ClangTidyCheck { |
| 25 | public: |
Alexander Kornienko | fb3e2cd | 2015-05-17 12:31:12 +0000 | [diff] [blame] | 26 | SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context); |
| 27 | |
| 28 | void storeOptions(ClangTidyOptions::OptionMap &Options) override; |
Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 29 | void registerMatchers(ast_matchers::MatchFinder *Finder) override; |
| 30 | void check(const ast_matchers::MatchFinder::MatchResult &Result) override; |
| 31 | |
| 32 | private: |
| 33 | void matchBoolBinOpExpr(ast_matchers::MatchFinder *Finder, bool Value, |
| 34 | StringRef OperatorName, StringRef BooleanId); |
| 35 | |
| 36 | void matchExprBinOpBool(ast_matchers::MatchFinder *Finder, bool Value, |
| 37 | StringRef OperatorName, StringRef BooleanId); |
| 38 | |
| 39 | void matchBoolCompOpExpr(ast_matchers::MatchFinder *Finder, bool Value, |
| 40 | StringRef OperatorName, StringRef BooleanId); |
| 41 | |
| 42 | void matchExprCompOpBool(ast_matchers::MatchFinder *Finder, bool Value, |
| 43 | StringRef OperatorName, StringRef BooleanId); |
| 44 | |
| 45 | void matchBoolCondition(ast_matchers::MatchFinder *Finder, bool Value, |
| 46 | StringRef BooleanId); |
| 47 | |
| 48 | void matchTernaryResult(ast_matchers::MatchFinder *Finder, bool Value, |
| 49 | StringRef TernaryId); |
| 50 | |
| 51 | void matchIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value, |
| 52 | StringRef Id); |
| 53 | |
| 54 | void matchIfAssignsBool(ast_matchers::MatchFinder *Finder, bool Value, |
| 55 | StringRef Id); |
| 56 | |
Alexander Kornienko | 6ae400d | 2015-07-01 12:39:40 +0000 | [diff] [blame] | 57 | void matchCompoundIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value, |
| 58 | StringRef Id); |
| 59 | |
Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 60 | void |
| 61 | replaceWithExpression(const ast_matchers::MatchFinder::MatchResult &Result, |
| 62 | const CXXBoolLiteralExpr *BoolLiteral, bool UseLHS, |
| 63 | bool Negated = false); |
| 64 | |
| 65 | void |
| 66 | replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult &Result, |
| 67 | const CXXBoolLiteralExpr *BoolLiteral); |
| 68 | |
| 69 | void |
| 70 | replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult &Result, |
| 71 | const CXXBoolLiteralExpr *FalseConditionRemoved); |
| 72 | |
| 73 | void |
| 74 | replaceWithCondition(const ast_matchers::MatchFinder::MatchResult &Result, |
| 75 | const ConditionalOperator *Ternary, |
| 76 | bool Negated = false); |
| 77 | |
| 78 | void replaceWithReturnCondition( |
| 79 | const ast_matchers::MatchFinder::MatchResult &Result, const IfStmt *If, |
| 80 | bool Negated = false); |
| 81 | |
| 82 | void |
| 83 | replaceWithAssignment(const ast_matchers::MatchFinder::MatchResult &Result, |
| 84 | const IfStmt *If, bool Negated = false); |
Alexander Kornienko | fb3e2cd | 2015-05-17 12:31:12 +0000 | [diff] [blame] | 85 | |
Alexander Kornienko | 6ae400d | 2015-07-01 12:39:40 +0000 | [diff] [blame] | 86 | void replaceCompoundReturnWithCondition( |
| 87 | const ast_matchers::MatchFinder::MatchResult &Result, |
| 88 | const CompoundStmt *Compound, bool Negated = false); |
| 89 | |
Alexander Kornienko | 4f74ec0 | 2015-12-28 13:21:22 +0000 | [diff] [blame] | 90 | void issueDiag(const ast_matchers::MatchFinder::MatchResult &Result, |
| 91 | SourceLocation Loc, StringRef Description, |
| 92 | SourceRange ReplacementRange, StringRef Replacement); |
| 93 | |
Alexander Kornienko | fb3e2cd | 2015-05-17 12:31:12 +0000 | [diff] [blame] | 94 | const bool ChainedConditionalReturn; |
| 95 | const bool ChainedConditionalAssignment; |
Alexander Kornienko | f5e72b0 | 2015-04-10 19:26:43 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace readability |
| 99 | } // namespace tidy |
| 100 | } // namespace clang |
| 101 | |
| 102 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H |