diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-01-17 16:57:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-01-17 16:57:34 +0000 |
commit | 4e99a5fc3b203397a91136c6e695e405fb8fc606 (patch) | |
tree | 2b733364d0b34dfb61041b5d7cbc4d7657963c60 | |
parent | 847794a7620bfd5fda09ee06bc0205d30e17e2aa (diff) |
Added method Expr::IgnoreParens(), which returns the first non-ParenExpr Expr*.
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
-rw-r--r-- | AST/Expr.cpp | 8 | ||||
-rw-r--r-- | Analysis/GRConstants.cpp | 11 | ||||
-rw-r--r-- | Sema/SemaChecking.cpp | 4 | ||||
-rw-r--r-- | Sema/SemaExpr.cpp | 4 | ||||
-rw-r--r-- | Sema/SemaUtil.h | 9 | ||||
-rw-r--r-- | include/clang/AST/Expr.h | 12 |
6 files changed, 25 insertions, 23 deletions
diff --git a/AST/Expr.cpp b/AST/Expr.cpp index e2aa6ca405..0e1eecd7d7 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -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: diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 2eda869c0e..64cc199b57 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -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())); } diff --git a/Sema/SemaChecking.cpp b/Sema/SemaChecking.cpp index 61c67f02fe..44c559b4d5 100644 --- a/Sema/SemaChecking.cpp +++ b/Sema/SemaChecking.cpp @@ -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. diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 81376a6500..a80bc43525 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -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); } diff --git a/Sema/SemaUtil.h b/Sema/SemaUtil.h index 1a15557fdf..9be668bc54 100644 --- a/Sema/SemaUtil.h +++ b/Sema/SemaUtil.h @@ -19,15 +19,6 @@ 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) { diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 9c34a7cb2a..0c2a3d085c 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -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 && |