clang-tools 10.0.0

SimplifyBooleanExprCheck.h
Go to the documentation of this file.
1 //===--- SimplifyBooleanExpr.h clang-tidy -----------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
11
12 #include "../ClangTidyCheck.h"
13
14 namespace clang {
15 namespace tidy {
16 namespace readability {
17
18 /// Looks for boolean expressions involving boolean constants and simplifies
19 /// them to use the appropriate boolean expression directly.
20 ///
21 /// For the user-facing documentation see:
22 /// http://clang.llvm.org/extra/clang-tidy/checks/readability-simplify-boolean-expr.html
23 class SimplifyBooleanExprCheck : public ClangTidyCheck {
24 public:
25 SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context);
26
27 void storeOptions(ClangTidyOptions::OptionMap &Options) override;
28 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
30
31 private:
32 class Visitor;
33
34 void reportBinOp(const ast_matchers::MatchFinder::MatchResult &Result,
35 const BinaryOperator *Op);
36
37 void matchBoolCondition(ast_matchers::MatchFinder *Finder, bool Value,
38 StringRef BooleanId);
39
40 void matchTernaryResult(ast_matchers::MatchFinder *Finder, bool Value,
41 StringRef TernaryId);
42
43 void matchIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
44 StringRef Id);
45
46 void matchIfAssignsBool(ast_matchers::MatchFinder *Finder, bool Value,
47 StringRef Id);
48
49 void matchCompoundIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
50 StringRef Id);
51
52 void
53 replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult &Result,
54 const CXXBoolLiteralExpr *BoolLiteral);
55
56 void
57 replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult &Result,
58 const CXXBoolLiteralExpr *FalseConditionRemoved);
59
60 void
61 replaceWithCondition(const ast_matchers::MatchFinder::MatchResult &Result,
62 const ConditionalOperator *Ternary,
63 bool Negated = false);
64
65 void replaceWithReturnCondition(
66 const ast_matchers::MatchFinder::MatchResult &Result, const IfStmt *If,
67 bool Negated = false);
68
69 void
70 replaceWithAssignment(const ast_matchers::MatchFinder::MatchResult &Result,
71 const IfStmt *If, bool Negated = false);
72
73 void replaceCompoundReturnWithCondition(
74 const ast_matchers::MatchFinder::MatchResult &Result,
75 const CompoundStmt *Compound, bool Negated = false);
76
77 void issueDiag(const ast_matchers::MatchFinder::MatchResult &Result,
78 SourceLocation Loc, StringRef Description,
79 SourceRange ReplacementRange, StringRef Replacement);
80
81 const bool ChainedConditionalReturn;
82 const bool ChainedConditionalAssignment;
83 };
84
85 } // namespace readability
86 } // namespace tidy
87 } // namespace clang
88
89 #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:37
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:500
clang::tidy::readability::SimplifyBooleanExprCheck
Looks for boolean expressions involving boolean constants and simplifies them to use the appropriate ...
Definition: SimplifyBooleanExprCheck.h:23
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:184
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:525
clang::tidy::readability::SimplifyBooleanExprCheck::SimplifyBooleanExprCheck
SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context)
Definition: SimplifyBooleanExprCheck.cpp:337
clang::tidy::readability::SimplifyBooleanExprCheck::Visitor
Definition: SimplifyBooleanExprCheck.cpp:320
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang::tidy::readability::SimplifyBooleanExprCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: SimplifyBooleanExprCheck.cpp:506
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
Description
const char * Description
Definition: Dexp.cpp:257