blob: 2932862e91f68e5c96f4ce425f4bcc51cd39c42c [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//
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
41 break;
42 }
43
44 return E;
45}
46
47/// Utility method to determine if a CallExpr is a call to a builtin.
48static inline bool isCallBuiltin(CallExpr* cexp) {
49 Expr* sub = IgnoreParenCasts(cexp->getCallee());
50
51 if (DeclRefExpr* E = dyn_cast<DeclRefExpr>(sub))
52 if (E->getDecl()->getIdentifier()->getBuiltinID() > 0)
53 return true;
54
55 return false;
56}
57
58} // end namespace clang
59
60#endif