StmtCXX.h revision 387b0fc2d81da3b564801d77e2f20681ee868887
1//===--- StmtCXX.h - Classes for representing C++ statements ----*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the C++ statement AST node classes. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_CLANG_AST_STMTCXX_H 15#define LLVM_CLANG_AST_STMTCXX_H 16 17#include "clang/AST/Stmt.h" 18 19namespace clang { 20 21class VarDecl; 22 23/// CXXCatchStmt - This represents a C++ catch block. 24/// 25class CXXCatchStmt : public Stmt { 26 SourceLocation CatchLoc; 27 /// The exception-declaration of the type. 28 VarDecl *ExceptionDecl; 29 /// The handler block. 30 Stmt *HandlerBlock; 31 32protected: 33 virtual void DoDestroy(ASTContext& Ctx); 34 35public: 36 CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock) 37 : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl), 38 HandlerBlock(handlerBlock) {} 39 40 virtual SourceRange getSourceRange() const { 41 return SourceRange(CatchLoc, HandlerBlock->getLocEnd()); 42 } 43 44 SourceLocation getCatchLoc() const { return CatchLoc; } 45 VarDecl *getExceptionDecl() const { return ExceptionDecl; } 46 QualType getCaughtType() const; 47 Stmt *getHandlerBlock() const { return HandlerBlock; } 48 49 static bool classof(const Stmt *T) { 50 return T->getStmtClass() == CXXCatchStmtClass; 51 } 52 static bool classof(const CXXCatchStmt *) { return true; } 53 54 virtual child_iterator child_begin(); 55 virtual child_iterator child_end(); 56}; 57 58/// CXXTryStmt - A C++ try block, including all handlers. 59/// 60class CXXTryStmt : public Stmt { 61 SourceLocation TryLoc; 62 unsigned NumHandlers; 63 64 CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, Stmt **handlers, 65 unsigned numHandlers); 66 67public: 68 static CXXTryStmt *Create(ASTContext &C, SourceLocation tryLoc, 69 Stmt *tryBlock, Stmt **handlers, 70 unsigned numHandlers); 71 72 virtual SourceRange getSourceRange() const { 73 return SourceRange(getTryLoc(), getEndLoc()); 74 } 75 76 SourceLocation getTryLoc() const { return TryLoc; } 77 SourceLocation getEndLoc() const { 78 Stmt const * const*Stmts = reinterpret_cast<Stmt const * const*>(this + 1); 79 return Stmts[NumHandlers]->getLocEnd(); 80 } 81 82 CompoundStmt *getTryBlock() { 83 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); 84 return llvm::cast<CompoundStmt>(Stmts[0]); 85 } 86 const CompoundStmt *getTryBlock() const { 87 Stmt const * const*Stmts = reinterpret_cast<Stmt const * const*>(this + 1); 88 return llvm::cast<CompoundStmt>(Stmts[0]); 89 } 90 91 unsigned getNumHandlers() const { return NumHandlers; } 92 CXXCatchStmt *getHandler(unsigned i) { 93 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); 94 return llvm::cast<CXXCatchStmt>(Stmts[i + 1]); 95 } 96 const CXXCatchStmt *getHandler(unsigned i) const { 97 Stmt const * const*Stmts = reinterpret_cast<Stmt const * const*>(this + 1); 98 return llvm::cast<CXXCatchStmt>(Stmts[i + 1]); 99 } 100 101 static bool classof(const Stmt *T) { 102 return T->getStmtClass() == CXXTryStmtClass; 103 } 104 static bool classof(const CXXTryStmt *) { return true; } 105 106 virtual child_iterator child_begin(); 107 virtual child_iterator child_end(); 108}; 109 110 111} // end namespace clang 112 113#endif 114