Stmt.h revision 9eea2ca5f2cb5d77569274702b5b06273e426dc2
1//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10//  This file defines the Stmt interface and subclasses.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_AST_STMT_H
15#define LLVM_CLANG_AST_STMT_H
16
17#include "llvm/Support/Casting.h"
18#include "clang/Basic/SourceLocation.h"
19#include "clang/AST/StmtIterator.h"
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/iterator"
22#include "llvm/Bitcode/SerializationFwd.h"
23#include <iosfwd>
24
25using llvm::dyn_cast_or_null;
26
27namespace clang {
28  class Expr;
29  class Decl;
30  class ScopedDecl;
31  class IdentifierInfo;
32  class SourceManager;
33  class SwitchStmt;
34  class PrinterHelper;
35
36/// Stmt - This represents one statement.
37///
38class Stmt {
39public:
40  enum StmtClass {
41#define STMT(N, CLASS, PARENT) CLASS##Class = N,
42#define FIRST_STMT(N) firstStmtConstant = N,
43#define LAST_STMT(N) lastStmtConstant = N,
44#define FIRST_EXPR(N) firstExprConstant = N,
45#define LAST_EXPR(N) lastExprConstant = N
46#include "clang/AST/StmtNodes.def"
47};
48private:
49  const StmtClass sClass;
50public:
51  Stmt(StmtClass SC) : sClass(SC) {
52    if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
53  }
54  virtual ~Stmt() {}
55
56  StmtClass getStmtClass() const { return sClass; }
57  const char *getStmtClassName() const;
58
59  /// SourceLocation tokens are not useful in isolation - they are low level
60  /// value objects created/interpreted by SourceManager. We assume AST
61  /// clients will have a pointer to the respective SourceManager.
62  virtual SourceRange getSourceRange() const = 0;
63  SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
64  SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
65
66  // global temp stats (until we have a per-module visitor)
67  static void addStmtClass(const StmtClass s);
68  static bool CollectingStats(bool enable=false);
69  static void PrintStats();
70
71  /// dump - This does a local dump of the specified AST fragment.  It dumps the
72  /// specified node and a few nodes underneath it, but not the whole subtree.
73  /// This is useful in a debugger.
74  void dump() const;
75  void dump(SourceManager &SM) const;
76
77  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
78  void dumpAll() const;
79  void dumpAll(SourceManager &SM) const;
80
81  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
82  /// back to its original source language syntax.
83  void dumpPretty() const;
84  void printPretty(std::ostream &OS, PrinterHelper* = NULL) const;
85
86  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
87  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
88  void viewAST() const;
89
90  // Implement isa<T> support.
91  static bool classof(const Stmt *) { return true; }
92
93  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
94  ///  contain implicit control-flow in the order their subexpressions
95  ///  are evaluated.  This predicate returns true if this statement has
96  ///  such implicit control-flow.  Such statements are also specially handled
97  ///  within CFGs.
98  bool hasImplicitControlFlow() const;
99
100  /// Child Iterators: All subclasses must implement child_begin and child_end
101  ///  to permit easy iteration over the substatements/subexpessions of an
102  ///  AST node.  This permits easy iteration over all nodes in the AST.
103  typedef StmtIterator       child_iterator;
104  typedef ConstStmtIterator  const_child_iterator;
105
106  virtual child_iterator child_begin() = 0;
107  virtual child_iterator child_end()   = 0;
108
109  const_child_iterator child_begin() const {
110    return const_child_iterator(const_cast<Stmt*>(this)->child_begin());
111  }
112
113  const_child_iterator child_end() const {
114    return const_child_iterator(const_cast<Stmt*>(this)->child_end());
115  }
116
117  void Emit(llvm::Serializer& S) const;
118  static Stmt* Materialize(llvm::Deserializer& D);
119
120  virtual void directEmit(llvm::Serializer& S) const {
121    // This method will eventually be a pure-virtual function.
122    assert (false && "Not implemented.");
123  }
124};
125
126/// DeclStmt - Adaptor class for mixing declarations with statements and
127/// expressions. For example, CompoundStmt mixes statements, expressions
128/// and declarations (variables, types). Another example is ForStmt, where
129/// the first statement can be an expression or a declaration.
130///
131class DeclStmt : public Stmt {
132  ScopedDecl *TheDecl;
133public:
134  DeclStmt(ScopedDecl *D) : Stmt(DeclStmtClass), TheDecl(D) {}
135
136  const ScopedDecl *getDecl() const { return TheDecl; }
137  ScopedDecl *getDecl() { return TheDecl; }
138
139  virtual SourceRange getSourceRange() const { return SourceRange(); }
140
141  static bool classof(const Stmt *T) {
142    return T->getStmtClass() == DeclStmtClass;
143  }
144  static bool classof(const DeclStmt *) { return true; }
145
146  // Iterators
147  virtual child_iterator child_begin();
148  virtual child_iterator child_end();
149
150  virtual void directEmit(llvm::Serializer& S) const;
151  static DeclStmt* directMaterialize(llvm::Deserializer& D);
152};
153
154/// NullStmt - This is the null statement ";": C99 6.8.3p3.
155///
156class NullStmt : public Stmt {
157  SourceLocation SemiLoc;
158public:
159  NullStmt(SourceLocation L) : Stmt(NullStmtClass), SemiLoc(L) {}
160
161  SourceLocation getSemiLoc() const { return SemiLoc; }
162
163  virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
164
165  static bool classof(const Stmt *T) {
166    return T->getStmtClass() == NullStmtClass;
167  }
168  static bool classof(const NullStmt *) { return true; }
169
170  // Iterators
171  virtual child_iterator child_begin();
172  virtual child_iterator child_end();
173
174  virtual void directEmit(llvm::Serializer& S) const;
175  static NullStmt* directMaterialize(llvm::Deserializer& D);
176};
177
178/// CompoundStmt - This represents a group of statements like { stmt stmt }.
179///
180class CompoundStmt : public Stmt {
181  llvm::SmallVector<Stmt*, 16> Body;
182  SourceLocation LBracLoc, RBracLoc;
183public:
184  CompoundStmt(Stmt **StmtStart, unsigned NumStmts,
185               SourceLocation LB, SourceLocation RB)
186    : Stmt(CompoundStmtClass), Body(StmtStart, StmtStart+NumStmts),
187      LBracLoc(LB), RBracLoc(RB) {}
188
189  bool body_empty() const { return Body.empty(); }
190
191  typedef llvm::SmallVector<Stmt*, 16>::iterator body_iterator;
192  body_iterator body_begin() { return Body.begin(); }
193  body_iterator body_end() { return Body.end(); }
194  Stmt *body_back() { return Body.back(); }
195
196  typedef llvm::SmallVector<Stmt*, 16>::const_iterator const_body_iterator;
197  const_body_iterator body_begin() const { return Body.begin(); }
198  const_body_iterator body_end() const { return Body.end(); }
199  const Stmt *body_back() const { return Body.back(); }
200
201  typedef llvm::SmallVector<Stmt*, 16>::reverse_iterator reverse_body_iterator;
202  reverse_body_iterator body_rbegin() { return Body.rbegin(); }
203  reverse_body_iterator body_rend() { return Body.rend(); }
204
205  typedef llvm::SmallVector<Stmt*, 16>::const_reverse_iterator
206    const_reverse_body_iterator;
207  const_reverse_body_iterator body_rbegin() const { return Body.rbegin(); }
208  const_reverse_body_iterator body_rend() const { return Body.rend(); }
209
210  void push_back(Stmt *S) { Body.push_back(S); }
211
212  virtual SourceRange getSourceRange() const {
213    return SourceRange(LBracLoc, RBracLoc);
214  }
215
216  SourceLocation getLBracLoc() const { return LBracLoc; }
217  SourceLocation getRBracLoc() const { return RBracLoc; }
218
219  static bool classof(const Stmt *T) {
220    return T->getStmtClass() == CompoundStmtClass;
221  }
222  static bool classof(const CompoundStmt *) { return true; }
223
224  // Iterators
225  virtual child_iterator child_begin();
226  virtual child_iterator child_end();
227
228  virtual void directEmit(llvm::Serializer& S) const;
229  static CompoundStmt* directMaterialize(llvm::Deserializer& D);
230};
231
232// SwitchCase is the base class for CaseStmt and DefaultStmt,
233class SwitchCase : public Stmt {
234  // A pointer to the following CaseStmt or DefaultStmt class,
235  // used by SwitchStmt.
236  SwitchCase *NextSwitchCase;
237protected:
238  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
239
240public:
241  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
242
243  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
244
245  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
246
247  virtual Stmt* v_getSubStmt() = 0;
248  Stmt *getSubStmt() { return v_getSubStmt(); }
249
250  virtual SourceRange getSourceRange() const { return SourceRange(); }
251
252  static bool classof(const Stmt *T) {
253    return T->getStmtClass() == CaseStmtClass ||
254    T->getStmtClass() == DefaultStmtClass;
255  }
256  static bool classof(const SwitchCase *) { return true; }
257};
258
259class CaseStmt : public SwitchCase {
260  enum { SUBSTMT, LHS, RHS, END_EXPR };
261  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
262                             // GNU "case 1 ... 4" extension
263  SourceLocation CaseLoc;
264public:
265  CaseStmt(Expr *lhs, Expr *rhs, Stmt *substmt, SourceLocation caseLoc)
266    : SwitchCase(CaseStmtClass) {
267    SubExprs[SUBSTMT] = substmt;
268    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
269    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
270    CaseLoc = caseLoc;
271  }
272
273  SourceLocation getCaseLoc() const { return CaseLoc; }
274
275  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
276  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
277  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
278  virtual Stmt* v_getSubStmt() { return getSubStmt(); }
279  const Expr *getLHS() const {
280    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
281  }
282  const Expr *getRHS() const {
283    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
284  }
285  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
286
287  virtual SourceRange getSourceRange() const {
288    return SourceRange(CaseLoc, SubExprs[SUBSTMT]->getLocEnd());
289  }
290  static bool classof(const Stmt *T) {
291    return T->getStmtClass() == CaseStmtClass;
292  }
293  static bool classof(const CaseStmt *) { return true; }
294
295  // Iterators
296  virtual child_iterator child_begin();
297  virtual child_iterator child_end();
298
299  virtual void directEmit(llvm::Serializer& S) const;
300  static CaseStmt* directMaterialize(llvm::Deserializer& D);
301};
302
303class DefaultStmt : public SwitchCase {
304  Stmt* SubStmt;
305  SourceLocation DefaultLoc;
306public:
307  DefaultStmt(SourceLocation DL, Stmt *substmt) :
308    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL) {}
309
310  Stmt *getSubStmt() { return SubStmt; }
311  virtual Stmt* v_getSubStmt() { return getSubStmt(); }
312  const Stmt *getSubStmt() const { return SubStmt; }
313
314  SourceLocation getDefaultLoc() const { return DefaultLoc; }
315
316  virtual SourceRange getSourceRange() const {
317    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
318  }
319  static bool classof(const Stmt *T) {
320    return T->getStmtClass() == DefaultStmtClass;
321  }
322  static bool classof(const DefaultStmt *) { return true; }
323
324  // Iterators
325  virtual child_iterator child_begin();
326  virtual child_iterator child_end();
327
328  virtual void directEmit(llvm::Serializer& S) const;
329  static DefaultStmt* directMaterialize(llvm::Deserializer& D);
330};
331
332class LabelStmt : public Stmt {
333  IdentifierInfo *Label;
334  Stmt *SubStmt;
335  SourceLocation IdentLoc;
336public:
337  LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt)
338    : Stmt(LabelStmtClass), Label(label),
339      SubStmt(substmt), IdentLoc(IL) {}
340
341  SourceLocation getIdentLoc() const { return IdentLoc; }
342  IdentifierInfo *getID() const { return Label; }
343  const char *getName() const;
344  Stmt *getSubStmt() { return SubStmt; }
345  const Stmt *getSubStmt() const { return SubStmt; }
346
347  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
348  void setSubStmt(Stmt *SS) { SubStmt = SS; }
349
350  virtual SourceRange getSourceRange() const {
351    return SourceRange(IdentLoc, SubStmt->getLocEnd());
352  }
353  static bool classof(const Stmt *T) {
354    return T->getStmtClass() == LabelStmtClass;
355  }
356  static bool classof(const LabelStmt *) { return true; }
357
358  // Iterators
359  virtual child_iterator child_begin();
360  virtual child_iterator child_end();
361
362  virtual void directEmit(llvm::Serializer& S) const;
363  static LabelStmt* directMaterialize(llvm::Deserializer& D);
364};
365
366
367/// IfStmt - This represents an if/then/else.
368///
369class IfStmt : public Stmt {
370  enum { COND, THEN, ELSE, END_EXPR };
371  Stmt* SubExprs[END_EXPR];
372  SourceLocation IfLoc;
373public:
374  IfStmt(SourceLocation IL, Expr *cond, Stmt *then, Stmt *elsev = 0)
375    : Stmt(IfStmtClass)  {
376    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
377    SubExprs[THEN] = then;
378    SubExprs[ELSE] = elsev;
379    IfLoc = IL;
380  }
381
382  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
383  const Stmt *getThen() const { return SubExprs[THEN]; }
384  const Stmt *getElse() const { return SubExprs[ELSE]; }
385
386  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
387  Stmt *getThen() { return SubExprs[THEN]; }
388  Stmt *getElse() { return SubExprs[ELSE]; }
389
390  virtual SourceRange getSourceRange() const {
391    if (SubExprs[ELSE])
392      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
393    else
394      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
395  }
396
397  static bool classof(const Stmt *T) {
398    return T->getStmtClass() == IfStmtClass;
399  }
400  static bool classof(const IfStmt *) { return true; }
401
402  // Iterators
403  virtual child_iterator child_begin();
404  virtual child_iterator child_end();
405};
406
407/// SwitchStmt - This represents a 'switch' stmt.
408///
409class SwitchStmt : public Stmt {
410  enum { COND, BODY, END_EXPR };
411  Stmt* SubExprs[END_EXPR];
412  // This points to a linked list of case and default statements.
413  SwitchCase *FirstCase;
414  SourceLocation SwitchLoc;
415public:
416  SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) {
417      SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
418      SubExprs[BODY] = NULL;
419    }
420
421  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
422  const Stmt *getBody() const { return SubExprs[BODY]; }
423  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
424
425  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
426  Stmt *getBody() { return SubExprs[BODY]; }
427  SwitchCase *getSwitchCaseList() { return FirstCase; }
428
429  void setBody(Stmt *S, SourceLocation SL) {
430    SubExprs[BODY] = S;
431    SwitchLoc = SL;
432  }
433  void addSwitchCase(SwitchCase *SC) {
434    if (FirstCase)
435      SC->setNextSwitchCase(FirstCase);
436
437    FirstCase = SC;
438  }
439  virtual SourceRange getSourceRange() const {
440    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
441  }
442  static bool classof(const Stmt *T) {
443    return T->getStmtClass() == SwitchStmtClass;
444  }
445  static bool classof(const SwitchStmt *) { return true; }
446
447  // Iterators
448  virtual child_iterator child_begin();
449  virtual child_iterator child_end();
450
451  void directEmit(llvm::Serializer& S) const;
452  static SwitchStmt* directMaterialize(llvm::Deserializer& D);
453};
454
455
456/// WhileStmt - This represents a 'while' stmt.
457///
458class WhileStmt : public Stmt {
459  enum { COND, BODY, END_EXPR };
460  Stmt* SubExprs[END_EXPR];
461  SourceLocation WhileLoc;
462public:
463  WhileStmt(Expr *cond, Stmt *body, SourceLocation WL) : Stmt(WhileStmtClass) {
464    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
465    SubExprs[BODY] = body;
466    WhileLoc = WL;
467  }
468
469  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
470  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
471  Stmt *getBody() { return SubExprs[BODY]; }
472  const Stmt *getBody() const { return SubExprs[BODY]; }
473
474  virtual SourceRange getSourceRange() const {
475    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
476  }
477  static bool classof(const Stmt *T) {
478    return T->getStmtClass() == WhileStmtClass;
479  }
480  static bool classof(const WhileStmt *) { return true; }
481
482  // Iterators
483  virtual child_iterator child_begin();
484  virtual child_iterator child_end();
485};
486
487/// DoStmt - This represents a 'do/while' stmt.
488///
489class DoStmt : public Stmt {
490  enum { COND, BODY, END_EXPR };
491  Stmt* SubExprs[END_EXPR];
492  SourceLocation DoLoc;
493public:
494  DoStmt(Stmt *body, Expr *cond, SourceLocation DL)
495    : Stmt(DoStmtClass), DoLoc(DL) {
496    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
497    SubExprs[BODY] = body;
498    DoLoc = DL;
499  }
500
501  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
502  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
503  Stmt *getBody() { return SubExprs[BODY]; }
504  const Stmt *getBody() const { return SubExprs[BODY]; }
505
506  virtual SourceRange getSourceRange() const {
507    return SourceRange(DoLoc, SubExprs[BODY]->getLocEnd());
508  }
509  static bool classof(const Stmt *T) {
510    return T->getStmtClass() == DoStmtClass;
511  }
512  static bool classof(const DoStmt *) { return true; }
513
514  // Iterators
515  virtual child_iterator child_begin();
516  virtual child_iterator child_end();
517};
518
519
520/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
521/// the init/cond/inc parts of the ForStmt will be null if they were not
522/// specified in the source.
523///
524class ForStmt : public Stmt {
525  enum { INIT, COND, INC, BODY, END_EXPR };
526  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
527  SourceLocation ForLoc;
528public:
529  ForStmt(Stmt *Init, Expr *Cond, Expr *Inc, Stmt *Body, SourceLocation FL)
530    : Stmt(ForStmtClass) {
531    SubExprs[INIT] = Init;
532    SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
533    SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
534    SubExprs[BODY] = Body;
535    ForLoc = FL;
536  }
537
538  Stmt *getInit() { return SubExprs[INIT]; }
539  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
540  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
541  Stmt *getBody() { return SubExprs[BODY]; }
542
543  const Stmt *getInit() const { return SubExprs[INIT]; }
544  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
545  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
546  const Stmt *getBody() const { return SubExprs[BODY]; }
547
548  virtual SourceRange getSourceRange() const {
549    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
550  }
551  static bool classof(const Stmt *T) {
552    return T->getStmtClass() == ForStmtClass;
553  }
554  static bool classof(const ForStmt *) { return true; }
555
556  // Iterators
557  virtual child_iterator child_begin();
558  virtual child_iterator child_end();
559};
560
561/// GotoStmt - This represents a direct goto.
562///
563class GotoStmt : public Stmt {
564  LabelStmt *Label;
565  SourceLocation GotoLoc;
566  SourceLocation LabelLoc;
567public:
568  GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL)
569    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
570
571  LabelStmt *getLabel() const { return Label; }
572
573  virtual SourceRange getSourceRange() const {
574    return SourceRange(GotoLoc, LabelLoc);
575  }
576  static bool classof(const Stmt *T) {
577    return T->getStmtClass() == GotoStmtClass;
578  }
579  static bool classof(const GotoStmt *) { return true; }
580
581  // Iterators
582  virtual child_iterator child_begin();
583  virtual child_iterator child_end();
584};
585
586/// IndirectGotoStmt - This represents an indirect goto.
587///
588class IndirectGotoStmt : public Stmt {
589  Expr *Target;
590public:
591  IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), Target(target){}
592
593  Expr *getTarget() { return Target; }
594  const Expr *getTarget() const { return Target; }
595
596  virtual SourceRange getSourceRange() const { return SourceRange(); }
597
598  static bool classof(const Stmt *T) {
599    return T->getStmtClass() == IndirectGotoStmtClass;
600  }
601  static bool classof(const IndirectGotoStmt *) { return true; }
602
603  // Iterators
604  virtual child_iterator child_begin();
605  virtual child_iterator child_end();
606};
607
608
609/// ContinueStmt - This represents a continue.
610///
611class ContinueStmt : public Stmt {
612  SourceLocation ContinueLoc;
613public:
614  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
615
616  virtual SourceRange getSourceRange() const {
617    return SourceRange(ContinueLoc);
618  }
619  static bool classof(const Stmt *T) {
620    return T->getStmtClass() == ContinueStmtClass;
621  }
622  static bool classof(const ContinueStmt *) { return true; }
623
624  // Iterators
625  virtual child_iterator child_begin();
626  virtual child_iterator child_end();
627};
628
629/// BreakStmt - This represents a break.
630///
631class BreakStmt : public Stmt {
632  SourceLocation BreakLoc;
633public:
634  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
635
636  virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
637
638  static bool classof(const Stmt *T) {
639    return T->getStmtClass() == BreakStmtClass;
640  }
641  static bool classof(const BreakStmt *) { return true; }
642
643  // Iterators
644  virtual child_iterator child_begin();
645  virtual child_iterator child_end();
646
647  void directEmit(llvm::Serializer& S) const;
648  static BreakStmt* directMaterialize(llvm::Deserializer& D);
649};
650
651
652/// ReturnStmt - This represents a return, optionally of an expression.
653///
654class ReturnStmt : public Stmt {
655  Expr *RetExpr;
656  SourceLocation RetLoc;
657public:
658  ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
659    RetExpr(E), RetLoc(RL) {}
660
661  const Expr *getRetValue() const { return RetExpr; }
662  Expr *getRetValue() { return RetExpr; }
663
664  virtual SourceRange getSourceRange() const;
665
666  static bool classof(const Stmt *T) {
667    return T->getStmtClass() == ReturnStmtClass;
668  }
669  static bool classof(const ReturnStmt *) { return true; }
670
671  // Iterators
672  virtual child_iterator child_begin();
673  virtual child_iterator child_end();
674
675  virtual void directEmit(llvm::Serializer& S) const;
676  static ReturnStmt* directMaterialize(llvm::Deserializer& D);
677};
678
679/// AsmStmt - This represents a GNU inline-assembly statement extension.
680///
681class AsmStmt : public Stmt {
682  SourceLocation AsmLoc, RParenLoc;
683  // FIXME: This doesn't capture most of the interesting pieces.
684public:
685  AsmStmt(SourceLocation asmloc, SourceLocation rparenloc)
686    : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc) {}
687
688  virtual SourceRange getSourceRange() const {
689    return SourceRange(AsmLoc, RParenLoc);
690  }
691
692  static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
693  static bool classof(const AsmStmt *) { return true; }
694
695  virtual child_iterator child_begin();
696  virtual child_iterator child_end();
697};
698
699/// ObjcAtCatchStmt - This represents objective-c's @catch statement.
700class ObjcAtCatchStmt : public Stmt {
701private:
702  // Points to next @catch statement, or null
703  ObjcAtCatchStmt *NextAtCatchStmt;
704  enum { SELECTOR, BODY, END_EXPR };
705  Stmt *SubExprs[END_EXPR];
706  SourceLocation AtCatchLoc, RParenLoc;
707
708public:
709  ObjcAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc,
710                  Stmt *catchVarStmtDecl, Stmt *atCatchStmt, Stmt *atCatchList)
711  : Stmt(ObjcAtCatchStmtClass) {
712      SubExprs[SELECTOR] = catchVarStmtDecl;
713      SubExprs[BODY] = atCatchStmt;
714      SubExprs[END_EXPR] = NULL;
715      if (!atCatchList)
716        NextAtCatchStmt = NULL;
717      else {
718        ObjcAtCatchStmt *AtCatchList =
719          static_cast<ObjcAtCatchStmt*>(atCatchList);
720        while (AtCatchList->NextAtCatchStmt)
721          AtCatchList = AtCatchList->NextAtCatchStmt;
722        AtCatchList->NextAtCatchStmt = this;
723      }
724      AtCatchLoc = atCatchLoc;
725      RParenLoc = rparenloc;
726    }
727
728  const Stmt *getCatchBody() const { return SubExprs[BODY]; }
729  Stmt *getCatchBody() { return SubExprs[BODY]; }
730  const ObjcAtCatchStmt *getNextCatchStmt() const { return NextAtCatchStmt; }
731  ObjcAtCatchStmt *getNextCatchStmt() { return NextAtCatchStmt; }
732  const Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; }
733  Stmt *getCatchParamStmt() { return SubExprs[SELECTOR]; }
734
735  SourceLocation getRParenLoc() const { return RParenLoc; }
736
737  virtual SourceRange getSourceRange() const {
738    return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd());
739  }
740
741  static bool classof(const Stmt *T) {
742    return T->getStmtClass() == ObjcAtCatchStmtClass;
743  }
744  static bool classof(const ObjcAtCatchStmt *) { return true; }
745
746  virtual child_iterator child_begin();
747  virtual child_iterator child_end();
748
749};
750
751/// ObjcAtFinallyStmt - This represent objective-c's @finally Statement
752class ObjcAtFinallyStmt : public Stmt {
753  private:
754    Stmt *AtFinallyStmt;
755    SourceLocation AtFinallyLoc;
756
757  public:
758    ObjcAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
759    : Stmt(ObjcAtFinallyStmtClass),
760      AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {}
761
762    const Stmt *getFinallyBody () const { return AtFinallyStmt; }
763    Stmt *getFinallyBody () { return AtFinallyStmt; }
764
765    virtual SourceRange getSourceRange() const {
766      return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd());
767    }
768
769    static bool classof(const Stmt *T) {
770      return T->getStmtClass() == ObjcAtFinallyStmtClass;
771    }
772    static bool classof(const ObjcAtFinallyStmt *) { return true; }
773
774    virtual child_iterator child_begin();
775    virtual child_iterator child_end();
776
777};
778
779/// ObjcAtTryStmt - This represent objective-c's over-all
780/// @try ... @catch ... @finally statement.
781class ObjcAtTryStmt : public Stmt {
782private:
783  enum { TRY, CATCH, FINALLY, END_TRY };
784  Stmt* SubStmts[END_TRY];
785
786  SourceLocation AtTryLoc;
787
788public:
789  ObjcAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
790                Stmt *atCatchStmt,
791                Stmt *atFinallyStmt)
792  : Stmt(ObjcAtTryStmtClass) {
793      SubStmts[TRY] = atTryStmt;
794      SubStmts[CATCH] = atCatchStmt;
795      SubStmts[FINALLY] = atFinallyStmt;
796      SubStmts[END_TRY] = NULL;
797      AtTryLoc = atTryLoc;
798    }
799
800  const Stmt *getTryBody() const { return SubStmts[TRY]; }
801  Stmt *getTryBody() { return SubStmts[TRY]; }
802  const ObjcAtCatchStmt *getCatchStmts() const {
803    return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]);
804  }
805  ObjcAtCatchStmt *getCatchStmts() {
806    return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]);
807  }
808  const ObjcAtFinallyStmt *getFinallyStmt() const {
809    return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]);
810  }
811  ObjcAtFinallyStmt *getFinallyStmt() {
812    return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]);
813  }
814  virtual SourceRange getSourceRange() const {
815    return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd());
816  }
817
818  static bool classof(const Stmt *T) {
819    return T->getStmtClass() == ObjcAtTryStmtClass;
820  }
821  static bool classof(const ObjcAtTryStmt *) { return true; }
822
823  virtual child_iterator child_begin();
824  virtual child_iterator child_end();
825
826};
827
828/// ObjcAtThrowStmt - This represents objective-c's @throw statement.
829class ObjcAtThrowStmt : public Stmt {
830private:
831  Stmt *Throw;
832  SourceLocation AtThrowLoc;
833
834public:
835  ObjcAtThrowStmt(SourceLocation atThrowLoc, Stmt *throwExpr)
836  : Stmt(ObjcAtThrowStmtClass), Throw(throwExpr) {
837    AtThrowLoc = atThrowLoc;
838  }
839
840  Expr *const getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
841
842  virtual SourceRange getSourceRange() const {
843    return SourceRange(AtThrowLoc, Throw->getLocEnd());
844  }
845
846  static bool classof(const Stmt *T) {
847    return T->getStmtClass() == ObjcAtThrowStmtClass;
848  }
849  static bool classof(const ObjcAtThrowStmt *) { return true; }
850
851  virtual child_iterator child_begin();
852  virtual child_iterator child_end();
853};
854
855}  // end namespace clang
856
857#endif
858