blob: b7feda9b8fcaad2372515b704c6582a7bba21436 [file] [log] [blame]
Chris Lattner4b009652007-07-25 00:24:17 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner959e5be2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4b009652007-07-25 00:24:17 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the Stmt class and statement subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#include "clang/AST/Stmt.h"
15#include "clang/AST/ExprCXX.h"
Steve Naroff9ed3e772008-05-29 21:12:08 +000016#include "clang/AST/ExprObjC.h"
Sebastian Redl743c8162008-12-22 19:15:10 +000017#include "clang/AST/Type.h"
Ted Kremenek39dc20a2009-02-06 01:42:09 +000018#include "clang/AST/ASTContext.h"
Chris Lattner4b009652007-07-25 00:24:17 +000019using namespace clang;
20
Chris Lattner4b009652007-07-25 00:24:17 +000021static struct StmtClassNameTable {
Chris Lattner603bf122007-08-25 01:42:24 +000022 const char *Name;
23 unsigned Counter;
24 unsigned Size;
Chris Lattner9c0da3b2007-08-25 01:55:00 +000025} StmtClassInfo[Stmt::lastExprConstant+1];
Chris Lattner603bf122007-08-25 01:42:24 +000026
27static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
28 static bool Initialized = false;
29 if (Initialized)
30 return StmtClassInfo[E];
31
32 // Intialize the table on the first use.
33 Initialized = true;
Douglas Gregor19330152008-11-14 12:46:07 +000034#define STMT(CLASS, PARENT) \
35 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
36 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Chris Lattner4b009652007-07-25 00:24:17 +000037#include "clang/AST/StmtNodes.def"
Nico Weber7340a2f2008-08-05 23:15:29 +000038
Chris Lattner603bf122007-08-25 01:42:24 +000039 return StmtClassInfo[E];
40}
41
Chris Lattner4b009652007-07-25 00:24:17 +000042const char *Stmt::getStmtClassName() const {
Chris Lattner603bf122007-08-25 01:42:24 +000043 return getStmtInfoTableEntry(sClass).Name;
Chris Lattner4b009652007-07-25 00:24:17 +000044}
45
Chris Lattnerdaac6942009-03-04 04:23:07 +000046void Stmt::DestroyChildren(ASTContext &C) {
47 for (child_iterator I = child_begin(), E = child_end(); I !=E; )
Douglas Gregor0e7e7f42009-01-16 06:50:08 +000048 if (Stmt* Child = *I++) Child->Destroy(C);
Ted Kremenekafdf8112008-05-20 00:43:19 +000049}
50
Chris Lattnerdaac6942009-03-04 04:23:07 +000051void Stmt::Destroy(ASTContext &C) {
Ted Kremenekafdf8112008-05-20 00:43:19 +000052 DestroyChildren(C);
Ted Kremenekbde41092008-05-20 04:10:52 +000053 // FIXME: Eventually all Stmts should be allocated with the allocator
54 // in ASTContext, just like with Decls.
Ted Kremenek39dc20a2009-02-06 01:42:09 +000055 this->~Stmt();
56 C.Deallocate((void *)this);
Ted Kremenek1ed5dc62008-05-19 22:02:12 +000057}
58
Chris Lattnerdaac6942009-03-04 04:23:07 +000059void DeclStmt::Destroy(ASTContext &C) {
Ted Kremenek39dc20a2009-02-06 01:42:09 +000060 this->~DeclStmt();
61 C.Deallocate((void *)this);
Ted Kremeneka1e77702008-05-21 15:53:55 +000062}
63
Chris Lattner4b009652007-07-25 00:24:17 +000064void Stmt::PrintStats() {
Chris Lattner603bf122007-08-25 01:42:24 +000065 // Ensure the table is primed.
66 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weber7340a2f2008-08-05 23:15:29 +000067
Chris Lattner4b009652007-07-25 00:24:17 +000068 unsigned sum = 0;
69 fprintf(stderr, "*** Stmt/Expr Stats:\n");
Chris Lattner9c0da3b2007-08-25 01:55:00 +000070 for (int i = 0; i != Stmt::lastExprConstant+1; i++) {
Chris Lattner603bf122007-08-25 01:42:24 +000071 if (StmtClassInfo[i].Name == 0) continue;
72 sum += StmtClassInfo[i].Counter;
Chris Lattner4b009652007-07-25 00:24:17 +000073 }
74 fprintf(stderr, " %d stmts/exprs total.\n", sum);
75 sum = 0;
Chris Lattner9c0da3b2007-08-25 01:55:00 +000076 for (int i = 0; i != Stmt::lastExprConstant+1; i++) {
Chris Lattner603bf122007-08-25 01:42:24 +000077 if (StmtClassInfo[i].Name == 0) continue;
Nico Weber7340a2f2008-08-05 23:15:29 +000078 fprintf(stderr, " %d %s, %d each (%d bytes)\n",
Chris Lattner603bf122007-08-25 01:42:24 +000079 StmtClassInfo[i].Counter, StmtClassInfo[i].Name,
80 StmtClassInfo[i].Size,
81 StmtClassInfo[i].Counter*StmtClassInfo[i].Size);
82 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Chris Lattner4b009652007-07-25 00:24:17 +000083 }
84 fprintf(stderr, "Total bytes = %d\n", sum);
85}
86
87void Stmt::addStmtClass(StmtClass s) {
Chris Lattner603bf122007-08-25 01:42:24 +000088 ++getStmtInfoTableEntry(s).Counter;
Chris Lattner4b009652007-07-25 00:24:17 +000089}
90
91static bool StatSwitch = false;
92
93bool Stmt::CollectingStats(bool enable) {
94 if (enable) StatSwitch = true;
Chris Lattner603bf122007-08-25 01:42:24 +000095 return StatSwitch;
Chris Lattner4b009652007-07-25 00:24:17 +000096}
97
98
Chris Lattner4b009652007-07-25 00:24:17 +000099const char *LabelStmt::getName() const {
100 return getID()->getName();
101}
102
Steve Naroffc32a20d2007-08-31 23:49:30 +0000103// This is defined here to avoid polluting Stmt.h with importing Expr.h
Nico Weber7340a2f2008-08-05 23:15:29 +0000104SourceRange ReturnStmt::getSourceRange() const {
Steve Naroffc32a20d2007-08-31 23:49:30 +0000105 if (RetExpr)
106 return SourceRange(RetLoc, RetExpr->getLocEnd());
107 else
108 return SourceRange(RetLoc);
109}
110
Ted Kremenekad5682f2007-10-01 16:34:52 +0000111bool Stmt::hasImplicitControlFlow() const {
112 switch (sClass) {
113 default:
114 return false;
Nico Weber7340a2f2008-08-05 23:15:29 +0000115
Ted Kremenekad5682f2007-10-01 16:34:52 +0000116 case CallExprClass:
117 case ConditionalOperatorClass:
118 case ChooseExprClass:
119 case StmtExprClass:
120 case DeclStmtClass:
Nico Weber7340a2f2008-08-05 23:15:29 +0000121 return true;
122
Ted Kremenekad5682f2007-10-01 16:34:52 +0000123 case Stmt::BinaryOperatorClass: {
124 const BinaryOperator* B = cast<BinaryOperator>(this);
125 if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma)
126 return true;
127 else
128 return false;
129 }
130 }
131}
132
Chris Lattnere8625112009-03-10 04:59:06 +0000133Expr *AsmStmt::getOutputExpr(unsigned i) {
Ted Kremenekb30de272008-10-27 18:40:21 +0000134 return cast<Expr>(Exprs[i]);
135}
Chris Lattnere8625112009-03-10 04:59:06 +0000136
137/// getOutputConstraint - Return the constraint string for the specified
138/// output operand. All output constraints are known to be non-empty (either
139/// '=' or '+').
140std::string AsmStmt::getOutputConstraint(unsigned i) const {
141 return std::string(Constraints[i]->getStrData(),
142 Constraints[i]->getByteLength());
Ted Kremenekb30de272008-10-27 18:40:21 +0000143}
Chris Lattnere8625112009-03-10 04:59:06 +0000144
145
146Expr *AsmStmt::getInputExpr(unsigned i) {
Ted Kremenekb30de272008-10-27 18:40:21 +0000147 return cast<Expr>(Exprs[i + NumOutputs]);
148}
Chris Lattnere8625112009-03-10 04:59:06 +0000149
150/// getInputConstraint - Return the specified input constraint. Unlike output
151/// constraints, these can be empty.
152std::string AsmStmt::getInputConstraint(unsigned i) const {
153 return std::string(Constraints[i + NumOutputs]->getStrData(),
154 Constraints[i + NumOutputs]->getByteLength());
Ted Kremenekb30de272008-10-27 18:40:21 +0000155}
156
Chris Lattner20ac04c2009-03-10 06:33:24 +0000157
158/// getNamedOperand - Given a symbolic operand reference like %[foo],
159/// translate this into a numeric value needed to reference the same operand.
160/// This returns -1 if the operand name is invalid.
161int AsmStmt::getNamedOperand(const std::string &SymbolicName) const {
162 unsigned NumPlusOperands = 0;
163
164 // Check if this is an output operand.
165 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
166 if (getOutputName(i) == SymbolicName)
167 return i;
168
169 // Keep track of the number of '+' operands.
170 if (isOutputPlusConstraint(i)) ++NumPlusOperands;
171 }
172
173 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
174 if (getInputName(i) == SymbolicName)
175 return getNumOutputs() + NumPlusOperands + i;
176
177 // Not found.
178 return -1;
179}
180
181
Chris Lattner006d1542008-01-30 05:01:46 +0000182//===----------------------------------------------------------------------===//
183// Constructors
184//===----------------------------------------------------------------------===//
185
Anders Carlssonde6a9c42008-02-05 23:03:50 +0000186AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile,
Chris Lattner006d1542008-01-30 05:01:46 +0000187 unsigned numoutputs, unsigned numinputs,
188 std::string *names, StringLiteral **constraints,
189 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
190 StringLiteral **clobbers, SourceLocation rparenloc)
Anders Carlsson965d5202007-11-22 01:36:19 +0000191 : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
Anders Carlssonde6a9c42008-02-05 23:03:50 +0000192 , IsSimple(issimple), IsVolatile(isvolatile)
193 , NumOutputs(numoutputs), NumInputs(numinputs) {
Anders Carlsson965d5202007-11-22 01:36:19 +0000194 for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) {
195 Names.push_back(names[i]);
196 Exprs.push_back(exprs[i]);
Nico Weber7340a2f2008-08-05 23:15:29 +0000197 Constraints.push_back(constraints[i]);
Anders Carlsson965d5202007-11-22 01:36:19 +0000198 }
Nico Weber7340a2f2008-08-05 23:15:29 +0000199
Anders Carlsson965d5202007-11-22 01:36:19 +0000200 for (unsigned i = 0; i != numclobbers; i++)
201 Clobbers.push_back(clobbers[i]);
202}
203
Chris Lattner006d1542008-01-30 05:01:46 +0000204ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
205 Stmt *Body, SourceLocation FCL,
Nico Weber7340a2f2008-08-05 23:15:29 +0000206 SourceLocation RPL)
Chris Lattner006d1542008-01-30 05:01:46 +0000207: Stmt(ObjCForCollectionStmtClass) {
208 SubExprs[ELEM] = Elem;
209 SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
210 SubExprs[BODY] = Body;
211 ForLoc = FCL;
212 RParenLoc = RPL;
213}
214
215
Nico Weber7340a2f2008-08-05 23:15:29 +0000216ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc,
217 SourceLocation rparenloc,
Steve Naroff0e8b96a2009-03-03 19:52:17 +0000218 ParmVarDecl *catchVarDecl, Stmt *atCatchStmt,
Chris Lattner006d1542008-01-30 05:01:46 +0000219 Stmt *atCatchList)
220: Stmt(ObjCAtCatchStmtClass) {
Steve Naroff0e8b96a2009-03-03 19:52:17 +0000221 ExceptionDecl = catchVarDecl;
Chris Lattner006d1542008-01-30 05:01:46 +0000222 SubExprs[BODY] = atCatchStmt;
Eli Friedmanf3e02ed2008-05-25 04:34:57 +0000223 SubExprs[NEXT_CATCH] = NULL;
Daniel Dunbard23d9922009-03-01 04:28:32 +0000224 // FIXME: O(N^2) in number of catch blocks.
Eli Friedmanf3e02ed2008-05-25 04:34:57 +0000225 if (atCatchList) {
Ted Kremenek61aa7f92008-02-01 21:28:59 +0000226 ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList);
227
Nico Weber7340a2f2008-08-05 23:15:29 +0000228 while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt())
Ted Kremenek61aa7f92008-02-01 21:28:59 +0000229 AtCatchList = NextCatch;
Nico Weber7340a2f2008-08-05 23:15:29 +0000230
Ted Kremenek61aa7f92008-02-01 21:28:59 +0000231 AtCatchList->SubExprs[NEXT_CATCH] = this;
Chris Lattner006d1542008-01-30 05:01:46 +0000232 }
233 AtCatchLoc = atCatchLoc;
234 RParenLoc = rparenloc;
235}
236
237
Ted Kremenek51be0562007-08-24 21:09:09 +0000238//===----------------------------------------------------------------------===//
239// Child Iterators for iterating over subexpressions/substatements
240//===----------------------------------------------------------------------===//
241
242// DeclStmt
Ted Kremenek1bc18e62008-10-07 23:09:49 +0000243Stmt::child_iterator DeclStmt::child_begin() {
244 return StmtIterator(DG.begin(), DG.end());
Ted Kremenekb59f9cf2008-08-05 20:46:55 +0000245}
246
Ted Kremenek1bc18e62008-10-07 23:09:49 +0000247Stmt::child_iterator DeclStmt::child_end() {
248 return StmtIterator(DG.end(), DG.end());
Ted Kremenek62f23bb2008-10-06 20:54:44 +0000249}
250
Ted Kremenek51be0562007-08-24 21:09:09 +0000251// NullStmt
Ted Kremeneka6478552007-10-18 23:28:49 +0000252Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
253Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
Ted Kremenek51be0562007-08-24 21:09:09 +0000254
255// CompoundStmt
256Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
Ted Kremenek0c97e042009-02-07 01:47:29 +0000257Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; }
Ted Kremenek51be0562007-08-24 21:09:09 +0000258
Ted Kremeneke07b67e2007-08-30 16:50:46 +0000259// CaseStmt
260Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; }
261Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; }
262
263// DefaultStmt
264Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; }
265Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; }
Ted Kremenek51be0562007-08-24 21:09:09 +0000266
267// LabelStmt
268Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
Chris Lattnerf3e2a252007-08-30 00:53:54 +0000269Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
Ted Kremenek51be0562007-08-24 21:09:09 +0000270
271// IfStmt
272Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; }
273Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; }
274
275// SwitchStmt
276Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; }
277Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; }
278
279// WhileStmt
280Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; }
281Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; }
282
283// DoStmt
284Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; }
285Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
286
287// ForStmt
288Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; }
289Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; }
290
Ted Kremenek42730c52008-01-07 19:49:32 +0000291// ObjCForCollectionStmt
Nico Weber7340a2f2008-08-05 23:15:29 +0000292Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
293 return &SubExprs[0];
Fariborz Jahanian9e920f32008-01-02 22:54:34 +0000294}
Nico Weber7340a2f2008-08-05 23:15:29 +0000295Stmt::child_iterator ObjCForCollectionStmt::child_end() {
296 return &SubExprs[0]+END_EXPR;
Fariborz Jahanian9e920f32008-01-02 22:54:34 +0000297}
298
Ted Kremenek51be0562007-08-24 21:09:09 +0000299// GotoStmt
Ted Kremeneka6478552007-10-18 23:28:49 +0000300Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
301Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
Ted Kremenek51be0562007-08-24 21:09:09 +0000302
303// IndirectGotoStmt
Ted Kremenek156714e2008-06-17 03:11:08 +0000304Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); }
305const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); }
Ted Kremenek51be0562007-08-24 21:09:09 +0000306
Ted Kremenek156714e2008-06-17 03:11:08 +0000307Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; }
308Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; }
Ted Kremenek51be0562007-08-24 21:09:09 +0000309
310// ContinueStmt
Ted Kremeneka6478552007-10-18 23:28:49 +0000311Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
312Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); }
Ted Kremenek51be0562007-08-24 21:09:09 +0000313
314// BreakStmt
Ted Kremeneka6478552007-10-18 23:28:49 +0000315Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); }
316Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
Ted Kremenek51be0562007-08-24 21:09:09 +0000317
318// ReturnStmt
Ted Kremenek156714e2008-06-17 03:11:08 +0000319const Expr* ReturnStmt::getRetValue() const {
320 return cast_or_null<Expr>(RetExpr);
321}
322Expr* ReturnStmt::getRetValue() {
323 return cast_or_null<Expr>(RetExpr);
Ted Kremenek51be0562007-08-24 21:09:09 +0000324}
325
Ted Kremenek156714e2008-06-17 03:11:08 +0000326Stmt::child_iterator ReturnStmt::child_begin() {
327 return &RetExpr;
328}
329Stmt::child_iterator ReturnStmt::child_end() {
330 return RetExpr ? &RetExpr+1 : &RetExpr;
Ted Kremenek8a66ed42007-08-27 20:58:16 +0000331}
Ted Kremenek51be0562007-08-24 21:09:09 +0000332
Chris Lattner8a40a832007-10-29 04:04:16 +0000333// AsmStmt
Ted Kremenekb30de272008-10-27 18:40:21 +0000334Stmt::child_iterator AsmStmt::child_begin() {
335 return Exprs.empty() ? 0 : &Exprs[0];
336}
337Stmt::child_iterator AsmStmt::child_end() {
338 return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size();
339}
Chris Lattner8a40a832007-10-29 04:04:16 +0000340
Ted Kremenek42730c52008-01-07 19:49:32 +0000341// ObjCAtCatchStmt
342Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; }
Nico Weber7340a2f2008-08-05 23:15:29 +0000343Stmt::child_iterator ObjCAtCatchStmt::child_end() {
344 return &SubExprs[0]+END_EXPR;
Fariborz Jahanian06798362007-11-01 23:59:59 +0000345}
Fariborz Jahanian70952482007-11-01 21:12:44 +0000346
Ted Kremenek42730c52008-01-07 19:49:32 +0000347// ObjCAtFinallyStmt
348Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; }
349Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; }
Fariborz Jahanian70952482007-11-01 21:12:44 +0000350
Ted Kremenek42730c52008-01-07 19:49:32 +0000351// ObjCAtTryStmt
352Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; }
Nico Weber7340a2f2008-08-05 23:15:29 +0000353Stmt::child_iterator ObjCAtTryStmt::child_end() {
354 return &SubStmts[0]+END_EXPR;
Fariborz Jahanian06798362007-11-01 23:59:59 +0000355}
Fariborz Jahanian70952482007-11-01 21:12:44 +0000356
Ted Kremenek42730c52008-01-07 19:49:32 +0000357// ObjCAtThrowStmt
358Stmt::child_iterator ObjCAtThrowStmt::child_begin() {
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000359 return &Throw;
360}
361
Ted Kremenek42730c52008-01-07 19:49:32 +0000362Stmt::child_iterator ObjCAtThrowStmt::child_end() {
Fariborz Jahanian08df2c62007-11-07 02:00:49 +0000363 return &Throw+1;
364}
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000365
366// ObjCAtSynchronizedStmt
367Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() {
Fariborz Jahanian499bf412008-01-29 22:59:37 +0000368 return &SubStmts[0];
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000369}
370
371Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() {
Fariborz Jahanian499bf412008-01-29 22:59:37 +0000372 return &SubStmts[0]+END_EXPR;
Fariborz Jahanianc9fd4d12008-01-29 19:14:59 +0000373}
374
Sebastian Redl743c8162008-12-22 19:15:10 +0000375// CXXCatchStmt
376Stmt::child_iterator CXXCatchStmt::child_begin() {
377 return &HandlerBlock;
378}
379
380Stmt::child_iterator CXXCatchStmt::child_end() {
381 return &HandlerBlock + 1;
382}
383
384QualType CXXCatchStmt::getCaughtType() {
385 if (ExceptionDecl)
386 return llvm::cast<VarDecl>(ExceptionDecl)->getType();
387 return QualType();
388}
389
390void CXXCatchStmt::Destroy(ASTContext& C) {
Sebastian Redl237116b2008-12-22 21:35:02 +0000391 if (ExceptionDecl)
392 ExceptionDecl->Destroy(C);
Sebastian Redl743c8162008-12-22 19:15:10 +0000393 Stmt::Destroy(C);
394}
Sebastian Redl237116b2008-12-22 21:35:02 +0000395
396// CXXTryStmt
397Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; }
398Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); }
399
400CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
401 Stmt **handlers, unsigned numHandlers)
402 : Stmt(CXXTryStmtClass), TryLoc(tryLoc) {
403 Stmts.push_back(tryBlock);
404 Stmts.insert(Stmts.end(), handlers, handlers + numHandlers);
405}