File indexing completed on 2026-05-10 08:36:22
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
0011
0012 #include "../ClangTidyCheck.h"
0013
0014 namespace clang::tidy::readability {
0015
0016
0017
0018
0019
0020
0021 class SimplifyBooleanExprCheck : public ClangTidyCheck {
0022 public:
0023 SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context);
0024
0025 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0026 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0027 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0028 std::optional<TraversalKind> getCheckTraversalKind() const override {
0029 return TK_IgnoreUnlessSpelledInSource;
0030 }
0031
0032 private:
0033 class Visitor;
0034
0035 void reportBinOp(const ASTContext &Context, const BinaryOperator *Op);
0036
0037 void replaceWithThenStatement(const ASTContext &Context,
0038 const IfStmt *IfStatement,
0039 const Expr *BoolLiteral);
0040
0041 void replaceWithElseStatement(const ASTContext &Context,
0042 const IfStmt *IfStatement,
0043 const Expr *BoolLiteral);
0044
0045 void replaceWithCondition(const ASTContext &Context,
0046 const ConditionalOperator *Ternary, bool Negated);
0047
0048 void replaceWithReturnCondition(const ASTContext &Context, const IfStmt *If,
0049 const Expr *BoolLiteral, bool Negated);
0050
0051 void replaceWithAssignment(const ASTContext &Context, const IfStmt *If,
0052 const Expr *Var, SourceLocation Loc, bool Negated);
0053
0054 void replaceCompoundReturnWithCondition(const ASTContext &Context,
0055 const ReturnStmt *Ret, bool Negated,
0056 const IfStmt *If,
0057 const Expr *ThenReturn);
0058
0059 bool reportDeMorgan(const ASTContext &Context, const UnaryOperator *Outer,
0060 const BinaryOperator *Inner, bool TryOfferFix,
0061 const Stmt *Parent, const ParenExpr *Parens);
0062
0063 bool issueDiag(const ASTContext &Context, SourceLocation Loc,
0064 StringRef Description, SourceRange ReplacementRange,
0065 StringRef Replacement);
0066
0067 bool canBeBypassed(const Stmt *S) const;
0068
0069 const bool IgnoreMacros;
0070 const bool ChainedConditionalReturn;
0071 const bool ChainedConditionalAssignment;
0072 const bool SimplifyDeMorgan;
0073 const bool SimplifyDeMorganRelaxed;
0074 };
0075
0076 }
0077
0078 #endif