clang-tools  4.0.0
SimplifyBooleanExprCheck.h
Go to the documentation of this file.
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 
19 /// Looks for boolean expressions involving boolean constants and simplifies
20 /// them to use the appropriate boolean expression directly.
21 ///
22 /// For the user-facing documentation see:
23 /// http://clang.llvm.org/extra/clang-tidy/checks/readability-simplify-boolean-expr.html
25 public:
27 
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 
57  void matchCompoundIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
58  StringRef Id);
59 
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);
85 
86  void replaceCompoundReturnWithCondition(
87  const ast_matchers::MatchFinder::MatchResult &Result,
88  const CompoundStmt *Compound, bool Negated = false);
89 
90  void issueDiag(const ast_matchers::MatchFinder::MatchResult &Result,
91  SourceLocation Loc, StringRef Description,
92  SourceRange ReplacementRange, StringRef Replacement);
93 
94  const bool ChainedConditionalReturn;
95  const bool ChainedConditionalAssignment;
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
SourceLocation Loc
'#' location in the include directive
const std::string Name
Definition: USRFinder.cpp:164
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:262
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context)
std::map< std::string, std::string > OptionMap
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
ClangTidyContext & Context
Definition: ClangTidy.cpp:87
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
const NamedDecl * Result
Definition: USRFinder.cpp:162