summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-13 17:28:01 +0000
committerChris Lattner <sabre@nondot.org>2009-03-13 17:28:01 +0000
commitef26c77c5608445b5a91f4ca8060edc994ae01c5 (patch)
tree3ba0a110dd68b7aebf08e5c00406a7a47e3da4bf /clang/lib/AST/Expr.cpp
parentdfab7abdea112331419512f0d16b369a60d9890d (diff)
downloadbcm5719-llvm-ef26c77c5608445b5a91f4ca8060edc994ae01c5.tar.gz
bcm5719-llvm-ef26c77c5608445b5a91f4ca8060edc994ae01c5.zip
add a helper function to strip noop casts.
llvm-svn: 66909
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index bd6bd298e9e..9612f7ff2af 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -796,6 +796,40 @@ Expr *Expr::IgnoreParenCasts() {
}
}
+/// IgnoreParenNoopCasts - Ignore parentheses and casts that do not change the
+/// value (including ptr->int casts of the same size). Strip off any
+/// ParenExpr or CastExprs, returning their operand.
+Expr *Expr::IgnoreParenNoopCasts(ASTContext &Ctx) {
+ Expr *E = this;
+ while (true) {
+ if (ParenExpr *P = dyn_cast<ParenExpr>(E)) {
+ E = P->getSubExpr();
+ continue;
+ }
+
+ if (CastExpr *P = dyn_cast<CastExpr>(E)) {
+ // We ignore integer <-> casts that are of the same width, ptr<->ptr and
+ // ptr<->int casts of the same width. We also ignore all identify casts.
+ Expr *SE = P->getSubExpr();
+
+ if (Ctx.hasSameUnqualifiedType(E->getType(), SE->getType())) {
+ E = SE;
+ continue;
+ }
+
+ if ((E->getType()->isPointerType() || E->getType()->isIntegralType()) &&
+ (SE->getType()->isPointerType() || SE->getType()->isIntegralType()) &&
+ Ctx.getTypeSize(E->getType()) == Ctx.getTypeSize(SE->getType())) {
+ E = SE;
+ continue;
+ }
+ }
+
+ return E;
+ }
+}
+
+
/// hasAnyTypeDependentArguments - Determines if any of the expressions
/// in Exprs is type-dependent.
bool Expr::hasAnyTypeDependentArguments(Expr** Exprs, unsigned NumExprs) {
OpenPOWER on IntegriCloud