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