diff options
Diffstat (limited to 'clang/lib/AST')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 10 | ||||
-rw-r--r-- | clang/lib/AST/DeclBase.cpp | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 1dd782936f2..aa0fc702a4e 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -321,22 +321,22 @@ void FunctionDecl::Destroy(ASTContext& C) { } -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/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index a20786035a2..707383af3a8 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/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 @@ DeclContext *Decl::castToDeclContext(const Decl *D) { } } +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) || |