[cfe-commits] r66814 - in /cfe/trunk: Driver/RewriteBlocks.cpp Driver/RewriteObjC.cpp include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp

Ted Kremenek kremenek at apple.com
Thu Mar 12 11:33:24 PDT 2009


Author: kremenek
Date: Thu Mar 12 13:33:24 2009
New Revision: 66814

URL: http://llvm.org/viewvc/llvm-project?rev=66814&view=rev
Log:
API fix: All "bodies" for functions, Objective-C methods, blocks, are assumed to
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.

Modified:
    cfe/trunk/Driver/RewriteBlocks.cpp
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclBase.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/Driver/RewriteBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteBlocks.cpp?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteBlocks.cpp (original)
+++ cfe/trunk/Driver/RewriteBlocks.cpp Thu Mar 12 13:33:24 2009
@@ -1076,9 +1076,9 @@
     // 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);

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Thu Mar 12 13:33:24 2009
@@ -4426,11 +4426,13 @@
     // 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 @@
     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;

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Mar 12 13:33:24 2009
@@ -606,9 +606,9 @@
   /// 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 @@
   /// 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 @@
 
   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(); 

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Thu Mar 12 13:33:24 2009
@@ -39,6 +39,7 @@
 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 @@
   // 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);

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Mar 12 13:33:24 2009
@@ -306,11 +306,11 @@
 }
 
 
-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);
     }
   }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=66814&r1=66813&r2=66814&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Mar 12 13:33:24 2009
@@ -2774,11 +2774,11 @@
   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;





More information about the cfe-commits mailing list