Haojian Wu | ada2862 | 2016-10-17 08:33:59 +0000 | [diff] [blame] | 1 | //===---------- ASTUtils.cpp - clang-tidy ---------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "ASTUtils.h" |
| 11 | |
| 12 | #include "clang/ASTMatchers/ASTMatchFinder.h" |
| 13 | #include "clang/ASTMatchers/ASTMatchers.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace utils { |
| 18 | using namespace ast_matchers; |
| 19 | |
| 20 | const FunctionDecl *getSurroundingFunction(ASTContext &Context, |
| 21 | const Stmt &Statement) { |
| 22 | return selectFirst<const FunctionDecl>( |
| 23 | "function", match(stmt(hasAncestor(functionDecl().bind("function"))), |
| 24 | Statement, Context)); |
| 25 | } |
Aaron Ballman | 72163a9 | 2017-04-24 14:57:09 +0000 | [diff] [blame] | 26 | |
| 27 | bool IsBinaryOrTernary(const Expr *E) { |
| 28 | const Expr *E_base = E->IgnoreImpCasts(); |
| 29 | if (clang::isa<clang::BinaryOperator>(E_base) || |
| 30 | clang::isa<clang::ConditionalOperator>(E_base)) { |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | if (const auto *Operator = |
| 35 | clang::dyn_cast<clang::CXXOperatorCallExpr>(E_base)) { |
| 36 | return Operator->isInfixBinaryOp(); |
| 37 | } |
| 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
Haojian Wu | ada2862 | 2016-10-17 08:33:59 +0000 | [diff] [blame] | 42 | } // namespace utils |
| 43 | } // namespace tidy |
| 44 | } // namespace clang |