blob: b167346fb49ee4fb22d5c7f3204abbc2f6bc3f7b [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//
5// This file was developed by Ted Kremenek and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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