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