Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 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 Naroff | f494b57 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprObjC.h" |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Ted Kremenek | 11e5a7f | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | using namespace clang; |
| 20 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | static struct StmtClassNameTable { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 22 | const char *Name; |
| 23 | unsigned Counter; |
| 24 | unsigned Size; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 25 | } StmtClassInfo[Stmt::lastExprConstant+1]; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 26 | |
| 27 | static 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 Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 34 | #define STMT(CLASS, PARENT) \ |
| 35 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 36 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 37 | #include "clang/AST/StmtNodes.def" |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 39 | return StmtClassInfo[E]; |
| 40 | } |
| 41 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 42 | const char *Stmt::getStmtClassName() const { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 43 | return getStmtInfoTableEntry(sClass).Name; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Chris Lattner | 24e1e70 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 46 | void Stmt::DestroyChildren(ASTContext &C) { |
| 47 | for (child_iterator I = child_begin(), E = child_end(); I !=E; ) |
Douglas Gregor | 860f6d4 | 2009-01-16 06:50:08 +0000 | [diff] [blame] | 48 | if (Stmt* Child = *I++) Child->Destroy(C); |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Chris Lattner | 24e1e70 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 51 | void Stmt::Destroy(ASTContext &C) { |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 52 | DestroyChildren(C); |
Ted Kremenek | f809e3b | 2008-05-20 04:10:52 +0000 | [diff] [blame] | 53 | // FIXME: Eventually all Stmts should be allocated with the allocator |
| 54 | // in ASTContext, just like with Decls. |
Ted Kremenek | 11e5a7f | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 55 | this->~Stmt(); |
| 56 | C.Deallocate((void *)this); |
Ted Kremenek | 9c1863e | 2008-05-19 22:02:12 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Chris Lattner | 24e1e70 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 59 | void DeclStmt::Destroy(ASTContext &C) { |
Ted Kremenek | 11e5a7f | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 60 | this->~DeclStmt(); |
| 61 | C.Deallocate((void *)this); |
Ted Kremenek | 8e355f2 | 2008-05-21 15:53:55 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 64 | void Stmt::PrintStats() { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 65 | // Ensure the table is primed. |
| 66 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 67 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | unsigned sum = 0; |
| 69 | fprintf(stderr, "*** Stmt/Expr Stats:\n"); |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 70 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 71 | if (StmtClassInfo[i].Name == 0) continue; |
| 72 | sum += StmtClassInfo[i].Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 73 | } |
| 74 | fprintf(stderr, " %d stmts/exprs total.\n", sum); |
| 75 | sum = 0; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 76 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 77 | if (StmtClassInfo[i].Name == 0) continue; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 78 | fprintf(stderr, " %d %s, %d each (%d bytes)\n", |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 79 | 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; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 83 | } |
| 84 | fprintf(stderr, "Total bytes = %d\n", sum); |
| 85 | } |
| 86 | |
| 87 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 88 | ++getStmtInfoTableEntry(s).Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static bool StatSwitch = false; |
| 92 | |
| 93 | bool Stmt::CollectingStats(bool enable) { |
| 94 | if (enable) StatSwitch = true; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 95 | return StatSwitch; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 99 | const char *LabelStmt::getName() const { |
| 100 | return getID()->getName(); |
| 101 | } |
| 102 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 103 | // This is defined here to avoid polluting Stmt.h with importing Expr.h |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 104 | SourceRange ReturnStmt::getSourceRange() const { |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 105 | if (RetExpr) |
| 106 | return SourceRange(RetLoc, RetExpr->getLocEnd()); |
| 107 | else |
| 108 | return SourceRange(RetLoc); |
| 109 | } |
| 110 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 111 | bool Stmt::hasImplicitControlFlow() const { |
| 112 | switch (sClass) { |
| 113 | default: |
| 114 | return false; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 115 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 116 | case CallExprClass: |
| 117 | case ConditionalOperatorClass: |
| 118 | case ChooseExprClass: |
| 119 | case StmtExprClass: |
| 120 | case DeclStmtClass: |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 121 | return true; |
| 122 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 123 | 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 Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame^] | 133 | Expr *AsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 134 | return cast<Expr>(Exprs[i]); |
| 135 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame^] | 136 | |
| 137 | /// getOutputConstraint - Return the constraint string for the specified |
| 138 | /// output operand. All output constraints are known to be non-empty (either |
| 139 | /// '=' or '+'). |
| 140 | std::string AsmStmt::getOutputConstraint(unsigned i) const { |
| 141 | return std::string(Constraints[i]->getStrData(), |
| 142 | Constraints[i]->getByteLength()); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 143 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame^] | 144 | |
| 145 | |
| 146 | Expr *AsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 147 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 148 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame^] | 149 | |
| 150 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 151 | /// constraints, these can be empty. |
| 152 | std::string AsmStmt::getInputConstraint(unsigned i) const { |
| 153 | return std::string(Constraints[i + NumOutputs]->getStrData(), |
| 154 | Constraints[i + NumOutputs]->getByteLength()); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 157 | //===----------------------------------------------------------------------===// |
| 158 | // Constructors |
| 159 | //===----------------------------------------------------------------------===// |
| 160 | |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 161 | AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 162 | unsigned numoutputs, unsigned numinputs, |
| 163 | std::string *names, StringLiteral **constraints, |
| 164 | Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, |
| 165 | StringLiteral **clobbers, SourceLocation rparenloc) |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 166 | : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr) |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 167 | , IsSimple(issimple), IsVolatile(isvolatile) |
| 168 | , NumOutputs(numoutputs), NumInputs(numinputs) { |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 169 | for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) { |
| 170 | Names.push_back(names[i]); |
| 171 | Exprs.push_back(exprs[i]); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 172 | Constraints.push_back(constraints[i]); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 173 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 174 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 175 | for (unsigned i = 0; i != numclobbers; i++) |
| 176 | Clobbers.push_back(clobbers[i]); |
| 177 | } |
| 178 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 179 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 180 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 181 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 182 | : Stmt(ObjCForCollectionStmtClass) { |
| 183 | SubExprs[ELEM] = Elem; |
| 184 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 185 | SubExprs[BODY] = Body; |
| 186 | ForLoc = FCL; |
| 187 | RParenLoc = RPL; |
| 188 | } |
| 189 | |
| 190 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 191 | ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, |
| 192 | SourceLocation rparenloc, |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 193 | ParmVarDecl *catchVarDecl, Stmt *atCatchStmt, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 194 | Stmt *atCatchList) |
| 195 | : Stmt(ObjCAtCatchStmtClass) { |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 196 | ExceptionDecl = catchVarDecl; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 197 | SubExprs[BODY] = atCatchStmt; |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 198 | SubExprs[NEXT_CATCH] = NULL; |
Daniel Dunbar | 93b2bdb | 2009-03-01 04:28:32 +0000 | [diff] [blame] | 199 | // FIXME: O(N^2) in number of catch blocks. |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 200 | if (atCatchList) { |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 201 | ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList); |
| 202 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 203 | while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 204 | AtCatchList = NextCatch; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 205 | |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 206 | AtCatchList->SubExprs[NEXT_CATCH] = this; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 207 | } |
| 208 | AtCatchLoc = atCatchLoc; |
| 209 | RParenLoc = rparenloc; |
| 210 | } |
| 211 | |
| 212 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 213 | //===----------------------------------------------------------------------===// |
| 214 | // Child Iterators for iterating over subexpressions/substatements |
| 215 | //===----------------------------------------------------------------------===// |
| 216 | |
| 217 | // DeclStmt |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 218 | Stmt::child_iterator DeclStmt::child_begin() { |
| 219 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | 14f8b4f | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 222 | Stmt::child_iterator DeclStmt::child_end() { |
| 223 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 65aa3b9 | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 224 | } |
| 225 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 226 | // NullStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 227 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 228 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 229 | |
| 230 | // CompoundStmt |
| 231 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 232 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 233 | |
Ted Kremenek | d97bb6c | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 234 | // CaseStmt |
| 235 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 236 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 237 | |
| 238 | // DefaultStmt |
| 239 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 240 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 241 | |
| 242 | // LabelStmt |
| 243 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 244 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 245 | |
| 246 | // IfStmt |
| 247 | Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; } |
| 248 | Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 249 | |
| 250 | // SwitchStmt |
| 251 | Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; } |
| 252 | Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 253 | |
| 254 | // WhileStmt |
| 255 | Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; } |
| 256 | Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 257 | |
| 258 | // DoStmt |
| 259 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 260 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 261 | |
| 262 | // ForStmt |
| 263 | Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; } |
| 264 | Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 265 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 266 | // ObjCForCollectionStmt |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 267 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 268 | return &SubExprs[0]; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 269 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 270 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 271 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 274 | // GotoStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 275 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 276 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 277 | |
| 278 | // IndirectGotoStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 279 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 280 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 281 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 282 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 283 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 284 | |
| 285 | // ContinueStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 286 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 287 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 288 | |
| 289 | // BreakStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 290 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 291 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 292 | |
| 293 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 294 | const Expr* ReturnStmt::getRetValue() const { |
| 295 | return cast_or_null<Expr>(RetExpr); |
| 296 | } |
| 297 | Expr* ReturnStmt::getRetValue() { |
| 298 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 301 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 302 | return &RetExpr; |
| 303 | } |
| 304 | Stmt::child_iterator ReturnStmt::child_end() { |
| 305 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 2298f91 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 306 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 307 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 308 | // AsmStmt |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 309 | Stmt::child_iterator AsmStmt::child_begin() { |
| 310 | return Exprs.empty() ? 0 : &Exprs[0]; |
| 311 | } |
| 312 | Stmt::child_iterator AsmStmt::child_end() { |
| 313 | return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size(); |
| 314 | } |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 315 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 316 | // ObjCAtCatchStmt |
| 317 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 318 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 319 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 320 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 321 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 322 | // ObjCAtFinallyStmt |
| 323 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 324 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 325 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 326 | // ObjCAtTryStmt |
| 327 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 328 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 329 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 330 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 331 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 332 | // ObjCAtThrowStmt |
| 333 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 334 | return &Throw; |
| 335 | } |
| 336 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 337 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 338 | return &Throw+1; |
| 339 | } |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 340 | |
| 341 | // ObjCAtSynchronizedStmt |
| 342 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 343 | return &SubStmts[0]; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 347 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 348 | } |
| 349 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 350 | // CXXCatchStmt |
| 351 | Stmt::child_iterator CXXCatchStmt::child_begin() { |
| 352 | return &HandlerBlock; |
| 353 | } |
| 354 | |
| 355 | Stmt::child_iterator CXXCatchStmt::child_end() { |
| 356 | return &HandlerBlock + 1; |
| 357 | } |
| 358 | |
| 359 | QualType CXXCatchStmt::getCaughtType() { |
| 360 | if (ExceptionDecl) |
| 361 | return llvm::cast<VarDecl>(ExceptionDecl)->getType(); |
| 362 | return QualType(); |
| 363 | } |
| 364 | |
| 365 | void CXXCatchStmt::Destroy(ASTContext& C) { |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 366 | if (ExceptionDecl) |
| 367 | ExceptionDecl->Destroy(C); |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 368 | Stmt::Destroy(C); |
| 369 | } |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 370 | |
| 371 | // CXXTryStmt |
| 372 | Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; } |
| 373 | Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); } |
| 374 | |
| 375 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
| 376 | Stmt **handlers, unsigned numHandlers) |
| 377 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc) { |
| 378 | Stmts.push_back(tryBlock); |
| 379 | Stmts.insert(Stmts.end(), handlers, handlers + numHandlers); |
| 380 | } |