blob: 1a15557fdfa27c4bf13c669af7e3c71a3c42fcdc [file] [log] [blame]
Ted Kremenek588e5eb2007-11-25 00:58:00 +00001//===--- SemaUtil.h - Utility functions for semantic analysis -------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-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 Kremenek588e5eb2007-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
22/// Utility method to plow through parentheses to get the first nested
23/// non-ParenExpr expr.
24static inline Expr* IgnoreParen(Expr* E) {
25 while (ParenExpr* P = dyn_cast<ParenExpr>(E))
26 E = P->getSubExpr();
27
28 return E;
29}
30
31/// Utility method to plow through parenthesis and casts.
32static inline Expr* IgnoreParenCasts(Expr* E) {
33 while(true) {
34 if (ParenExpr* P = dyn_cast<ParenExpr>(E))
35 E = P->getSubExpr();
36 else if (CastExpr* P = dyn_cast<CastExpr>(E))
37 E = P->getSubExpr();
38 else if (ImplicitCastExpr* P = dyn_cast<ImplicitCastExpr>(E))
39 E = P->getSubExpr();
40 else
Chris Lattner998568f2007-12-28 05:38:24 +000041 return E;
Ted Kremenek588e5eb2007-11-25 00:58:00 +000042 }
Ted Kremenek588e5eb2007-11-25 00:58:00 +000043}
44
45/// Utility method to determine if a CallExpr is a call to a builtin.
46static inline bool isCallBuiltin(CallExpr* cexp) {
47 Expr* sub = IgnoreParenCasts(cexp->getCallee());
48
49 if (DeclRefExpr* E = dyn_cast<DeclRefExpr>(sub))
50 if (E->getDecl()->getIdentifier()->getBuiltinID() > 0)
51 return true;
52
53 return false;
54}
55
56} // end namespace clang
57
58#endif