2015-04-11 03:26:43 +08:00
|
|
|
//===--- SimplifyBooleanExpr.h clang-tidy -----------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace readability {
|
|
|
|
|
2015-08-28 02:01:58 +08:00
|
|
|
/// Looks for boolean expressions involving boolean constants and simplifies
|
|
|
|
/// them to use the appropriate boolean expression directly.
|
2015-04-11 03:26:43 +08:00
|
|
|
///
|
2016-02-12 23:09:05 +08:00
|
|
|
/// For the user-facing documentation see:
|
|
|
|
/// http://clang.llvm.org/extra/clang-tidy/checks/readability-simplify-boolean-expr.html
|
2015-04-11 03:26:43 +08:00
|
|
|
class SimplifyBooleanExprCheck : public ClangTidyCheck {
|
|
|
|
public:
|
2015-05-17 20:31:12 +08:00
|
|
|
SimplifyBooleanExprCheck(StringRef Name, ClangTidyContext *Context);
|
|
|
|
|
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Options) override;
|
2015-04-11 03:26:43 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
|
|
|
|
private:
|
2017-05-16 01:06:51 +08:00
|
|
|
class Visitor;
|
2015-04-11 03:26:43 +08:00
|
|
|
|
2017-05-16 01:06:51 +08:00
|
|
|
void reportBinOp(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const BinaryOperator *Op);
|
2015-04-11 03:26:43 +08:00
|
|
|
|
|
|
|
void matchBoolCondition(ast_matchers::MatchFinder *Finder, bool Value,
|
|
|
|
StringRef BooleanId);
|
|
|
|
|
|
|
|
void matchTernaryResult(ast_matchers::MatchFinder *Finder, bool Value,
|
|
|
|
StringRef TernaryId);
|
|
|
|
|
|
|
|
void matchIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
|
|
|
|
StringRef Id);
|
|
|
|
|
|
|
|
void matchIfAssignsBool(ast_matchers::MatchFinder *Finder, bool Value,
|
|
|
|
StringRef Id);
|
|
|
|
|
2015-07-01 20:39:40 +08:00
|
|
|
void matchCompoundIfReturnsBool(ast_matchers::MatchFinder *Finder, bool Value,
|
|
|
|
StringRef Id);
|
|
|
|
|
2015-04-11 03:26:43 +08:00
|
|
|
void
|
|
|
|
replaceWithThenStatement(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const CXXBoolLiteralExpr *BoolLiteral);
|
|
|
|
|
|
|
|
void
|
|
|
|
replaceWithElseStatement(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const CXXBoolLiteralExpr *FalseConditionRemoved);
|
|
|
|
|
|
|
|
void
|
|
|
|
replaceWithCondition(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const ConditionalOperator *Ternary,
|
|
|
|
bool Negated = false);
|
|
|
|
|
|
|
|
void replaceWithReturnCondition(
|
|
|
|
const ast_matchers::MatchFinder::MatchResult &Result, const IfStmt *If,
|
|
|
|
bool Negated = false);
|
|
|
|
|
|
|
|
void
|
|
|
|
replaceWithAssignment(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const IfStmt *If, bool Negated = false);
|
2015-05-17 20:31:12 +08:00
|
|
|
|
2015-07-01 20:39:40 +08:00
|
|
|
void replaceCompoundReturnWithCondition(
|
|
|
|
const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
const CompoundStmt *Compound, bool Negated = false);
|
|
|
|
|
2015-12-28 21:21:22 +08:00
|
|
|
void issueDiag(const ast_matchers::MatchFinder::MatchResult &Result,
|
|
|
|
SourceLocation Loc, StringRef Description,
|
|
|
|
SourceRange ReplacementRange, StringRef Replacement);
|
|
|
|
|
2015-05-17 20:31:12 +08:00
|
|
|
const bool ChainedConditionalReturn;
|
|
|
|
const bool ChainedConditionalAssignment;
|
2015-04-11 03:26:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace readability
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_SIMPLIFY_BOOLEAN_EXPR_H
|