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