Stmt.h revision da083b2ce8db27ce6e508cb77cb12c0fc8b7cad9
1//===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
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 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/LLVM.h"
18#include "clang/Basic/SourceLocation.h"
19#include "clang/AST/PrettyPrinter.h"
20#include "clang/AST/StmtIterator.h"
21#include "clang/AST/DeclGroup.h"
22#include "clang/AST/Attr.h"
23#include "clang/Lex/Token.h"
24#include "llvm/ADT/SmallVector.h"
25#include "llvm/Support/Compiler.h"
26#include "llvm/Support/raw_ostream.h"
27#include <string>
28
29namespace llvm {
30  class FoldingSetNodeID;
31}
32
33namespace clang {
34  class ASTContext;
35  class Expr;
36  class Decl;
37  class ParmVarDecl;
38  class QualType;
39  class IdentifierInfo;
40  class LabelDecl;
41  class SourceManager;
42  class StringLiteral;
43  class SwitchStmt;
44  class VarDecl;
45
46  //===--------------------------------------------------------------------===//
47  // ExprIterator - Iterators for iterating over Stmt* arrays that contain
48  //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
49  //  references to children (to be compatible with StmtIterator).
50  //===--------------------------------------------------------------------===//
51
52  class Stmt;
53  class Expr;
54
55  class ExprIterator {
56    Stmt** I;
57  public:
58    ExprIterator(Stmt** i) : I(i) {}
59    ExprIterator() : I(0) {}
60    ExprIterator& operator++() { ++I; return *this; }
61    ExprIterator operator-(size_t i) { return I-i; }
62    ExprIterator operator+(size_t i) { return I+i; }
63    Expr* operator[](size_t idx);
64    // FIXME: Verify that this will correctly return a signed distance.
65    signed operator-(const ExprIterator& R) const { return I - R.I; }
66    Expr* operator*() const;
67    Expr* operator->() const;
68    bool operator==(const ExprIterator& R) const { return I == R.I; }
69    bool operator!=(const ExprIterator& R) const { return I != R.I; }
70    bool operator>(const ExprIterator& R) const { return I > R.I; }
71    bool operator>=(const ExprIterator& R) const { return I >= R.I; }
72  };
73
74  class ConstExprIterator {
75    const Stmt * const *I;
76  public:
77    ConstExprIterator(const Stmt * const *i) : I(i) {}
78    ConstExprIterator() : I(0) {}
79    ConstExprIterator& operator++() { ++I; return *this; }
80    ConstExprIterator operator+(size_t i) const { return I+i; }
81    ConstExprIterator operator-(size_t i) const { return I-i; }
82    const Expr * operator[](size_t idx) const;
83    signed operator-(const ConstExprIterator& R) const { return I - R.I; }
84    const Expr * operator*() const;
85    const Expr * operator->() const;
86    bool operator==(const ConstExprIterator& R) const { return I == R.I; }
87    bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
88    bool operator>(const ConstExprIterator& R) const { return I > R.I; }
89    bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
90  };
91
92//===----------------------------------------------------------------------===//
93// AST classes for statements.
94//===----------------------------------------------------------------------===//
95
96/// Stmt - This represents one statement.
97///
98class Stmt {
99public:
100  enum StmtClass {
101    NoStmtClass = 0,
102#define STMT(CLASS, PARENT) CLASS##Class,
103#define STMT_RANGE(BASE, FIRST, LAST) \
104        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
105#define LAST_STMT_RANGE(BASE, FIRST, LAST) \
106        first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
107#define ABSTRACT_STMT(STMT)
108#include "clang/AST/StmtNodes.inc"
109  };
110
111  // Make vanilla 'new' and 'delete' illegal for Stmts.
112protected:
113  void* operator new(size_t bytes) throw() {
114    llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
115  }
116  void operator delete(void* data) throw() {
117    llvm_unreachable("Stmts cannot be released with regular 'delete'.");
118  }
119
120  class StmtBitfields {
121    friend class Stmt;
122
123    /// \brief The statement class.
124    unsigned sClass : 8;
125  };
126  enum { NumStmtBits = 8 };
127
128  class CompoundStmtBitfields {
129    friend class CompoundStmt;
130    unsigned : NumStmtBits;
131
132    unsigned NumStmts : 32 - NumStmtBits;
133  };
134
135  class ExprBitfields {
136    friend class Expr;
137    friend class DeclRefExpr; // computeDependence
138    friend class InitListExpr; // ctor
139    friend class DesignatedInitExpr; // ctor
140    friend class BlockDeclRefExpr; // ctor
141    friend class ASTStmtReader; // deserialization
142    friend class CXXNewExpr; // ctor
143    friend class DependentScopeDeclRefExpr; // ctor
144    friend class CXXConstructExpr; // ctor
145    friend class CallExpr; // ctor
146    friend class OffsetOfExpr; // ctor
147    friend class ObjCMessageExpr; // ctor
148    friend class ObjCArrayLiteral; // ctor
149    friend class ObjCDictionaryLiteral; // ctor
150    friend class ShuffleVectorExpr; // ctor
151    friend class ParenListExpr; // ctor
152    friend class CXXUnresolvedConstructExpr; // ctor
153    friend class CXXDependentScopeMemberExpr; // ctor
154    friend class OverloadExpr; // ctor
155    friend class PseudoObjectExpr; // ctor
156    friend class AtomicExpr; // ctor
157    unsigned : NumStmtBits;
158
159    unsigned ValueKind : 2;
160    unsigned ObjectKind : 2;
161    unsigned TypeDependent : 1;
162    unsigned ValueDependent : 1;
163    unsigned InstantiationDependent : 1;
164    unsigned ContainsUnexpandedParameterPack : 1;
165  };
166  enum { NumExprBits = 16 };
167
168  class CharacterLiteralBitfields {
169    friend class CharacterLiteral;
170    unsigned : NumExprBits;
171
172    unsigned Kind : 2;
173  };
174
175  class FloatingLiteralBitfields {
176    friend class FloatingLiteral;
177    unsigned : NumExprBits;
178
179    unsigned IsIEEE : 1; // Distinguishes between PPC128 and IEEE128.
180    unsigned IsExact : 1;
181  };
182
183  class UnaryExprOrTypeTraitExprBitfields {
184    friend class UnaryExprOrTypeTraitExpr;
185    unsigned : NumExprBits;
186
187    unsigned Kind : 2;
188    unsigned IsType : 1; // true if operand is a type, false if an expression.
189  };
190
191  class DeclRefExprBitfields {
192    friend class DeclRefExpr;
193    friend class ASTStmtReader; // deserialization
194    unsigned : NumExprBits;
195
196    unsigned HasQualifier : 1;
197    unsigned HasTemplateKWAndArgsInfo : 1;
198    unsigned HasFoundDecl : 1;
199    unsigned HadMultipleCandidates : 1;
200    unsigned RefersToEnclosingLocal : 1;
201  };
202
203  class CastExprBitfields {
204    friend class CastExpr;
205    unsigned : NumExprBits;
206
207    unsigned Kind : 6;
208    unsigned BasePathSize : 32 - 6 - NumExprBits;
209  };
210
211  class CallExprBitfields {
212    friend class CallExpr;
213    unsigned : NumExprBits;
214
215    unsigned NumPreArgs : 1;
216  };
217
218  class ExprWithCleanupsBitfields {
219    friend class ExprWithCleanups;
220    friend class ASTStmtReader; // deserialization
221
222    unsigned : NumExprBits;
223
224    unsigned NumObjects : 32 - NumExprBits;
225  };
226
227  class PseudoObjectExprBitfields {
228    friend class PseudoObjectExpr;
229    friend class ASTStmtReader; // deserialization
230
231    unsigned : NumExprBits;
232
233    // These don't need to be particularly wide, because they're
234    // strictly limited by the forms of expressions we permit.
235    unsigned NumSubExprs : 8;
236    unsigned ResultIndex : 32 - 8 - NumExprBits;
237  };
238
239  class ObjCIndirectCopyRestoreExprBitfields {
240    friend class ObjCIndirectCopyRestoreExpr;
241    unsigned : NumExprBits;
242
243    unsigned ShouldCopy : 1;
244  };
245
246  class InitListExprBitfields {
247    friend class InitListExpr;
248
249    unsigned : NumExprBits;
250
251    /// Whether this initializer list originally had a GNU array-range
252    /// designator in it. This is a temporary marker used by CodeGen.
253    unsigned HadArrayRangeDesignator : 1;
254
255    /// Whether this initializer list initializes a std::initializer_list
256    /// object.
257    unsigned InitializesStdInitializerList : 1;
258  };
259
260  class TypeTraitExprBitfields {
261    friend class TypeTraitExpr;
262    friend class ASTStmtReader;
263    friend class ASTStmtWriter;
264
265    unsigned : NumExprBits;
266
267    /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
268    unsigned Kind : 8;
269
270    /// \brief If this expression is not value-dependent, this indicates whether
271    /// the trait evaluated true or false.
272    unsigned Value : 1;
273
274    /// \brief The number of arguments to this type trait.
275    unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
276  };
277
278  union {
279    // FIXME: this is wasteful on 64-bit platforms.
280    void *Aligner;
281
282    StmtBitfields StmtBits;
283    CompoundStmtBitfields CompoundStmtBits;
284    ExprBitfields ExprBits;
285    CharacterLiteralBitfields CharacterLiteralBits;
286    FloatingLiteralBitfields FloatingLiteralBits;
287    UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
288    DeclRefExprBitfields DeclRefExprBits;
289    CastExprBitfields CastExprBits;
290    CallExprBitfields CallExprBits;
291    ExprWithCleanupsBitfields ExprWithCleanupsBits;
292    PseudoObjectExprBitfields PseudoObjectExprBits;
293    ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
294    InitListExprBitfields InitListExprBits;
295    TypeTraitExprBitfields TypeTraitExprBits;
296  };
297
298  friend class ASTStmtReader;
299  friend class ASTStmtWriter;
300
301public:
302  // Only allow allocation of Stmts using the allocator in ASTContext
303  // or by doing a placement new.
304  void* operator new(size_t bytes, ASTContext& C,
305                     unsigned alignment = 8) throw() {
306    return ::operator new(bytes, C, alignment);
307  }
308
309  void* operator new(size_t bytes, ASTContext* C,
310                     unsigned alignment = 8) throw() {
311    return ::operator new(bytes, *C, alignment);
312  }
313
314  void* operator new(size_t bytes, void* mem) throw() {
315    return mem;
316  }
317
318  void operator delete(void*, ASTContext&, unsigned) throw() { }
319  void operator delete(void*, ASTContext*, unsigned) throw() { }
320  void operator delete(void*, std::size_t) throw() { }
321  void operator delete(void*, void*) throw() { }
322
323public:
324  /// \brief A placeholder type used to construct an empty shell of a
325  /// type, that will be filled in later (e.g., by some
326  /// de-serialization).
327  struct EmptyShell { };
328
329private:
330  /// \brief Whether statistic collection is enabled.
331  static bool StatisticsEnabled;
332
333protected:
334  /// \brief Construct an empty statement.
335  explicit Stmt(StmtClass SC, EmptyShell) {
336    StmtBits.sClass = SC;
337    if (StatisticsEnabled) Stmt::addStmtClass(SC);
338  }
339
340public:
341  Stmt(StmtClass SC) {
342    StmtBits.sClass = SC;
343    if (StatisticsEnabled) Stmt::addStmtClass(SC);
344  }
345
346  StmtClass getStmtClass() const {
347    return static_cast<StmtClass>(StmtBits.sClass);
348  }
349  const char *getStmtClassName() const;
350
351  /// SourceLocation tokens are not useful in isolation - they are low level
352  /// value objects created/interpreted by SourceManager. We assume AST
353  /// clients will have a pointer to the respective SourceManager.
354  SourceRange getSourceRange() const LLVM_READONLY;
355  SourceLocation getLocStart() const LLVM_READONLY;
356  SourceLocation getLocEnd() const LLVM_READONLY;
357
358  // global temp stats (until we have a per-module visitor)
359  static void addStmtClass(const StmtClass s);
360  static void EnableStatistics();
361  static void PrintStats();
362
363  /// dump - This does a local dump of the specified AST fragment.  It dumps the
364  /// specified node and a few nodes underneath it, but not the whole subtree.
365  /// This is useful in a debugger.
366  LLVM_ATTRIBUTE_USED void dump() const;
367  LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
368  void dump(raw_ostream &OS, SourceManager &SM) const;
369
370  /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
371  void dumpAll() const;
372  void dumpAll(SourceManager &SM) const;
373
374  /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
375  /// back to its original source language syntax.
376  void dumpPretty(ASTContext &Context) const;
377  void printPretty(raw_ostream &OS, PrinterHelper *Helper,
378                   const PrintingPolicy &Policy,
379                   unsigned Indentation = 0) const;
380
381  /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
382  ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
383  void viewAST() const;
384
385  /// Skip past any implicit AST nodes which might surround this
386  /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
387  Stmt *IgnoreImplicit();
388
389  const Stmt *stripLabelLikeStatements() const;
390  Stmt *stripLabelLikeStatements() {
391    return const_cast<Stmt*>(
392      const_cast<const Stmt*>(this)->stripLabelLikeStatements());
393  }
394
395  // Implement isa<T> support.
396  static bool classof(const Stmt *) { return true; }
397
398  /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
399  ///  contain implicit control-flow in the order their subexpressions
400  ///  are evaluated.  This predicate returns true if this statement has
401  ///  such implicit control-flow.  Such statements are also specially handled
402  ///  within CFGs.
403  bool hasImplicitControlFlow() const;
404
405  /// Child Iterators: All subclasses must implement 'children'
406  /// to permit easy iteration over the substatements/subexpessions of an
407  /// AST node.  This permits easy iteration over all nodes in the AST.
408  typedef StmtIterator       child_iterator;
409  typedef ConstStmtIterator  const_child_iterator;
410
411  typedef StmtRange          child_range;
412  typedef ConstStmtRange     const_child_range;
413
414  child_range children();
415  const_child_range children() const {
416    return const_cast<Stmt*>(this)->children();
417  }
418
419  child_iterator child_begin() { return children().first; }
420  child_iterator child_end() { return children().second; }
421
422  const_child_iterator child_begin() const { return children().first; }
423  const_child_iterator child_end() const { return children().second; }
424
425  /// \brief Produce a unique representation of the given statement.
426  ///
427  /// \param ID once the profiling operation is complete, will contain
428  /// the unique representation of the given statement.
429  ///
430  /// \param Context the AST context in which the statement resides
431  ///
432  /// \param Canonical whether the profile should be based on the canonical
433  /// representation of this statement (e.g., where non-type template
434  /// parameters are identified by index/level rather than their
435  /// declaration pointers) or the exact representation of the statement as
436  /// written in the source.
437  void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
438               bool Canonical) const;
439};
440
441/// DeclStmt - Adaptor class for mixing declarations with statements and
442/// expressions. For example, CompoundStmt mixes statements, expressions
443/// and declarations (variables, types). Another example is ForStmt, where
444/// the first statement can be an expression or a declaration.
445///
446class DeclStmt : public Stmt {
447  DeclGroupRef DG;
448  SourceLocation StartLoc, EndLoc;
449
450public:
451  DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
452           SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
453                                    StartLoc(startLoc), EndLoc(endLoc) {}
454
455  /// \brief Build an empty declaration statement.
456  explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
457
458  /// isSingleDecl - This method returns true if this DeclStmt refers
459  /// to a single Decl.
460  bool isSingleDecl() const {
461    return DG.isSingleDecl();
462  }
463
464  const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
465  Decl *getSingleDecl() { return DG.getSingleDecl(); }
466
467  const DeclGroupRef getDeclGroup() const { return DG; }
468  DeclGroupRef getDeclGroup() { return DG; }
469  void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
470
471  SourceLocation getStartLoc() const { return StartLoc; }
472  void setStartLoc(SourceLocation L) { StartLoc = L; }
473  SourceLocation getEndLoc() const { return EndLoc; }
474  void setEndLoc(SourceLocation L) { EndLoc = L; }
475
476  SourceRange getSourceRange() const LLVM_READONLY {
477    return SourceRange(StartLoc, EndLoc);
478  }
479
480  static bool classof(const Stmt *T) {
481    return T->getStmtClass() == DeclStmtClass;
482  }
483  static bool classof(const DeclStmt *) { return true; }
484
485  // Iterators over subexpressions.
486  child_range children() {
487    return child_range(child_iterator(DG.begin(), DG.end()),
488                       child_iterator(DG.end(), DG.end()));
489  }
490
491  typedef DeclGroupRef::iterator decl_iterator;
492  typedef DeclGroupRef::const_iterator const_decl_iterator;
493
494  decl_iterator decl_begin() { return DG.begin(); }
495  decl_iterator decl_end() { return DG.end(); }
496  const_decl_iterator decl_begin() const { return DG.begin(); }
497  const_decl_iterator decl_end() const { return DG.end(); }
498
499  typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
500  reverse_decl_iterator decl_rbegin() {
501    return reverse_decl_iterator(decl_end());
502  }
503  reverse_decl_iterator decl_rend() {
504    return reverse_decl_iterator(decl_begin());
505  }
506};
507
508/// NullStmt - This is the null statement ";": C99 6.8.3p3.
509///
510class NullStmt : public Stmt {
511  SourceLocation SemiLoc;
512
513  /// \brief True if the null statement was preceded by an empty macro, e.g:
514  /// @code
515  ///   #define CALL(x)
516  ///   CALL(0);
517  /// @endcode
518  bool HasLeadingEmptyMacro;
519public:
520  NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
521    : Stmt(NullStmtClass), SemiLoc(L),
522      HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
523
524  /// \brief Build an empty null statement.
525  explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
526      HasLeadingEmptyMacro(false) { }
527
528  SourceLocation getSemiLoc() const { return SemiLoc; }
529  void setSemiLoc(SourceLocation L) { SemiLoc = L; }
530
531  bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
532
533  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(SemiLoc); }
534
535  static bool classof(const Stmt *T) {
536    return T->getStmtClass() == NullStmtClass;
537  }
538  static bool classof(const NullStmt *) { return true; }
539
540  child_range children() { return child_range(); }
541
542  friend class ASTStmtReader;
543  friend class ASTStmtWriter;
544};
545
546/// CompoundStmt - This represents a group of statements like { stmt stmt }.
547///
548class CompoundStmt : public Stmt {
549  Stmt** Body;
550  SourceLocation LBracLoc, RBracLoc;
551public:
552  CompoundStmt(ASTContext &C, Stmt **StmtStart, unsigned NumStmts,
553               SourceLocation LB, SourceLocation RB);
554
555  // \brief Build an empty compound statment with a location.
556  explicit CompoundStmt(SourceLocation Loc)
557    : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
558    CompoundStmtBits.NumStmts = 0;
559  }
560
561  // \brief Build an empty compound statement.
562  explicit CompoundStmt(EmptyShell Empty)
563    : Stmt(CompoundStmtClass, Empty), Body(0) {
564    CompoundStmtBits.NumStmts = 0;
565  }
566
567  void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
568
569  bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
570  unsigned size() const { return CompoundStmtBits.NumStmts; }
571
572  typedef Stmt** body_iterator;
573  body_iterator body_begin() { return Body; }
574  body_iterator body_end() { return Body + size(); }
575  Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
576
577  void setLastStmt(Stmt *S) {
578    assert(!body_empty() && "setLastStmt");
579    Body[size()-1] = S;
580  }
581
582  typedef Stmt* const * const_body_iterator;
583  const_body_iterator body_begin() const { return Body; }
584  const_body_iterator body_end() const { return Body + size(); }
585  const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
586
587  typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
588  reverse_body_iterator body_rbegin() {
589    return reverse_body_iterator(body_end());
590  }
591  reverse_body_iterator body_rend() {
592    return reverse_body_iterator(body_begin());
593  }
594
595  typedef std::reverse_iterator<const_body_iterator>
596          const_reverse_body_iterator;
597
598  const_reverse_body_iterator body_rbegin() const {
599    return const_reverse_body_iterator(body_end());
600  }
601
602  const_reverse_body_iterator body_rend() const {
603    return const_reverse_body_iterator(body_begin());
604  }
605
606  SourceRange getSourceRange() const LLVM_READONLY {
607    return SourceRange(LBracLoc, RBracLoc);
608  }
609
610  SourceLocation getLBracLoc() const { return LBracLoc; }
611  void setLBracLoc(SourceLocation L) { LBracLoc = L; }
612  SourceLocation getRBracLoc() const { return RBracLoc; }
613  void setRBracLoc(SourceLocation L) { RBracLoc = L; }
614
615  static bool classof(const Stmt *T) {
616    return T->getStmtClass() == CompoundStmtClass;
617  }
618  static bool classof(const CompoundStmt *) { return true; }
619
620  // Iterators
621  child_range children() {
622    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
623  }
624
625  const_child_range children() const {
626    return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
627  }
628};
629
630// SwitchCase is the base class for CaseStmt and DefaultStmt,
631class SwitchCase : public Stmt {
632protected:
633  // A pointer to the following CaseStmt or DefaultStmt class,
634  // used by SwitchStmt.
635  SwitchCase *NextSwitchCase;
636
637  SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
638
639public:
640  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
641
642  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
643
644  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
645
646  Stmt *getSubStmt();
647  const Stmt *getSubStmt() const {
648    return const_cast<SwitchCase*>(this)->getSubStmt();
649  }
650
651  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
652
653  static bool classof(const Stmt *T) {
654    return T->getStmtClass() == CaseStmtClass ||
655           T->getStmtClass() == DefaultStmtClass;
656  }
657  static bool classof(const SwitchCase *) { return true; }
658};
659
660class CaseStmt : public SwitchCase {
661  enum { LHS, RHS, SUBSTMT, END_EXPR };
662  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
663                             // GNU "case 1 ... 4" extension
664  SourceLocation CaseLoc;
665  SourceLocation EllipsisLoc;
666  SourceLocation ColonLoc;
667public:
668  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
669           SourceLocation ellipsisLoc, SourceLocation colonLoc)
670    : SwitchCase(CaseStmtClass) {
671    SubExprs[SUBSTMT] = 0;
672    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
673    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
674    CaseLoc = caseLoc;
675    EllipsisLoc = ellipsisLoc;
676    ColonLoc = colonLoc;
677  }
678
679  /// \brief Build an empty switch case statement.
680  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
681
682  SourceLocation getCaseLoc() const { return CaseLoc; }
683  void setCaseLoc(SourceLocation L) { CaseLoc = L; }
684  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
685  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
686  SourceLocation getColonLoc() const { return ColonLoc; }
687  void setColonLoc(SourceLocation L) { ColonLoc = L; }
688
689  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
690  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
691  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
692
693  const Expr *getLHS() const {
694    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
695  }
696  const Expr *getRHS() const {
697    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
698  }
699  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
700
701  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
702  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
703  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
704
705
706  SourceRange getSourceRange() const LLVM_READONLY {
707    // Handle deeply nested case statements with iteration instead of recursion.
708    const CaseStmt *CS = this;
709    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
710      CS = CS2;
711
712    return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
713  }
714  static bool classof(const Stmt *T) {
715    return T->getStmtClass() == CaseStmtClass;
716  }
717  static bool classof(const CaseStmt *) { return true; }
718
719  // Iterators
720  child_range children() {
721    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
722  }
723};
724
725class DefaultStmt : public SwitchCase {
726  Stmt* SubStmt;
727  SourceLocation DefaultLoc;
728  SourceLocation ColonLoc;
729public:
730  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
731    SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
732    ColonLoc(CL) {}
733
734  /// \brief Build an empty default statement.
735  explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
736
737  Stmt *getSubStmt() { return SubStmt; }
738  const Stmt *getSubStmt() const { return SubStmt; }
739  void setSubStmt(Stmt *S) { SubStmt = S; }
740
741  SourceLocation getDefaultLoc() const { return DefaultLoc; }
742  void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
743  SourceLocation getColonLoc() const { return ColonLoc; }
744  void setColonLoc(SourceLocation L) { ColonLoc = L; }
745
746  SourceRange getSourceRange() const LLVM_READONLY {
747    return SourceRange(DefaultLoc, SubStmt->getLocEnd());
748  }
749  static bool classof(const Stmt *T) {
750    return T->getStmtClass() == DefaultStmtClass;
751  }
752  static bool classof(const DefaultStmt *) { return true; }
753
754  // Iterators
755  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
756};
757
758
759/// LabelStmt - Represents a label, which has a substatement.  For example:
760///    foo: return;
761///
762class LabelStmt : public Stmt {
763  LabelDecl *TheDecl;
764  Stmt *SubStmt;
765  SourceLocation IdentLoc;
766public:
767  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
768    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
769  }
770
771  // \brief Build an empty label statement.
772  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
773
774  SourceLocation getIdentLoc() const { return IdentLoc; }
775  LabelDecl *getDecl() const { return TheDecl; }
776  void setDecl(LabelDecl *D) { TheDecl = D; }
777  const char *getName() const;
778  Stmt *getSubStmt() { return SubStmt; }
779  const Stmt *getSubStmt() const { return SubStmt; }
780  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
781  void setSubStmt(Stmt *SS) { SubStmt = SS; }
782
783  SourceRange getSourceRange() const LLVM_READONLY {
784    return SourceRange(IdentLoc, SubStmt->getLocEnd());
785  }
786  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
787
788  static bool classof(const Stmt *T) {
789    return T->getStmtClass() == LabelStmtClass;
790  }
791  static bool classof(const LabelStmt *) { return true; }
792};
793
794
795/// \brief Represents an attribute applied to a statement.
796///
797/// Represents an attribute applied to a statement. For example:
798///   [[omp::for(...)]] for (...) { ... }
799///
800class AttributedStmt : public Stmt {
801  Stmt *SubStmt;
802  SourceLocation AttrLoc;
803  unsigned NumAttrs;
804  const Attr *Attrs[1];
805
806  friend class ASTStmtReader;
807
808  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
809    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
810      NumAttrs(Attrs.size()) {
811    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
812  }
813
814  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
815    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
816    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
817  }
818
819public:
820  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
821                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
822  // \brief Build an empty attributed statement.
823  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
824
825  SourceLocation getAttrLoc() const { return AttrLoc; }
826  ArrayRef<const Attr*> getAttrs() const {
827    return ArrayRef<const Attr*>(Attrs, NumAttrs);
828  }
829  Stmt *getSubStmt() { return SubStmt; }
830  const Stmt *getSubStmt() const { return SubStmt; }
831
832  SourceRange getSourceRange() const LLVM_READONLY {
833    return SourceRange(AttrLoc, SubStmt->getLocEnd());
834  }
835  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
836
837  static bool classof(const Stmt *T) {
838    return T->getStmtClass() == AttributedStmtClass;
839  }
840  static bool classof(const AttributedStmt *) { return true; }
841};
842
843
844/// IfStmt - This represents an if/then/else.
845///
846class IfStmt : public Stmt {
847  enum { VAR, COND, THEN, ELSE, END_EXPR };
848  Stmt* SubExprs[END_EXPR];
849
850  SourceLocation IfLoc;
851  SourceLocation ElseLoc;
852
853public:
854  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
855         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
856
857  /// \brief Build an empty if/then/else statement
858  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
859
860  /// \brief Retrieve the variable declared in this "if" statement, if any.
861  ///
862  /// In the following example, "x" is the condition variable.
863  /// \code
864  /// if (int x = foo()) {
865  ///   printf("x is %d", x);
866  /// }
867  /// \endcode
868  VarDecl *getConditionVariable() const;
869  void setConditionVariable(ASTContext &C, VarDecl *V);
870
871  /// If this IfStmt has a condition variable, return the faux DeclStmt
872  /// associated with the creation of that condition variable.
873  const DeclStmt *getConditionVariableDeclStmt() const {
874    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
875  }
876
877  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
878  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
879  const Stmt *getThen() const { return SubExprs[THEN]; }
880  void setThen(Stmt *S) { SubExprs[THEN] = S; }
881  const Stmt *getElse() const { return SubExprs[ELSE]; }
882  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
883
884  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
885  Stmt *getThen() { return SubExprs[THEN]; }
886  Stmt *getElse() { return SubExprs[ELSE]; }
887
888  SourceLocation getIfLoc() const { return IfLoc; }
889  void setIfLoc(SourceLocation L) { IfLoc = L; }
890  SourceLocation getElseLoc() const { return ElseLoc; }
891  void setElseLoc(SourceLocation L) { ElseLoc = L; }
892
893  SourceRange getSourceRange() const LLVM_READONLY {
894    if (SubExprs[ELSE])
895      return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
896    else
897      return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
898  }
899
900  // Iterators over subexpressions.  The iterators will include iterating
901  // over the initialization expression referenced by the condition variable.
902  child_range children() {
903    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
904  }
905
906  static bool classof(const Stmt *T) {
907    return T->getStmtClass() == IfStmtClass;
908  }
909  static bool classof(const IfStmt *) { return true; }
910};
911
912/// SwitchStmt - This represents a 'switch' stmt.
913///
914class SwitchStmt : public Stmt {
915  enum { VAR, COND, BODY, END_EXPR };
916  Stmt* SubExprs[END_EXPR];
917  // This points to a linked list of case and default statements.
918  SwitchCase *FirstCase;
919  SourceLocation SwitchLoc;
920
921  /// If the SwitchStmt is a switch on an enum value, this records whether
922  /// all the enum values were covered by CaseStmts.  This value is meant to
923  /// be a hint for possible clients.
924  unsigned AllEnumCasesCovered : 1;
925
926public:
927  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
928
929  /// \brief Build a empty switch statement.
930  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
931
932  /// \brief Retrieve the variable declared in this "switch" statement, if any.
933  ///
934  /// In the following example, "x" is the condition variable.
935  /// \code
936  /// switch (int x = foo()) {
937  ///   case 0: break;
938  ///   // ...
939  /// }
940  /// \endcode
941  VarDecl *getConditionVariable() const;
942  void setConditionVariable(ASTContext &C, VarDecl *V);
943
944  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
945  /// associated with the creation of that condition variable.
946  const DeclStmt *getConditionVariableDeclStmt() const {
947    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
948  }
949
950  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
951  const Stmt *getBody() const { return SubExprs[BODY]; }
952  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
953
954  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
955  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
956  Stmt *getBody() { return SubExprs[BODY]; }
957  void setBody(Stmt *S) { SubExprs[BODY] = S; }
958  SwitchCase *getSwitchCaseList() { return FirstCase; }
959
960  /// \brief Set the case list for this switch statement.
961  ///
962  /// The caller is responsible for incrementing the retain counts on
963  /// all of the SwitchCase statements in this list.
964  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
965
966  SourceLocation getSwitchLoc() const { return SwitchLoc; }
967  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
968
969  void setBody(Stmt *S, SourceLocation SL) {
970    SubExprs[BODY] = S;
971    SwitchLoc = SL;
972  }
973  void addSwitchCase(SwitchCase *SC) {
974    assert(!SC->getNextSwitchCase()
975           && "case/default already added to a switch");
976    SC->setNextSwitchCase(FirstCase);
977    FirstCase = SC;
978  }
979
980  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
981  /// switch over an enum value then all cases have been explicitly covered.
982  void setAllEnumCasesCovered() {
983    AllEnumCasesCovered = 1;
984  }
985
986  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
987  /// have been explicitly covered.
988  bool isAllEnumCasesCovered() const {
989    return (bool) AllEnumCasesCovered;
990  }
991
992  SourceRange getSourceRange() const LLVM_READONLY {
993    return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
994  }
995  // Iterators
996  child_range children() {
997    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
998  }
999
1000  static bool classof(const Stmt *T) {
1001    return T->getStmtClass() == SwitchStmtClass;
1002  }
1003  static bool classof(const SwitchStmt *) { return true; }
1004};
1005
1006
1007/// WhileStmt - This represents a 'while' stmt.
1008///
1009class WhileStmt : public Stmt {
1010  enum { VAR, COND, BODY, END_EXPR };
1011  Stmt* SubExprs[END_EXPR];
1012  SourceLocation WhileLoc;
1013public:
1014  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1015            SourceLocation WL);
1016
1017  /// \brief Build an empty while statement.
1018  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1019
1020  /// \brief Retrieve the variable declared in this "while" statement, if any.
1021  ///
1022  /// In the following example, "x" is the condition variable.
1023  /// \code
1024  /// while (int x = random()) {
1025  ///   // ...
1026  /// }
1027  /// \endcode
1028  VarDecl *getConditionVariable() const;
1029  void setConditionVariable(ASTContext &C, VarDecl *V);
1030
1031  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1032  /// associated with the creation of that condition variable.
1033  const DeclStmt *getConditionVariableDeclStmt() const {
1034    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1035  }
1036
1037  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1038  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1039  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1040  Stmt *getBody() { return SubExprs[BODY]; }
1041  const Stmt *getBody() const { return SubExprs[BODY]; }
1042  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1043
1044  SourceLocation getWhileLoc() const { return WhileLoc; }
1045  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1046
1047  SourceRange getSourceRange() const LLVM_READONLY {
1048    return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
1049  }
1050  static bool classof(const Stmt *T) {
1051    return T->getStmtClass() == WhileStmtClass;
1052  }
1053  static bool classof(const WhileStmt *) { return true; }
1054
1055  // Iterators
1056  child_range children() {
1057    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1058  }
1059};
1060
1061/// DoStmt - This represents a 'do/while' stmt.
1062///
1063class DoStmt : public Stmt {
1064  enum { BODY, COND, END_EXPR };
1065  Stmt* SubExprs[END_EXPR];
1066  SourceLocation DoLoc;
1067  SourceLocation WhileLoc;
1068  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
1069
1070public:
1071  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1072         SourceLocation RP)
1073    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1074    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1075    SubExprs[BODY] = body;
1076  }
1077
1078  /// \brief Build an empty do-while statement.
1079  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1080
1081  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1082  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1083  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1084  Stmt *getBody() { return SubExprs[BODY]; }
1085  const Stmt *getBody() const { return SubExprs[BODY]; }
1086  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1087
1088  SourceLocation getDoLoc() const { return DoLoc; }
1089  void setDoLoc(SourceLocation L) { DoLoc = L; }
1090  SourceLocation getWhileLoc() const { return WhileLoc; }
1091  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1092
1093  SourceLocation getRParenLoc() const { return RParenLoc; }
1094  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1095
1096  SourceRange getSourceRange() const LLVM_READONLY {
1097    return SourceRange(DoLoc, RParenLoc);
1098  }
1099  static bool classof(const Stmt *T) {
1100    return T->getStmtClass() == DoStmtClass;
1101  }
1102  static bool classof(const DoStmt *) { return true; }
1103
1104  // Iterators
1105  child_range children() {
1106    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1107  }
1108};
1109
1110
1111/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
1112/// the init/cond/inc parts of the ForStmt will be null if they were not
1113/// specified in the source.
1114///
1115class ForStmt : public Stmt {
1116  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1117  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1118  SourceLocation ForLoc;
1119  SourceLocation LParenLoc, RParenLoc;
1120
1121public:
1122  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
1123          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
1124
1125  /// \brief Build an empty for statement.
1126  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1127
1128  Stmt *getInit() { return SubExprs[INIT]; }
1129
1130  /// \brief Retrieve the variable declared in this "for" statement, if any.
1131  ///
1132  /// In the following example, "y" is the condition variable.
1133  /// \code
1134  /// for (int x = random(); int y = mangle(x); ++x) {
1135  ///   // ...
1136  /// }
1137  /// \endcode
1138  VarDecl *getConditionVariable() const;
1139  void setConditionVariable(ASTContext &C, VarDecl *V);
1140
1141  /// If this ForStmt has a condition variable, return the faux DeclStmt
1142  /// associated with the creation of that condition variable.
1143  const DeclStmt *getConditionVariableDeclStmt() const {
1144    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1145  }
1146
1147  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1148  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1149  Stmt *getBody() { return SubExprs[BODY]; }
1150
1151  const Stmt *getInit() const { return SubExprs[INIT]; }
1152  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1153  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1154  const Stmt *getBody() const { return SubExprs[BODY]; }
1155
1156  void setInit(Stmt *S) { SubExprs[INIT] = S; }
1157  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1158  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1159  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1160
1161  SourceLocation getForLoc() const { return ForLoc; }
1162  void setForLoc(SourceLocation L) { ForLoc = L; }
1163  SourceLocation getLParenLoc() const { return LParenLoc; }
1164  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1165  SourceLocation getRParenLoc() const { return RParenLoc; }
1166  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1167
1168  SourceRange getSourceRange() const LLVM_READONLY {
1169    return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1170  }
1171  static bool classof(const Stmt *T) {
1172    return T->getStmtClass() == ForStmtClass;
1173  }
1174  static bool classof(const ForStmt *) { return true; }
1175
1176  // Iterators
1177  child_range children() {
1178    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1179  }
1180};
1181
1182/// GotoStmt - This represents a direct goto.
1183///
1184class GotoStmt : public Stmt {
1185  LabelDecl *Label;
1186  SourceLocation GotoLoc;
1187  SourceLocation LabelLoc;
1188public:
1189  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1190    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1191
1192  /// \brief Build an empty goto statement.
1193  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1194
1195  LabelDecl *getLabel() const { return Label; }
1196  void setLabel(LabelDecl *D) { Label = D; }
1197
1198  SourceLocation getGotoLoc() const { return GotoLoc; }
1199  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1200  SourceLocation getLabelLoc() const { return LabelLoc; }
1201  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1202
1203  SourceRange getSourceRange() const LLVM_READONLY {
1204    return SourceRange(GotoLoc, LabelLoc);
1205  }
1206  static bool classof(const Stmt *T) {
1207    return T->getStmtClass() == GotoStmtClass;
1208  }
1209  static bool classof(const GotoStmt *) { return true; }
1210
1211  // Iterators
1212  child_range children() { return child_range(); }
1213};
1214
1215/// IndirectGotoStmt - This represents an indirect goto.
1216///
1217class IndirectGotoStmt : public Stmt {
1218  SourceLocation GotoLoc;
1219  SourceLocation StarLoc;
1220  Stmt *Target;
1221public:
1222  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1223                   Expr *target)
1224    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1225      Target((Stmt*)target) {}
1226
1227  /// \brief Build an empty indirect goto statement.
1228  explicit IndirectGotoStmt(EmptyShell Empty)
1229    : Stmt(IndirectGotoStmtClass, Empty) { }
1230
1231  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1232  SourceLocation getGotoLoc() const { return GotoLoc; }
1233  void setStarLoc(SourceLocation L) { StarLoc = L; }
1234  SourceLocation getStarLoc() const { return StarLoc; }
1235
1236  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1237  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1238  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1239
1240  /// getConstantTarget - Returns the fixed target of this indirect
1241  /// goto, if one exists.
1242  LabelDecl *getConstantTarget();
1243  const LabelDecl *getConstantTarget() const {
1244    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1245  }
1246
1247  SourceRange getSourceRange() const LLVM_READONLY {
1248    return SourceRange(GotoLoc, Target->getLocEnd());
1249  }
1250
1251  static bool classof(const Stmt *T) {
1252    return T->getStmtClass() == IndirectGotoStmtClass;
1253  }
1254  static bool classof(const IndirectGotoStmt *) { return true; }
1255
1256  // Iterators
1257  child_range children() { return child_range(&Target, &Target+1); }
1258};
1259
1260
1261/// ContinueStmt - This represents a continue.
1262///
1263class ContinueStmt : public Stmt {
1264  SourceLocation ContinueLoc;
1265public:
1266  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1267
1268  /// \brief Build an empty continue statement.
1269  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1270
1271  SourceLocation getContinueLoc() const { return ContinueLoc; }
1272  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1273
1274  SourceRange getSourceRange() const LLVM_READONLY {
1275    return SourceRange(ContinueLoc);
1276  }
1277
1278  static bool classof(const Stmt *T) {
1279    return T->getStmtClass() == ContinueStmtClass;
1280  }
1281  static bool classof(const ContinueStmt *) { return true; }
1282
1283  // Iterators
1284  child_range children() { return child_range(); }
1285};
1286
1287/// BreakStmt - This represents a break.
1288///
1289class BreakStmt : public Stmt {
1290  SourceLocation BreakLoc;
1291public:
1292  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1293
1294  /// \brief Build an empty break statement.
1295  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1296
1297  SourceLocation getBreakLoc() const { return BreakLoc; }
1298  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1299
1300  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(BreakLoc); }
1301
1302  static bool classof(const Stmt *T) {
1303    return T->getStmtClass() == BreakStmtClass;
1304  }
1305  static bool classof(const BreakStmt *) { return true; }
1306
1307  // Iterators
1308  child_range children() { return child_range(); }
1309};
1310
1311
1312/// ReturnStmt - This represents a return, optionally of an expression:
1313///   return;
1314///   return 4;
1315///
1316/// Note that GCC allows return with no argument in a function declared to
1317/// return a value, and it allows returning a value in functions declared to
1318/// return void.  We explicitly model this in the AST, which means you can't
1319/// depend on the return type of the function and the presence of an argument.
1320///
1321class ReturnStmt : public Stmt {
1322  Stmt *RetExpr;
1323  SourceLocation RetLoc;
1324  const VarDecl *NRVOCandidate;
1325
1326public:
1327  ReturnStmt(SourceLocation RL)
1328    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1329
1330  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1331    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1332      NRVOCandidate(NRVOCandidate) {}
1333
1334  /// \brief Build an empty return expression.
1335  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1336
1337  const Expr *getRetValue() const;
1338  Expr *getRetValue();
1339  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1340
1341  SourceLocation getReturnLoc() const { return RetLoc; }
1342  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1343
1344  /// \brief Retrieve the variable that might be used for the named return
1345  /// value optimization.
1346  ///
1347  /// The optimization itself can only be performed if the variable is
1348  /// also marked as an NRVO object.
1349  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1350  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1351
1352  SourceRange getSourceRange() const LLVM_READONLY;
1353
1354  static bool classof(const Stmt *T) {
1355    return T->getStmtClass() == ReturnStmtClass;
1356  }
1357  static bool classof(const ReturnStmt *) { return true; }
1358
1359  // Iterators
1360  child_range children() {
1361    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1362    return child_range();
1363  }
1364};
1365
1366/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1367///
1368class AsmStmt : public Stmt {
1369protected:
1370  SourceLocation AsmLoc;
1371  bool IsSimple;
1372  bool IsVolatile;
1373
1374  unsigned NumOutputs;
1375  unsigned NumInputs;
1376  unsigned NumClobbers;
1377
1378  IdentifierInfo **Names;
1379
1380  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1381          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1382    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1383    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1384
1385public:
1386  /// \brief Build an empty inline-assembly statement.
1387  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1388    Stmt(SC, Empty), Names(0) { }
1389
1390  SourceLocation getAsmLoc() const { return AsmLoc; }
1391  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1392
1393  bool isSimple() const { return IsSimple; }
1394  void setSimple(bool V) { IsSimple = V; }
1395
1396  bool isVolatile() const { return IsVolatile; }
1397  void setVolatile(bool V) { IsVolatile = V; }
1398
1399  SourceRange getSourceRange() const LLVM_READONLY { return SourceRange(); }
1400
1401  //===--- Asm String Analysis ---===//
1402
1403  /// Assemble final IR asm string.
1404  virtual std::string generateAsmString(ASTContext &C) const = 0;
1405
1406  //===--- Output operands ---===//
1407
1408  unsigned getNumOutputs() const { return NumOutputs; }
1409
1410  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1411    return Names[i];
1412  }
1413
1414  StringRef getOutputName(unsigned i) const {
1415    if (IdentifierInfo *II = getOutputIdentifier(i))
1416      return II->getName();
1417
1418    return StringRef();
1419  }
1420
1421  //===--- Input operands ---===//
1422
1423  unsigned getNumInputs() const { return NumInputs; }
1424
1425  IdentifierInfo *getInputIdentifier(unsigned i) const {
1426    return Names[i + NumOutputs];
1427  }
1428
1429  StringRef getInputName(unsigned i) const {
1430    if (IdentifierInfo *II = getInputIdentifier(i))
1431      return II->getName();
1432
1433    return StringRef();
1434  }
1435
1436  //===--- Other ---===//
1437
1438  static bool classof(const Stmt *T) {
1439    return T->getStmtClass() == GCCAsmStmtClass ||
1440      T->getStmtClass() == MSAsmStmtClass;
1441  }
1442  static bool classof(const AsmStmt *) { return true; }
1443};
1444
1445/// This represents a GCC inline-assembly statement extension.
1446///
1447class GCCAsmStmt : public AsmStmt {
1448  SourceLocation RParenLoc;
1449  StringLiteral *AsmStr;
1450
1451  // FIXME: If we wanted to, we could allocate all of these in one big array.
1452  StringLiteral **Constraints;
1453  Stmt **Exprs;
1454  StringLiteral **Clobbers;
1455
1456public:
1457  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1458             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1459             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1460             StringLiteral *asmstr, unsigned numclobbers,
1461             StringLiteral **clobbers, SourceLocation rparenloc);
1462
1463  /// \brief Build an empty inline-assembly statement.
1464  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1465    Constraints(0), Exprs(0), Clobbers(0) { }
1466
1467  SourceLocation getRParenLoc() const { return RParenLoc; }
1468  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1469
1470  //===--- Asm String Analysis ---===//
1471
1472  const StringLiteral *getAsmString() const { return AsmStr; }
1473  StringLiteral *getAsmString() { return AsmStr; }
1474  void setAsmString(StringLiteral *E) { AsmStr = E; }
1475
1476  /// AsmStringPiece - this is part of a decomposed asm string specification
1477  /// (for use with the AnalyzeAsmString function below).  An asm string is
1478  /// considered to be a concatenation of these parts.
1479  class AsmStringPiece {
1480  public:
1481    enum Kind {
1482      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1483      Operand  // Operand reference, with optional modifier %c4.
1484    };
1485  private:
1486    Kind MyKind;
1487    std::string Str;
1488    unsigned OperandNo;
1489  public:
1490    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1491    AsmStringPiece(unsigned OpNo, char Modifier)
1492      : MyKind(Operand), Str(), OperandNo(OpNo) {
1493      Str += Modifier;
1494    }
1495
1496    bool isString() const { return MyKind == String; }
1497    bool isOperand() const { return MyKind == Operand; }
1498
1499    const std::string &getString() const {
1500      assert(isString());
1501      return Str;
1502    }
1503
1504    unsigned getOperandNo() const {
1505      assert(isOperand());
1506      return OperandNo;
1507    }
1508
1509    /// getModifier - Get the modifier for this operand, if present.  This
1510    /// returns '\0' if there was no modifier.
1511    char getModifier() const {
1512      assert(isOperand());
1513      return Str[0];
1514    }
1515  };
1516
1517  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1518  /// it into pieces.  If the asm string is erroneous, emit errors and return
1519  /// true, otherwise return false.  This handles canonicalization and
1520  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1521  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1522  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1523                            ASTContext &C, unsigned &DiagOffs) const;
1524
1525  /// Assemble final IR asm string.
1526  std::string generateAsmString(ASTContext &C) const;
1527
1528  //===--- Output operands ---===//
1529
1530  /// getOutputConstraint - Return the constraint string for the specified
1531  /// output operand.  All output constraints are known to be non-empty (either
1532  /// '=' or '+').
1533  StringRef getOutputConstraint(unsigned i) const;
1534
1535  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1536    return Constraints[i];
1537  }
1538  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1539    return Constraints[i];
1540  }
1541
1542  Expr *getOutputExpr(unsigned i);
1543
1544  const Expr *getOutputExpr(unsigned i) const {
1545    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1546  }
1547
1548  /// isOutputPlusConstraint - Return true if the specified output constraint
1549  /// is a "+" constraint (which is both an input and an output) or false if it
1550  /// is an "=" constraint (just an output).
1551  bool isOutputPlusConstraint(unsigned i) const {
1552    return getOutputConstraint(i)[0] == '+';
1553  }
1554
1555  /// getNumPlusOperands - Return the number of output operands that have a "+"
1556  /// constraint.
1557  unsigned getNumPlusOperands() const;
1558
1559  //===--- Input operands ---===//
1560
1561  /// getInputConstraint - Return the specified input constraint.  Unlike output
1562  /// constraints, these can be empty.
1563  StringRef getInputConstraint(unsigned i) const;
1564
1565  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1566    return Constraints[i + NumOutputs];
1567  }
1568  StringLiteral *getInputConstraintLiteral(unsigned i) {
1569    return Constraints[i + NumOutputs];
1570  }
1571
1572  Expr *getInputExpr(unsigned i);
1573  void setInputExpr(unsigned i, Expr *E);
1574
1575  const Expr *getInputExpr(unsigned i) const {
1576    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1577  }
1578
1579  void setOutputsAndInputsAndClobbers(ASTContext &C,
1580                                      IdentifierInfo **Names,
1581                                      StringLiteral **Constraints,
1582                                      Stmt **Exprs,
1583                                      unsigned NumOutputs,
1584                                      unsigned NumInputs,
1585                                      StringLiteral **Clobbers,
1586                                      unsigned NumClobbers);
1587
1588  //===--- Other ---===//
1589
1590  /// getNamedOperand - Given a symbolic operand reference like %[foo],
1591  /// translate this into a numeric value needed to reference the same operand.
1592  /// This returns -1 if the operand name is invalid.
1593  int getNamedOperand(StringRef SymbolicName) const;
1594
1595  unsigned getNumClobbers() const { return NumClobbers; }
1596  StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1597  const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1598
1599  SourceRange getSourceRange() const LLVM_READONLY {
1600    return SourceRange(AsmLoc, RParenLoc);
1601  }
1602
1603  static bool classof(const Stmt *T) {
1604    return T->getStmtClass() == GCCAsmStmtClass;
1605  }
1606  static bool classof(const GCCAsmStmt *) { return true; }
1607
1608  // Input expr iterators.
1609
1610  typedef ExprIterator inputs_iterator;
1611  typedef ConstExprIterator const_inputs_iterator;
1612
1613  inputs_iterator begin_inputs() {
1614    return &Exprs[0] + NumOutputs;
1615  }
1616
1617  inputs_iterator end_inputs() {
1618    return &Exprs[0] + NumOutputs + NumInputs;
1619  }
1620
1621  const_inputs_iterator begin_inputs() const {
1622    return &Exprs[0] + NumOutputs;
1623  }
1624
1625  const_inputs_iterator end_inputs() const {
1626    return &Exprs[0] + NumOutputs + NumInputs;
1627  }
1628
1629  // Output expr iterators.
1630
1631  typedef ExprIterator outputs_iterator;
1632  typedef ConstExprIterator const_outputs_iterator;
1633
1634  outputs_iterator begin_outputs() {
1635    return &Exprs[0];
1636  }
1637  outputs_iterator end_outputs() {
1638    return &Exprs[0] + NumOutputs;
1639  }
1640
1641  const_outputs_iterator begin_outputs() const {
1642    return &Exprs[0];
1643  }
1644  const_outputs_iterator end_outputs() const {
1645    return &Exprs[0] + NumOutputs;
1646  }
1647
1648  child_range children() {
1649    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1650  }
1651};
1652
1653/// This represents a Microsoft inline-assembly statement extension.
1654///
1655class MSAsmStmt : public AsmStmt {
1656  SourceLocation AsmLoc, LBraceLoc, EndLoc;
1657  std::string AsmStr;
1658
1659  unsigned NumAsmToks;
1660
1661  Token *AsmToks;
1662  Stmt **Exprs;
1663  StringRef *Clobbers;
1664
1665public:
1666  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
1667            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1668            ArrayRef<IdentifierInfo*> inputs, ArrayRef<IdentifierInfo*> outputs,
1669            ArrayRef<Expr*> inputexprs, ArrayRef<Expr*> outputexprs,
1670            StringRef asmstr, ArrayRef<StringRef> clobbers,
1671            SourceLocation endloc);
1672
1673  /// \brief Build an empty MS-style inline-assembly statement.
1674  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1675    NumAsmToks(0), AsmToks(0), Exprs(0), Clobbers(0) { }
1676
1677  SourceLocation getLBraceLoc() const { return LBraceLoc; }
1678  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1679  SourceLocation getEndLoc() const { return EndLoc; }
1680  void setEndLoc(SourceLocation L) { EndLoc = L; }
1681
1682  bool hasBraces() const { return LBraceLoc.isValid(); }
1683
1684  unsigned getNumAsmToks() { return NumAsmToks; }
1685  Token *getAsmToks() { return AsmToks; }
1686
1687  //===--- Asm String Analysis ---===//
1688
1689  const std::string *getAsmString() const { return &AsmStr; }
1690  std::string *getAsmString() { return &AsmStr; }
1691  void setAsmString(StringRef &E) { AsmStr = E.str(); }
1692
1693  /// Assemble final IR asm string.
1694  std::string generateAsmString(ASTContext &C) const;
1695
1696  //===--- Output operands ---===//
1697
1698  Expr *getOutputExpr(unsigned i);
1699
1700  const Expr *getOutputExpr(unsigned i) const {
1701    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1702  }
1703
1704  //===--- Input operands ---===//
1705
1706  Expr *getInputExpr(unsigned i);
1707  void setInputExpr(unsigned i, Expr *E);
1708
1709  const Expr *getInputExpr(unsigned i) const {
1710    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1711  }
1712
1713  //===--- Other ---===//
1714
1715  unsigned getNumClobbers() const { return NumClobbers; }
1716  StringRef getClobber(unsigned i) const { return Clobbers[i]; }
1717
1718  SourceRange getSourceRange() const LLVM_READONLY {
1719    return SourceRange(AsmLoc, EndLoc);
1720  }
1721  static bool classof(const Stmt *T) {
1722    return T->getStmtClass() == MSAsmStmtClass;
1723  }
1724  static bool classof(const MSAsmStmt *) { return true; }
1725
1726  child_range children() {
1727    return child_range(&Exprs[0], &Exprs[0]);
1728  }
1729};
1730
1731class SEHExceptStmt : public Stmt {
1732  SourceLocation  Loc;
1733  Stmt           *Children[2];
1734
1735  enum { FILTER_EXPR, BLOCK };
1736
1737  SEHExceptStmt(SourceLocation Loc,
1738                Expr *FilterExpr,
1739                Stmt *Block);
1740
1741  friend class ASTReader;
1742  friend class ASTStmtReader;
1743  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1744
1745public:
1746  static SEHExceptStmt* Create(ASTContext &C,
1747                               SourceLocation ExceptLoc,
1748                               Expr *FilterExpr,
1749                               Stmt *Block);
1750  SourceRange getSourceRange() const LLVM_READONLY {
1751    return SourceRange(getExceptLoc(), getEndLoc());
1752  }
1753
1754  SourceLocation getExceptLoc() const { return Loc; }
1755  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1756
1757  Expr *getFilterExpr() const {
1758    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1759  }
1760
1761  CompoundStmt *getBlock() const {
1762    return llvm::cast<CompoundStmt>(Children[BLOCK]);
1763  }
1764
1765  child_range children() {
1766    return child_range(Children,Children+2);
1767  }
1768
1769  static bool classof(const Stmt *T) {
1770    return T->getStmtClass() == SEHExceptStmtClass;
1771  }
1772
1773  static bool classof(SEHExceptStmt *) { return true; }
1774
1775};
1776
1777class SEHFinallyStmt : public Stmt {
1778  SourceLocation  Loc;
1779  Stmt           *Block;
1780
1781  SEHFinallyStmt(SourceLocation Loc,
1782                 Stmt *Block);
1783
1784  friend class ASTReader;
1785  friend class ASTStmtReader;
1786  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1787
1788public:
1789  static SEHFinallyStmt* Create(ASTContext &C,
1790                                SourceLocation FinallyLoc,
1791                                Stmt *Block);
1792
1793  SourceRange getSourceRange() const LLVM_READONLY {
1794    return SourceRange(getFinallyLoc(), getEndLoc());
1795  }
1796
1797  SourceLocation getFinallyLoc() const { return Loc; }
1798  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1799
1800  CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
1801
1802  child_range children() {
1803    return child_range(&Block,&Block+1);
1804  }
1805
1806  static bool classof(const Stmt *T) {
1807    return T->getStmtClass() == SEHFinallyStmtClass;
1808  }
1809
1810  static bool classof(SEHFinallyStmt *) { return true; }
1811
1812};
1813
1814class SEHTryStmt : public Stmt {
1815  bool            IsCXXTry;
1816  SourceLocation  TryLoc;
1817  Stmt           *Children[2];
1818
1819  enum { TRY = 0, HANDLER = 1 };
1820
1821  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1822             SourceLocation TryLoc,
1823             Stmt *TryBlock,
1824             Stmt *Handler);
1825
1826  friend class ASTReader;
1827  friend class ASTStmtReader;
1828  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1829
1830public:
1831  static SEHTryStmt* Create(ASTContext &C,
1832                            bool isCXXTry,
1833                            SourceLocation TryLoc,
1834                            Stmt *TryBlock,
1835                            Stmt *Handler);
1836
1837  SourceRange getSourceRange() const LLVM_READONLY {
1838    return SourceRange(getTryLoc(), getEndLoc());
1839  }
1840
1841  SourceLocation getTryLoc() const { return TryLoc; }
1842  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1843
1844  bool getIsCXXTry() const { return IsCXXTry; }
1845
1846  CompoundStmt* getTryBlock() const {
1847    return llvm::cast<CompoundStmt>(Children[TRY]);
1848  }
1849
1850  Stmt *getHandler() const { return Children[HANDLER]; }
1851
1852  /// Returns 0 if not defined
1853  SEHExceptStmt  *getExceptHandler() const;
1854  SEHFinallyStmt *getFinallyHandler() const;
1855
1856  child_range children() {
1857    return child_range(Children,Children+2);
1858  }
1859
1860  static bool classof(const Stmt *T) {
1861    return T->getStmtClass() == SEHTryStmtClass;
1862  }
1863
1864  static bool classof(SEHTryStmt *) { return true; }
1865};
1866
1867}  // end namespace clang
1868
1869#endif
1870