Stmt.cpp revision 208954
1//===--- Stmt.cpp - Statement AST Node Implementation ---------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
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"
16#include "clang/AST/ExprObjC.h"
17#include "clang/AST/StmtCXX.h"
18#include "clang/AST/StmtObjC.h"
19#include "clang/AST/Type.h"
20#include "clang/AST/ASTContext.h"
21#include "clang/AST/ASTDiagnostic.h"
22#include "clang/Basic/TargetInfo.h"
23#include <cstdio>
24using namespace clang;
25
26static struct StmtClassNameTable {
27  const char *Name;
28  unsigned Counter;
29  unsigned Size;
30} StmtClassInfo[Stmt::lastStmtConstant+1];
31
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;
39#define ABSTRACT_STMT(STMT)
40#define STMT(CLASS, PARENT) \
41  StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS;    \
42  StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS);
43#include "clang/AST/StmtNodes.inc"
44
45  return StmtClassInfo[E];
46}
47
48const char *Stmt::getStmtClassName() const {
49  return getStmtInfoTableEntry((StmtClass)sClass).Name;
50}
51
52void Stmt::PrintStats() {
53  // Ensure the table is primed.
54  getStmtInfoTableEntry(Stmt::NullStmtClass);
55
56  unsigned sum = 0;
57  fprintf(stderr, "*** Stmt/Expr Stats:\n");
58  for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
59    if (StmtClassInfo[i].Name == 0) continue;
60    sum += StmtClassInfo[i].Counter;
61  }
62  fprintf(stderr, "  %d stmts/exprs total.\n", sum);
63  sum = 0;
64  for (int i = 0; i != Stmt::lastStmtConstant+1; i++) {
65    if (StmtClassInfo[i].Name == 0) continue;
66    if (StmtClassInfo[i].Counter == 0) continue;
67    fprintf(stderr, "    %d %s, %d each (%d bytes)\n",
68            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;
72  }
73  fprintf(stderr, "Total bytes = %d\n", sum);
74}
75
76void Stmt::addStmtClass(StmtClass s) {
77  ++getStmtInfoTableEntry(s).Counter;
78}
79
80static bool StatSwitch = false;
81
82bool Stmt::CollectingStats(bool Enable) {
83  if (Enable) StatSwitch = true;
84  return StatSwitch;
85}
86
87void CompoundStmt::setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts) {
88  if (this->Body)
89    C.Deallocate(Body);
90  this->NumStmts = NumStmts;
91
92  Body = new (C) Stmt*[NumStmts];
93  memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts);
94}
95
96const char *LabelStmt::getName() const {
97  return getID()->getNameStart();
98}
99
100// This is defined here to avoid polluting Stmt.h with importing Expr.h
101SourceRange ReturnStmt::getSourceRange() const {
102  if (RetExpr)
103    return SourceRange(RetLoc, RetExpr->getLocEnd());
104  else
105    return SourceRange(RetLoc);
106}
107
108bool Stmt::hasImplicitControlFlow() const {
109  switch (sClass) {
110    default:
111      return false;
112
113    case CallExprClass:
114    case ConditionalOperatorClass:
115    case ChooseExprClass:
116    case StmtExprClass:
117    case DeclStmtClass:
118      return true;
119
120    case Stmt::BinaryOperatorClass: {
121      const BinaryOperator* B = cast<BinaryOperator>(this);
122      if (B->isLogicalOp() || B->getOpcode() == BinaryOperator::Comma)
123        return true;
124      else
125        return false;
126    }
127  }
128}
129
130Expr *AsmStmt::getOutputExpr(unsigned i) {
131  return cast<Expr>(Exprs[i]);
132}
133
134/// getOutputConstraint - Return the constraint string for the specified
135/// output operand.  All output constraints are known to be non-empty (either
136/// '=' or '+').
137llvm::StringRef AsmStmt::getOutputConstraint(unsigned i) const {
138  return getOutputConstraintLiteral(i)->getString();
139}
140
141/// 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
151Expr *AsmStmt::getInputExpr(unsigned i) {
152  return cast<Expr>(Exprs[i + NumOutputs]);
153}
154
155/// getInputConstraint - Return the specified input constraint.  Unlike output
156/// constraints, these can be empty.
157llvm::StringRef AsmStmt::getInputConstraint(unsigned i) const {
158  return getInputConstraintLiteral(i)->getString();
159}
160
161
162void AsmStmt::setOutputsAndInputsAndClobbers(ASTContext &C,
163                                             IdentifierInfo **Names,
164                                             StringLiteral **Constraints,
165                                             Stmt **Exprs,
166                                             unsigned NumOutputs,
167                                             unsigned NumInputs,
168                                             StringLiteral **Clobbers,
169                                             unsigned NumClobbers) {
170  this->NumOutputs = NumOutputs;
171  this->NumInputs = NumInputs;
172  this->NumClobbers = NumClobbers;
173
174  unsigned NumExprs = NumOutputs + NumInputs;
175
176  C.Deallocate(this->Names);
177  this->Names = new (C) IdentifierInfo*[NumExprs];
178  std::copy(Names, Names + NumExprs, this->Names);
179
180  C.Deallocate(this->Exprs);
181  this->Exprs = new (C) Stmt*[NumExprs];
182  std::copy(Exprs, Exprs + NumExprs, this->Exprs);
183
184  C.Deallocate(this->Constraints);
185  this->Constraints = new (C) StringLiteral*[NumExprs];
186  std::copy(Constraints, Constraints + NumExprs, this->Constraints);
187
188  C.Deallocate(this->Clobbers);
189  this->Clobbers = new (C) StringLiteral*[NumClobbers];
190  std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers);
191}
192
193/// 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.
196int AsmStmt::getNamedOperand(llvm::StringRef SymbolicName) const {
197  unsigned NumPlusOperands = 0;
198
199  // 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;
203  }
204
205  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
213/// 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.
216unsigned AsmStmt::AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece>&Pieces,
217                                   ASTContext &C, unsigned &DiagOffs) const {
218  const char *StrStart = getAsmString()->getStrData();
219  const char *StrEnd = StrStart + getAsmString()->getByteLength();
220  const char *CurPtr = StrStart;
221
222  // "Simple" inline asms have no constraints or operands, just convert the asm
223  // string to escape $'s.
224  if (isSimple()) {
225    std::string Result;
226    for (; CurPtr != StrEnd; ++CurPtr) {
227      switch (*CurPtr) {
228      case '$':
229        Result += "$$";
230        break;
231      default:
232        Result += *CurPtr;
233        break;
234      }
235    }
236    Pieces.push_back(AsmStringPiece(Result));
237    return 0;
238  }
239
240  // CurStringPiece - The current string that we are building up as we scan the
241  // asm string.
242  std::string CurStringPiece;
243
244  bool HasVariants = !C.Target.hasNoAsmVariants();
245
246  while (1) {
247    // Done with the string?
248    if (CurPtr == StrEnd) {
249      if (!CurStringPiece.empty())
250        Pieces.push_back(AsmStringPiece(CurStringPiece));
251      return 0;
252    }
253
254    char CurChar = *CurPtr++;
255    switch (CurChar) {
256    case '$': CurStringPiece += "$$"; continue;
257    case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue;
258    case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue;
259    case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue;
260    case '%':
261      break;
262    default:
263      CurStringPiece += CurChar;
264      continue;
265    }
266
267    // Escaped "%" character in asm string.
268    if (CurPtr == StrEnd) {
269      // % at end of string is invalid (no escape).
270      DiagOffs = CurPtr-StrStart-1;
271      return diag::err_asm_invalid_escape;
272    }
273
274    char EscapedChar = *CurPtr++;
275    if (EscapedChar == '%') {  // %% -> %
276      // Escaped percentage sign.
277      CurStringPiece += '%';
278      continue;
279    }
280
281    if (EscapedChar == '=') {  // %= -> Generate an unique ID.
282      CurStringPiece += "${:uid}";
283      continue;
284    }
285
286    // Otherwise, we have an operand.  If we have accumulated a string so far,
287    // add it to the Pieces list.
288    if (!CurStringPiece.empty()) {
289      Pieces.push_back(AsmStringPiece(CurStringPiece));
290      CurStringPiece.clear();
291    }
292
293    // Handle %x4 and %x[foo] by capturing x as the modifier character.
294    char Modifier = '\0';
295    if (isalpha(EscapedChar)) {
296      Modifier = EscapedChar;
297      EscapedChar = *CurPtr++;
298    }
299
300    if (isdigit(EscapedChar)) {
301      // %n - Assembler operand n
302      unsigned N = 0;
303
304      --CurPtr;
305      while (CurPtr != StrEnd && isdigit(*CurPtr))
306        N = N*10 + ((*CurPtr++)-'0');
307
308      unsigned NumOperands =
309        getNumOutputs() + getNumPlusOperands() + getNumInputs();
310      if (N >= NumOperands) {
311        DiagOffs = CurPtr-StrStart-1;
312        return diag::err_asm_invalid_operand_number;
313      }
314
315      Pieces.push_back(AsmStringPiece(N, Modifier));
316      continue;
317    }
318
319    // Handle %[foo], a symbolic operand reference.
320    if (EscapedChar == '[') {
321      DiagOffs = CurPtr-StrStart-1;
322
323      // Find the ']'.
324      const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr);
325      if (NameEnd == 0)
326        return diag::err_asm_unterminated_symbolic_operand_name;
327      if (NameEnd == CurPtr)
328        return diag::err_asm_empty_symbolic_operand_name;
329
330      llvm::StringRef SymbolicName(CurPtr, NameEnd - CurPtr);
331
332      int N = getNamedOperand(SymbolicName);
333      if (N == -1) {
334        // Verify that an operand with that name exists.
335        DiagOffs = CurPtr-StrStart;
336        return diag::err_asm_unknown_symbolic_operand_name;
337      }
338      Pieces.push_back(AsmStringPiece(N, Modifier));
339
340      CurPtr = NameEnd+1;
341      continue;
342    }
343
344    DiagOffs = CurPtr-StrStart-1;
345    return diag::err_asm_invalid_escape;
346  }
347}
348
349QualType CXXCatchStmt::getCaughtType() const {
350  if (ExceptionDecl)
351    return ExceptionDecl->getType();
352  return QualType();
353}
354
355//===----------------------------------------------------------------------===//
356// Constructors
357//===----------------------------------------------------------------------===//
358
359AsmStmt::AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
360                 bool isvolatile, bool msasm,
361                 unsigned numoutputs, unsigned numinputs,
362                 IdentifierInfo **names, StringLiteral **constraints,
363                 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
364                 StringLiteral **clobbers, SourceLocation rparenloc)
365  : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
366  , IsSimple(issimple), IsVolatile(isvolatile), MSAsm(msasm)
367  , NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) {
368
369  unsigned NumExprs = NumOutputs +NumInputs;
370
371  Names = new (C) IdentifierInfo*[NumExprs];
372  std::copy(names, names + NumExprs, Names);
373
374  Exprs = new (C) Stmt*[NumExprs];
375  std::copy(exprs, exprs + NumExprs, Exprs);
376
377  Constraints = new (C) StringLiteral*[NumExprs];
378  std::copy(constraints, constraints + NumExprs, Constraints);
379
380  Clobbers = new (C) StringLiteral*[NumClobbers];
381  std::copy(clobbers, clobbers + NumClobbers, Clobbers);
382}
383
384ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect,
385                                             Stmt *Body,  SourceLocation FCL,
386                                             SourceLocation RPL)
387: Stmt(ObjCForCollectionStmtClass) {
388  SubExprs[ELEM] = Elem;
389  SubExprs[COLLECTION] = reinterpret_cast<Stmt*>(Collect);
390  SubExprs[BODY] = Body;
391  ForLoc = FCL;
392  RParenLoc = RPL;
393}
394
395ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
396                             Stmt **CatchStmts, unsigned NumCatchStmts,
397                             Stmt *atFinallyStmt)
398  : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc),
399    NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != 0)
400{
401  Stmt **Stmts = getStmts();
402  Stmts[0] = atTryStmt;
403  for (unsigned I = 0; I != NumCatchStmts; ++I)
404    Stmts[I + 1] = CatchStmts[I];
405
406  if (HasFinally)
407    Stmts[NumCatchStmts + 1] = atFinallyStmt;
408}
409
410ObjCAtTryStmt *ObjCAtTryStmt::Create(ASTContext &Context,
411                                     SourceLocation atTryLoc,
412                                     Stmt *atTryStmt,
413                                     Stmt **CatchStmts,
414                                     unsigned NumCatchStmts,
415                                     Stmt *atFinallyStmt) {
416  unsigned Size = sizeof(ObjCAtTryStmt) +
417    (1 + NumCatchStmts + (atFinallyStmt != 0)) * sizeof(Stmt *);
418  void *Mem = Context.Allocate(Size, llvm::alignof<ObjCAtTryStmt>());
419  return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts,
420                                 atFinallyStmt);
421}
422
423ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(ASTContext &Context,
424                                                 unsigned NumCatchStmts,
425                                                 bool HasFinally) {
426  unsigned Size = sizeof(ObjCAtTryStmt) +
427    (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *);
428  void *Mem = Context.Allocate(Size, llvm::alignof<ObjCAtTryStmt>());
429  return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally);
430}
431
432SourceRange ObjCAtTryStmt::getSourceRange() const {
433  SourceLocation EndLoc;
434  if (HasFinally)
435    EndLoc = getFinallyStmt()->getLocEnd();
436  else if (NumCatchStmts)
437    EndLoc = getCatchStmt(NumCatchStmts - 1)->getLocEnd();
438  else
439    EndLoc = getTryBody()->getLocEnd();
440
441  return SourceRange(AtTryLoc, EndLoc);
442}
443
444CXXTryStmt *CXXTryStmt::Create(ASTContext &C, SourceLocation tryLoc,
445                               Stmt *tryBlock, Stmt **handlers,
446                               unsigned numHandlers) {
447  std::size_t Size = sizeof(CXXTryStmt);
448  Size += ((numHandlers + 1) * sizeof(Stmt));
449
450  void *Mem = C.Allocate(Size, llvm::alignof<CXXTryStmt>());
451  return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers, numHandlers);
452}
453
454CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock,
455                       Stmt **handlers, unsigned numHandlers)
456  : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(numHandlers) {
457  Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1);
458  Stmts[0] = tryBlock;
459  std::copy(handlers, handlers + NumHandlers, Stmts + 1);
460}
461
462//===----------------------------------------------------------------------===//
463// AST Destruction.
464//===----------------------------------------------------------------------===//
465
466void Stmt::DestroyChildren(ASTContext &C) {
467  for (child_iterator I = child_begin(), E = child_end(); I !=E; )
468    if (Stmt* Child = *I++) Child->Destroy(C);
469}
470
471static void BranchDestroy(ASTContext &C, Stmt *S, Stmt **SubExprs,
472                          unsigned NumExprs) {
473  // We do not use child_iterator here because that will include
474  // the expressions referenced by the condition variable.
475  for (Stmt **I = SubExprs, **E = SubExprs + NumExprs; I != E; ++I)
476    if (Stmt *Child = *I) Child->Destroy(C);
477
478  S->~Stmt();
479  C.Deallocate((void *) S);
480}
481
482void Stmt::DoDestroy(ASTContext &C) {
483  DestroyChildren(C);
484  this->~Stmt();
485  C.Deallocate((void *)this);
486}
487
488void CXXCatchStmt::DoDestroy(ASTContext& C) {
489  if (ExceptionDecl)
490    ExceptionDecl->Destroy(C);
491  Stmt::DoDestroy(C);
492}
493
494void DeclStmt::DoDestroy(ASTContext &C) {
495  // Don't use StmtIterator to iterate over the Decls, as that can recurse
496  // into VLA size expressions (which are owned by the VLA).  Further, Decls
497  // are owned by the DeclContext, and will be destroyed with them.
498  if (DG.isDeclGroup())
499    DG.getDeclGroup().Destroy(C);
500}
501
502void IfStmt::DoDestroy(ASTContext &C) {
503  BranchDestroy(C, this, SubExprs, END_EXPR);
504}
505
506void ForStmt::DoDestroy(ASTContext &C) {
507  BranchDestroy(C, this, SubExprs, END_EXPR);
508}
509
510void SwitchStmt::DoDestroy(ASTContext &C) {
511  // Destroy the SwitchCase statements in this switch. In the normal
512  // case, this loop will merely decrement the reference counts from
513  // the Retain() calls in addSwitchCase();
514  SwitchCase *SC = FirstCase;
515  while (SC) {
516    SwitchCase *Next = SC->getNextSwitchCase();
517    SC->Destroy(C);
518    SC = Next;
519  }
520
521  BranchDestroy(C, this, SubExprs, END_EXPR);
522}
523
524void WhileStmt::DoDestroy(ASTContext &C) {
525  BranchDestroy(C, this, SubExprs, END_EXPR);
526}
527
528void AsmStmt::DoDestroy(ASTContext &C) {
529  DestroyChildren(C);
530
531  C.Deallocate(Names);
532  C.Deallocate(Constraints);
533  C.Deallocate(Exprs);
534  C.Deallocate(Clobbers);
535
536  this->~AsmStmt();
537  C.Deallocate((void *)this);
538}
539
540//===----------------------------------------------------------------------===//
541//  Child Iterators for iterating over subexpressions/substatements
542//===----------------------------------------------------------------------===//
543
544// DeclStmt
545Stmt::child_iterator DeclStmt::child_begin() {
546  return StmtIterator(DG.begin(), DG.end());
547}
548
549Stmt::child_iterator DeclStmt::child_end() {
550  return StmtIterator(DG.end(), DG.end());
551}
552
553// NullStmt
554Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
555Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
556
557// CompoundStmt
558Stmt::child_iterator CompoundStmt::child_begin() { return &Body[0]; }
559Stmt::child_iterator CompoundStmt::child_end() { return &Body[0]+NumStmts; }
560
561// CaseStmt
562Stmt::child_iterator CaseStmt::child_begin() { return &SubExprs[0]; }
563Stmt::child_iterator CaseStmt::child_end() { return &SubExprs[END_EXPR]; }
564
565// DefaultStmt
566Stmt::child_iterator DefaultStmt::child_begin() { return &SubStmt; }
567Stmt::child_iterator DefaultStmt::child_end() { return &SubStmt+1; }
568
569// LabelStmt
570Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
571Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
572
573// IfStmt
574Stmt::child_iterator IfStmt::child_begin() {
575  return child_iterator(Var, &SubExprs[0]);
576}
577Stmt::child_iterator IfStmt::child_end() {
578  return child_iterator(0, &SubExprs[0]+END_EXPR);
579}
580
581// SwitchStmt
582Stmt::child_iterator SwitchStmt::child_begin() {
583  return child_iterator(Var, &SubExprs[0]);
584}
585Stmt::child_iterator SwitchStmt::child_end() {
586  return child_iterator(0, &SubExprs[0]+END_EXPR);
587}
588
589// WhileStmt
590Stmt::child_iterator WhileStmt::child_begin() {
591  return child_iterator(Var, &SubExprs[0]);
592}
593Stmt::child_iterator WhileStmt::child_end() {
594  return child_iterator(0, &SubExprs[0]+END_EXPR);
595}
596
597// DoStmt
598Stmt::child_iterator DoStmt::child_begin() { return &SubExprs[0]; }
599Stmt::child_iterator DoStmt::child_end() { return &SubExprs[0]+END_EXPR; }
600
601// ForStmt
602Stmt::child_iterator ForStmt::child_begin() {
603  return child_iterator(CondVar, &SubExprs[0]);
604}
605Stmt::child_iterator ForStmt::child_end() {
606  return child_iterator(0, &SubExprs[0]+END_EXPR);
607}
608
609// ObjCForCollectionStmt
610Stmt::child_iterator ObjCForCollectionStmt::child_begin() {
611  return &SubExprs[0];
612}
613Stmt::child_iterator ObjCForCollectionStmt::child_end() {
614  return &SubExprs[0]+END_EXPR;
615}
616
617// GotoStmt
618Stmt::child_iterator GotoStmt::child_begin() { return child_iterator(); }
619Stmt::child_iterator GotoStmt::child_end() { return child_iterator(); }
620
621// IndirectGotoStmt
622Expr* IndirectGotoStmt::getTarget() { return cast<Expr>(Target); }
623const Expr* IndirectGotoStmt::getTarget() const { return cast<Expr>(Target); }
624
625Stmt::child_iterator IndirectGotoStmt::child_begin() { return &Target; }
626Stmt::child_iterator IndirectGotoStmt::child_end() { return &Target+1; }
627
628// ContinueStmt
629Stmt::child_iterator ContinueStmt::child_begin() { return child_iterator(); }
630Stmt::child_iterator ContinueStmt::child_end() { return child_iterator(); }
631
632// BreakStmt
633Stmt::child_iterator BreakStmt::child_begin() { return child_iterator(); }
634Stmt::child_iterator BreakStmt::child_end() { return child_iterator(); }
635
636// ReturnStmt
637const Expr* ReturnStmt::getRetValue() const {
638  return cast_or_null<Expr>(RetExpr);
639}
640Expr* ReturnStmt::getRetValue() {
641  return cast_or_null<Expr>(RetExpr);
642}
643
644Stmt::child_iterator ReturnStmt::child_begin() {
645  return &RetExpr;
646}
647Stmt::child_iterator ReturnStmt::child_end() {
648  return RetExpr ? &RetExpr+1 : &RetExpr;
649}
650
651// AsmStmt
652Stmt::child_iterator AsmStmt::child_begin() {
653  return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0];
654}
655Stmt::child_iterator AsmStmt::child_end() {
656  return NumOutputs + NumInputs == 0 ? 0 : &Exprs[0] + NumOutputs + NumInputs;
657}
658
659// ObjCAtCatchStmt
660Stmt::child_iterator ObjCAtCatchStmt::child_begin() { return &Body; }
661Stmt::child_iterator ObjCAtCatchStmt::child_end() { return &Body + 1; }
662
663// ObjCAtFinallyStmt
664Stmt::child_iterator ObjCAtFinallyStmt::child_begin() { return &AtFinallyStmt; }
665Stmt::child_iterator ObjCAtFinallyStmt::child_end() { return &AtFinallyStmt+1; }
666
667// ObjCAtTryStmt
668Stmt::child_iterator ObjCAtTryStmt::child_begin() { return getStmts(); }
669
670Stmt::child_iterator ObjCAtTryStmt::child_end() {
671  return getStmts() + 1 + NumCatchStmts + HasFinally;
672}
673
674// ObjCAtThrowStmt
675Stmt::child_iterator ObjCAtThrowStmt::child_begin() {
676  return &Throw;
677}
678
679Stmt::child_iterator ObjCAtThrowStmt::child_end() {
680  return &Throw+1;
681}
682
683// ObjCAtSynchronizedStmt
684Stmt::child_iterator ObjCAtSynchronizedStmt::child_begin() {
685  return &SubStmts[0];
686}
687
688Stmt::child_iterator ObjCAtSynchronizedStmt::child_end() {
689  return &SubStmts[0]+END_EXPR;
690}
691
692// CXXCatchStmt
693Stmt::child_iterator CXXCatchStmt::child_begin() {
694  return &HandlerBlock;
695}
696
697Stmt::child_iterator CXXCatchStmt::child_end() {
698  return &HandlerBlock + 1;
699}
700
701// CXXTryStmt
702Stmt::child_iterator CXXTryStmt::child_begin() {
703  return reinterpret_cast<Stmt **>(this + 1);
704}
705
706Stmt::child_iterator CXXTryStmt::child_end() {
707  return reinterpret_cast<Stmt **>(this + 1) + NumHandlers + 1;
708}
709