blob: acd77beaca4b6cb70b07a01ea8bca31804515f69 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
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 Narofff494b572008-05-29 21:12:08 +000016#include "clang/AST/ExprObjC.h"
Chris Lattner16f00492009-04-26 01:32:48 +000017#include "clang/AST/StmtCXX.h"
18#include "clang/AST/StmtObjC.h"
Sebastian Redl4b07b292008-12-22 19:15:10 +000019#include "clang/AST/Type.h"
Ted Kremenek11e5a7f2009-02-06 01:42:09 +000020#include "clang/AST/ASTContext.h"
Chris Lattner3182db12009-03-10 23:51:40 +000021#include "clang/AST/ASTDiagnostic.h"
Chris Lattner9bffb072010-04-23 16:29:58 +000022#include "clang/Basic/TargetInfo.h"
Torok Edwinf42e4a62009-08-24 13:25:12 +000023#include <cstdio>
Reid Spencer5f016e22007-07-11 17:01:13 +000024using namespace clang;
25
Reid Spencer5f016e22007-07-11 17:01:13 +000026static struct StmtClassNameTable {
Chris Lattner63381352007-08-25 01:42:24 +000027 const char *Name;
28 unsigned Counter;
29 unsigned Size;
Sean Hunt4bfe1962010-05-05 15:24:00 +000030} StmtClassInfo[Stmt::lastStmtConstant+1];
Chris Lattner63381352007-08-25 01:42:24 +000031
32static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) {
33 static bool Initialized = false;
34 if (Initialized)
35 return StmtClassInfo[E];
36
37 // Intialize the table on the first use.
38 Initialized = true;
Sean Hunt7381d5c2010-05-18 06:22:21 +000039#define ABSTRACT_STMT(STMT)
Douglas Gregorf2cad862008-11-14 12:46:07 +000040#define STMT(CLASS, PARENT) \
41 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \
42 StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
Sean Hunt4bfe1962010-05-05 15:24:00 +000043#include "clang/AST/StmtNodes.inc"
Nico Weber608b17f2008-08-05 23:15:29 +000044
Chris Lattner63381352007-08-25 01:42:24 +000045 return StmtClassInfo[E];
46}
47
Reid Spencer5f016e22007-07-11 17:01:13 +000048const char *Stmt::getStmtClassName() const {
John McCall8e6285a2010-10-26 08:39:16 +000049 return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name;
Reid Spencer5f016e22007-07-11 17:01:13 +000050}
51
52void Stmt::PrintStats() {
Chris Lattner63381352007-08-25 01:42:24 +000053 // Ensure the table is primed.
54 getStmtInfoTableEntry(Stmt::NullStmtClass);
Nico Weber608b17f2008-08-05 23:15:29 +000055
Reid Spencer5f016e22007-07-11 17:01:13 +000056 unsigned sum = 0;
57 fprintf(stderr, "*** Stmt/Expr Stats:\n");
Sean Hunt4bfe1962010-05-05 15:24:00 +000058 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Chris Lattner63381352007-08-25 01:42:24 +000059 if (StmtClassInfo[i].Name == 0) continue;
60 sum += StmtClassInfo[i].Counter;
Reid Spencer5f016e22007-07-11 17:01:13 +000061 }
62 fprintf(stderr, " %d stmts/exprs total.\n", sum);
63 sum = 0;
Sean Hunt4bfe1962010-05-05 15:24:00 +000064 for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
Chris Lattner63381352007-08-25 01:42:24 +000065 if (StmtClassInfo[i].Name == 0) continue;
Douglas Gregordbe833d2009-05-26 14:40:08 +000066 if (StmtClassInfo[i].Counter == 0) continue;
Nico Weber608b17f2008-08-05 23:15:29 +000067 fprintf(stderr, " %d %s, %d each (%d bytes)\n",
Chris Lattner63381352007-08-25 01:42:24 +000068 StmtClassInfo[i].Counter, StmtClassInfo[i].Name,
69 StmtClassInfo[i].Size,
70 StmtClassInfo[i].Counter*StmtClassInfo[i].Size);
71 sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size;
Reid Spencer5f016e22007-07-11 17:01:13 +000072 }
73 fprintf(stderr, "Total bytes = %d\n", sum);
74}
75
76void Stmt::addStmtClass(StmtClass s) {
Chris Lattner63381352007-08-25 01:42:24 +000077 ++getStmtInfoTableEntry(s).Counter;
Reid Spencer5f016e22007-07-11 17:01:13 +000078}
79
80static bool StatSwitch = false;
81
Kovarththanan Rajaratnam2024f4d2009-11-29 14:54:35 +000082bool Stmt::CollectingStats(bool Enable) {
83 if (Enable) StatSwitch = true;
Chris Lattner63381352007-08-25 01:42:24 +000084 return StatSwitch;
Reid Spencer5f016e22007-07-11 17:01:13 +000085}
86
Douglas Gregor025452f2009-04-17 00:04:06 +000087void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
88 if (this->Body)
89 C.Deallocate(Body);
John McCall8e6285a2010-10-26 08:39:16 +000090 this->CompoundStmtBits.NumStmts = NumStmts;
Douglas Gregor025452f2009-04-17 00:04:06 +000091
92 Body = new (C) Stmt*[NumStmts];
93 memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
94}
Reid Spencer5f016e22007-07-11 17:01:13 +000095
Reid Spencer5f016e22007-07-11 17:01:13 +000096const char *LabelStmt::getName() const {
Daniel Dunbare013d682009-10-18 20:26:12 +000097 return getID()->getNameStart();
Reid Spencer5f016e22007-07-11 17:01:13 +000098}
99
Steve Naroff507f2d52007-08-31 23:49:30 +0000100// This is defined here to avoid polluting Stmt.h with importing Expr.h
Nico Weber608b17f2008-08-05 23:15:29 +0000101SourceRange ReturnStmt::getSourceRange() const {
Steve Naroff507f2d52007-08-31 23:49:30 +0000102 if (RetExpr)
103 return SourceRange(RetLoc, RetExpr->getLocEnd());
104 else
105 return SourceRange(RetLoc);
106}
107
Ted Kremenekd48ade62007-10-01 16:34:52 +0000108bool Stmt::hasImplicitControlFlow() const {
John McCall8e6285a2010-10-26 08:39:16 +0000109 switch (StmtBits.sClass) {
Ted Kremenekd48ade62007-10-01 16:34:52 +0000110 default:
111 return false;
Nico Weber608b17f2008-08-05 23:15:29 +0000112
Ted Kremenekd48ade62007-10-01 16:34:52 +0000113 case CallExprClass:
114 case ConditionalOperatorClass:
115 case ChooseExprClass:
116 case StmtExprClass:
117 case DeclStmtClass:
Nico Weber608b17f2008-08-05 23:15:29 +0000118 return true;
119
Ted Kremenekd48ade62007-10-01 16:34:52 +0000120 case Stmt::BinaryOperatorClass: {
121 const BinaryOperator* B = cast<BinaryOperator>(this);
John McCall2de56d12010-08-25 11:45:40 +0000122 if (B->isLogicalOp() || B->getOpcode() == BO_Comma)
Ted Kremenekd48ade62007-10-01 16:34:52 +0000123 return true;
124 else
125 return false;
126 }
127 }
128}
129
Chris Lattnerb3277932009-03-10 04:59:06 +0000130Expr *AsmStmt::getOutputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000131 return cast<Expr>(Exprs[i]);
132}
Chris Lattnerb3277932009-03-10 04:59:06 +0000133
134/// getOutputConstraint - Return the constraint string for the specified
135/// output operand. All output constraints are known to be non-empty (either
136/// '=' or '+').
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000137llvm::StringRef AsmStmt::getOutputConstraint(unsigned i) const {
138 return getOutputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000139}
Chris Lattnerb3277932009-03-10 04:59:06 +0000140
Chris Lattner85759272009-03-11 00:23:13 +0000141/// getNumPlusOperands - Return the number of output operands that have a "+"
142/// constraint.
143unsigned AsmStmt::getNumPlusOperands() const {
144 unsigned Res = 0;
145 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i)
146 if (isOutputPlusConstraint(i))
147 ++Res;
148 return Res;
149}
150
Chris Lattnerb3277932009-03-10 04:59:06 +0000151Expr *AsmStmt::getInputExpr(unsigned i) {
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000152 return cast<Expr>(Exprs[i + NumOutputs]);
153}
Chris Lattnerb3277932009-03-10 04:59:06 +0000154
155/// getInputConstraint - Return the specified input constraint. Unlike output
156/// constraints, these can be empty.
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000157llvm::StringRef AsmStmt::getInputConstraint(unsigned i) const {
158 return getInputConstraintLiteral(i)->getString();
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000159}
160
Chris Lattner10ca96a2009-03-10 06:33:24 +0000161
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000162void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000163 IdentifierInfo **Names,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000164 StringLiteral **Constraints,
165 Stmt **Exprs,
166 unsigned NumOutputs,
Sean Huntc3021132010-05-05 15:23:54 +0000167 unsigned NumInputs,
Anders Carlssonfdba9c02010-01-30 19:34:25 +0000168 StringLiteral **Clobbers,
169 unsigned NumClobbers) {
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000170 this->NumOutputs = NumOutputs;
171 this->NumInputs = NumInputs;
Anders Carlsson966146e2010-01-30 23:19:41 +0000172 this->NumClobbers = NumClobbers;
173
174 unsigned NumExprs = NumOutputs + NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000175
Anders Carlsson966146e2010-01-30 23:19:41 +0000176 C.Deallocate(this->Names);
177 this->Names = new (C) IdentifierInfo*[NumExprs];
178 std::copy(Names, Names + NumExprs, this->Names);
Sean Huntc3021132010-05-05 15:23:54 +0000179
Anders Carlsson966146e2010-01-30 23:19:41 +0000180 C.Deallocate(this->Exprs);
181 this->Exprs = new (C) Stmt*[NumExprs];
182 std::copy(Exprs, Exprs + NumExprs, this->Exprs);
Sean Huntc3021132010-05-05 15:23:54 +0000183
Anders Carlsson966146e2010-01-30 23:19:41 +0000184 C.Deallocate(this->Constraints);
185 this->Constraints = new (C) StringLiteral*[NumExprs];
186 std::copy(Constraints, Constraints + NumExprs, this->Constraints);
Sean Huntc3021132010-05-05 15:23:54 +0000187
Anders Carlsson966146e2010-01-30 23:19:41 +0000188 C.Deallocate(this->Clobbers);
189 this->Clobbers = new (C) StringLiteral*[NumClobbers];
190 std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
Douglas Gregorcd7d5a92009-04-17 20:57:14 +0000191}
192
Chris Lattner10ca96a2009-03-10 06:33:24 +0000193/// getNamedOperand - Given a symbolic operand reference like %[foo],
194/// translate this into a numeric value needed to reference the same operand.
195/// This returns -1 if the operand name is invalid.
Anders Carlssonacb6bcb2010-01-30 20:38:10 +0000196int AsmStmt::getNamedOperand(llvm::StringRef SymbolicName) const {
Chris Lattner10ca96a2009-03-10 06:33:24 +0000197 unsigned NumPlusOperands = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000198
Chris Lattner10ca96a2009-03-10 06:33:24 +0000199 // Check if this is an output operand.
200 for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) {
201 if (getOutputName(i) == SymbolicName)
202 return i;
Chris Lattner10ca96a2009-03-10 06:33:24 +0000203 }
Mike Stump1eb44332009-09-09 15:08:12 +0000204
Chris Lattner10ca96a2009-03-10 06:33:24 +0000205 for (unsigned i = 0, e = getNumInputs(); i != e; ++i)
206 if (getInputName(i) == SymbolicName)
207 return getNumOutputs() + NumPlusOperands + i;
208
209 // Not found.
210 return -1;
211}
212
Chris Lattner458cd9c2009-03-10 23:21:44 +0000213/// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
214/// it into pieces. If the asm string is erroneous, emit errors and return
215/// true, otherwise return false.
Chris Lattnerfb5058e2009-03-10 23:41:04 +0000216unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
217 ASTContext &C, unsigned &DiagOffs) const {
Benjamin Kramer2f4eaef2010-08-17 12:54:38 +0000218 llvm::StringRef Str = getAsmString()->getString();
219 const char *StrStart = Str.begin();
220 const char *StrEnd = Str.end();
Chris Lattner3182db12009-03-10 23:51:40 +0000221 const char *CurPtr = StrStart;
Mike Stump1eb44332009-09-09 15:08:12 +0000222
Chris Lattner458cd9c2009-03-10 23:21:44 +0000223 // "Simple" inline asms have no constraints or operands, just convert the asm
224 // string to escape $'s.
225 if (isSimple()) {
226 std::string Result;
Chris Lattner3182db12009-03-10 23:51:40 +0000227 for (; CurPtr != StrEnd; ++CurPtr) {
228 switch (*CurPtr) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000229 case '$':
230 Result += "$$";
231 break;
232 default:
Chris Lattner3182db12009-03-10 23:51:40 +0000233 Result += *CurPtr;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000234 break;
235 }
236 }
237 Pieces.push_back(AsmStringPiece(Result));
Chris Lattner3182db12009-03-10 23:51:40 +0000238 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000239 }
240
241 // CurStringPiece - The current string that we are building up as we scan the
242 // asm string.
243 std::string CurStringPiece;
Mike Stump1eb44332009-09-09 15:08:12 +0000244
Chris Lattner9bffb072010-04-23 16:29:58 +0000245 bool HasVariants = !C.Target.hasNoAsmVariants();
Sean Huntc3021132010-05-05 15:23:54 +0000246
Chris Lattner458cd9c2009-03-10 23:21:44 +0000247 while (1) {
248 // Done with the string?
Chris Lattner3182db12009-03-10 23:51:40 +0000249 if (CurPtr == StrEnd) {
Chris Lattner458cd9c2009-03-10 23:21:44 +0000250 if (!CurStringPiece.empty())
251 Pieces.push_back(AsmStringPiece(CurStringPiece));
Chris Lattner3182db12009-03-10 23:51:40 +0000252 return 0;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000253 }
Mike Stump1eb44332009-09-09 15:08:12 +0000254
Chris Lattner3182db12009-03-10 23:51:40 +0000255 char CurChar = *CurPtr++;
Chris Lattner018b54e2010-04-05 18:44:00 +0000256 switch (CurChar) {
257 case '$': CurStringPiece += "$$"; continue;
Chris Lattner9bffb072010-04-23 16:29:58 +0000258 case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
259 case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
260 case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
Chris Lattner018b54e2010-04-05 18:44:00 +0000261 case '%':
262 break;
263 default:
Chris Lattner458cd9c2009-03-10 23:21:44 +0000264 CurStringPiece += CurChar;
265 continue;
266 }
Sean Huntc3021132010-05-05 15:23:54 +0000267
Chris Lattner458cd9c2009-03-10 23:21:44 +0000268 // Escaped "%" character in asm string.
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000269 if (CurPtr == StrEnd) {
270 // % at end of string is invalid (no escape).
271 DiagOffs = CurPtr-StrStart-1;
272 return diag::err_asm_invalid_escape;
273 }
Mike Stump1eb44332009-09-09 15:08:12 +0000274
Chris Lattner3182db12009-03-10 23:51:40 +0000275 char EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000276 if (EscapedChar == '%') { // %% -> %
277 // Escaped percentage sign.
278 CurStringPiece += '%';
279 continue;
280 }
Mike Stump1eb44332009-09-09 15:08:12 +0000281
Chris Lattner458cd9c2009-03-10 23:21:44 +0000282 if (EscapedChar == '=') { // %= -> Generate an unique ID.
283 CurStringPiece += "${:uid}";
284 continue;
285 }
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Chris Lattner458cd9c2009-03-10 23:21:44 +0000287 // Otherwise, we have an operand. If we have accumulated a string so far,
288 // add it to the Pieces list.
289 if (!CurStringPiece.empty()) {
290 Pieces.push_back(AsmStringPiece(CurStringPiece));
291 CurStringPiece.clear();
292 }
Mike Stump1eb44332009-09-09 15:08:12 +0000293
Chris Lattner458cd9c2009-03-10 23:21:44 +0000294 // Handle %x4 and %x[foo] by capturing x as the modifier character.
295 char Modifier = '\0';
296 if (isalpha(EscapedChar)) {
297 Modifier = EscapedChar;
Chris Lattner3182db12009-03-10 23:51:40 +0000298 EscapedChar = *CurPtr++;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000299 }
Mike Stump1eb44332009-09-09 15:08:12 +0000300
Chris Lattner458cd9c2009-03-10 23:21:44 +0000301 if (isdigit(EscapedChar)) {
302 // %n - Assembler operand n
Chris Lattnercafc2222009-03-11 22:52:17 +0000303 unsigned N = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000304
Chris Lattnercafc2222009-03-11 22:52:17 +0000305 --CurPtr;
306 while (CurPtr != StrEnd && isdigit(*CurPtr))
Chris Lattner32a47ed2009-03-11 23:09:16 +0000307 N = N*10 + ((*CurPtr++)-'0');
Mike Stump1eb44332009-09-09 15:08:12 +0000308
Chris Lattner85759272009-03-11 00:23:13 +0000309 unsigned NumOperands =
310 getNumOutputs() + getNumPlusOperands() + getNumInputs();
311 if (N >= NumOperands) {
312 DiagOffs = CurPtr-StrStart-1;
313 return diag::err_asm_invalid_operand_number;
314 }
315
Chris Lattner458cd9c2009-03-10 23:21:44 +0000316 Pieces.push_back(AsmStringPiece(N, Modifier));
317 continue;
318 }
Mike Stump1eb44332009-09-09 15:08:12 +0000319
Chris Lattner458cd9c2009-03-10 23:21:44 +0000320 // Handle %[foo], a symbolic operand reference.
321 if (EscapedChar == '[') {
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000322 DiagOffs = CurPtr-StrStart-1;
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000324 // Find the ']'.
Chris Lattner3182db12009-03-10 23:51:40 +0000325 const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000326 if (NameEnd == 0)
327 return diag::err_asm_unterminated_symbolic_operand_name;
328 if (NameEnd == CurPtr)
329 return diag::err_asm_empty_symbolic_operand_name;
Mike Stump1eb44332009-09-09 15:08:12 +0000330
Anders Carlsson95c9ce92010-01-30 20:48:08 +0000331 llvm::StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Chris Lattner458cd9c2009-03-10 23:21:44 +0000333 int N = getNamedOperand(SymbolicName);
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000334 if (N == -1) {
335 // Verify that an operand with that name exists.
336 DiagOffs = CurPtr-StrStart;
337 return diag::err_asm_unknown_symbolic_operand_name;
338 }
Chris Lattner458cd9c2009-03-10 23:21:44 +0000339 Pieces.push_back(AsmStringPiece(N, Modifier));
Mike Stump1eb44332009-09-09 15:08:12 +0000340
Chris Lattnereab8cfb2009-03-11 00:06:36 +0000341 CurPtr = NameEnd+1;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000342 continue;
343 }
Mike Stump1eb44332009-09-09 15:08:12 +0000344
Chris Lattner2ff0f422009-03-10 23:57:07 +0000345 DiagOffs = CurPtr-StrStart-1;
Chris Lattner3182db12009-03-10 23:51:40 +0000346 return diag::err_asm_invalid_escape;
Chris Lattner458cd9c2009-03-10 23:21:44 +0000347 }
348}
349
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000350QualType CXXCatchStmt::getCaughtType() const {
351 if (ExceptionDecl)
352 return ExceptionDecl->getType();
353 return QualType();
354}
355
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000356//===----------------------------------------------------------------------===//
357// Constructors
358//===----------------------------------------------------------------------===//
359
Sean Huntc3021132010-05-05 15:23:54 +0000360AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
361 bool isvolatile, bool msasm,
Anders Carlsson966146e2010-01-30 23:19:41 +0000362 unsigned numoutputs, unsigned numinputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +0000363 IdentifierInfo **names, StringLiteral **constraints,
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000364 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
365 StringLiteral **clobbers, SourceLocation rparenloc)
Anders Carlssonb235fc22007-11-22 01:36:19 +0000366 : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
Mike Stump3b11fd32010-01-04 22:37:17 +0000367 , IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
Anders Carlsson966146e2010-01-30 23:19:41 +0000368 , NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
Nico Weber608b17f2008-08-05 23:15:29 +0000369
Anders Carlsson966146e2010-01-30 23:19:41 +0000370 unsigned NumExprs = NumOutputs +NumInputs;
Sean Huntc3021132010-05-05 15:23:54 +0000371
Anders Carlsson966146e2010-01-30 23:19:41 +0000372 Names = new (C) IdentifierInfo*[NumExprs];
373 std::copy(names, names + NumExprs, Names);
374
375 Exprs = new (C) Stmt*[NumExprs];
376 std::copy(exprs, exprs + NumExprs, Exprs);
377
378 Constraints = new (C) StringLiteral*[NumExprs];
379 std::copy(constraints, constraints + NumExprs, Constraints);
380
381 Clobbers = new (C) StringLiteral*[NumClobbers];
382 std::copy(clobbers, clobbers + NumClobbers, Clobbers);
Anders Carlssonb235fc22007-11-22 01:36:19 +0000383}
384
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000385ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
386 Stmt *Body, SourceLocation FCL,
Nico Weber608b17f2008-08-05 23:15:29 +0000387 SourceLocation RPL)
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000388: Stmt(ObjCForCollectionStmtClass) {
389 SubExprs[ELEM] = Elem;
390 SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
391 SubExprs[BODY] = Body;
392 ForLoc = FCL;
393 RParenLoc = RPL;
394}
395
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000396ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
397 Stmt **CatchStmts, unsigned NumCatchStmts,
398 Stmt *atFinallyStmt)
399 : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
400 NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0)
401{
402 Stmt **Stmts = getStmts();
403 Stmts[0] = atTryStmt;
404 for (unsigned I = 0; I != NumCatchStmts; ++I)
405 Stmts[I + 1] = CatchStmts[I];
Sean Huntc3021132010-05-05 15:23:54 +0000406
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000407 if (HasFinally)
408 Stmts[NumCatchStmts + 1] = atFinallyStmt;
409}
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000410
Sean Huntc3021132010-05-05 15:23:54 +0000411ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context,
412 SourceLocation atTryLoc,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000413 Stmt *atTryStmt,
Sean Huntc3021132010-05-05 15:23:54 +0000414 Stmt **CatchStmts,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000415 unsigned NumCatchStmts,
416 Stmt *atFinallyStmt) {
Sean Huntc3021132010-05-05 15:23:54 +0000417 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000418 (1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000419 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000420 return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
421 atFinallyStmt);
422}
Ted Kremenekff981022008-02-01 21:28:59 +0000423
Sean Huntc3021132010-05-05 15:23:54 +0000424ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000425 unsigned NumCatchStmts,
426 bool HasFinally) {
Sean Huntc3021132010-05-05 15:23:54 +0000427 unsigned Size = sizeof(ObjCAtTryStmt) +
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000428 (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
Chris Lattner32488542010-10-30 05:14:06 +0000429 void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>());
Sean Huntc3021132010-05-05 15:23:54 +0000430 return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000431}
Nico Weber608b17f2008-08-05 23:15:29 +0000432
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000433SourceRange ObjCAtTryStmt::getSourceRange() const {
434 SourceLocation EndLoc;
435 if (HasFinally)
436 EndLoc = getFinallyStmt()->getLocEnd();
437 else if (NumCatchStmts)
438 EndLoc = getCatchStmt(NumCatchStmts - 1)->getLocEnd();
439 else
440 EndLoc = getTryBody()->getLocEnd();
Sean Huntc3021132010-05-05 15:23:54 +0000441
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000442 return SourceRange(AtTryLoc, EndLoc);
Chris Lattnerdb6ed172008-01-30 05:01:46 +0000443}
444
Sam Weiniga1a396d2010-02-03 03:56:39 +0000445CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
Sean Huntc3021132010-05-05 15:23:54 +0000446 Stmt *tryBlock, Stmt **handlers,
Sam Weiniga1a396d2010-02-03 03:56:39 +0000447 unsigned numHandlers) {
448 std::size_t Size = sizeof(CXXTryStmt);
449 Size += ((numHandlers + 1) * sizeof(Stmt));
450
Chris Lattner32488542010-10-30 05:14:06 +0000451 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Sam Weiniga1a396d2010-02-03 03:56:39 +0000452 return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
453}
454
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000455CXXTryStmt *CXXTryStmt::Create(ASTContext &C, EmptyShell Empty,
456 unsigned numHandlers) {
457 std::size_t Size = sizeof(CXXTryStmt);
458 Size += ((numHandlers + 1) * sizeof(Stmt));
459
Chris Lattner32488542010-10-30 05:14:06 +0000460 void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>());
Argyrios Kyrtzidis7cb45e32010-07-22 16:03:56 +0000461 return new (Mem) CXXTryStmt(Empty, numHandlers);
462}
463
Sam Weiniga1a396d2010-02-03 03:56:39 +0000464CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000465 Stmt **handlers, unsigned numHandlers)
466 : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
Sam Weiniga1a396d2010-02-03 03:56:39 +0000467 Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
Sam Weinigb0e4cb62010-02-03 02:09:59 +0000468 Stmts[0] = tryBlock;
469 std::copy(handlers, handlers + NumHandlers, Stmts + 1);
470}
471
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000472IfStmt::IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000473 Stmt *then, SourceLocation EL, Stmt *elsev)
474 : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000475{
476 setConditionVariable(C, var);
477 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
478 SubExprs[THEN] = then;
479 SubExprs[ELSE] = elsev;
480}
481
482VarDecl *IfStmt::getConditionVariable() const {
483 if (!SubExprs[VAR])
484 return 0;
485
486 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
487 return cast<VarDecl>(DS->getSingleDecl());
488}
489
490void IfStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
491 if (!V) {
492 SubExprs[VAR] = 0;
493 return;
494 }
495
496 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V),
497 V->getSourceRange().getBegin(),
498 V->getSourceRange().getEnd());
499}
500
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000501ForStmt::ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
502 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
503 SourceLocation RP)
504 : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP)
505{
506 SubExprs[INIT] = Init;
507 setConditionVariable(C, condVar);
508 SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
509 SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
510 SubExprs[BODY] = Body;
511}
512
513VarDecl *ForStmt::getConditionVariable() const {
514 if (!SubExprs[CONDVAR])
515 return 0;
516
517 DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]);
518 return cast<VarDecl>(DS->getSingleDecl());
519}
520
521void ForStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
522 if (!V) {
523 SubExprs[CONDVAR] = 0;
524 return;
525 }
526
527 SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V),
528 V->getSourceRange().getBegin(),
529 V->getSourceRange().getEnd());
530}
531
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000532SwitchStmt::SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond)
Ted Kremenek780d8852010-09-09 00:06:01 +0000533 : Stmt(SwitchStmtClass), FirstCase(0), AllEnumCasesCovered(0)
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000534{
535 setConditionVariable(C, Var);
536 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
537 SubExprs[BODY] = NULL;
538}
539
540VarDecl *SwitchStmt::getConditionVariable() const {
541 if (!SubExprs[VAR])
542 return 0;
543
544 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
545 return cast<VarDecl>(DS->getSingleDecl());
546}
547
548void SwitchStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
549 if (!V) {
550 SubExprs[VAR] = 0;
551 return;
552 }
553
554 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V),
555 V->getSourceRange().getBegin(),
556 V->getSourceRange().getEnd());
557}
558
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000559WhileStmt::WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
560 SourceLocation WL)
561: Stmt(WhileStmtClass)
562{
563 setConditionVariable(C, Var);
564 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
565 SubExprs[BODY] = body;
566 WhileLoc = WL;
567}
568
569VarDecl *WhileStmt::getConditionVariable() const {
570 if (!SubExprs[VAR])
571 return 0;
572
573 DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]);
574 return cast<VarDecl>(DS->getSingleDecl());
575}
576
577void WhileStmt::setConditionVariable(ASTContext &C, VarDecl *V) {
578 if (!V) {
579 SubExprs[VAR] = 0;
580 return;
581 }
582
583 SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V),
584 V->getSourceRange().getBegin(),
585 V->getSourceRange().getEnd());
586}
587
Ted Kremenek82977772007-08-24 21:09:09 +0000588//===----------------------------------------------------------------------===//
589// Child Iterators for iterating over subexpressions/substatements
590//===----------------------------------------------------------------------===//
591
592// DeclStmt
Ted Kremenek8ffb1592008-10-07 23:09:49 +0000593Stmt::child_iterator DeclStmt::child_begin() {
594 return StmtIterator(DG.begin(), DG.end());
Ted Kremenek14f8b4f2008-08-05 20:46:55 +0000595}
596
Ted Kremenek8ffb1592008-10-07 23:09:49 +0000597Stmt::child_iterator DeclStmt::child_end() {
598 return StmtIterator(DG.end(), DG.end());
Ted Kremenek65aa3b92008-10-06 20:54:44 +0000599}
600
Ted Kremenek82977772007-08-24 21:09:09 +0000601// NullStmt
Ted Kremenek9ac59282007-10-18 23:28:49 +0000602Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
603Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
Ted Kremenek82977772007-08-24 21:09:09 +0000604
605// CompoundStmt
606Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
John McCall8e6285a2010-10-26 08:39:16 +0000607Stmt::child_iterator CompoundStmt::child_end() {
608 return &Body[0]+CompoundStmtBits.NumStmts;
609}
Ted Kremenek82977772007-08-24 21:09:09 +0000610
Ted Kremenekd97bb6c2007-08-30 16:50:46 +0000611// CaseStmt
612Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; }
613Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; }
614
615// DefaultStmt
616Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; }
617Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; }
Ted Kremenek82977772007-08-24 21:09:09 +0000618
619// LabelStmt
620Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
Chris Lattnerb3938792007-08-30 00:53:54 +0000621Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
Ted Kremenek82977772007-08-24 21:09:09 +0000622
623// IfStmt
Ted Kremenek35628d12009-12-23 23:38:34 +0000624Stmt::child_iterator IfStmt::child_begin() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000625 return &SubExprs[0];
Ted Kremenek35628d12009-12-23 23:38:34 +0000626}
627Stmt::child_iterator IfStmt::child_end() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000628 return &SubExprs[0]+END_EXPR;
Ted Kremenek35628d12009-12-23 23:38:34 +0000629}
Ted Kremenek82977772007-08-24 21:09:09 +0000630
631// SwitchStmt
Ted Kremeneka3be0ea2009-12-24 00:39:05 +0000632Stmt::child_iterator SwitchStmt::child_begin() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000633 return &SubExprs[0];
Ted Kremeneka3be0ea2009-12-24 00:39:05 +0000634}
635Stmt::child_iterator SwitchStmt::child_end() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000636 return &SubExprs[0]+END_EXPR;
Ted Kremeneka3be0ea2009-12-24 00:39:05 +0000637}
Ted Kremenek82977772007-08-24 21:09:09 +0000638
639// WhileStmt
Ted Kremenek7d02b8c2009-12-24 00:54:19 +0000640Stmt::child_iterator WhileStmt::child_begin() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000641 return &SubExprs[0];
Ted Kremenek7d02b8c2009-12-24 00:54:19 +0000642}
643Stmt::child_iterator WhileStmt::child_end() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000644 return &SubExprs[0]+END_EXPR;
Ted Kremenek7d02b8c2009-12-24 00:54:19 +0000645}
Ted Kremenek82977772007-08-24 21:09:09 +0000646
647// DoStmt
648Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; }
649Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
650
651// ForStmt
Ted Kremenekf0d975f2009-12-24 01:48:39 +0000652Stmt::child_iterator ForStmt::child_begin() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000653 return &SubExprs[0];
Ted Kremenekf0d975f2009-12-24 01:48:39 +0000654}
655Stmt::child_iterator ForStmt::child_end() {
Douglas Gregor43dec6b2010-06-21 23:44:13 +0000656 return &SubExprs[0]+END_EXPR;
Ted Kremenekf0d975f2009-12-24 01:48:39 +0000657}
Ted Kremenek82977772007-08-24 21:09:09 +0000658
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000659// ObjCForCollectionStmt
Nico Weber608b17f2008-08-05 23:15:29 +0000660Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
661 return &SubExprs[0];
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000662}
Nico Weber608b17f2008-08-05 23:15:29 +0000663Stmt::child_iterator ObjCForCollectionStmt::child_end() {
664 return &SubExprs[0]+END_EXPR;
Fariborz Jahanian0196cab2008-01-02 22:54:34 +0000665}
666
Ted Kremenek82977772007-08-24 21:09:09 +0000667// GotoStmt
Ted Kremenek9ac59282007-10-18 23:28:49 +0000668Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
669Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
Ted Kremenek82977772007-08-24 21:09:09 +0000670
671// IndirectGotoStmt
John McCall95c225d2010-10-28 08:53:48 +0000672LabelStmt *IndirectGotoStmt::getConstantTarget() {
673 if (AddrLabelExpr *E =
674 dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts()))
675 return E->getLabel();
676 return 0;
677}
Ted Kremenek82977772007-08-24 21:09:09 +0000678
Ted Kremenek1060aff2008-06-17 03:11:08 +0000679Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; }
680Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; }
Ted Kremenek82977772007-08-24 21:09:09 +0000681
682// ContinueStmt
Ted Kremenek9ac59282007-10-18 23:28:49 +0000683Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
684Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); }
Ted Kremenek82977772007-08-24 21:09:09 +0000685
686// BreakStmt
Ted Kremenek9ac59282007-10-18 23:28:49 +0000687Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); }
688Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
Ted Kremenek82977772007-08-24 21:09:09 +0000689
690// ReturnStmt
Ted Kremenek1060aff2008-06-17 03:11:08 +0000691const Expr* ReturnStmt::getRetValue() const {
692 return cast_or_null<Expr>(RetExpr);
693}
694Expr* ReturnStmt::getRetValue() {
695 return cast_or_null<Expr>(RetExpr);
Ted Kremenek82977772007-08-24 21:09:09 +0000696}
697
Ted Kremenek1060aff2008-06-17 03:11:08 +0000698Stmt::child_iterator ReturnStmt::child_begin() {
699 return &RetExpr;
700}
701Stmt::child_iterator ReturnStmt::child_end() {
702 return RetExpr ? &RetExpr+1 : &RetExpr;
Ted Kremenek2298f912007-08-27 20:58:16 +0000703}
Ted Kremenek82977772007-08-24 21:09:09 +0000704
Chris Lattnerfe795952007-10-29 04:04:16 +0000705// AsmStmt
Mike Stump1eb44332009-09-09 15:08:12 +0000706Stmt::child_iterator AsmStmt::child_begin() {
Anders Carlsson966146e2010-01-30 23:19:41 +0000707 return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0];
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000708}
709Stmt::child_iterator AsmStmt::child_end() {
Anders Carlsson966146e2010-01-30 23:19:41 +0000710 return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0] + NumOutputs + NumInputs;
Ted Kremenekce2fc3a2008-10-27 18:40:21 +0000711}
Chris Lattnerfe795952007-10-29 04:04:16 +0000712
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000713// ObjCAtCatchStmt
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000714Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &Body; }
715Stmt::child_iterator ObjCAtCatchStmt::child_end() { return &Body + 1; }
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000716
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000717// ObjCAtFinallyStmt
718Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; }
719Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; }
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000720
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000721// ObjCAtTryStmt
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +0000722Stmt::child_iterator ObjCAtTryStmt::child_begin() { return getStmts(); }
723
724Stmt::child_iterator ObjCAtTryStmt::child_end() {
725 return getStmts() + 1 + NumCatchStmts + HasFinally;
Fariborz Jahanian3b1191d2007-11-01 23:59:59 +0000726}
Fariborz Jahanianb210bd02007-11-01 21:12:44 +0000727
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000728// ObjCAtThrowStmt
729Stmt::child_iterator ObjCAtThrowStmt::child_begin() {
Fariborz Jahanian39f8f152007-11-07 02:00:49 +0000730 return &Throw;
731}
732
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000733Stmt::child_iterator ObjCAtThrowStmt::child_end() {
Fariborz Jahanian39f8f152007-11-07 02:00:49 +0000734 return &Throw+1;
735}
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +0000736
737// ObjCAtSynchronizedStmt
738Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() {
Fariborz Jahaniana0f55792008-01-29 22:59:37 +0000739 return &SubStmts[0];
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +0000740}
741
742Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() {
Fariborz Jahaniana0f55792008-01-29 22:59:37 +0000743 return &SubStmts[0]+END_EXPR;
Fariborz Jahanianfa3ee8e2008-01-29 19:14:59 +0000744}
745
Sebastian Redl4b07b292008-12-22 19:15:10 +0000746// CXXCatchStmt
747Stmt::child_iterator CXXCatchStmt::child_begin() {
748 return &HandlerBlock;
749}
750
751Stmt::child_iterator CXXCatchStmt::child_end() {
752 return &HandlerBlock + 1;
753}
754
Sebastian Redl8351da02008-12-22 21:35:02 +0000755// CXXTryStmt
Sam Weiniga1a396d2010-02-03 03:56:39 +0000756Stmt::child_iterator CXXTryStmt::child_begin() {
757 return reinterpret_cast<Stmt **>(this + 1);
758}
759
760Stmt::child_iterator CXXTryStmt::child_end() {
761 return reinterpret_cast<Stmt **>(this + 1) + NumHandlers + 1;
762}