StmtCXX.h revision 212904
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 32public: 33 CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock) 34 : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl), 35 HandlerBlock(handlerBlock) {} 36 37 CXXCatchStmt(EmptyShell Empty) 38 : Stmt(CXXCatchStmtClass), ExceptionDecl(0), HandlerBlock(0) {} 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 friend class ASTStmtReader; 58}; 59 60/// CXXTryStmt - A C++ try block, including all handlers. 61/// 62class CXXTryStmt : public Stmt { 63 SourceLocation TryLoc; 64 unsigned NumHandlers; 65 66 CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, Stmt **handlers, 67 unsigned numHandlers); 68 69 CXXTryStmt(EmptyShell Empty, unsigned numHandlers) 70 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { } 71 72 Stmt const * const *getStmts() const { 73 return reinterpret_cast<Stmt const * const*>(this + 1); 74 } 75 Stmt **getStmts() { 76 return reinterpret_cast<Stmt **>(this + 1); 77 } 78 79public: 80 static CXXTryStmt *Create(ASTContext &C, SourceLocation tryLoc, 81 Stmt *tryBlock, Stmt **handlers, 82 unsigned numHandlers); 83 84 static CXXTryStmt *Create(ASTContext &C, EmptyShell Empty, 85 unsigned numHandlers); 86 87 virtual SourceRange getSourceRange() const { 88 return SourceRange(getTryLoc(), getEndLoc()); 89 } 90 91 SourceLocation getTryLoc() const { return TryLoc; } 92 SourceLocation getEndLoc() const { 93 return getStmts()[NumHandlers]->getLocEnd(); 94 } 95 96 CompoundStmt *getTryBlock() { 97 return llvm::cast<CompoundStmt>(getStmts()[0]); 98 } 99 const CompoundStmt *getTryBlock() const { 100 return llvm::cast<CompoundStmt>(getStmts()[0]); 101 } 102 103 unsigned getNumHandlers() const { return NumHandlers; } 104 CXXCatchStmt *getHandler(unsigned i) { 105 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]); 106 } 107 const CXXCatchStmt *getHandler(unsigned i) const { 108 return llvm::cast<CXXCatchStmt>(getStmts()[i + 1]); 109 } 110 111 static bool classof(const Stmt *T) { 112 return T->getStmtClass() == CXXTryStmtClass; 113 } 114 static bool classof(const CXXTryStmt *) { return true; } 115 116 virtual child_iterator child_begin(); 117 virtual child_iterator child_end(); 118 119 friend class ASTStmtReader; 120}; 121 122 123} // end namespace clang 124 125#endif 126