]> granicus.if.org Git - clang/commitdiff
Instantiate the BlockDecl in ActOnBlockStart() so we can use it as a DeclContext.
authorSteve Naroff <snaroff@apple.com>
Wed, 8 Oct 2008 18:44:00 +0000 (18:44 +0000)
committerSteve Naroff <snaroff@apple.com>
Wed, 8 Oct 2008 18:44:00 +0000 (18:44 +0000)
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
lib/AST/Decl.cpp
lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index 88cbe8542148872f40fec5130893f1cb894e1c1d..bb8c14c40880442de46c2b929c4a01e6f72459db 100644 (file)
@@ -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<ParmVarDecl*, 8>::const_iterator param_iterator;
index c900a734ae0caae6bef9a31227b10ee1bbdc2ac1..fe2e95d157939354978d102b4406c0c2b540126d 100644 (file)
@@ -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<BlockDecl>();
-  return new (Mem) BlockDecl(DC, L, args, numargs, body);
+  return new (Mem) BlockDecl(DC, L, args, numargs);
 }
 
 FieldDecl *FieldDecl::Create(ASTContext &C, SourceLocation L,
index 406d9f7e7e17fe2bd5a61b318ac78d108b8cee6f..0600ae142433ce223dfc18c7121d5dfcd5645dce 100644 (file)
@@ -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;
index b8b614db073a7905f4c92fe285a14736dd3fcc4a..cdba6ec6ea6c91c76635a70ba964c816e791a263 100644 (file)
@@ -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