1 //===--- StmtCXX.h - Classes for representing C++ statements ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the C++ statement AST node classes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_STMTCXX_H
15 #define LLVM_CLANG_AST_STMTCXX_H
17 #include "clang/AST/Stmt.h"
23 /// CXXCatchStmt - This represents a C++ catch block.
25 class CXXCatchStmt : public Stmt {
26 SourceLocation CatchLoc;
27 /// The exception-declaration of the type.
28 VarDecl *ExceptionDecl;
29 /// The handler block.
33 CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock)
34 : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl),
35 HandlerBlock(handlerBlock) {}
37 CXXCatchStmt(EmptyShell Empty)
38 : Stmt(CXXCatchStmtClass), ExceptionDecl(0), HandlerBlock(0) {}
40 SourceRange getSourceRange() const {
41 return SourceRange(CatchLoc, HandlerBlock->getLocEnd());
44 SourceLocation getCatchLoc() const { return CatchLoc; }
45 VarDecl *getExceptionDecl() const { return ExceptionDecl; }
46 QualType getCaughtType() const;
47 Stmt *getHandlerBlock() const { return HandlerBlock; }
49 static bool classof(const Stmt *T) {
50 return T->getStmtClass() == CXXCatchStmtClass;
52 static bool classof(const CXXCatchStmt *) { return true; }
54 child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
56 friend class ASTStmtReader;
59 /// CXXTryStmt - A C++ try block, including all handlers.
61 class CXXTryStmt : public Stmt {
62 SourceLocation TryLoc;
65 CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, Stmt **handlers,
66 unsigned numHandlers);
68 CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
69 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
71 Stmt const * const *getStmts() const {
72 return reinterpret_cast<Stmt const * const*>(this + 1);
75 return reinterpret_cast<Stmt **>(this + 1);
79 static CXXTryStmt *Create(ASTContext &C, SourceLocation tryLoc,
80 Stmt *tryBlock, Stmt **handlers,
81 unsigned numHandlers);
83 static CXXTryStmt *Create(ASTContext &C, EmptyShell Empty,
84 unsigned numHandlers);
86 SourceRange getSourceRange() const {
87 return SourceRange(getTryLoc(), getEndLoc());
90 SourceLocation getTryLoc() const { return TryLoc; }
91 SourceLocation getEndLoc() const {
92 return getStmts()[NumHandlers]->getLocEnd();
95 CompoundStmt *getTryBlock() {
96 return llvm::cast<CompoundStmt>(getStmts()[0]);
98 const CompoundStmt *getTryBlock() const {
99 return llvm::cast<CompoundStmt>(getStmts()[0]);
102 unsigned getNumHandlers() const { return NumHandlers; }
103 CXXCatchStmt *getHandler(unsigned i) {
104 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]);
106 const CXXCatchStmt *getHandler(unsigned i) const {
107 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]);
110 static bool classof(const Stmt *T) {
111 return T->getStmtClass() == CXXTryStmtClass;
113 static bool classof(const CXXTryStmt *) { return true; }
115 child_range children() {
116 return child_range(getStmts(), getStmts() + getNumHandlers() + 1);
119 friend class ASTStmtReader;
123 } // end namespace clang