From 8bafa2cf9f2404cf5efd29a1420dc17d2113d853 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 26 Sep 2008 23:24:14 +0000 Subject: [PATCH] Internally store the body of a BlockExpr using a Stmt* instead of a CompoundStmt*, and use the getBody() method to do the appropriate checking. This both removes the type-punning warnings in Expr.cpp and also makes BlockExpr have more consistency checks against modifications to its body (via StmtIterator). llvm-svn: 56710 --- clang/include/clang/AST/Expr.h | 6 +++--- clang/lib/AST/Expr.cpp | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 9430b51dead8..a9c1e68012de 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -1492,7 +1492,7 @@ private: class BlockExpr : public Expr { SourceLocation CaretLocation; llvm::SmallVector Args; - CompoundStmt *Body; + Stmt *Body; public: BlockExpr(SourceLocation caretloc, QualType ty, ParmVarDecl **args, unsigned numargs, CompoundStmt *body) : Expr(BlockExprClass, ty), @@ -1503,8 +1503,8 @@ public: /// getFunctionType - Return the underlying function type for this block. const FunctionType *getFunctionType() const; - const CompoundStmt *getBody() const { return Body; } - CompoundStmt *getBody() { return Body; } + const CompoundStmt *getBody() const { return cast(Body); } + CompoundStmt *getBody() { return cast(Body); } virtual SourceRange getSourceRange() const { return SourceRange(getCaretLocation(), Body->getLocEnd()); diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 456b87b64e01..6a4b6b0493d3 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -1460,13 +1460,8 @@ Stmt::child_iterator ObjCMessageExpr::child_end() { } // Blocks -Stmt::child_iterator BlockExpr::child_begin() { - return reinterpret_cast(&Body); -} -Stmt::child_iterator BlockExpr::child_end() { - return reinterpret_cast(&Body)+1; -} - -Stmt::child_iterator BlockDeclRefExpr::child_begin(){return child_iterator();} -Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator();} +Stmt::child_iterator BlockExpr::child_begin() { return &Body; } +Stmt::child_iterator BlockExpr::child_end() { return &Body+1; } +Stmt::child_iterator BlockDeclRefExpr::child_begin() { return child_iterator();} +Stmt::child_iterator BlockDeclRefExpr::child_end() { return child_iterator(); }