diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2017-04-24 14:57:09 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2017-04-24 14:57:09 +0000 |
commit | c442dc17de9a8cd848cbf761c8f212f402a98b18 (patch) | |
tree | 152d7b767ce07cca692c461ee7c618834e3e74d9 /clang-tidy/utils | |
parent | 4c946c16297924c594e35d4b7758c579df02df9b (diff) |
Extend readability-container-size-empty to add comparisons to empty-state objects.
Patch by Josh Zimmerman.
git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@301185 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-tidy/utils')
-rw-r--r-- | clang-tidy/utils/ASTUtils.cpp | 16 | ||||
-rw-r--r-- | clang-tidy/utils/ASTUtils.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/clang-tidy/utils/ASTUtils.cpp b/clang-tidy/utils/ASTUtils.cpp index cedac4f5..eff45b5b 100644 --- a/clang-tidy/utils/ASTUtils.cpp +++ b/clang-tidy/utils/ASTUtils.cpp @@ -23,6 +23,22 @@ const FunctionDecl *getSurroundingFunction(ASTContext &Context, "function", match(stmt(hasAncestor(functionDecl().bind("function"))), Statement, Context)); } + +bool IsBinaryOrTernary(const Expr *E) { + const Expr *E_base = E->IgnoreImpCasts(); + if (clang::isa<clang::BinaryOperator>(E_base) || + clang::isa<clang::ConditionalOperator>(E_base)) { + return true; + } + + if (const auto *Operator = + clang::dyn_cast<clang::CXXOperatorCallExpr>(E_base)) { + return Operator->isInfixBinaryOp(); + } + + return false; +} + } // namespace utils } // namespace tidy } // namespace clang diff --git a/clang-tidy/utils/ASTUtils.h b/clang-tidy/utils/ASTUtils.h index 898ba9e6..7f753270 100644 --- a/clang-tidy/utils/ASTUtils.h +++ b/clang-tidy/utils/ASTUtils.h @@ -18,6 +18,8 @@ namespace utils { // Returns the (closest) Function declaration surrounding |Statement| or NULL. const FunctionDecl *getSurroundingFunction(ASTContext &Context, const Stmt &Statement); +// Determine whether Expr is a Binary or Ternary expression. +bool IsBinaryOrTernary(const Expr *E); } // namespace utils } // namespace tidy } // namespace clang |