]> granicus.if.org Git - clang/commitdiff
Move IgnoreParenCasts to be a method on Expr.
authorChris Lattner <sabre@nondot.org>
Wed, 13 Feb 2008 01:02:39 +0000 (01:02 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 13 Feb 2008 01:02:39 +0000 (01:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47040 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
Sema/SemaChecking.cpp
Sema/SemaUtil.h
include/clang/AST/Expr.h

index 00ff897ffb13b82d3161c1c9193ec7f5d8a4ca4a..c7a2005bc8f3ae52e7607edbad41cbcc92cf881f 100644 (file)
@@ -474,6 +474,23 @@ Expr* Expr::IgnoreParens() {
   return E;
 }
 
+/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
+/// or CastExprs or ImplicitCastExprs, returning their operand.
+Expr *Expr::IgnoreParenCasts() {
+  Expr *E = this;
+  while (true) {
+    if (ParenExpr *P = dyn_cast<ParenExpr>(E))
+      E = P->getSubExpr();
+    else if (CastExpr *P = dyn_cast<CastExpr>(E))
+      E = P->getSubExpr();
+    else if (ImplicitCastExpr *P = dyn_cast<ImplicitCastExpr>(E))
+      E = P->getSubExpr();
+    else
+      return E;
+  }
+}
+
+
 bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
   switch (getStmtClass()) {
   default:
index 76363c9dc0a358b90c67686ab20a4ba9e36b38fb..1dfb145db85c744a063ed0d9af5baccef0f24c4f 100644 (file)
@@ -88,7 +88,7 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) {
 /// CheckBuiltinCFStringArgument - Checks that the argument to the builtin
 /// CFString constructor is correct
 bool Sema::CheckBuiltinCFStringArgument(Expr* Arg) {
-  Arg = IgnoreParenCasts(Arg);
+  Arg = Arg->IgnoreParenCasts();
   
   StringLiteral *Literal = dyn_cast<StringLiteral>(Arg);
 
@@ -267,7 +267,7 @@ Sema::CheckPrintfArguments(CallExpr *TheCall, bool HasVAListArg,
     return;
   }
   
-  Expr *OrigFormatExpr = IgnoreParenCasts(TheCall->getArg(format_idx));
+  Expr *OrigFormatExpr = TheCall->getArg(format_idx)->IgnoreParenCasts();
   
   // CHECK: format string is not a string literal.
   // 
@@ -527,7 +527,7 @@ static DeclRefExpr* EvalAddr(Expr* E);
 void
 Sema::CheckReturnStackAddr(Expr *RetValExp, QualType lhsType,
                            SourceLocation ReturnLoc) {
-  
+   
   // Perform checking for returned stack addresses.
   if (lhsType->isPointerType()) {
     if (DeclRefExpr *DR = EvalAddr(RetValExp))
index 9be668bc54e3749451a1c07e9749600080513311..35452b18e6f145953d264925e0e3c0882c71687f 100644 (file)
 
 namespace clang {
 
-/// Utility method to plow through parenthesis and casts.
-static inline Expr* IgnoreParenCasts(Expr* E) {
-  while(true) {
-    if (ParenExpr* P = dyn_cast<ParenExpr>(E))
-      E = P->getSubExpr();
-    else if (CastExpr* P = dyn_cast<CastExpr>(E))
-      E = P->getSubExpr();
-    else if (ImplicitCastExpr* P = dyn_cast<ImplicitCastExpr>(E))
-      E = P->getSubExpr();
-    else
-      return E;
-  }
-}
-
 /// Utility method to determine if a CallExpr is a call to a builtin.
 static inline bool isCallBuiltin(CallExpr* cexp) {
-  Expr* sub = IgnoreParenCasts(cexp->getCallee());
+  Expr* sub = cexp->getCallee()->IgnoreParenCasts();
   
   if (DeclRefExpr* E = dyn_cast<DeclRefExpr>(sub))
     if (E->getDecl()->getIdentifier()->getBuiltinID() > 0)
index ae1ae6c644b73d5a66db4813494a708f87ce1d18..47f2269f48bee6af99ce9773abe5e2dc6152c67c 100644 (file)
@@ -116,11 +116,18 @@ public:
   ///  then this method recursively returns its subexpression, and so forth.
   ///  Otherwise, the method returns the current Expr.
   Expr* IgnoreParens();
+
+  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
+  /// or CastExprs or ImplicitCastExprs, returning their operand.
+  Expr *IgnoreParenCasts();
   
   const Expr* IgnoreParens() const {
     return const_cast<Expr*>(this)->IgnoreParens();
   }
-
+  const Expr *IgnoreParenCasts() const {
+    return const_cast<Expr*>(this)->IgnoreParenCasts();
+  }
+  
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() >= firstExprConstant &&
            T->getStmtClass() <= lastExprConstant;