]> granicus.if.org Git - clang/commitdiff
API fix: All "bodies" for functions, Objective-C methods, blocks, are assumed to
authorTed Kremenek <kremenek@apple.com>
Thu, 12 Mar 2009 18:33:24 +0000 (18:33 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 12 Mar 2009 18:33:24 +0000 (18:33 +0000)
be CompoundStmts. I think this is a valid assumption, and felt that the API
should reflect it. Others please validate this assumption to make sure I didn't
break anything.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66814 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteBlocks.cpp
Driver/RewriteObjC.cpp
include/clang/AST/Decl.h
include/clang/AST/DeclBase.h
lib/AST/Decl.cpp
lib/Sema/SemaDecl.cpp

index 7eacc0a995ea34b169f70d29269493e1b24f8f96..2672d32ef05c2cba76c81792d3771cf8b4ddb836 100644 (file)
@@ -1076,9 +1076,9 @@ void RewriteBlocks::HandleDeclInMainFile(Decl *D) {
     // definitions using the same code.
     RewriteFunctionProtoType(FD->getType(), FD);
     
-    if (Stmt *Body = FD->getBody()) {
+    if (CompoundStmt *Body = FD->getBody()) {
       CurFunctionDef = FD;
-      FD->setBody(RewriteFunctionBody(Body));
+      FD->setBody(cast_or_null<CompoundStmt>(RewriteFunctionBody(Body)));
       // This synthesizes and inserts the block "impl" struct, invoke function,
       // and any copy/dispose helper functions.
       InsertBlockLiteralsWithinFunction(FD);
index c4f67627ceccc7d8b6a7574ac22a199c4ec50540..1e2cac39de90bd0a2fce6787ce2db7699394c035 100644 (file)
@@ -4426,11 +4426,13 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
     // definitions using the same code.
     RewriteBlocksInFunctionProtoType(FD->getType(), FD);
 
-    if (Stmt *Body = FD->getBody()) {
+    if (CompoundStmt *Body = FD->getBody()) {
       CurFunctionDef = FD;
       CollectPropertySetters(Body);
       CurrentBody = Body;
-      FD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));
+      Body =
+       cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
+      FD->setBody(Body);
       CurrentBody = 0;
       if (PropParentMap) {
         delete PropParentMap;
@@ -4444,11 +4446,13 @@ void RewriteObjC::HandleDeclInMainFile(Decl *D) {
     return;
   }
   if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
-    if (Stmt *Body = MD->getBody()) {
+    if (CompoundStmt *Body = MD->getBody()) {
       CurMethodDef = MD;
       CollectPropertySetters(Body);
       CurrentBody = Body;
-      MD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));
+      Body =
+       cast_or_null<CompoundStmt>(RewriteFunctionBodyOrGlobalInitializer(Body));
+      MD->setBody(Body);
       CurrentBody = 0;
       if (PropParentMap) {
         delete PropParentMap;
index 8037d84c3084923ef49702806d44651b58201865..1991d934eaea11961b1aba2dbf8ad5d55615b7ef 100644 (file)
@@ -606,9 +606,9 @@ public:
   /// function. The variant that accepts a FunctionDecl pointer will
   /// set that function declaration to the actual declaration
   /// containing the body (if there is one).
-  Stmt *getBody(const FunctionDecl *&Definition) const;
+  CompoundStmt *getBody(const FunctionDecl *&Definition) const;
 
-  virtual Stmt *getBody() const { 
+  virtual CompoundStmt *getBody() const { 
     const FunctionDecl* Definition;
     return getBody(Definition);
   }
@@ -619,7 +619,7 @@ public:
   /// previous definition); for that information, use getBody.
   bool isThisDeclarationADefinition() const { return Body != 0; }
 
-  void setBody(Stmt *B) { Body = B; }
+  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
   /// Whether this function is virtual, either by explicit marking, or by
   /// overriding a virtual function. Only valid on C++ member functions.
@@ -1198,8 +1198,8 @@ public:
 
   SourceLocation getCaretLocation() const { return getLocation(); }
 
-  Stmt *getBody() const { return Body; }
-  void setBody(Stmt *B) { Body = B; }
+  CompoundStmt *getBody() const { return (CompoundStmt*) Body; }
+  void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
 
   void setArgs(ParmVarDecl **args, unsigned numargs) {
     Args.clear(); 
index 183acb341bd8df6a439d785d80de21f588efc62f..86d96a5b1ce68a9b5b92c0f48d1b2ccd3a8d0a04 100644 (file)
@@ -39,6 +39,7 @@ class ObjCCategoryImplDecl;
 class LinkageSpecDecl;
 class BlockDecl;
 class DeclarationName;
+class CompoundStmt;
 
 /// Decl - This represents one declaration (or definition), e.g. a variable, 
 /// typedef, function, struct, etc.  
@@ -293,7 +294,7 @@ public:
   // getBody - If this Decl represents a declaration for a body of code,
   //  such as a function or method definition, this method returns the top-level
   //  Stmt* of that body.  Otherwise this method returns null.  
-  virtual Stmt* getBody() const { return 0; }
+  virtual CompoundStmt* getBody() const { return 0; }
   
   // global temp stats (until we have a per-module visitor)
   static void addDeclKind(Kind k);
index 9bc07d5ce3fcc3d5a9c91a9130a6d92622a9d324..5786c562107b3e2df4ae4b4f62719dc953758cb8 100644 (file)
@@ -306,11 +306,11 @@ void FunctionDecl::Destroy(ASTContext& C) {
 }
 
 
-Stmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
+CompoundStmt *FunctionDecl::getBody(const FunctionDecl *&Definition) const {
   for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
     if (FD->Body) {
       Definition = FD;
-      return FD->Body;
+      return cast<CompoundStmt>(FD->Body);
     }
   }
 
index 7d3d1c68f2f12c66d6f620e9e1df728165104a25..bedf05ed35e9e8b30f2e8c2ff5d93188487ce422 100644 (file)
@@ -2774,11 +2774,11 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) {
   Decl *dcl = static_cast<Decl *>(D);
   Stmt *Body = static_cast<Stmt*>(BodyArg.release());
   if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(dcl)) {
-    FD->setBody(Body);
+    FD->setBody(cast<CompoundStmt>(Body));
     assert(FD == getCurFunctionDecl() && "Function parsing confused");
   } else if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(dcl)) {
     assert(MD == getCurMethodDecl() && "Method parsing confused");
-    MD->setBody((Stmt*)Body);
+    MD->setBody(cast<CompoundStmt>(Body));
   } else {
     Body->Destroy(Context);
     return 0;