Stmt.h revision 4210f3dfd73ad3482f9cfa0a382e1fd78f22976d
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  virtual void directEmit(llvm::Serializer& S) const;
407  static IfStmt* directMaterialize(llvm::Deserializer& D);
408};
409
410/// SwitchStmt - This represents a 'switch' stmt.
411///
412class SwitchStmt : public Stmt {
413  enum { COND, BODY, END_EXPR };
414  Stmt* SubExprs[END_EXPR];
415  // This points to a linked list of case and default statements.
416  SwitchCase *FirstCase;
417  SourceLocation SwitchLoc;
418public:
419  SwitchStmt(Expr *cond) : Stmt(SwitchStmtClass), FirstCase(0) {
420      SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
421      SubExprs[BODY] = NULL;
422    }
423
424  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
425  const Stmt *getBody() const { return SubExprs[BODY]; }
426  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
427
428  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
429  Stmt *getBody() { return SubExprs[BODY]; }
430  SwitchCase *getSwitchCaseList() { return FirstCase; }
431
432  void setBody(Stmt *S, SourceLocation SL) {
433    SubExprs[BODY] = S;
434    SwitchLoc = SL;
435  }
436  void addSwitchCase(SwitchCase *SC) {
437    if (FirstCase)
438      SC->setNextSwitchCase(FirstCase);
439
440    FirstCase = SC;
441  }
442  virtual SourceRange getSourceRange() const {
443    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
444  }
445  static bool classof(const Stmt *T) {
446    return T->getStmtClass() == SwitchStmtClass;
447  }
448  static bool classof(const SwitchStmt *) { return true; }
449
450  // Iterators
451  virtual child_iterator child_begin();
452  virtual child_iterator child_end();
453
454  virtual void directEmit(llvm::Serializer& S) const;
455  static SwitchStmt* directMaterialize(llvm::Deserializer& D);
456};
457
458
459/// WhileStmt - This represents a 'while' stmt.
460///
461class WhileStmt : public Stmt {
462  enum { COND, BODY, END_EXPR };
463  Stmt* SubExprs[END_EXPR];
464  SourceLocation WhileLoc;
465public:
466  WhileStmt(Expr *cond, Stmt *body, SourceLocation WL) : Stmt(WhileStmtClass) {
467    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
468    SubExprs[BODY] = body;
469    WhileLoc = WL;
470  }
471
472  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
473  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
474  Stmt *getBody() { return SubExprs[BODY]; }
475  const Stmt *getBody() const { return SubExprs[BODY]; }
476
477  virtual SourceRange getSourceRange() const {
478    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
479  }
480  static bool classof(const Stmt *T) {
481    return T->getStmtClass() == WhileStmtClass;
482  }
483  static bool classof(const WhileStmt *) { return true; }
484
485  // Iterators
486  virtual child_iterator child_begin();
487  virtual child_iterator child_end();
488};
489
490/// DoStmt - This represents a 'do/while' stmt.
491///
492class DoStmt : public Stmt {
493  enum { COND, BODY, END_EXPR };
494  Stmt* SubExprs[END_EXPR];
495  SourceLocation DoLoc;
496public:
497  DoStmt(Stmt *body, Expr *cond, SourceLocation DL)
498    : Stmt(DoStmtClass), DoLoc(DL) {
499    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
500    SubExprs[BODY] = body;
501    DoLoc = DL;
502  }
503
504  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
505  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
506  Stmt *getBody() { return SubExprs[BODY]; }
507  const Stmt *getBody() const { return SubExprs[BODY]; }
508
509  virtual SourceRange getSourceRange() const {
510    return SourceRange(DoLoc, SubExprs[BODY]->getLocEnd());
511  }
512  static bool classof(const Stmt *T) {
513    return T->getStmtClass() == DoStmtClass;
514  }
515  static bool classof(const DoStmt *) { return true; }
516
517  // Iterators
518  virtual child_iterator child_begin();
519  virtual child_iterator child_end();
520};
521
522
523/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
524/// the init/cond/inc parts of the ForStmt will be null if they were not
525/// specified in the source.
526///
527class ForStmt : public Stmt {
528  enum { INIT, COND, INC, BODY, END_EXPR };
529  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
530  SourceLocation ForLoc;
531public:
532  ForStmt(Stmt *Init, Expr *Cond, Expr *Inc, Stmt *Body, SourceLocation FL)
533    : Stmt(ForStmtClass) {
534    SubExprs[INIT] = Init;
535    SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
536    SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
537    SubExprs[BODY] = Body;
538    ForLoc = FL;
539  }
540
541  Stmt *getInit() { return SubExprs[INIT]; }
542  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
543  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
544  Stmt *getBody() { return SubExprs[BODY]; }
545
546  const Stmt *getInit() const { return SubExprs[INIT]; }
547  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
548  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
549  const Stmt *getBody() const { return SubExprs[BODY]; }
550
551  virtual SourceRange getSourceRange() const {
552    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
553  }
554  static bool classof(const Stmt *T) {
555    return T->getStmtClass() == ForStmtClass;
556  }
557  static bool classof(const ForStmt *) { return true; }
558
559  // Iterators
560  virtual child_iterator child_begin();
561  virtual child_iterator child_end();
562};
563
564/// GotoStmt - This represents a direct goto.
565///
566class GotoStmt : public Stmt {
567  LabelStmt *Label;
568  SourceLocation GotoLoc;
569  SourceLocation LabelLoc;
570public:
571  GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL)
572    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
573
574  LabelStmt *getLabel() const { return Label; }
575
576  virtual SourceRange getSourceRange() const {
577    return SourceRange(GotoLoc, LabelLoc);
578  }
579  static bool classof(const Stmt *T) {
580    return T->getStmtClass() == GotoStmtClass;
581  }
582  static bool classof(const GotoStmt *) { return true; }
583
584  // Iterators
585  virtual child_iterator child_begin();
586  virtual child_iterator child_end();
587};
588
589/// IndirectGotoStmt - This represents an indirect goto.
590///
591class IndirectGotoStmt : public Stmt {
592  Expr *Target;
593public:
594  IndirectGotoStmt(Expr *target) : Stmt(IndirectGotoStmtClass), Target(target){}
595
596  Expr *getTarget() { return Target; }
597  const Expr *getTarget() const { return Target; }
598
599  virtual SourceRange getSourceRange() const { return SourceRange(); }
600
601  static bool classof(const Stmt *T) {
602    return T->getStmtClass() == IndirectGotoStmtClass;
603  }
604  static bool classof(const IndirectGotoStmt *) { return true; }
605
606  // Iterators
607  virtual child_iterator child_begin();
608  virtual child_iterator child_end();
609};
610
611
612/// ContinueStmt - This represents a continue.
613///
614class ContinueStmt : public Stmt {
615  SourceLocation ContinueLoc;
616public:
617  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
618
619  virtual SourceRange getSourceRange() const {
620    return SourceRange(ContinueLoc);
621  }
622  static bool classof(const Stmt *T) {
623    return T->getStmtClass() == ContinueStmtClass;
624  }
625  static bool classof(const ContinueStmt *) { return true; }
626
627  // Iterators
628  virtual child_iterator child_begin();
629  virtual child_iterator child_end();
630};
631
632/// BreakStmt - This represents a break.
633///
634class BreakStmt : public Stmt {
635  SourceLocation BreakLoc;
636public:
637  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
638
639  virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
640
641  static bool classof(const Stmt *T) {
642    return T->getStmtClass() == BreakStmtClass;
643  }
644  static bool classof(const BreakStmt *) { return true; }
645
646  // Iterators
647  virtual child_iterator child_begin();
648  virtual child_iterator child_end();
649
650  virtual void directEmit(llvm::Serializer& S) const;
651  static BreakStmt* directMaterialize(llvm::Deserializer& D);
652};
653
654
655/// ReturnStmt - This represents a return, optionally of an expression.
656///
657class ReturnStmt : public Stmt {
658  Expr *RetExpr;
659  SourceLocation RetLoc;
660public:
661  ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
662    RetExpr(E), RetLoc(RL) {}
663
664  const Expr *getRetValue() const { return RetExpr; }
665  Expr *getRetValue() { return RetExpr; }
666
667  virtual SourceRange getSourceRange() const;
668
669  static bool classof(const Stmt *T) {
670    return T->getStmtClass() == ReturnStmtClass;
671  }
672  static bool classof(const ReturnStmt *) { return true; }
673
674  // Iterators
675  virtual child_iterator child_begin();
676  virtual child_iterator child_end();
677
678  virtual void directEmit(llvm::Serializer& S) const;
679  static ReturnStmt* directMaterialize(llvm::Deserializer& D);
680};
681
682/// AsmStmt - This represents a GNU inline-assembly statement extension.
683///
684class AsmStmt : public Stmt {
685  SourceLocation AsmLoc, RParenLoc;
686  // FIXME: This doesn't capture most of the interesting pieces.
687public:
688  AsmStmt(SourceLocation asmloc, SourceLocation rparenloc)
689    : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc) {}
690
691  virtual SourceRange getSourceRange() const {
692    return SourceRange(AsmLoc, RParenLoc);
693  }
694
695  static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
696  static bool classof(const AsmStmt *) { return true; }
697
698  virtual child_iterator child_begin();
699  virtual child_iterator child_end();
700};
701
702/// ObjcAtCatchStmt - This represents objective-c's @catch statement.
703class ObjcAtCatchStmt : public Stmt {
704private:
705  // Points to next @catch statement, or null
706  ObjcAtCatchStmt *NextAtCatchStmt;
707  enum { SELECTOR, BODY, END_EXPR };
708  Stmt *SubExprs[END_EXPR];
709  SourceLocation AtCatchLoc, RParenLoc;
710
711public:
712  ObjcAtCatchStmt(SourceLocation atCatchLoc, SourceLocation rparenloc,
713                  Stmt *catchVarStmtDecl, Stmt *atCatchStmt, Stmt *atCatchList)
714  : Stmt(ObjcAtCatchStmtClass) {
715      SubExprs[SELECTOR] = catchVarStmtDecl;
716      SubExprs[BODY] = atCatchStmt;
717      SubExprs[END_EXPR] = NULL;
718      if (!atCatchList)
719        NextAtCatchStmt = NULL;
720      else {
721        ObjcAtCatchStmt *AtCatchList =
722          static_cast<ObjcAtCatchStmt*>(atCatchList);
723        while (AtCatchList->NextAtCatchStmt)
724          AtCatchList = AtCatchList->NextAtCatchStmt;
725        AtCatchList->NextAtCatchStmt = this;
726      }
727      AtCatchLoc = atCatchLoc;
728      RParenLoc = rparenloc;
729    }
730
731  const Stmt *getCatchBody() const { return SubExprs[BODY]; }
732  Stmt *getCatchBody() { return SubExprs[BODY]; }
733  const ObjcAtCatchStmt *getNextCatchStmt() const { return NextAtCatchStmt; }
734  ObjcAtCatchStmt *getNextCatchStmt() { return NextAtCatchStmt; }
735  const Stmt *getCatchParamStmt() const { return SubExprs[SELECTOR]; }
736  Stmt *getCatchParamStmt() { return SubExprs[SELECTOR]; }
737
738  SourceLocation getRParenLoc() const { return RParenLoc; }
739
740  virtual SourceRange getSourceRange() const {
741    return SourceRange(AtCatchLoc, SubExprs[BODY]->getLocEnd());
742  }
743
744  static bool classof(const Stmt *T) {
745    return T->getStmtClass() == ObjcAtCatchStmtClass;
746  }
747  static bool classof(const ObjcAtCatchStmt *) { return true; }
748
749  virtual child_iterator child_begin();
750  virtual child_iterator child_end();
751
752};
753
754/// ObjcAtFinallyStmt - This represent objective-c's @finally Statement
755class ObjcAtFinallyStmt : public Stmt {
756  private:
757    Stmt *AtFinallyStmt;
758    SourceLocation AtFinallyLoc;
759
760  public:
761    ObjcAtFinallyStmt(SourceLocation atFinallyLoc, Stmt *atFinallyStmt)
762    : Stmt(ObjcAtFinallyStmtClass),
763      AtFinallyStmt(atFinallyStmt), AtFinallyLoc(atFinallyLoc) {}
764
765    const Stmt *getFinallyBody () const { return AtFinallyStmt; }
766    Stmt *getFinallyBody () { return AtFinallyStmt; }
767
768    virtual SourceRange getSourceRange() const {
769      return SourceRange(AtFinallyLoc, AtFinallyStmt->getLocEnd());
770    }
771
772    static bool classof(const Stmt *T) {
773      return T->getStmtClass() == ObjcAtFinallyStmtClass;
774    }
775    static bool classof(const ObjcAtFinallyStmt *) { return true; }
776
777    virtual child_iterator child_begin();
778    virtual child_iterator child_end();
779
780};
781
782/// ObjcAtTryStmt - This represent objective-c's over-all
783/// @try ... @catch ... @finally statement.
784class ObjcAtTryStmt : public Stmt {
785private:
786  enum { TRY, CATCH, FINALLY, END_TRY };
787  Stmt* SubStmts[END_TRY];
788
789  SourceLocation AtTryLoc;
790
791public:
792  ObjcAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt,
793                Stmt *atCatchStmt,
794                Stmt *atFinallyStmt)
795  : Stmt(ObjcAtTryStmtClass) {
796      SubStmts[TRY] = atTryStmt;
797      SubStmts[CATCH] = atCatchStmt;
798      SubStmts[FINALLY] = atFinallyStmt;
799      SubStmts[END_TRY] = NULL;
800      AtTryLoc = atTryLoc;
801    }
802
803  const Stmt *getTryBody() const { return SubStmts[TRY]; }
804  Stmt *getTryBody() { return SubStmts[TRY]; }
805  const ObjcAtCatchStmt *getCatchStmts() const {
806    return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]);
807  }
808  ObjcAtCatchStmt *getCatchStmts() {
809    return dyn_cast_or_null<ObjcAtCatchStmt>(SubStmts[CATCH]);
810  }
811  const ObjcAtFinallyStmt *getFinallyStmt() const {
812    return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]);
813  }
814  ObjcAtFinallyStmt *getFinallyStmt() {
815    return dyn_cast_or_null<ObjcAtFinallyStmt>(SubStmts[FINALLY]);
816  }
817  virtual SourceRange getSourceRange() const {
818    return SourceRange(AtTryLoc, SubStmts[TRY]->getLocEnd());
819  }
820
821  static bool classof(const Stmt *T) {
822    return T->getStmtClass() == ObjcAtTryStmtClass;
823  }
824  static bool classof(const ObjcAtTryStmt *) { return true; }
825
826  virtual child_iterator child_begin();
827  virtual child_iterator child_end();
828
829};
830
831/// ObjcAtThrowStmt - This represents objective-c's @throw statement.
832class ObjcAtThrowStmt : public Stmt {
833private:
834  Stmt *Throw;
835  SourceLocation AtThrowLoc;
836
837public:
838  ObjcAtThrowStmt(SourceLocation atThrowLoc, Stmt *throwExpr)
839  : Stmt(ObjcAtThrowStmtClass), Throw(throwExpr) {
840    AtThrowLoc = atThrowLoc;
841  }
842
843  Expr *const getThrowExpr() const { return reinterpret_cast<Expr*>(Throw); }
844
845  virtual SourceRange getSourceRange() const {
846    return SourceRange(AtThrowLoc, Throw->getLocEnd());
847  }
848
849  static bool classof(const Stmt *T) {
850    return T->getStmtClass() == ObjcAtThrowStmtClass;
851  }
852  static bool classof(const ObjcAtThrowStmt *) { return true; }
853
854  virtual child_iterator child_begin();
855  virtual child_iterator child_end();
856};
857
858}  // end namespace clang
859
860#endif
861