diff options
| author | Steve Naroff <snaroff@apple.com> | 2008-09-17 18:37:59 +0000 | 
|---|---|---|
| committer | Steve Naroff <snaroff@apple.com> | 2008-09-17 18:37:59 +0000 | 
| commit | 43bafa78b3a141025fdbbd3ce42fdad403ae3d55 (patch) | |
| tree | d022716225180d3b9efd62acc6ed975a1857fa99 | |
| parent | f3fcd7a464afc7c640b8c611ac422f7904c3faa7 (diff) | |
| download | bcm5719-llvm-43bafa78b3a141025fdbbd3ce42fdad403ae3d55.tar.gz bcm5719-llvm-43bafa78b3a141025fdbbd3ce42fdad403ae3d55.zip  | |
Remove BlockStmtExpr. 
Block literals are now represented by the concrete BlockExpr class.
This is cleanup (removes a FIXME).
No functionality change.
llvm-svn: 56288
| -rw-r--r-- | clang/Driver/RewriteBlocks.cpp | 12 | ||||
| -rw-r--r-- | clang/include/clang/AST/Expr.h | 51 | ||||
| -rw-r--r-- | clang/include/clang/AST/StmtNodes.def | 5 | ||||
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/AST/StmtSerialization.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 4 | 
7 files changed, 33 insertions, 54 deletions
diff --git a/clang/Driver/RewriteBlocks.cpp b/clang/Driver/RewriteBlocks.cpp index 34bf785a9d1..753f4ffa2ef 100644 --- a/clang/Driver/RewriteBlocks.cpp +++ b/clang/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<BlockStmtExpr>(CE)) { +  if (BlockExpr *CBE = dyn_cast<BlockExpr>(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<BlockStmtExpr>(*CI)) { +      if (BlockExpr *CBE = dyn_cast<BlockExpr>(*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/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index 25aa8613768..18860534f1b 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/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<ParmVarDecl*, 8> 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<ParmVarDecl*, 8>::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/clang/include/clang/AST/StmtNodes.def b/clang/include/clang/AST/StmtNodes.def index ce74fea5dc3..ed8861ba996 100644 --- a/clang/include/clang/AST/StmtNodes.def +++ b/clang/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/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 8a545d6f401..8d49c8ef0ed 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/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<Stmt**>(&Body);  } -Stmt::child_iterator BlockStmtExpr::child_end() { +Stmt::child_iterator BlockExpr::child_end() {    return reinterpret_cast<Stmt**>(&Body)+1;  } diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index fbff987b07d..e95b8c84096 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -891,7 +891,7 @@ void StmtPrinter::VisitBlockExpr(BlockExpr *Node) {      const FunctionTypeProto *FT = cast<FunctionTypeProto>(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/clang/lib/AST/StmtSerialization.cpp b/clang/lib/AST/StmtSerialization.cpp index 5dbd3cd541b..dea0ba43422 100644 --- a/clang/lib/AST/StmtSerialization.cpp +++ b/clang/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<CompoundStmt>(*/D.ReadOwnedPtr<Stmt>(C)/*)*/; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 0df91d51a95..b7d5c8e12c0 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/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  | 

