From 1c90bfcbd7ff5d09694acf50a32dbb716a968b61 Mon Sep 17 00:00:00 2001 From: Steve Naroff Date: Wed, 8 Oct 2008 18:44:00 +0000 Subject: [PATCH] Instantiate the BlockDecl in ActOnBlockStart() so we can use it as a DeclContext. This required changes to attach the compound statement later on (like we do for functions). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57304 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Decl.h | 8 ++++---- lib/AST/Decl.cpp | 5 ++--- lib/Sema/Sema.h | 2 ++ lib/Sema/SemaExpr.cpp | 8 ++++---- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 88cbe85421..bb8c14c408 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -992,21 +992,21 @@ class BlockDecl : public Decl, public DeclContext { Stmt *Body; protected: BlockDecl(DeclContext *DC, SourceLocation CaretLoc, - ParmVarDecl **args, unsigned numargs, Stmt *body) + ParmVarDecl **args, unsigned numargs) : Decl(Block, CaretLoc), DeclContext(Block), - Args(args, args+numargs), Body(body) {} + Args(args, args+numargs), Body(0) {} virtual ~BlockDecl(); virtual void Destroy(ASTContext& C); public: static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L, - ParmVarDecl **args, unsigned numargs, - CompoundStmt *body); + ParmVarDecl **args, unsigned numargs); SourceLocation getCaretLocation() const { return getLocation(); } Stmt *getBody() const { return Body; } + void setBody(Stmt *B) { Body = B; } /// arg_iterator - Iterate over the ParmVarDecl's for this block. typedef llvm::SmallVector::const_iterator param_iterator; diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index c900a734ae..fe2e95d157 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -77,10 +77,9 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC, } BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, - ParmVarDecl **args, unsigned numargs, - CompoundStmt *body) { + ParmVarDecl **args, unsigned numargs) { void *Mem = C.getAllocator().Allocate(); - return new (Mem) BlockDecl(DC, L, args, numargs, body); + return new (Mem) BlockDecl(DC, L, args, numargs); } FieldDecl *FieldDecl::Create(ASTContext &C, SourceLocation L, diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 406d9f7e7e..0600ae1424 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -1070,6 +1070,8 @@ struct BlockSemaInfo { bool hasPrototype; bool isVariadic; + BlockDecl *TheDecl; + /// TheScope - This is the scope for the block itself, which contains /// arguments etc. Scope *TheScope; diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index b8b614db07..cdba6ec6ea 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -2889,6 +2889,8 @@ void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *BlockScope, BSI->Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param); BSI->isVariadic = FTI.isVariadic; } + BSI->TheDecl = BlockDecl::Create(Context, CurContext, CaretLoc, + &BSI->Params[0], BSI->Params.size()); } /// ActOnBlockError - If there is an error parsing a block, this callback @@ -2932,10 +2934,8 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body, BlockTy = Context.getBlockPointerType(BlockTy); - BlockDecl *NewBD = BlockDecl::Create(Context, CurContext, CaretLoc, - &BSI->Params[0], BSI->Params.size(), - Body.take()); - return new BlockExpr(NewBD, BlockTy); + BSI->TheDecl->setBody(Body.take()); + return new BlockExpr(BSI->TheDecl, BlockTy); } /// ExprsMatchFnType - return true if the Exprs in array Args have -- 2.40.0