From: Steve Naroff Date: Wed, 17 Sep 2008 18:37:59 +0000 (+0000) Subject: Remove BlockStmtExpr. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c3c902835ef7d37300463ad47176ec21a67dc8b;p=clang Remove BlockStmtExpr. Block literals are now represented by the concrete BlockExpr class. This is cleanup (removes a FIXME). No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@56288 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp index 34bf785a9d..753f4ffa2e 100644 --- a/Driver/RewriteBlocks.cpp +++ b/Driver/RewriteBlocks.cpp @@ -94,7 +94,7 @@ public: void InsertBlockLiteralsWithinMethod(ObjCMethodDecl *MD); // Block specific rewrite rules. - void RewriteBlockStmtExpr(BlockStmtExpr *Exp); + void RewriteBlockExpr(BlockExpr *Exp); void RewriteBlockCall(CallExpr *Exp); void RewriteBlockPointerDecl(NamedDecl *VD); @@ -349,7 +349,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i, // first add the implicit argument. S += Tag + " *__cself, "; std::string ParamStr; - for (BlockStmtExpr::arg_iterator AI = CE->arg_begin(), + for (BlockExpr::arg_iterator AI = CE->arg_begin(), E = CE->arg_end(); AI != E; ++AI) { if (AI != CE->arg_begin()) S += ", "; ParamStr = (*AI)->getName(); @@ -398,7 +398,7 @@ std::string RewriteBlocks::SynthesizeBlockFunc(BlockExpr *CE, int i, (*I)->getType().getAsStringInternal(Name); S += Name + " = __cself->" + (*I)->getName() + "; // bound by copy\n"; } - if (BlockStmtExpr *CBE = dyn_cast(CE)) { + if (BlockExpr *CBE = dyn_cast(CE)) { std::string BodyBuf; SourceLocation BodyLocStart = CBE->getBody()->getLocStart(); @@ -635,10 +635,10 @@ Stmt *RewriteBlocks::RewriteFunctionBody(Stmt *S) { for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end(); CI != E; ++CI) if (*CI) { - if (BlockStmtExpr *CBE = dyn_cast(*CI)) { + if (BlockExpr *CBE = dyn_cast(*CI)) { // We intentionally avoid rewritting the contents of a closure block // expr. InsertBlockLiteralsWithinFunction() will rewrite the body. - RewriteBlockStmtExpr(CBE); + RewriteBlockExpr(CBE); } else { Stmt *newStmt = RewriteFunctionBody(*CI); if (newStmt) @@ -831,7 +831,7 @@ void RewriteBlocks::RewriteBlockPointerDecl(NamedDecl *ND) { return; } -void RewriteBlocks::RewriteBlockStmtExpr(BlockStmtExpr *Exp) { +void RewriteBlocks::RewriteBlockExpr(BlockExpr *Exp) { Blocks.push_back(Exp); bool haveByRefDecls = false; diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index 25aa861376..18860534f1 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1486,21 +1486,29 @@ private: // Clang Extensions //===----------------------------------------------------------------------===// -/// BlockExpr - Common base class between BlockStmtExpr and BlockExprExpr. -/// FIXME: Combine with BlockStmtExpr...no more need for a common base. +/// BlockExpr - Represent a block literal with a syntax: +/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } class BlockExpr : public Expr { SourceLocation CaretLocation; llvm::SmallVector Args; -protected: - BlockExpr(StmtClass SC, QualType ty, SourceLocation caretloc, - ParmVarDecl **args, unsigned numargs) - : Expr(SC, ty), CaretLocation(caretloc), Args(args, args+numargs) {} + CompoundStmt *Body; public: + BlockExpr(SourceLocation caretloc, QualType ty, ParmVarDecl **args, + unsigned numargs, CompoundStmt *body) : Expr(BlockExprClass, ty), + CaretLocation(caretloc), Args(args, args+numargs), Body(body) {} + SourceLocation getCaretLocation() const { return CaretLocation; } /// getFunctionType - Return the underlying function type for this block. const FunctionType *getFunctionType() const; - + + const CompoundStmt *getBody() const { return Body; } + CompoundStmt *getBody() { return Body; } + + virtual SourceRange getSourceRange() const { + return SourceRange(getCaretLocation(), Body->getLocEnd()); + } + /// arg_iterator - Iterate over the ParmVarDecl's for the arguments to this /// block. typedef llvm::SmallVector::const_iterator arg_iterator; @@ -1509,41 +1517,18 @@ public: arg_iterator arg_end() const { return Args.end(); } static bool classof(const Stmt *T) { - return T->getStmtClass() == BlockStmtExprClass; + return T->getStmtClass() == BlockExprClass; } static bool classof(const BlockExpr *) { return true; } -}; - -/// BlockStmtExpr - Represent a block literal with a syntax: -/// ^{ statement-body } or ^(int arg1, float arg2){ statement-body } -class BlockStmtExpr : public BlockExpr { - CompoundStmt *Body; -public: - BlockStmtExpr(SourceLocation CaretLoc, QualType Ty, ParmVarDecl **args, - unsigned numargs, CompoundStmt *body) : - BlockExpr(BlockStmtExprClass, Ty, CaretLoc, - args, numargs), Body(body) {} - - const CompoundStmt *getBody() const { return Body; } - CompoundStmt *getBody() { return Body; } - - virtual SourceRange getSourceRange() const { - return SourceRange(getCaretLocation(), Body->getLocEnd()); - } - static bool classof(const Stmt *T) { - return T->getStmtClass() == BlockStmtExprClass; - } - static bool classof(const BlockStmtExpr *) { return true; } - // Iterators virtual child_iterator child_begin(); virtual child_iterator child_end(); virtual void EmitImpl(llvm::Serializer& S) const; - static BlockStmtExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); + static BlockExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); }; - + /// BlockDeclRefExpr - A reference to a declared variable, function, /// enum, etc. class BlockDeclRefExpr : public Expr { diff --git a/include/clang/AST/StmtNodes.def b/include/clang/AST/StmtNodes.def index ce74fea5dc..ed8861ba99 100644 --- a/include/clang/AST/StmtNodes.def +++ b/include/clang/AST/StmtNodes.def @@ -110,10 +110,9 @@ STMT(76, ObjCPropertyRefExpr , Expr) STMT(77, OverloadExpr , Expr) STMT(78, ShuffleVectorExpr , Expr) STMT(79, BlockExpr , Expr) -STMT(80, BlockStmtExpr , BlockExpr) -STMT(81, BlockDeclRefExpr , Expr) +STMT(80, BlockDeclRefExpr , Expr) -LAST_EXPR(81) +LAST_EXPR(80) #undef STMT #undef FIRST_STMT diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 8a545d6f40..8d49c8ef0e 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1448,10 +1448,10 @@ Stmt::child_iterator ObjCMessageExpr::child_end() { } // Blocks -Stmt::child_iterator BlockStmtExpr::child_begin() { +Stmt::child_iterator BlockExpr::child_begin() { return reinterpret_cast(&Body); } -Stmt::child_iterator BlockStmtExpr::child_end() { +Stmt::child_iterator BlockExpr::child_end() { return reinterpret_cast(&Body)+1; } diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index fbff987b07..e95b8c8409 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -891,7 +891,7 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { const FunctionTypeProto *FT = cast(AFT); OS << '('; std::string ParamStr; - for (BlockStmtExpr::arg_iterator AI = Node->arg_begin(), + for (BlockExpr::arg_iterator AI = Node->arg_begin(), E = Node->arg_end(); AI != E; ++AI) { if (AI != Node->arg_begin()) OS << ", "; ParamStr = (*AI)->getName(); @@ -907,11 +907,6 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { } } -void StmtPrinter::VisitBlockStmtExpr(BlockStmtExpr *Node) { - VisitBlockExpr(Node); - PrintRawCompoundStmt(Node->getBody()); -} - void StmtPrinter::VisitBlockDeclRefExpr(BlockDeclRefExpr *Node) { OS << Node->getDecl()->getName(); } diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index 5dbd3cd541..dea0ba4342 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -1112,13 +1112,13 @@ ObjCStringLiteral* ObjCStringLiteral::CreateImpl(Deserializer& D, ASTContext& C) // Serialization for Clang Extensions. //===----------------------------------------------------------------------===// -void BlockStmtExpr::EmitImpl(Serializer& S) const { +void BlockExpr::EmitImpl(Serializer& S) const { S.Emit(getType()); S.Emit(getCaretLocation()); S.EmitOwnedPtr(Body); } -BlockStmtExpr* BlockStmtExpr::CreateImpl(Deserializer& D, ASTContext& C) { +BlockExpr* BlockExpr::CreateImpl(Deserializer& D, ASTContext& C) { QualType Q = QualType::ReadVal(D); SourceLocation L = SourceLocation::ReadVal(D); /*CompoundStmt* BodyStmt = cast(*/D.ReadOwnedPtr(C)/*)*/; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 0df91d51a9..b7d5c8e12c 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2886,8 +2886,8 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body, BSI->isVariadic); BlockTy = Context.getBlockPointerType(BlockTy); - return new BlockStmtExpr(CaretLoc, BlockTy, - &BSI->Params[0], BSI->Params.size(), Body.take()); + return new BlockExpr(CaretLoc, BlockTy, &BSI->Params[0], BSI->Params.size(), + Body.take()); } /// ExprsMatchFnType - return true if the Exprs in array Args have