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 7eacc0a..2672d32 100644
--- a/Driver/RewriteBlocks.cpp
+++ b/Driver/RewriteBlocks.cpp
@@ -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);
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index c4f6762..1e2cac3 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -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;
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 8037d84..1991d93 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -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();
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index 183acb3..86d96a5 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -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);
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 9bc07d5..5786c56 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -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);
}
}
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7d3d1c6..bedf05e 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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;