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 | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame^] | 410 | CXXTryStmt::CXXTryStmt(ASTContext &C, SourceLocation tryLoc, Stmt *tryBlock, |
| 411 | Stmt **handlers, unsigned numHandlers) |
| 412 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) { |
| 413 | Stmts = new (C) Stmt*[NumHandlers + 1]; |
| 414 | Stmts[0] = tryBlock; |
| 415 | std::copy(handlers, handlers + NumHandlers, Stmts + 1); |
| 416 | } |
| 417 | |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 418 | //===----------------------------------------------------------------------===// |
| 419 | // AST Destruction. |
| 420 | //===----------------------------------------------------------------------===// |
| 421 | |
| 422 | void Stmt::DestroyChildren(ASTContext &C) { |
| 423 | for (child_iterator I = child_begin(), E = child_end(); I !=E; ) |
| 424 | if (Stmt* Child = *I++) Child->Destroy(C); |
| 425 | } |
| 426 | |
| 427 | static void BranchDestroy(ASTContext &C, Stmt *S, Stmt **SubExprs, |
| 428 | unsigned NumExprs) { |
| 429 | // We do not use child_iterator here because that will include |
| 430 | // the expressions referenced by the condition variable. |
| 431 | for (Stmt **I = SubExprs, **E = SubExprs + NumExprs; I != E; ++I) |
| 432 | if (Stmt *Child = *I) Child->Destroy(C); |
| 433 | |
| 434 | S->~Stmt(); |
| 435 | C.Deallocate((void *) S); |
| 436 | } |
| 437 | |
| 438 | void Stmt::DoDestroy(ASTContext &C) { |
| 439 | DestroyChildren(C); |
| 440 | this->~Stmt(); |
| 441 | C.Deallocate((void *)this); |
| 442 | } |
| 443 | |
| 444 | void CXXCatchStmt::DoDestroy(ASTContext& C) { |
| 445 | if (ExceptionDecl) |
| 446 | ExceptionDecl->Destroy(C); |
| 447 | Stmt::DoDestroy(C); |
| 448 | } |
| 449 | |
| 450 | void DeclStmt::DoDestroy(ASTContext &C) { |
| 451 | // Don't use StmtIterator to iterate over the Decls, as that can recurse |
| 452 | // into VLA size expressions (which are owned by the VLA). Further, Decls |
| 453 | // are owned by the DeclContext, and will be destroyed with them. |
| 454 | if (DG.isDeclGroup()) |
| 455 | DG.getDeclGroup().Destroy(C); |
| 456 | } |
| 457 | |
| 458 | void IfStmt::DoDestroy(ASTContext &C) { |
| 459 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 460 | } |
| 461 | |
| 462 | void ForStmt::DoDestroy(ASTContext &C) { |
| 463 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 464 | } |
| 465 | |
| 466 | void SwitchStmt::DoDestroy(ASTContext &C) { |
| 467 | // Destroy the SwitchCase statements in this switch. In the normal |
| 468 | // case, this loop will merely decrement the reference counts from |
| 469 | // the Retain() calls in addSwitchCase(); |
| 470 | SwitchCase *SC = FirstCase; |
| 471 | while (SC) { |
| 472 | SwitchCase *Next = SC->getNextSwitchCase(); |
| 473 | SC->Destroy(C); |
| 474 | SC = Next; |
| 475 | } |
| 476 | |
| 477 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 478 | } |
| 479 | |
| 480 | void WhileStmt::DoDestroy(ASTContext &C) { |
| 481 | BranchDestroy(C, this, SubExprs, END_EXPR); |
| 482 | } |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 483 | |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 484 | void AsmStmt::DoDestroy(ASTContext &C) { |
| 485 | DestroyChildren(C); |
| 486 | |
| 487 | C.Deallocate(Names); |
| 488 | C.Deallocate(Constraints); |
| 489 | C.Deallocate(Exprs); |
| 490 | C.Deallocate(Clobbers); |
| 491 | |
Benjamin Kramer | a053154 | 2010-01-31 09:01:55 +0000 | [diff] [blame] | 492 | this->~AsmStmt(); |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 493 | C.Deallocate((void *)this); |
| 494 | } |
| 495 | |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame^] | 496 | void CXXTryStmt::DoDestroy(ASTContext& C) { |
| 497 | DestroyChildren(C); |
| 498 | C.Deallocate(Stmts); |
| 499 | |
| 500 | this->~CXXTryStmt(); |
| 501 | C.Deallocate((void *)this); |
| 502 | } |
| 503 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 504 | //===----------------------------------------------------------------------===// |
| 505 | // Child Iterators for iterating over subexpressions/substatements |
| 506 | //===----------------------------------------------------------------------===// |
| 507 | |
| 508 | // DeclStmt |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 509 | Stmt::child_iterator DeclStmt::child_begin() { |
| 510 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | 14f8b4f | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Ted Kremenek | 8ffb159 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 513 | Stmt::child_iterator DeclStmt::child_end() { |
| 514 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 65aa3b9 | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 517 | // NullStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 518 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 519 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 520 | |
| 521 | // CompoundStmt |
| 522 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
Ted Kremenek | 8189cde | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 523 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 524 | |
Ted Kremenek | d97bb6c | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 525 | // CaseStmt |
| 526 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 527 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 528 | |
| 529 | // DefaultStmt |
| 530 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 531 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 532 | |
| 533 | // LabelStmt |
| 534 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | b393879 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 535 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 536 | |
| 537 | // IfStmt |
Ted Kremenek | 35628d1 | 2009-12-23 23:38:34 +0000 | [diff] [blame] | 538 | Stmt::child_iterator IfStmt::child_begin() { |
| 539 | return child_iterator(Var, &SubExprs[0]); |
| 540 | } |
| 541 | Stmt::child_iterator IfStmt::child_end() { |
| 542 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 543 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 544 | |
| 545 | // SwitchStmt |
Ted Kremenek | a3be0ea | 2009-12-24 00:39:05 +0000 | [diff] [blame] | 546 | Stmt::child_iterator SwitchStmt::child_begin() { |
| 547 | return child_iterator(Var, &SubExprs[0]); |
| 548 | } |
| 549 | Stmt::child_iterator SwitchStmt::child_end() { |
| 550 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 551 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 552 | |
| 553 | // WhileStmt |
Ted Kremenek | 7d02b8c | 2009-12-24 00:54:19 +0000 | [diff] [blame] | 554 | Stmt::child_iterator WhileStmt::child_begin() { |
| 555 | return child_iterator(Var, &SubExprs[0]); |
| 556 | } |
| 557 | Stmt::child_iterator WhileStmt::child_end() { |
| 558 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
| 559 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 560 | |
| 561 | // DoStmt |
| 562 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 563 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 564 | |
| 565 | // ForStmt |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 566 | Stmt::child_iterator ForStmt::child_begin() { |
| 567 | return child_iterator(CondVar, &SubExprs[0]); |
| 568 | } |
| 569 | Stmt::child_iterator ForStmt::child_end() { |
Ted Kremenek | 6281213 | 2009-12-24 01:59:46 +0000 | [diff] [blame] | 570 | return child_iterator(0, &SubExprs[0]+END_EXPR); |
Ted Kremenek | f0d975f | 2009-12-24 01:48:39 +0000 | [diff] [blame] | 571 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 572 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 573 | // ObjCForCollectionStmt |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 574 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 575 | return &SubExprs[0]; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 576 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 577 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 578 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0196cab | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 581 | // GotoStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 582 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 583 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 584 | |
| 585 | // IndirectGotoStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 586 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 587 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 588 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 589 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 590 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 591 | |
| 592 | // ContinueStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 593 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 594 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 595 | |
| 596 | // BreakStmt |
Ted Kremenek | 9ac5928 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 597 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 598 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 599 | |
| 600 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 601 | const Expr* ReturnStmt::getRetValue() const { |
| 602 | return cast_or_null<Expr>(RetExpr); |
| 603 | } |
| 604 | Expr* ReturnStmt::getRetValue() { |
| 605 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 608 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 609 | return &RetExpr; |
| 610 | } |
| 611 | Stmt::child_iterator ReturnStmt::child_end() { |
| 612 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 2298f91 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 613 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 614 | |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 615 | // AsmStmt |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 616 | Stmt::child_iterator AsmStmt::child_begin() { |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 617 | return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0]; |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 618 | } |
| 619 | Stmt::child_iterator AsmStmt::child_end() { |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 620 | return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0] + NumOutputs + NumInputs; |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 621 | } |
Chris Lattner | fe79595 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 622 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 623 | // ObjCAtCatchStmt |
| 624 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 625 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 626 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 627 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 628 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 629 | // ObjCAtFinallyStmt |
| 630 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 631 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 632 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 633 | // ObjCAtTryStmt |
| 634 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 635 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 636 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 3b1191d | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 637 | } |
Fariborz Jahanian | b210bd0 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 638 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 639 | // ObjCAtThrowStmt |
| 640 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 641 | return &Throw; |
| 642 | } |
| 643 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 644 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 39f8f15 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 645 | return &Throw+1; |
| 646 | } |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 647 | |
| 648 | // ObjCAtSynchronizedStmt |
| 649 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 650 | return &SubStmts[0]; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | a0f5579 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 654 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | fa3ee8e | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 657 | // CXXCatchStmt |
| 658 | Stmt::child_iterator CXXCatchStmt::child_begin() { |
| 659 | return &HandlerBlock; |
| 660 | } |
| 661 | |
| 662 | Stmt::child_iterator CXXCatchStmt::child_end() { |
| 663 | return &HandlerBlock + 1; |
| 664 | } |
| 665 | |
Sebastian Redl | 8351da0 | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 666 | // CXXTryStmt |
| 667 | Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; } |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame^] | 668 | Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+NumHandlers+1; } |