]> granicus.if.org Git - clang/commitdiff
Added method Expr::IgnoreParens(), which returns the first non-ParenExpr Expr*.
authorTed Kremenek <kremenek@apple.com>
Thu, 17 Jan 2008 16:57:34 +0000 (16:57 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 17 Jan 2008 16:57:34 +0000 (16:57 +0000)
Refactored the use of this method into both the Sema module and Analysis module,
which were using their own static functions that did the same thing.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46129 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
Analysis/GRConstants.cpp
Sema/SemaChecking.cpp
Sema/SemaExpr.cpp
Sema/SemaUtil.h
include/clang/AST/Expr.h

index e2aa6ca405586d9d86dc145464a5eeaa37fa428a..0e1eecd7d79caeaf0aaf4c35bc162c96b13c026b 100644 (file)
@@ -439,6 +439,14 @@ bool Expr::hasStaticStorage() const {
   }
 }
 
+Expr* Expr::IgnoreParens() {
+  Expr* E = this;
+  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
+    E = P->getSubExpr();
+  
+  return E;
+}
+
 bool Expr::isConstantExpr(ASTContext &Ctx, SourceLocation *Loc) const {
   switch (getStmtClass()) {
   default:
index 2eda869c0ec53f9aa53cd23a0df990c4fc335a10..64cc199b57771d3eed66a0f3203b16b4c0279455 100644 (file)
@@ -216,13 +216,6 @@ public:
 };
 } // end anonymous namespace
 
-static inline Expr* IgnoreParen(Expr* E) {
-  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
-    E = P->getSubExpr();
-  
-  return E;
-}
-
 void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
   Builder = &builder;
   Nodes->clear();
@@ -237,7 +230,7 @@ void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
 
 ExprVariantTy GRConstants::GetBinding(Expr* E) {
   DSPtr P(NULL);
-  E = IgnoreParen(E);
+  E = E->IgnoreParens();
   
   switch (E->getStmtClass()) {
     case Stmt::DeclRefExprClass:
@@ -364,7 +357,7 @@ void GRConstants::VisitBinSub(BinaryOperator* B) {
 
 
 void GRConstants::VisitBinAssign(BinaryOperator* B) {
-  if (DeclRefExpr* D = dyn_cast<DeclRefExpr>(IgnoreParen(B->getLHS())))
+  if (DeclRefExpr* D = dyn_cast<DeclRefExpr>(B->getLHS()->IgnoreParens()))
     AddBinding(D->getDecl(), GetBinding(B->getRHS()));
 }
 
index 61c67f02feede6b718a53219aaae3be3d440bf8f..44c559b4d514144ab35f00950c6665dc48959b02 100644 (file)
@@ -751,8 +751,8 @@ static DeclRefExpr* EvalVal(Expr *E) {
 void Sema::CheckFloatComparison(SourceLocation loc, Expr* lex, Expr *rex) {
   bool EmitWarning = true;
   
-  Expr* LeftExprSansParen = IgnoreParen(lex);
-  Expr* RightExprSansParen = IgnoreParen(rex);
+  Expr* LeftExprSansParen = lex->IgnoreParens();
+  Expr* RightExprSansParen = lex->IgnoreParens();
 
   // Special case: check for x == x (which is OK).
   // Do not emit warnings for such cases.
index 81376a65005036f74c10630f885a1a4b15a8ae36..a80bc4352595908992e4be780aed67aeec523a44 100644 (file)
@@ -1418,8 +1418,8 @@ inline QualType Sema::CheckCompareOperands( // C99 6.5.8
   // x == x, x != x, x < x, etc.  These always evaluate to a constant, and
   // often indicate logic errors in the program.
   if (!lType->isFloatingType()) {
-    if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(IgnoreParen(lex)))
-      if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(IgnoreParen(rex)))
+    if (DeclRefExpr* DRL = dyn_cast<DeclRefExpr>(lex->IgnoreParens()))
+      if (DeclRefExpr* DRR = dyn_cast<DeclRefExpr>(rex->IgnoreParens()))
         if (DRL->getDecl() == DRR->getDecl())
           Diag(loc, diag::warn_selfcomparison);      
   }
index 1a15557fdfa27c4bf13c669af7e3c71a3c42fcdc..9be668bc54e3749451a1c07e9749600080513311 100644 (file)
 
 namespace clang {
 
-/// Utility method to plow through parentheses to get the first nested
-/// non-ParenExpr expr.
-static inline Expr* IgnoreParen(Expr* E) {
-  while (ParenExpr* P = dyn_cast<ParenExpr>(E))
-    E = P->getSubExpr();
-  
-  return E;
-}
-
 /// Utility method to plow through parenthesis and casts.
 static inline Expr* IgnoreParenCasts(Expr* E) {
   while(true) {
index 9c34a7cb2ad1ea0e3fad6e2b3f331fdcfa776c61..0c2a3d085ceac5b4a51d508ee950fd8fb6e6d50c 100644 (file)
@@ -109,7 +109,17 @@ public:
   /// hasStaticStorage - Return true if this expression has static storage
   /// duration.  This means that the address of this expression is a link-time
   /// constant.
-  bool hasStaticStorage() const;
+  bool hasStaticStorage() const;  
+  
+  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
+  ///  its subexpression.  If that subexpression is also a ParenExpr, 
+  ///  then this method recursively returns its subexpression, and so forth.
+  ///  Otherwise, the method returns the current Expr.
+  Expr* IgnoreParens();
+  
+  const Expr* IgnoreParens() const {
+    return const_cast<Expr*>(this)->IgnoreParens();
+  }
 
   static bool classof(const Stmt *T) { 
     return T->getStmtClass() >= firstExprConstant &&