blob: 9be668bc54e3749451a1c07e9749600080513311 [file] [log] [blame]
Ted Kremenek30c66752007-11-25 00:58:00 +00001//===--- SemaUtil.h - Utility functions for semantic analysis -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Ted Kremenek30c66752007-11-25 00:58:00 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file provides a few static inline functions that are useful for
11// performing semantic analysis.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CLANG_SEMA_UTIL_H
16#define LLVM_CLANG_SEMA_UTIL_H
17
18#include "clang/AST/Expr.h"
19
20namespace clang {
21
Ted Kremenek30c66752007-11-25 00:58:00 +000022/// Utility method to plow through parenthesis and casts.
23static inline Expr* IgnoreParenCasts(Expr* E) {
24 while(true) {
25 if (ParenExpr* P = dyn_cast<ParenExpr>(E))
26 E = P->getSubExpr();
27 else if (CastExpr* P = dyn_cast<CastExpr>(E))
28 E = P->getSubExpr();
29 else if (ImplicitCastExpr* P = dyn_cast<ImplicitCastExpr>(E))
30 E = P->getSubExpr();
31 else
Chris Lattner3d5a8f32007-12-28 05:38:24 +000032 return E;
Ted Kremenek30c66752007-11-25 00:58:00 +000033 }
Ted Kremenek30c66752007-11-25 00:58:00 +000034}
35
36/// Utility method to determine if a CallExpr is a call to a builtin.
37static inline bool isCallBuiltin(CallExpr* cexp) {
38 Expr* sub = IgnoreParenCasts(cexp->getCallee());
39
40 if (DeclRefExpr* E = dyn_cast<DeclRefExpr>(sub))
41 if (E->getDecl()->getIdentifier()->getBuiltinID() > 0)
42 return true;
43
44 return false;
45}
46
47} // end namespace clang
48
49#endif