blob: eff45b5be14a0971125c2527d5f864a6aa321940 [file] [log] [blame]
Haojian Wuada28622016-10-17 08:33:59 +00001//===---------- 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
15namespace clang {
16namespace tidy {
17namespace utils {
18using namespace ast_matchers;
19
20const 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 Ballman72163a92017-04-24 14:57:09 +000026
27bool 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 Wuada28622016-10-17 08:33:59 +000042} // namespace utils
43} // namespace tidy
44} // namespace clang