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 virtual 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 virtual child_iterator child_begin();
55 virtual child_iterator child_end();
57 friend class ASTStmtReader;
60 /// CXXTryStmt - A C++ try block, including all handlers.
62 class CXXTryStmt : public Stmt {
63 SourceLocation TryLoc;
66 CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, Stmt **handlers,
67 unsigned numHandlers);
69 CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
70 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
72 Stmt const * const *getStmts() const {
73 return reinterpret_cast<Stmt const * const*>(this + 1);
76 return reinterpret_cast<Stmt **>(this + 1);
80 static CXXTryStmt *Create(ASTContext &C, SourceLocation tryLoc,
81 Stmt *tryBlock, Stmt **handlers,
82 unsigned numHandlers);
84 static CXXTryStmt *Create(ASTContext &C, EmptyShell Empty,
85 unsigned numHandlers);
87 virtual SourceRange getSourceRange() const {
88 return SourceRange(getTryLoc(), getEndLoc());
91 SourceLocation getTryLoc() const { return TryLoc; }
92 SourceLocation getEndLoc() const {
93 return getStmts()[NumHandlers]->getLocEnd();
96 CompoundStmt *getTryBlock() {
97 return llvm::cast<CompoundStmt>(getStmts()[0]);
99 const CompoundStmt *getTryBlock() const {
100 return llvm::cast<CompoundStmt>(getStmts()[0]);
103 unsigned getNumHandlers() const { return NumHandlers; }
104 CXXCatchStmt *getHandler(unsigned i) {
105 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]);
107 const CXXCatchStmt *getHandler(unsigned i) const {
108 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]);
111 static bool classof(const Stmt *T) {
112 return T->getStmtClass() == CXXTryStmtClass;
114 static bool classof(const CXXTryStmt *) { return true; }
116 virtual child_iterator child_begin();
117 virtual child_iterator child_end();
119 friend class ASTStmtReader;
123 } // end namespace clang