Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:22

0001 //===--- SimplifyBooleanExpr.h clang-tidy -----------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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 /// Looks for boolean expressions involving boolean constants and simplifies
0017 /// them to use the appropriate boolean expression directly.
0018 ///
0019 /// For the user-facing documentation see:
0020 /// http://clang.llvm.org/extra/clang-tidy/checks/readability/simplify-boolean-expr.html
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 } // namespace clang::tidy::readability
0077 
0078 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H