clang-tools 6.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
24 class SimplifyBooleanExprCheck : public ClangTidyCheck {
25 public:
26 SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context);
27
28 void storeOptions(ClangTidyOptions::OptionMap &Options) override;
29 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31
32 private:
33 class Visitor;
34
35 void reportBinOp(const ast_matchers::MatchFinder::MatchResult &Result,
36 const BinaryOperator *Op);
37
38 void matchBoolCondition(ast_matchers::MatchFinder *Finder, bool Value,
39 StringRef BooleanId);
40
41 void matchTernaryResult(ast_matchers::MatchFinder *Finder, bool Value,
42 StringRef TernaryId);
43
44 void matchIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
45 StringRef Id);
46
47 void matchIfAssignsBool(ast_matchers::MatchFinder *Finder, bool Value,
48 StringRef Id);
49
50 void matchCompoundIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
51 StringRef Id);
52
53 void
54 replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult &Result,
55 const CXXBoolLiteralExpr *BoolLiteral);
56
57 void
58 replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult &Result,
59 const CXXBoolLiteralExpr *FalseConditionRemoved);
60
61 void
62 replaceWithCondition(const ast_matchers::MatchFinder::MatchResult &Result,
63 const ConditionalOperator *Ternary,
64 bool Negated = false);
65
66 void replaceWithReturnCondition(
67 const ast_matchers::MatchFinder::MatchResult &Result, const IfStmt *If,
68 bool Negated = false);
69
70 void
71 replaceWithAssignment(const ast_matchers::MatchFinder::MatchResult &Result,
72 const IfStmt *If, bool Negated = false);
73
74 void replaceCompoundReturnWithCondition(
75 const ast_matchers::MatchFinder::MatchResult &Result,
76 const CompoundStmt *Compound, bool Negated = false);
77
78 void issueDiag(const ast_matchers::MatchFinder::MatchResult &Result,
79 SourceLocation Loc, StringRef Description,
80 SourceRange ReplacementRange, StringRef Replacement);
81
82 const bool ChainedConditionalReturn;
83 const bool ChainedConditionalAssignment;
84 };
85
86 } // namespace readability
87 } // namespace tidy
88 } // namespace clang
89
90 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
Loc
SourceLocation Loc
&#39;#&#39; location in the include directive
Definition: IncludeOrderCheck.cpp:36
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::readability::SimplifyBooleanExprCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Options) override
Should store all options supported by this check with their current values or default values for opti...
Definition: SimplifyBooleanExprCheck.cpp:501
clang::tidy::readability::SimplifyBooleanExprCheck
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Definition: SimplifyBooleanExprCheck.h:24
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidy.h:183
clang::tidy::readability::SimplifyBooleanExprCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: SimplifyBooleanExprCheck.cpp:526
clang::tidy::readability::SimplifyBooleanExprCheck::SimplifyBooleanExprCheck
SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context)
Definition: SimplifyBooleanExprCheck.cpp:337
clang::tidy::readability::SimplifyBooleanExprCheck::Visitor
Definition: SimplifyBooleanExprCheck.cpp:318
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang::tidy::readability::SimplifyBooleanExprCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: SimplifyBooleanExprCheck.cpp:507
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104