}
}
+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:
};
} // 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();
ExprVariantTy GRConstants::GetBinding(Expr* E) {
DSPtr P(NULL);
- E = IgnoreParen(E);
+ E = E->IgnoreParens();
switch (E->getStmtClass()) {
case Stmt::DeclRefExprClass:
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()));
}
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.
// 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);
}
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) {
/// 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 &&