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