From: Ted Kremenek Date: Thu, 12 Mar 2009 18:33:24 +0000 (+0000) Subject: API fix: All "bodies" for functions, Objective-C methods, blocks, are assumed to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eaab20669b6a9910a5deb0110fdd8f7581d86a36;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66814 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteBlocks.cpp b/Driver/RewriteBlocks.cpp index 7eacc0a995..2672d32ef0 100644 --- a/Driver/RewriteBlocks.cpp +++ b/Driver/RewriteBlocks.cpp @@ -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(RewriteFunctionBody(Body))); // This synthesizes and inserts the block "impl" struct, invoke function, // and any copy/dispose helper functions. InsertBlockLiteralsWithinFunction(FD); diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp index c4f67627ce..1e2cac39de 100644 --- a/Driver/RewriteObjC.cpp +++ b/Driver/RewriteObjC.cpp @@ -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(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(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(RewriteFunctionBodyOrGlobalInitializer(Body)); + MD->setBody(Body); CurrentBody = 0; if (PropParentMap) { delete PropParentMap; diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index 8037d84c30..1991d934ea 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -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(); diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h index 183acb341b..86d96a5b1c 100644 --- a/include/clang/AST/DeclBase.h +++ b/include/clang/AST/DeclBase.h @@ -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); diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9bc07d5ce3..5786c56210 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -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(FD->Body); } } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 7d3d1c68f2..bedf05ed35 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -2774,11 +2774,11 @@ Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtArg BodyArg) { Decl *dcl = static_cast(D); Stmt *Body = static_cast(BodyArg.release()); if (FunctionDecl *FD = dyn_cast_or_null(dcl)) { - FD->setBody(Body); + FD->setBody(cast(Body)); assert(FD == getCurFunctionDecl() && "Function parsing confused"); } else if (ObjCMethodDecl *MD = dyn_cast_or_null(dcl)) { assert(MD == getCurMethodDecl() && "Method parsing confused"); - MD->setBody((Stmt*)Body); + MD->setBody(cast(Body)); } else { Body->Destroy(Context); return 0;