Implement function-try-blocks. However, there's a very subtle bug that I can't track down.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70155 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 1dd7829..aa0fc70 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -321,22 +321,22 @@
}
-CompoundStmt *FunctionDecl::getBody(ASTContext &Context,
- const FunctionDecl *&Definition) const {
+Stmt *FunctionDecl::getBody(ASTContext &Context,
+ const FunctionDecl *&Definition) const {
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
if (FD->Body) {
Definition = FD;
- return cast<CompoundStmt>(FD->Body.get(Context.getExternalSource()));
+ return FD->Body.get(Context.getExternalSource());
}
}
return 0;
}
-CompoundStmt *FunctionDecl::getBodyIfAvailable() const {
+Stmt *FunctionDecl::getBodyIfAvailable() const {
for (const FunctionDecl *FD = this; FD != 0; FD = FD->PreviousDeclaration) {
if (FD->Body && !FD->Body.isOffset()) {
- return cast<CompoundStmt>(FD->Body.get(0));
+ return FD->Body.get(0);
}
}
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index a207860..707383a 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -20,6 +20,8 @@
#include "clang/AST/ExternalASTSource.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/Type.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/StmtCXX.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -341,6 +343,21 @@
}
}
+CompoundStmt* Decl::getCompoundBody(ASTContext &Context) const {
+ return dyn_cast_or_null<CompoundStmt>(getBody(Context));
+}
+
+SourceLocation Decl::getBodyRBrace(ASTContext &Context) const {
+ Stmt *Body = getBody(Context);
+ if (!Body)
+ return SourceLocation();
+ if (CompoundStmt *CS = dyn_cast<CompoundStmt>(Body))
+ return CS->getRBracLoc();
+ assert(isa<CXXTryStmt>(Body) &&
+ "Body can only be CompoundStmt or CXXTryStmt");
+ return cast<CXXTryStmt>(Body)->getSourceRange().getEnd();
+}
+
#ifndef NDEBUG
void Decl::CheckAccessDeclContext() const {
assert((Access != AS_none || isa<TranslationUnitDecl>(this) ||