Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 959e5be | 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. |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +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 | 9ed3e77 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprObjC.h" |
Sebastian Redl | 743c816 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 17 | #include "clang/AST/Type.h" |
Ted Kremenek | 39dc20a | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 19 | #include "clang/AST/ASTDiagnostic.h" |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 22 | static struct StmtClassNameTable { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 23 | const char *Name; |
| 24 | unsigned Counter; |
| 25 | unsigned Size; |
Chris Lattner | 9c0da3b | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 26 | } StmtClassInfo[Stmt::lastExprConstant+1]; |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 27 | |
| 28 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 29 | static bool Initialized = false; |
| 30 | if (Initialized) |
| 31 | return StmtClassInfo[E]; |
| 32 | |
| 33 | // Intialize the table on the first use. |
| 34 | Initialized = true; |
Douglas Gregor | 1933015 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 35 | #define STMT(CLASS, PARENT) \ |
| 36 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 37 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 38 | #include "clang/AST/StmtNodes.def" |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 40 | return StmtClassInfo[E]; |
| 41 | } |
| 42 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 43 | const char *Stmt::getStmtClassName() const { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 44 | return getStmtInfoTableEntry(sClass).Name; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Chris Lattner | daac694 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 47 | void Stmt::DestroyChildren(ASTContext &C) { |
| 48 | for (child_iterator I = child_begin(), E = child_end(); I !=E; ) |
Douglas Gregor | 0e7e7f4 | 2009-01-16 06:50:08 +0000 | [diff] [blame] | 49 | if (Stmt* Child = *I++) Child->Destroy(C); |
Ted Kremenek | afdf811 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Chris Lattner | daac694 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 52 | void Stmt::Destroy(ASTContext &C) { |
Ted Kremenek | afdf811 | 2008-05-20 00:43:19 +0000 | [diff] [blame] | 53 | DestroyChildren(C); |
Ted Kremenek | bde4109 | 2008-05-20 04:10:52 +0000 | [diff] [blame] | 54 | // FIXME: Eventually all Stmts should be allocated with the allocator |
| 55 | // in ASTContext, just like with Decls. |
Ted Kremenek | 39dc20a | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 56 | this->~Stmt(); |
| 57 | C.Deallocate((void *)this); |
Ted Kremenek | 1ed5dc6 | 2008-05-19 22:02:12 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Chris Lattner | daac694 | 2009-03-04 04:23:07 +0000 | [diff] [blame] | 60 | void DeclStmt::Destroy(ASTContext &C) { |
Ted Kremenek | 39dc20a | 2009-02-06 01:42:09 +0000 | [diff] [blame] | 61 | this->~DeclStmt(); |
| 62 | C.Deallocate((void *)this); |
Ted Kremenek | a1e7770 | 2008-05-21 15:53:55 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 65 | void Stmt::PrintStats() { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 66 | // Ensure the table is primed. |
| 67 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 68 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 69 | unsigned sum = 0; |
| 70 | fprintf(stderr, "*** Stmt/Expr Stats:\n"); |
Chris Lattner | 9c0da3b | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 71 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 72 | if (StmtClassInfo[i].Name == 0) continue; |
| 73 | sum += StmtClassInfo[i].Counter; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 74 | } |
| 75 | fprintf(stderr, " %d stmts/exprs total.\n", sum); |
| 76 | sum = 0; |
Chris Lattner | 9c0da3b | 2007-08-25 01:55:00 +0000 | [diff] [blame] | 77 | for (int i = 0; i != Stmt::lastExprConstant+1; i++) { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 78 | if (StmtClassInfo[i].Name == 0) continue; |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 79 | fprintf(stderr, " %d %s, %d each (%d bytes)\n", |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 80 | StmtClassInfo[i].Counter, StmtClassInfo[i].Name, |
| 81 | StmtClassInfo[i].Size, |
| 82 | StmtClassInfo[i].Counter*StmtClassInfo[i].Size); |
| 83 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 84 | } |
| 85 | fprintf(stderr, "Total bytes = %d\n", sum); |
| 86 | } |
| 87 | |
| 88 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 89 | ++getStmtInfoTableEntry(s).Counter; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static bool StatSwitch = false; |
| 93 | |
| 94 | bool Stmt::CollectingStats(bool enable) { |
| 95 | if (enable) StatSwitch = true; |
Chris Lattner | 603bf12 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 96 | return StatSwitch; |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
Chris Lattner | 4b00965 | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 100 | const char *LabelStmt::getName() const { |
| 101 | return getID()->getName(); |
| 102 | } |
| 103 | |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 104 | // This is defined here to avoid polluting Stmt.h with importing Expr.h |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 105 | SourceRange ReturnStmt::getSourceRange() const { |
Steve Naroff | c32a20d | 2007-08-31 23:49:30 +0000 | [diff] [blame] | 106 | if (RetExpr) |
| 107 | return SourceRange(RetLoc, RetExpr->getLocEnd()); |
| 108 | else |
| 109 | return SourceRange(RetLoc); |
| 110 | } |
| 111 | |
Ted Kremenek | ad5682f | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 112 | bool Stmt::hasImplicitControlFlow() const { |
| 113 | switch (sClass) { |
| 114 | default: |
| 115 | return false; |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 116 | |
Ted Kremenek | ad5682f | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 117 | case CallExprClass: |
| 118 | case ConditionalOperatorClass: |
| 119 | case ChooseExprClass: |
| 120 | case StmtExprClass: |
| 121 | case DeclStmtClass: |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 122 | return true; |
| 123 | |
Ted Kremenek | ad5682f | 2007-10-01 16:34:52 +0000 | [diff] [blame] | 124 | case Stmt::BinaryOperatorClass: { |
| 125 | const BinaryOperator* B = cast<BinaryOperator>(this); |
| 126 | if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma) |
| 127 | return true; |
| 128 | else |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | |
Chris Lattner | e862511 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 134 | Expr *AsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | b30de27 | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 135 | return cast<Expr>(Exprs[i]); |
| 136 | } |
Chris Lattner | e862511 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 137 | |
| 138 | /// getOutputConstraint - Return the constraint string for the specified |
| 139 | /// output operand. All output constraints are known to be non-empty (either |
| 140 | /// '=' or '+'). |
| 141 | std::string AsmStmt::getOutputConstraint(unsigned i) const { |
| 142 | return std::string(Constraints[i]->getStrData(), |
| 143 | Constraints[i]->getByteLength()); |
Ted Kremenek | b30de27 | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 144 | } |
Chris Lattner | e862511 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 145 | |
| 146 | |
| 147 | Expr *AsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | b30de27 | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 148 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 149 | } |
Chris Lattner | e862511 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 150 | |
| 151 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 152 | /// constraints, these can be empty. |
| 153 | std::string AsmStmt::getInputConstraint(unsigned i) const { |
| 154 | return std::string(Constraints[i + NumOutputs]->getStrData(), |
| 155 | Constraints[i + NumOutputs]->getByteLength()); |
Ted Kremenek | b30de27 | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | 20ac04c | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 158 | |
| 159 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 160 | /// translate this into a numeric value needed to reference the same operand. |
| 161 | /// This returns -1 if the operand name is invalid. |
| 162 | int AsmStmt::getNamedOperand(const std::string &SymbolicName) const { |
| 163 | unsigned NumPlusOperands = 0; |
| 164 | |
| 165 | // Check if this is an output operand. |
| 166 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 167 | if (getOutputName(i) == SymbolicName) |
| 168 | return i; |
| 169 | |
| 170 | // Keep track of the number of '+' operands. |
| 171 | if (isOutputPlusConstraint(i)) ++NumPlusOperands; |
| 172 | } |
| 173 | |
| 174 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 175 | if (getInputName(i) == SymbolicName) |
| 176 | return getNumOutputs() + NumPlusOperands + i; |
| 177 | |
| 178 | // Not found. |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 183 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 184 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 185 | /// true, otherwise return false. |
Chris Lattner | c516473 | 2009-03-10 23:41:04 +0000 | [diff] [blame] | 186 | unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces, |
| 187 | ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 188 | const char *StrStart = getAsmString()->getStrData(); |
| 189 | const char *StrEnd = StrStart + getAsmString()->getByteLength(); |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 190 | const char *CurPtr = StrStart; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 191 | |
| 192 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 193 | // string to escape $'s. |
| 194 | if (isSimple()) { |
| 195 | std::string Result; |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 196 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 197 | switch (*CurPtr) { |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 198 | case '$': |
| 199 | Result += "$$"; |
| 200 | break; |
| 201 | default: |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 202 | Result += *CurPtr; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 203 | break; |
| 204 | } |
| 205 | } |
| 206 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 207 | return 0; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // CurStringPiece - The current string that we are building up as we scan the |
| 211 | // asm string. |
| 212 | std::string CurStringPiece; |
| 213 | |
| 214 | while (1) { |
| 215 | // Done with the string? |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 216 | if (CurPtr == StrEnd) { |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 217 | if (!CurStringPiece.empty()) |
| 218 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 219 | return 0; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 222 | char CurChar = *CurPtr++; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 223 | if (CurChar == '$') { |
| 224 | CurStringPiece += "$$"; |
| 225 | continue; |
| 226 | } else if (CurChar != '%') { |
| 227 | CurStringPiece += CurChar; |
| 228 | continue; |
| 229 | } |
| 230 | |
| 231 | // Escaped "%" character in asm string. |
| 232 | // FIXME: This should be caught during Sema. |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 233 | assert(CurPtr != StrEnd && "Trailing '%' in asm string."); |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 234 | |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 235 | char EscapedChar = *CurPtr++; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 236 | if (EscapedChar == '%') { // %% -> % |
| 237 | // Escaped percentage sign. |
| 238 | CurStringPiece += '%'; |
| 239 | continue; |
| 240 | } |
| 241 | |
| 242 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 243 | CurStringPiece += "${:uid}"; |
| 244 | continue; |
| 245 | } |
| 246 | |
| 247 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 248 | // add it to the Pieces list. |
| 249 | if (!CurStringPiece.empty()) { |
| 250 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 251 | CurStringPiece.clear(); |
| 252 | } |
| 253 | |
| 254 | // Handle %x4 and %x[foo] by capturing x as the modifier character. |
| 255 | char Modifier = '\0'; |
| 256 | if (isalpha(EscapedChar)) { |
| 257 | Modifier = EscapedChar; |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 258 | EscapedChar = *CurPtr++; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | if (isdigit(EscapedChar)) { |
| 262 | // %n - Assembler operand n |
| 263 | char *End; |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 264 | unsigned long N = strtoul(CurPtr-1, &End, 10); |
| 265 | assert(End != CurPtr-1 && "We know that EscapedChar is a digit!"); |
| 266 | CurPtr = End; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 267 | |
| 268 | // FIXME: This should be caught during Sema. |
| 269 | //unsigned NumOperands = S.getNumOutputs() + S.getNumInputs(); |
| 270 | //assert(N < NumOperands && "Operand number out of range!"); |
| 271 | |
| 272 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 273 | continue; |
| 274 | } |
| 275 | |
| 276 | // Handle %[foo], a symbolic operand reference. |
| 277 | if (EscapedChar == '[') { |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 278 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 279 | // FIXME: Should be caught by sema. |
| 280 | // FIXME: Does sema catch multiple operands with the same name? |
| 281 | assert(NameEnd != 0 && "Could not parse symbolic name"); |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 282 | std::string SymbolicName(CurPtr, NameEnd); |
| 283 | CurPtr = NameEnd+1; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 284 | |
| 285 | int N = getNamedOperand(SymbolicName); |
| 286 | assert(N != -1 && "FIXME: Catch in Sema."); |
| 287 | Pieces.push_back(AsmStringPiece(N, Modifier)); |
| 288 | continue; |
| 289 | } |
| 290 | |
Chris Lattner | d4dd42c | 2009-03-10 23:51:40 +0000 | [diff] [blame^] | 291 | DiagOffs = CurPtr-StrStart; |
| 292 | return diag::err_asm_invalid_escape; |
Chris Lattner | 5c6a6c5 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 296 | //===----------------------------------------------------------------------===// |
| 297 | // Constructors |
| 298 | //===----------------------------------------------------------------------===// |
| 299 | |
Anders Carlsson | de6a9c4 | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 300 | AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 301 | unsigned numoutputs, unsigned numinputs, |
| 302 | std::string *names, StringLiteral **constraints, |
| 303 | Expr **exprs, StringLiteral *asmstr, unsigned numclobbers, |
| 304 | StringLiteral **clobbers, SourceLocation rparenloc) |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 305 | : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr) |
Anders Carlsson | de6a9c4 | 2008-02-05 23:03:50 +0000 | [diff] [blame] | 306 | , IsSimple(issimple), IsVolatile(isvolatile) |
| 307 | , NumOutputs(numoutputs), NumInputs(numinputs) { |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 308 | for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) { |
| 309 | Names.push_back(names[i]); |
| 310 | Exprs.push_back(exprs[i]); |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 311 | Constraints.push_back(constraints[i]); |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 312 | } |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 313 | |
Anders Carlsson | 965d520 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 314 | for (unsigned i = 0; i != numclobbers; i++) |
| 315 | Clobbers.push_back(clobbers[i]); |
| 316 | } |
| 317 | |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 318 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 319 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 320 | SourceLocation RPL) |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 321 | : Stmt(ObjCForCollectionStmtClass) { |
| 322 | SubExprs[ELEM] = Elem; |
| 323 | SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect); |
| 324 | SubExprs[BODY] = Body; |
| 325 | ForLoc = FCL; |
| 326 | RParenLoc = RPL; |
| 327 | } |
| 328 | |
| 329 | |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 330 | ObjCAtCatchStmt::ObjCAtCatchStmt(SourceLocation atCatchLoc, |
| 331 | SourceLocation rparenloc, |
Steve Naroff | 0e8b96a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 332 | ParmVarDecl *catchVarDecl, Stmt *atCatchStmt, |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 333 | Stmt *atCatchList) |
| 334 | : Stmt(ObjCAtCatchStmtClass) { |
Steve Naroff | 0e8b96a | 2009-03-03 19:52:17 +0000 | [diff] [blame] | 335 | ExceptionDecl = catchVarDecl; |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 336 | SubExprs[BODY] = atCatchStmt; |
Eli Friedman | f3e02ed | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 337 | SubExprs[NEXT_CATCH] = NULL; |
Daniel Dunbar | d23d992 | 2009-03-01 04:28:32 +0000 | [diff] [blame] | 338 | // FIXME: O(N^2) in number of catch blocks. |
Eli Friedman | f3e02ed | 2008-05-25 04:34:57 +0000 | [diff] [blame] | 339 | if (atCatchList) { |
Ted Kremenek | 61aa7f9 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 340 | ObjCAtCatchStmt *AtCatchList = static_cast<ObjCAtCatchStmt*>(atCatchList); |
| 341 | |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 342 | while (ObjCAtCatchStmt* NextCatch = AtCatchList->getNextCatchStmt()) |
Ted Kremenek | 61aa7f9 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 343 | AtCatchList = NextCatch; |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 344 | |
Ted Kremenek | 61aa7f9 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 345 | AtCatchList->SubExprs[NEXT_CATCH] = this; |
Chris Lattner | 006d154 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 346 | } |
| 347 | AtCatchLoc = atCatchLoc; |
| 348 | RParenLoc = rparenloc; |
| 349 | } |
| 350 | |
| 351 | |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 352 | //===----------------------------------------------------------------------===// |
| 353 | // Child Iterators for iterating over subexpressions/substatements |
| 354 | //===----------------------------------------------------------------------===// |
| 355 | |
| 356 | // DeclStmt |
Ted Kremenek | 1bc18e6 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 357 | Stmt::child_iterator DeclStmt::child_begin() { |
| 358 | return StmtIterator(DG.begin(), DG.end()); |
Ted Kremenek | b59f9cf | 2008-08-05 20:46:55 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Ted Kremenek | 1bc18e6 | 2008-10-07 23:09:49 +0000 | [diff] [blame] | 361 | Stmt::child_iterator DeclStmt::child_end() { |
| 362 | return StmtIterator(DG.end(), DG.end()); |
Ted Kremenek | 62f23bb | 2008-10-06 20:54:44 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 365 | // NullStmt |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 366 | Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); } |
| 367 | Stmt::child_iterator NullStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 368 | |
| 369 | // CompoundStmt |
| 370 | Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; } |
Ted Kremenek | 0c97e04 | 2009-02-07 01:47:29 +0000 | [diff] [blame] | 371 | Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 372 | |
Ted Kremenek | e07b67e | 2007-08-30 16:50:46 +0000 | [diff] [blame] | 373 | // CaseStmt |
| 374 | Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; } |
| 375 | Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; } |
| 376 | |
| 377 | // DefaultStmt |
| 378 | Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; } |
| 379 | Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 380 | |
| 381 | // LabelStmt |
| 382 | Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; } |
Chris Lattner | f3e2a25 | 2007-08-30 00:53:54 +0000 | [diff] [blame] | 383 | Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 384 | |
| 385 | // IfStmt |
| 386 | Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; } |
| 387 | Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 388 | |
| 389 | // SwitchStmt |
| 390 | Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; } |
| 391 | Stmt::child_iterator SwitchStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 392 | |
| 393 | // WhileStmt |
| 394 | Stmt::child_iterator WhileStmt::child_begin() { return &SubExprs[0]; } |
| 395 | Stmt::child_iterator WhileStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 396 | |
| 397 | // DoStmt |
| 398 | Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; } |
| 399 | Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 400 | |
| 401 | // ForStmt |
| 402 | Stmt::child_iterator ForStmt::child_begin() { return &SubExprs[0]; } |
| 403 | Stmt::child_iterator ForStmt::child_end() { return &SubExprs[0]+END_EXPR; } |
| 404 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 405 | // ObjCForCollectionStmt |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 406 | Stmt::child_iterator ObjCForCollectionStmt::child_begin() { |
| 407 | return &SubExprs[0]; |
Fariborz Jahanian | 9e920f3 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 408 | } |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 409 | Stmt::child_iterator ObjCForCollectionStmt::child_end() { |
| 410 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 9e920f3 | 2008-01-02 22:54:34 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 413 | // GotoStmt |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 414 | Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); } |
| 415 | Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 416 | |
| 417 | // IndirectGotoStmt |
Ted Kremenek | 156714e | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 418 | Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); } |
| 419 | const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 420 | |
Ted Kremenek | 156714e | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 421 | Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; } |
| 422 | Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 423 | |
| 424 | // ContinueStmt |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 425 | Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); } |
| 426 | Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 427 | |
| 428 | // BreakStmt |
Ted Kremenek | a647855 | 2007-10-18 23:28:49 +0000 | [diff] [blame] | 429 | Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); } |
| 430 | Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 431 | |
| 432 | // ReturnStmt |
Ted Kremenek | 156714e | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 433 | const Expr* ReturnStmt::getRetValue() const { |
| 434 | return cast_or_null<Expr>(RetExpr); |
| 435 | } |
| 436 | Expr* ReturnStmt::getRetValue() { |
| 437 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Ted Kremenek | 156714e | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 440 | Stmt::child_iterator ReturnStmt::child_begin() { |
| 441 | return &RetExpr; |
| 442 | } |
| 443 | Stmt::child_iterator ReturnStmt::child_end() { |
| 444 | return RetExpr ? &RetExpr+1 : &RetExpr; |
Ted Kremenek | 8a66ed4 | 2007-08-27 20:58:16 +0000 | [diff] [blame] | 445 | } |
Ted Kremenek | 51be056 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 446 | |
Chris Lattner | 8a40a83 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 447 | // AsmStmt |
Ted Kremenek | b30de27 | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 448 | Stmt::child_iterator AsmStmt::child_begin() { |
| 449 | return Exprs.empty() ? 0 : &Exprs[0]; |
| 450 | } |
| 451 | Stmt::child_iterator AsmStmt::child_end() { |
| 452 | return Exprs.empty() ? 0 : &Exprs[0] + Exprs.size(); |
| 453 | } |
Chris Lattner | 8a40a83 | 2007-10-29 04:04:16 +0000 | [diff] [blame] | 454 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 455 | // ObjCAtCatchStmt |
| 456 | Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &SubExprs[0]; } |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 457 | Stmt::child_iterator ObjCAtCatchStmt::child_end() { |
| 458 | return &SubExprs[0]+END_EXPR; |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 459 | } |
Fariborz Jahanian | 7095248 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 460 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 461 | // ObjCAtFinallyStmt |
| 462 | Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; } |
| 463 | Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; } |
Fariborz Jahanian | 7095248 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 464 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 465 | // ObjCAtTryStmt |
| 466 | Stmt::child_iterator ObjCAtTryStmt::child_begin() { return &SubStmts[0]; } |
Nico Weber | 7340a2f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 467 | Stmt::child_iterator ObjCAtTryStmt::child_end() { |
| 468 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | 0679836 | 2007-11-01 23:59:59 +0000 | [diff] [blame] | 469 | } |
Fariborz Jahanian | 7095248 | 2007-11-01 21:12:44 +0000 | [diff] [blame] | 470 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 471 | // ObjCAtThrowStmt |
| 472 | Stmt::child_iterator ObjCAtThrowStmt::child_begin() { |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 473 | return &Throw; |
| 474 | } |
| 475 | |
Ted Kremenek | 42730c5 | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 476 | Stmt::child_iterator ObjCAtThrowStmt::child_end() { |
Fariborz Jahanian | 08df2c6 | 2007-11-07 02:00:49 +0000 | [diff] [blame] | 477 | return &Throw+1; |
| 478 | } |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 479 | |
| 480 | // ObjCAtSynchronizedStmt |
| 481 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() { |
Fariborz Jahanian | 499bf41 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 482 | return &SubStmts[0]; |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() { |
Fariborz Jahanian | 499bf41 | 2008-01-29 22:59:37 +0000 | [diff] [blame] | 486 | return &SubStmts[0]+END_EXPR; |
Fariborz Jahanian | c9fd4d1 | 2008-01-29 19:14:59 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Sebastian Redl | 743c816 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 489 | // CXXCatchStmt |
| 490 | Stmt::child_iterator CXXCatchStmt::child_begin() { |
| 491 | return &HandlerBlock; |
| 492 | } |
| 493 | |
| 494 | Stmt::child_iterator CXXCatchStmt::child_end() { |
| 495 | return &HandlerBlock + 1; |
| 496 | } |
| 497 | |
| 498 | QualType CXXCatchStmt::getCaughtType() { |
| 499 | if (ExceptionDecl) |
| 500 | return llvm::cast<VarDecl>(ExceptionDecl)->getType(); |
| 501 | return QualType(); |
| 502 | } |
| 503 | |
| 504 | void CXXCatchStmt::Destroy(ASTContext& C) { |
Sebastian Redl | 237116b | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 505 | if (ExceptionDecl) |
| 506 | ExceptionDecl->Destroy(C); |
Sebastian Redl | 743c816 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 507 | Stmt::Destroy(C); |
| 508 | } |
Sebastian Redl | 237116b | 2008-12-22 21:35:02 +0000 | [diff] [blame] | 509 | |
| 510 | // CXXTryStmt |
| 511 | Stmt::child_iterator CXXTryStmt::child_begin() { return &Stmts[0]; } |
| 512 | Stmt::child_iterator CXXTryStmt::child_end() { return &Stmts[0]+Stmts.size(); } |
| 513 | |
| 514 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
| 515 | Stmt **handlers, unsigned numHandlers) |
| 516 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc) { |
| 517 | Stmts.push_back(tryBlock); |
| 518 | Stmts.insert(Stmts.end(), handlers, handlers + numHandlers); |
| 519 | } |