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