Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 1 | //===--- 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 | |
| 20 | namespace clang { |
| 21 | |
| 22 | /// Utility method to plow through parentheses to get the first nested |
| 23 | /// non-ParenExpr expr. |
| 24 | static 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. |
| 32 | static 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 Lattner | 998568f | 2007-12-28 05:38:24 +0000 | [diff] [blame] | 41 | return E; |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 42 | } |
Ted Kremenek | 588e5eb | 2007-11-25 00:58:00 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | /// Utility method to determine if a CallExpr is a call to a builtin. |
| 46 | static 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 |