[cfe-commits] r46129 - in /cfe/trunk: AST/Expr.cpp Analysis/GRConstants.cpp Sema/SemaChecking.cpp Sema/SemaExpr.cpp Sema/SemaUtil.h include/clang/AST/Expr.h
Chris Lattner
clattner at apple.com
Thu Jan 17 09:04:34 PST 2008
thanks Ted!
-Chris
On Jan 17, 2008, at 8:57 AM, Ted Kremenek wrote:
> Author: kremenek
> Date: Thu Jan 17 10:57:34 2008
> New Revision: 46129
>
> URL: http://llvm.org/viewvc/llvm-project?rev=46129&view=rev
> Log:
> 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.
>
> Modified:
> cfe/trunk/AST/Expr.cpp
> cfe/trunk/Analysis/GRConstants.cpp
> cfe/trunk/Sema/SemaChecking.cpp
> cfe/trunk/Sema/SemaExpr.cpp
> cfe/trunk/Sema/SemaUtil.h
> cfe/trunk/include/clang/AST/Expr.h
>
> Modified: cfe/trunk/AST/Expr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/AST/Expr.cpp (original)
> +++ cfe/trunk/AST/Expr.cpp Thu Jan 17 10:57:34 2008
> @@ -439,6 +439,14 @@
> }
> }
>
> +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:
>
> Modified: cfe/trunk/Analysis/GRConstants.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/Analysis/GRConstants.cpp (original)
> +++ cfe/trunk/Analysis/GRConstants.cpp Thu Jan 17 10:57:34 2008
> @@ -216,13 +216,6 @@
> };
> } // 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 @@
>
> 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::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()));
> }
>
>
> Modified: cfe/trunk/Sema/SemaChecking.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaChecking.cpp?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/Sema/SemaChecking.cpp (original)
> +++ cfe/trunk/Sema/SemaChecking.cpp Thu Jan 17 10:57:34 2008
> @@ -751,8 +751,8 @@
> 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.
>
> Modified: cfe/trunk/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/Sema/SemaExpr.cpp Thu Jan 17 10:57:34 2008
> @@ -1418,8 +1418,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);
> }
>
> Modified: cfe/trunk/Sema/SemaUtil.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaUtil.h?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/Sema/SemaUtil.h (original)
> +++ cfe/trunk/Sema/SemaUtil.h Thu Jan 17 10:57:34 2008
> @@ -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) {
>
> Modified: cfe/trunk/include/clang/AST/Expr.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=46129&r1=46128&r2=46129&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/AST/Expr.h (original)
> +++ cfe/trunk/include/clang/AST/Expr.h Thu Jan 17 10:57:34 2008
> @@ -109,7 +109,17 @@
> /// 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 &&
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list