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" |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 17 | #include "clang/AST/StmtCXX.h" |
| 18 | #include "clang/AST/StmtObjC.h" |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 19 | #include "clang/AST/Type.h" |
Ted Kremenek | 11e5a7f | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTContext.h" |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 21 | #include "clang/AST/ASTDiagnostic.h" |
Torok Edwin | f42e4a6 | 2009-08-24 13:25:12 +0000 | [diff] [blame] | 22 | #include <cstdio> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | static struct StmtClassNameTable { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 26 | const char *Name; |
| 27 | unsigned Counter; |
| 28 | unsigned Size; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 29 | } StmtClassInfo[Stmt::lastExprConstant+1]; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 30 | |
| 31 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 32 | static bool Initialized = false; |
| 33 | if (Initialized) |
| 34 | return StmtClassInfo[E]; |
| 35 | |
| 36 | // Intialize the table on the first use. |
| 37 | Initialized = true; |
Douglas Gregor | f2cad86 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 38 | #define STMT(CLASS, PARENT) \ |
| 39 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 40 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 41 | #include "clang/AST/StmtNodes.def" |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 43 | return StmtClassInfo[E]; |
| 44 | } |
| 45 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | const char *Stmt::getStmtClassName() const { |
Douglas Gregor | 43d9d92 | 2009-08-08 01:41:12 +0000 | [diff] [blame] | 47 | return getStmtInfoTableEntry((StmtClass)sClass).Name; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void Stmt::PrintStats() { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 51 | // Ensure the table is primed. |
| 52 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 53 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 54 | unsigned sum = 0; |
| 55 | fprintf(stderr, "*** Stmt/Expr Stats:\n"); |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 56 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 57 | if (StmtClassInfo[i].Name == 0) continue; |
| 58 | sum += StmtClassInfo[i].Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | } |
| 60 | fprintf(stderr, " %d stmts/exprs total.\n", sum); |
| 61 | sum = 0; |
Chris Lattner | 1f683e9 | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 62 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 63 | if (StmtClassInfo[i].Name == 0) continue; |
Douglas Gregor | dbe833d | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 64 | if (StmtClassInfo[i].Counter == 0) continue; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 65 | fprintf(stderr, " %d %s, %d each (%d bytes)\n", |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 66 | StmtClassInfo[i].Counter, StmtClassInfo[i].Name, |
| 67 | StmtClassInfo[i].Size, |
| 68 | StmtClassInfo[i].Counter*StmtClassInfo[i].Size); |
| 69 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | } |
| 71 | fprintf(stderr, "Total bytes = %d\n", sum); |
| 72 | } |
| 73 | |
| 74 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 75 | ++getStmtInfoTableEntry(s).Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static bool StatSwitch = false; |
| 79 | |
Kovarththanan Rajaratnam | 2024f4d | 2009-11-29 14:54:35 +0000 | [diff] [blame] | 80 | bool Stmt::CollectingStats(bool Enable) { |
| 81 | if (Enable) StatSwitch = true; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 82 | return StatSwitch; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 85 | void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) { |
| 86 | if (this->Body) |
| 87 | C.Deallocate(Body); |
| 88 | this->NumStmts = NumStmts; |
| 89 | |
| 90 | Body = new (C) Stmt*[NumStmts]; |
| 91 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 92 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 94 | const char *LabelStmt::getName() const { |
Daniel Dunbar | e013d68 | 2009-10-18 20:26:12 +0000 | [diff] [blame] | 95 | return getID()->getNameStart(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 98 | // 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] | 99 | SourceRange ReturnStmt::getSourceRange() const { |
Steve Naroff | 507f2d5 | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 100 | if (RetExpr) |
| 101 | return SourceRange(RetLoc, RetExpr->getLocEnd()); |
| 102 | else |
| 103 | return SourceRange(RetLoc); |
| 104 | } |
| 105 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 106 | bool Stmt::hasImplicitControlFlow() const { |
| 107 | switch (sClass) { |
| 108 | default: |
| 109 | return false; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 110 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 111 | case CallExprClass: |
| 112 | case ConditionalOperatorClass: |
| 113 | case ChooseExprClass: |
| 114 | case StmtExprClass: |
| 115 | case DeclStmtClass: |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 116 | return true; |
| 117 | |
Ted Kremenek | d48ade6 | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 118 | case Stmt::BinaryOperatorClass: { |
| 119 | const BinaryOperator* B = cast<BinaryOperator>(this); |
| 120 | if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma) |
| 121 | return true; |
| 122 | else |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 128 | Expr *AsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 129 | return cast<Expr>(Exprs[i]); |
| 130 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 131 | |
| 132 | /// getOutputConstraint - Return the constraint string for the specified |
| 133 | /// output operand. All output constraints are known to be non-empty (either |
| 134 | /// '=' or '+'). |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 135 | llvm::StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
| 136 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 137 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 138 | |
Chris Lattner | 8575927 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 139 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 140 | /// constraint. |
| 141 | unsigned AsmStmt::getNumPlusOperands() const { |
| 142 | unsigned Res = 0; |
| 143 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 144 | if (isOutputPlusConstraint(i)) |
| 145 | ++Res; |
| 146 | return Res; |
| 147 | } |
| 148 | |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 149 | Expr *AsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 150 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 151 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 152 | |
| 153 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 154 | /// constraints, these can be empty. |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 155 | llvm::StringRef AsmStmt::getInputConstraint(unsigned i) const { |
| 156 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 157 | } |
| 158 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 159 | |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 160 | void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C, |
| 161 | const std::string *Names, |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 162 | StringLiteral **Constraints, |
| 163 | Stmt **Exprs, |
| 164 | unsigned NumOutputs, |
| 165 | unsigned NumInputs, |
| 166 | StringLiteral **Clobbers, |
| 167 | unsigned NumClobbers) { |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 168 | this->NumOutputs = NumOutputs; |
| 169 | this->NumInputs = NumInputs; |
| 170 | this->Names.clear(); |
| 171 | this->Names.insert(this->Names.end(), Names, Names + NumOutputs + NumInputs); |
| 172 | this->Constraints.clear(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 173 | this->Constraints.insert(this->Constraints.end(), |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 174 | Constraints, Constraints + NumOutputs + NumInputs); |
| 175 | this->Exprs.clear(); |
| 176 | this->Exprs.insert(this->Exprs.end(), Exprs, Exprs + NumOutputs + NumInputs); |
Anders Carlsson | fdba9c0 | 2010-01-30 19:34:25 +0000 | [diff] [blame] | 177 | |
| 178 | this->Clobbers.clear(); |
| 179 | this->Clobbers.insert(this->Clobbers.end(), Clobbers, Clobbers + NumClobbers); |
Douglas Gregor | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 182 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 183 | /// translate this into a numeric value needed to reference the same operand. |
| 184 | /// This returns -1 if the operand name is invalid. |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 185 | int AsmStmt::getNamedOperand(llvm::StringRef SymbolicName) const { |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 186 | unsigned NumPlusOperands = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 187 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 188 | // Check if this is an output operand. |
| 189 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 190 | if (getOutputName(i) == SymbolicName) |
| 191 | return i; |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 192 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 194 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 195 | if (getInputName(i) == SymbolicName) |
| 196 | return getNumOutputs() + NumPlusOperands + i; |
| 197 | |
| 198 | // Not found. |
| 199 | return -1; |
| 200 | } |
| 201 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 202 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 203 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 204 | /// true, otherwise return false. |
Chris Lattner | fb5058e | 2009-03-10 23:41:04 +0000 | [diff] [blame] | 205 | unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces, |
| 206 | ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 207 | const char *StrStart = getAsmString()->getStrData(); |
| 208 | const char *StrEnd = StrStart + getAsmString()->getByteLength(); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 209 | const char *CurPtr = StrStart; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 210 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 211 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 212 | // string to escape $'s. |
| 213 | if (isSimple()) { |
| 214 | std::string Result; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 215 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 216 | switch (*CurPtr) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 217 | case '$': |
| 218 | Result += "$$"; |
| 219 | break; |
| 220 | default: |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 221 | Result += *CurPtr; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 222 | break; |
| 223 | } |
| 224 | } |
| 225 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 226 | return 0; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // CurStringPiece - The current string that we are building up as we scan the |
| 230 | // asm string. |
| 231 | std::string CurStringPiece; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 233 | while (1) { |
| 234 | // Done with the string? |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 235 | if (CurPtr == StrEnd) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 236 | if (!CurStringPiece.empty()) |
| 237 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 238 | return 0; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 239 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 241 | char CurChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 242 | if (CurChar == '$') { |
| 243 | CurStringPiece += "$$"; |
| 244 | continue; |
| 245 | } else if (CurChar != '%') { |
| 246 | CurStringPiece += CurChar; |
| 247 | continue; |
| 248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 250 | // Escaped "%" character in asm string. |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 251 | if (CurPtr == StrEnd) { |
| 252 | // % at end of string is invalid (no escape). |
| 253 | DiagOffs = CurPtr-StrStart-1; |
| 254 | return diag::err_asm_invalid_escape; |
| 255 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 257 | char EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 258 | if (EscapedChar == '%') { // %% -> % |
| 259 | // Escaped percentage sign. |
| 260 | CurStringPiece += '%'; |
| 261 | continue; |
| 262 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 264 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 265 | CurStringPiece += "${:uid}"; |
| 266 | continue; |
| 267 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 268 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 269 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 270 | // add it to the Pieces list. |
| 271 | if (!CurStringPiece.empty()) { |
| 272 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 273 | CurStringPiece.clear(); |
| 274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 276 | // Handle %x4 and %x[foo] by capturing x as the modifier character. |
| 277 | char Modifier = '\0'; |
| 278 | if (isalpha(EscapedChar)) { |
| 279 | Modifier = EscapedChar; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 280 | EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 281 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 282 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 283 | if (isdigit(EscapedChar)) { |
| 284 | // %n - Assembler operand n |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 285 | unsigned N = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 286 | |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 287 | --CurPtr; |
| 288 | while (CurPtr != StrEnd && isdigit(*CurPtr)) |
Chris Lattner | 32a47ed | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 289 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 290 | |
Chris Lattner | 8575927 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 291 | unsigned NumOperands = |
| 292 | getNumOutputs() + getNumPlusOperands() + getNumInputs(); |
| 293 | if (N >= NumOperands) { |
| 294 | DiagOffs = CurPtr-StrStart-1; |
| 295 | return diag::err_asm_invalid_operand_number; |
| 296 | } |
| 297 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 298 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 299 | continue; |
| 300 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 301 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 302 | // Handle %[foo], a symbolic operand reference. |
| 303 | if (EscapedChar == '[') { |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 304 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 305 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 306 | // Find the ']'. |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 307 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 308 | if (NameEnd == 0) |
| 309 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 310 | if (NameEnd == CurPtr) |
| 311 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Anders Carlsson | 95c9ce9 | 2010-01-30 20:48:08 +0000 | [diff] [blame^] | 313 | llvm::StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 314 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 315 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 316 | if (N == -1) { |
| 317 | // Verify that an operand with that name exists. |
| 318 | DiagOffs = CurPtr-StrStart; |
| 319 | return diag::err_asm_unknown_symbolic_operand_name; |
| 320 | } |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 321 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 323 | CurPtr = NameEnd+1; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 324 | continue; |
| 325 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 326 | |
Chris Lattner | 2ff0f42 | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 327 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 328 | return diag::err_asm_invalid_escape; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 332 | //===----------------------------------------------------------------------===// |
| 333 | // Constructors |
| 334 | //===----------------------------------------------------------------------===// |
| 335 | |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 336 | AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, |
Mike Stump | 3b11fd3 | 2010-01-04 22:37:17 +0000 | [diff] [blame] | 337 | bool msasm, unsigned numoutputs, unsigned numinputs, |
Anders Carlsson | 703e394 | 2010-01-24 05:50:09 +0000 | [diff] [blame] | 338 | const std::string *names, StringLiteral **constraints, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 339 | Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, |
| 340 | StringLiteral **clobbers, SourceLocation rparenloc) |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 341 | : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr) |
Mike Stump | 3b11fd3 | 2010-01-04 22:37:17 +0000 | [diff] [blame] | 342 | , IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm) |
Anders Carlsson | dfab34a | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 343 | , NumOutputs(numoutputs), NumInputs(numinputs) { |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 344 | for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) { |
| 345 | Names.push_back(names[i]); |
| 346 | Exprs.push_back(exprs[i]); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 347 | Constraints.push_back(constraints[i]); |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 348 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 349 | |
Anders Carlsson | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 350 | for (unsigned i = 0; i != numclobbers; i++) |
| 351 | Clobbers.push_back(clobbers[i]); |
| 352 | } |
| 353 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 354 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 355 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 356 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 357 | : Stmt(ObjCForCollectionStmtClass) { |
| 358 | SubExprs[ELEM] = Elem; |
| 359 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 360 | SubExprs[BODY] = Body; |
| 361 | ForLoc = FCL; |
| 362 | RParenLoc = RPL; |
| 363 | } |
| 364 | |
| 365 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 366 | ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, |
| 367 | SourceLocation rparenloc, |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 368 | ParmVarDecl *catchVarDecl, Stmt *atCatchStmt, |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 369 | Stmt *atCatchList) |
| 370 | : Stmt(ObjCAtCatchStmtClass) { |
Steve Naroff | 7ba138a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 371 | ExceptionDecl = catchVarDecl; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 372 | SubExprs[BODY] = atCatchStmt; |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 373 | SubExprs[NEXT_CATCH] = NULL; |
Daniel Dunbar | 93b2bdb | 2009-03-01 04:28:32 +0000 | [diff] [blame] | 374 | // FIXME: O(N^2) in number of catch blocks. |
Eli Friedman | 0613c37 | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 375 | if (atCatchList) { |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 376 | ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList); |
| 377 | |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 378 | while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 379 | AtCatchList = NextCatch; |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 380 | |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 381 | AtCatchList->SubExprs[NEXT_CATCH] = this; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 382 | } |
| 383 | AtCatchLoc = atCatchLoc; |
| 384 | RParenLoc = rparenloc; |
| 385 | } |
| 386 | |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 387 | //===----------------------------------------------------------------------===// |
| 388 | // AST Destruction. |
| 389 | //===----------------------------------------------------------------------===// |
| 390 | |
| 391 | void Stmt::DestroyChildren(ASTContext &C) { |
| 392 | for (child_iterator I = child_begin(), E = child_end(); I !=E; ) |
| 393 | if (Stmt* Child = *I++) Child->Destroy(C); |
| 394 | } |
| 395 | |
| 396 | static void BranchDestroy(ASTContext &C, Stmt *S, Stmt **SubExprs, |
| 397 | unsigned NumExprs) { |
| 398 | // We do not use child_iterator here because that will include |
| 399 | // the expressions referenced by the condition variable. |
| 400 | for (Stmt **I = SubExprs, **E = SubExprs + NumExprs; I != E; ++I) |
| 401 | if (Stmt *Child = *I) Child->Destroy(C); |
| 402 | |
| 403 | S->~Stmt(); |
| 404 | C.Deallocate((void *) S); |
| 405 | } |
| 406 | |
| 407 | void Stmt::DoDestroy(ASTContext &C) { |
| 408 | DestroyChildren(C); |
| 409 | this->~Stmt(); |
| 410 | C.Deallocate((void *)this); |
| 411 | } |
| 412 | |
| 413 | void CXXCatchStmt::DoDestroy(ASTContext& C) { |
| 414 | if (ExceptionDecl) |
| 415 | ExceptionDecl->Destroy(C); |
| 416 | Stmt::DoDestroy(C); |
| 417 | } |
| 418 | |
| 419 | void DeclStmt::DoDestroy(ASTContext &C) { |
| 420 | // Don't use StmtIterator to iterate over the Decls, as that can recurse |
| 421 | // into VLA size expressions (which are owned by the VLA). Further, Decls |
| 422 | // are owned by the DeclContext, and will be destroyed with them. |
| 423 | if (DG.isDeclGroup()) |
| 424 | DG.getDeclGroup().Destroy(C); |
| 425 | } |
| 426 | |
| 427 | void IfStmt::DoDestroy(ASTContext &C) { |
| 428 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 429 | } |
| 430 | |
| 431 | void ForStmt::DoDestroy(ASTContext &C) { |
| 432 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 433 | } |
| 434 | |
| 435 | void SwitchStmt::DoDestroy(ASTContext &C) { |
| 436 | // Destroy the SwitchCase statements in this switch. In the normal |
| 437 | // case, this loop will merely decrement the reference counts from |
| 438 | // the Retain() calls in addSwitchCase(); |
| 439 | SwitchCase *SC = FirstCase; |
| 440 | while (SC) { |
| 441 | SwitchCase *Next = SC->getNextSwitchCase(); |
| 442 | SC->Destroy(C); |
| 443 | SC = Next; |
| 444 | } |
| 445 | |
| 446 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 447 | } |
| 448 | |
| 449 | void WhileStmt::DoDestroy(ASTContext &C) { |
| 450 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 451 | } |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 453 | //===----------------------------------------------------------------------===// |
| 454 | // Child Iterators for iterating over subexpressions/substatements |
| 455 | //===----------------------------------------------------------------------===// |
| 456 | |
| 457 | // DeclStmt |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 458 | Stmt::child_iterator DeclStmt::child_begin() { |
| 459 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | 14f8b4f | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 462 | Stmt::child_iterator DeclStmt::child_end() { |
| 463 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 65aa3b9 | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 466 | // NullStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 467 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 468 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 469 | |
| 470 | // CompoundStmt |
| 471 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 472 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 473 | |
Ted Kremenek | d97bb6c | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 474 | // CaseStmt |
| 475 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 476 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 477 | |
| 478 | // DefaultStmt |
| 479 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 480 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 481 | |
| 482 | // LabelStmt |
| 483 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 484 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 485 | |
| 486 | // IfStmt |
Ted Kremenek | 35628d1 | 2009-12-23 23:38:34 +0000 | [diff] [blame] | 487 | Stmt::child_iterator IfStmt::child_begin() { |
| 488 | return child_iterator(Var, &SubExprs[0]); |
| 489 | } |
| 490 | Stmt::child_iterator IfStmt::child_end() { |
| 491 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 492 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 493 | |
| 494 | // SwitchStmt |
Ted Kremenek | a3be0ea | 2009-12-24 00:39:05 +0000 | [diff] [blame] | 495 | Stmt::child_iterator SwitchStmt::child_begin() { |
| 496 | return child_iterator(Var, &SubExprs[0]); |
| 497 | } |
| 498 | Stmt::child_iterator SwitchStmt::child_end() { |
| 499 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 500 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 501 | |
| 502 | // WhileStmt |
Ted Kremenek | 7d02b8c | 2009-12-24 00:54:19 +0000 | [diff] [blame] | 503 | Stmt::child_iterator WhileStmt::child_begin() { |
| 504 | return child_iterator(Var, &SubExprs[0]); |
| 505 | } |
| 506 | Stmt::child_iterator WhileStmt::child_end() { |
| 507 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 508 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 509 | |
| 510 | // DoStmt |
| 511 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 512 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 513 | |
| 514 | // ForStmt |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 515 | Stmt::child_iterator ForStmt::child_begin() { |
| 516 | return child_iterator(CondVar, &SubExprs[0]); |
| 517 | } |
| 518 | Stmt::child_iterator ForStmt::child_end() { |
Ted Kremenek | 6281213 | 2009-12-24 01:59:46 +0000 | [diff] [blame] | 519 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 520 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 521 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 522 | // ObjCForCollectionStmt |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 523 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 524 | return &SubExprs[0]; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 525 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 526 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 527 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 530 | // GotoStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 531 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 532 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 533 | |
| 534 | // IndirectGotoStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 535 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 536 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 537 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 538 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 539 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 540 | |
| 541 | // ContinueStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 542 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 543 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 544 | |
| 545 | // BreakStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 546 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 547 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 548 | |
| 549 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 550 | const Expr* ReturnStmt::getRetValue() const { |
| 551 | return cast_or_null<Expr>(RetExpr); |
| 552 | } |
| 553 | Expr* ReturnStmt::getRetValue() { |
| 554 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 555 | } |
| 556 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 557 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 558 | return &RetExpr; |
| 559 | } |
| 560 | Stmt::child_iterator ReturnStmt::child_end() { |
| 561 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 2298f91 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 562 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 563 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 564 | // AsmStmt |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | Stmt::child_iterator AsmStmt::child_begin() { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 566 | return Exprs.empty() ? 0 : &Exprs[0]; |
| 567 | } |
| 568 | Stmt::child_iterator AsmStmt::child_end() { |
| 569 | return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size(); |
| 570 | } |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 571 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 572 | // ObjCAtCatchStmt |
| 573 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 574 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 575 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 576 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 577 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 578 | // ObjCAtFinallyStmt |
| 579 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 580 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 581 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 582 | // ObjCAtTryStmt |
| 583 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 584 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 585 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 586 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 587 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 588 | // ObjCAtThrowStmt |
| 589 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 590 | return &Throw; |
| 591 | } |
| 592 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 593 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 594 | return &Throw+1; |
| 595 | } |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 596 | |
| 597 | // ObjCAtSynchronizedStmt |
| 598 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 599 | return &SubStmts[0]; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 603 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 606 | // CXXCatchStmt |
| 607 | Stmt::child_iterator CXXCatchStmt::child_begin() { |
| 608 | return &HandlerBlock; |
| 609 | } |
| 610 | |
| 611 | Stmt::child_iterator CXXCatchStmt::child_end() { |
| 612 | return &HandlerBlock + 1; |
| 613 | } |
| 614 | |
Mike Stump | 6515afe | 2009-11-30 20:10:58 +0000 | [diff] [blame] | 615 | QualType CXXCatchStmt::getCaughtType() const { |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 616 | if (ExceptionDecl) |
Douglas Gregor | d308e62 | 2009-05-18 20:51:54 +0000 | [diff] [blame] | 617 | return ExceptionDecl->getType(); |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 618 | return QualType(); |
| 619 | } |
| 620 | |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 621 | // CXXTryStmt |
| 622 | Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; } |
| 623 | Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); } |
| 624 | |
| 625 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
| 626 | Stmt **handlers, unsigned numHandlers) |
| 627 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc) { |
| 628 | Stmts.push_back(tryBlock); |
| 629 | Stmts.insert(Stmts.end(), handlers, handlers + numHandlers); |
| 630 | } |