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" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 17 | using namespace clang; |
| 18 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 19 | static struct StmtClassNameTable { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 20 | const char *Name; |
| 21 | unsigned Counter; |
| 22 | unsigned Size; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 23 | } StmtClassInfo[Stmt::lastExprConstant+1]; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 24 | |
| 25 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 26 | static bool Initialized = false; |
| 27 | if (Initialized) |
| 28 | return StmtClassInfo[E]; |
| 29 | |
| 30 | // Intialize the table on the first use. |
| 31 | Initialized = true; |
Douglas Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame^] | 32 | #define STMT(CLASS, PARENT) \ |
| 33 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 34 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 35 | #include "clang/AST/StmtNodes.def" |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 37 | return StmtClassInfo[E]; |
| 38 | } |
| 39 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 40 | const char *Stmt::getStmtClassName() const { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 41 | return getStmtInfoTableEntry(sClass).Name; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 44 | void Stmt::DestroyChildren(ASTContext& C) { |
Ted Kremenek | 9c1863e | 2008-05-19 22:02:12 +0000 | [diff] [blame] | 45 | for (child_iterator I = child_begin(), E = child_end(); I !=E; ++I) |
Ted Kremenek | 27f8a28 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 46 | if (Stmt* Child = *I) Child->Destroy(C); |
| 47 | } |
| 48 | |
| 49 | void Stmt::Destroy(ASTContext& C) { |
| 50 | DestroyChildren(C); |
Ted Kremenek | f809e3b | 2008-05-20 04:10:52 +0000 | [diff] [blame] | 51 | // FIXME: Eventually all Stmts should be allocated with the allocator |
| 52 | // in ASTContext, just like with Decls. |
| 53 | // this->~Stmt(); |
| 54 | delete this; |
Ted Kremenek | 9c1863e | 2008-05-19 22:02:12 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Ted Kremenek | 8e355f2 | 2008-05-21 15:53:55 +0000 | [diff] [blame] | 57 | void DeclStmt::Destroy(ASTContext& C) { |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 58 | DG.Destroy(C); |
Ted Kremenek | 936ff13 | 2008-05-21 16:00:02 +0000 | [diff] [blame] | 59 | delete this; |
Ted Kremenek | 8e355f2 | 2008-05-21 15:53:55 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 62 | void Stmt::PrintStats() { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 63 | // Ensure the table is primed. |
| 64 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 65 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 66 | unsigned sum = 0; |
| 67 | fprintf(stderr, "*** Stmt/Expr Stats:\n"); |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 68 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 69 | if (StmtClassInfo[i].Name == 0) continue; |
| 70 | sum += StmtClassInfo[i].Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 71 | } |
| 72 | fprintf(stderr, " %d stmts/exprs total.\n", sum); |
| 73 | sum = 0; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 74 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 75 | if (StmtClassInfo[i].Name == 0) continue; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 76 | fprintf(stderr, " %d %s, %d each (%d bytes)\n", |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 77 | StmtClassInfo[i].Counter, StmtClassInfo[i].Name, |
| 78 | StmtClassInfo[i].Size, |
| 79 | StmtClassInfo[i].Counter*StmtClassInfo[i].Size); |
| 80 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | } |
| 82 | fprintf(stderr, "Total bytes = %d\n", sum); |
| 83 | } |
| 84 | |
| 85 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 86 | ++getStmtInfoTableEntry(s).Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static bool StatSwitch = false; |
| 90 | |
| 91 | bool Stmt::CollectingStats(bool enable) { |
| 92 | if (enable) StatSwitch = true; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 93 | return StatSwitch; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | const char *LabelStmt::getName() const { |
| 98 | return getID()->getName(); |
| 99 | } |
| 100 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 101 | // 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] | 102 | SourceRange ReturnStmt::getSourceRange() const { |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 103 | if (RetExpr) |
| 104 | return SourceRange(RetLoc, RetExpr->getLocEnd()); |
| 105 | else |
| 106 | return SourceRange(RetLoc); |
| 107 | } |
| 108 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 109 | bool Stmt::hasImplicitControlFlow() const { |
| 110 | switch (sClass) { |
| 111 | default: |
| 112 | return false; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 113 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 114 | case CallExprClass: |
| 115 | case ConditionalOperatorClass: |
| 116 | case ChooseExprClass: |
| 117 | case StmtExprClass: |
| 118 | case DeclStmtClass: |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 119 | return true; |
| 120 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 121 | case Stmt::BinaryOperatorClass: { |
| 122 | const BinaryOperator* B = cast<BinaryOperator>(this); |
| 123 | if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma) |
| 124 | return true; |
| 125 | else |
| 126 | return false; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 131 | const Expr* AsmStmt::getOutputExpr(unsigned i) const { |
| 132 | return cast<Expr>(Exprs[i]); |
| 133 | } |
| 134 | Expr* AsmStmt::getOutputExpr(unsigned i) { |
| 135 | return cast<Expr>(Exprs[i]); |
| 136 | } |
| 137 | Expr* AsmStmt::getInputExpr(unsigned i) { |
| 138 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 139 | } |
| 140 | const Expr* AsmStmt::getInputExpr(unsigned i) const { |
| 141 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 142 | } |
| 143 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 144 | //===----------------------------------------------------------------------===// |
| 145 | // Constructors |
| 146 | //===----------------------------------------------------------------------===// |
| 147 | |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 148 | AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 149 | unsigned numoutputs, unsigned numinputs, |
| 150 | std::string *names, StringLiteral **constraints, |
| 151 | Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, |
| 152 | StringLiteral **clobbers, SourceLocation rparenloc) |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 153 | : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr) |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 154 | , IsSimple(issimple), IsVolatile(isvolatile) |
| 155 | , NumOutputs(numoutputs), NumInputs(numinputs) { |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 156 | for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) { |
| 157 | Names.push_back(names[i]); |
| 158 | Exprs.push_back(exprs[i]); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 159 | Constraints.push_back(constraints[i]); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 160 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 161 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 162 | for (unsigned i = 0; i != numclobbers; i++) |
| 163 | Clobbers.push_back(clobbers[i]); |
| 164 | } |
| 165 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 166 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 167 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 168 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 169 | : Stmt(ObjCForCollectionStmtClass) { |
| 170 | SubExprs[ELEM] = Elem; |
| 171 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 172 | SubExprs[BODY] = Body; |
| 173 | ForLoc = FCL; |
| 174 | RParenLoc = RPL; |
| 175 | } |
| 176 | |
| 177 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 178 | ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, |
| 179 | SourceLocation rparenloc, |
| 180 | Stmt *catchVarStmtDecl, Stmt *atCatchStmt, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 181 | Stmt *atCatchList) |
| 182 | : Stmt(ObjCAtCatchStmtClass) { |
| 183 | SubExprs[SELECTOR] = catchVarStmtDecl; |
| 184 | SubExprs[BODY] = atCatchStmt; |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 185 | SubExprs[NEXT_CATCH] = NULL; |
| 186 | if (atCatchList) { |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 187 | ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList); |
| 188 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 189 | while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 190 | AtCatchList = NextCatch; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 191 | |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 192 | AtCatchList->SubExprs[NEXT_CATCH] = this; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 193 | } |
| 194 | AtCatchLoc = atCatchLoc; |
| 195 | RParenLoc = rparenloc; |
| 196 | } |
| 197 | |
| 198 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 199 | //===----------------------------------------------------------------------===// |
| 200 | // Child Iterators for iterating over subexpressions/substatements |
| 201 | //===----------------------------------------------------------------------===// |
| 202 | |
| 203 | // DeclStmt |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 204 | Stmt::child_iterator DeclStmt::child_begin() { |
| 205 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | 14f8b4f | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 208 | Stmt::child_iterator DeclStmt::child_end() { |
| 209 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 65aa3b9 | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 212 | // NullStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 213 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 214 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 215 | |
| 216 | // CompoundStmt |
| 217 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
| 218 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+Body.size(); } |
| 219 | |
Ted Kremenek | d97bb6c | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 220 | // CaseStmt |
| 221 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 222 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 223 | |
| 224 | // DefaultStmt |
| 225 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 226 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 227 | |
| 228 | // LabelStmt |
| 229 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 230 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 231 | |
| 232 | // IfStmt |
| 233 | Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; } |
| 234 | Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 235 | |
| 236 | // SwitchStmt |
| 237 | Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; } |
| 238 | Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 239 | |
| 240 | // WhileStmt |
| 241 | Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; } |
| 242 | Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 243 | |
| 244 | // DoStmt |
| 245 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 246 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 247 | |
| 248 | // ForStmt |
| 249 | Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; } |
| 250 | Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 251 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 252 | // ObjCForCollectionStmt |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 253 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 254 | return &SubExprs[0]; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 255 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 256 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 257 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 260 | // GotoStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 261 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 262 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 263 | |
| 264 | // IndirectGotoStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 265 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 266 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 267 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 268 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 269 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 270 | |
| 271 | // ContinueStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 272 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 273 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 274 | |
| 275 | // BreakStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 276 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 277 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 278 | |
| 279 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 280 | const Expr* ReturnStmt::getRetValue() const { |
| 281 | return cast_or_null<Expr>(RetExpr); |
| 282 | } |
| 283 | Expr* ReturnStmt::getRetValue() { |
| 284 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 285 | } |
| 286 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 287 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 288 | return &RetExpr; |
| 289 | } |
| 290 | Stmt::child_iterator ReturnStmt::child_end() { |
| 291 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 2298f91 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 292 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 293 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 294 | // AsmStmt |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 295 | Stmt::child_iterator AsmStmt::child_begin() { |
| 296 | return Exprs.empty() ? 0 : &Exprs[0]; |
| 297 | } |
| 298 | Stmt::child_iterator AsmStmt::child_end() { |
| 299 | return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size(); |
| 300 | } |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 301 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 302 | // ObjCAtCatchStmt |
| 303 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 304 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 305 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 306 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 308 | // ObjCAtFinallyStmt |
| 309 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 310 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 311 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 312 | // ObjCAtTryStmt |
| 313 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 314 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 315 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 316 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 317 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 318 | // ObjCAtThrowStmt |
| 319 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 320 | return &Throw; |
| 321 | } |
| 322 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 323 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 324 | return &Throw+1; |
| 325 | } |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 326 | |
| 327 | // ObjCAtSynchronizedStmt |
| 328 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 329 | return &SubStmts[0]; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 333 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 334 | } |
| 335 | |