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 | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 157 | |
| 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. |
| 161 | int 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 Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 182 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 183 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 184 | /// true, otherwise return false. |
Chris Lattner | fb5058e | 2009-03-10 23:41:04 +0000 | [diff] [blame^] | 185 | unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces, |
| 186 | ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 187 | const char *StrStart = getAsmString()->getStrData(); |
| 188 | const char *StrEnd = StrStart + getAsmString()->getByteLength(); |
| 189 | |
| 190 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 191 | // string to escape $'s. |
| 192 | if (isSimple()) { |
| 193 | std::string Result; |
| 194 | for (; StrStart != StrEnd; ++StrStart) { |
| 195 | switch (*StrStart) { |
| 196 | case '$': |
| 197 | Result += "$$"; |
| 198 | break; |
| 199 | default: |
| 200 | Result += *StrStart; |
| 201 | break; |
| 202 | } |
| 203 | } |
| 204 | Pieces.push_back(AsmStringPiece(Result)); |
| 205 | return false; |
| 206 | } |
| 207 | |
| 208 | // CurStringPiece - The current string that we are building up as we scan the |
| 209 | // asm string. |
| 210 | std::string CurStringPiece; |
| 211 | |
| 212 | while (1) { |
| 213 | // Done with the string? |
| 214 | if (StrStart == StrEnd) { |
| 215 | if (!CurStringPiece.empty()) |
| 216 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 217 | return false; |
| 218 | } |
| 219 | |
| 220 | char CurChar = *StrStart++; |
| 221 | if (CurChar == '$') { |
| 222 | CurStringPiece += "$$"; |
| 223 | continue; |
| 224 | } else if (CurChar != '%') { |
| 225 | CurStringPiece += CurChar; |
| 226 | continue; |
| 227 | } |
| 228 | |
| 229 | // Escaped "%" character in asm string. |
| 230 | // FIXME: This should be caught during Sema. |
| 231 | assert(StrStart != StrEnd && "Trailing '%' in asm string."); |
| 232 | |
| 233 | char EscapedChar = *StrStart++; |
| 234 | if (EscapedChar == '%') { // %% -> % |
| 235 | // Escaped percentage sign. |
| 236 | CurStringPiece += '%'; |
| 237 | continue; |
| 238 | } |
| 239 | |
| 240 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 241 | CurStringPiece += "${:uid}"; |
| 242 | continue; |
| 243 | } |
| 244 | |
| 245 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 246 | // add it to the Pieces list. |
| 247 | if (!CurStringPiece.empty()) { |
| 248 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 249 | CurStringPiece.clear(); |
| 250 | } |
| 251 | |
| 252 | // Handle %x4 and %x[foo] by capturing x as the modifier character. |
| 253 | char Modifier = '\0'; |
| 254 | if (isalpha(EscapedChar)) { |
| 255 | Modifier = EscapedChar; |
| 256 | EscapedChar = *StrStart++; |
| 257 | } |
| 258 | |
| 259 | if (isdigit(EscapedChar)) { |
| 260 | // %n - Assembler operand n |
| 261 | char *End; |
| 262 | unsigned long N = strtoul(StrStart-1, &End, 10); |
| 263 | assert(End != StrStart-1 && "We know that EscapedChar is a digit!"); |
| 264 | StrStart = End; |
| 265 | |
| 266 | // FIXME: This should be caught during Sema. |
| 267 | //unsigned NumOperands = S.getNumOutputs() + S.getNumInputs(); |
| 268 | //assert(N < NumOperands && "Operand number out of range!"); |
| 269 | |
| 270 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 271 | continue; |
| 272 | } |
| 273 | |
| 274 | // Handle %[foo], a symbolic operand reference. |
| 275 | if (EscapedChar == '[') { |
| 276 | const char *NameEnd = (const char*)memchr(StrStart, ']', StrEnd-StrStart); |
| 277 | // FIXME: Should be caught by sema. |
| 278 | // FIXME: Does sema catch multiple operands with the same name? |
| 279 | assert(NameEnd != 0 && "Could not parse symbolic name"); |
| 280 | std::string SymbolicName(StrStart, NameEnd); |
| 281 | StrStart = NameEnd+1; |
| 282 | |
| 283 | int N = getNamedOperand(SymbolicName); |
| 284 | assert(N != -1 && "FIXME: Catch in Sema."); |
| 285 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 286 | continue; |
| 287 | } |
| 288 | |
| 289 | assert(0 && "FIXME: Reject"); |
| 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 294 | //===----------------------------------------------------------------------===// |
| 295 | // Constructors |
| 296 | //===----------------------------------------------------------------------===// |
| 297 | |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 298 | AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 299 | unsigned numoutputs, unsigned numinputs, |
| 300 | std::string *names, StringLiteral **constraints, |
| 301 | Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, |
| 302 | StringLiteral **clobbers, SourceLocation rparenloc) |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 303 | : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr) |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 304 | , IsSimple(issimple), IsVolatile(isvolatile) |
| 305 | , NumOutputs(numoutputs), NumInputs(numinputs) { |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 306 | for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) { |
| 307 | Names.push_back(names[i]); |
| 308 | Exprs.push_back(exprs[i]); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 309 | Constraints.push_back(constraints[i]); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 310 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 311 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 312 | for (unsigned i = 0; i != numclobbers; i++) |
| 313 | Clobbers.push_back(clobbers[i]); |
| 314 | } |
| 315 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 316 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 317 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 318 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 319 | : Stmt(ObjCForCollectionStmtClass) { |
| 320 | SubExprs[ELEM] = Elem; |
| 321 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 322 | SubExprs[BODY] = Body; |
| 323 | ForLoc = FCL; |
| 324 | RParenLoc = RPL; |
| 325 | } |
| 326 | |
| 327 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 328 | ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, |
| 329 | SourceLocation rparenloc, |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 330 | ParmVarDecl *catchVarDecl, Stmt *atCatchStmt, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 331 | Stmt *atCatchList) |
| 332 | : Stmt(ObjCAtCatchStmtClass) { |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 333 | ExceptionDecl = catchVarDecl; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 334 | SubExprs[BODY] = atCatchStmt; |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 335 | SubExprs[NEXT_CATCH] = NULL; |
Daniel Dunbar | 93b2bdb | 2009-03-01 04:28:32 +0000 | [diff] [blame] | 336 | // FIXME: O(N^2) in number of catch blocks. |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 337 | if (atCatchList) { |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 338 | ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList); |
| 339 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 340 | while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 341 | AtCatchList = NextCatch; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 342 | |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 343 | AtCatchList->SubExprs[NEXT_CATCH] = this; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 344 | } |
| 345 | AtCatchLoc = atCatchLoc; |
| 346 | RParenLoc = rparenloc; |
| 347 | } |
| 348 | |
| 349 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 350 | //===----------------------------------------------------------------------===// |
| 351 | // Child Iterators for iterating over subexpressions/substatements |
| 352 | //===----------------------------------------------------------------------===// |
| 353 | |
| 354 | // DeclStmt |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 355 | Stmt::child_iterator DeclStmt::child_begin() { |
| 356 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | 14f8b4f | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 359 | Stmt::child_iterator DeclStmt::child_end() { |
| 360 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 65aa3b9 | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 361 | } |
| 362 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 363 | // NullStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 364 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 365 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 366 | |
| 367 | // CompoundStmt |
| 368 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 369 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 370 | |
Ted Kremenek | d97bb6c | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 371 | // CaseStmt |
| 372 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 373 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 374 | |
| 375 | // DefaultStmt |
| 376 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 377 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 378 | |
| 379 | // LabelStmt |
| 380 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 381 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 382 | |
| 383 | // IfStmt |
| 384 | Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; } |
| 385 | Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 386 | |
| 387 | // SwitchStmt |
| 388 | Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; } |
| 389 | Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 390 | |
| 391 | // WhileStmt |
| 392 | Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; } |
| 393 | Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 394 | |
| 395 | // DoStmt |
| 396 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 397 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 398 | |
| 399 | // ForStmt |
| 400 | Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; } |
| 401 | Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 402 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 403 | // ObjCForCollectionStmt |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 404 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 405 | return &SubExprs[0]; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 406 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 407 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 408 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 411 | // GotoStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 412 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 413 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 414 | |
| 415 | // IndirectGotoStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 416 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 417 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 418 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 419 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 420 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 421 | |
| 422 | // ContinueStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 423 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 424 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 425 | |
| 426 | // BreakStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 427 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 428 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 429 | |
| 430 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 431 | const Expr* ReturnStmt::getRetValue() const { |
| 432 | return cast_or_null<Expr>(RetExpr); |
| 433 | } |
| 434 | Expr* ReturnStmt::getRetValue() { |
| 435 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 438 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 439 | return &RetExpr; |
| 440 | } |
| 441 | Stmt::child_iterator ReturnStmt::child_end() { |
| 442 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 2298f91 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 443 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 444 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 445 | // AsmStmt |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 446 | Stmt::child_iterator AsmStmt::child_begin() { |
| 447 | return Exprs.empty() ? 0 : &Exprs[0]; |
| 448 | } |
| 449 | Stmt::child_iterator AsmStmt::child_end() { |
| 450 | return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size(); |
| 451 | } |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 453 | // ObjCAtCatchStmt |
| 454 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 455 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 456 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 457 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 458 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 459 | // ObjCAtFinallyStmt |
| 460 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 461 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 462 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 463 | // ObjCAtTryStmt |
| 464 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 465 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 466 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 467 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 468 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 469 | // ObjCAtThrowStmt |
| 470 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 471 | return &Throw; |
| 472 | } |
| 473 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 474 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 475 | return &Throw+1; |
| 476 | } |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 477 | |
| 478 | // ObjCAtSynchronizedStmt |
| 479 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 480 | return &SubStmts[0]; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 484 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 487 | // CXXCatchStmt |
| 488 | Stmt::child_iterator CXXCatchStmt::child_begin() { |
| 489 | return &HandlerBlock; |
| 490 | } |
| 491 | |
| 492 | Stmt::child_iterator CXXCatchStmt::child_end() { |
| 493 | return &HandlerBlock + 1; |
| 494 | } |
| 495 | |
| 496 | QualType CXXCatchStmt::getCaughtType() { |
| 497 | if (ExceptionDecl) |
| 498 | return llvm::cast<VarDecl>(ExceptionDecl)->getType(); |
| 499 | return QualType(); |
| 500 | } |
| 501 | |
| 502 | void CXXCatchStmt::Destroy(ASTContext& C) { |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 503 | if (ExceptionDecl) |
| 504 | ExceptionDecl->Destroy(C); |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 505 | Stmt::Destroy(C); |
| 506 | } |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 507 | |
| 508 | // CXXTryStmt |
| 509 | Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; } |
| 510 | Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); } |
| 511 | |
| 512 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
| 513 | Stmt **handlers, unsigned numHandlers) |
| 514 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc) { |
| 515 | Stmts.push_back(tryBlock); |
| 516 | Stmts.insert(Stmts.end(), handlers, handlers + numHandlers); |
| 517 | } |