Stmt.h revision cfa88f893915ceb8ae4ce2f17c46c24a4d67502f
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, ArrayRef<Stmt*> Stmts,
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  SourceLocation KeywordLoc;
623  SourceLocation ColonLoc;
624
625  SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
626    : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
627
628  SwitchCase(StmtClass SC, EmptyShell)
629    : Stmt(SC), NextSwitchCase(0) {}
630
631public:
632  const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
633
634  SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
635
636  void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
637
638  SourceLocation getKeywordLoc() const { return KeywordLoc; }
639  void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
640  SourceLocation getColonLoc() const { return ColonLoc; }
641  void setColonLoc(SourceLocation L) { ColonLoc = L; }
642
643  Stmt *getSubStmt();
644  const Stmt *getSubStmt() const {
645    return const_cast<SwitchCase*>(this)->getSubStmt();
646  }
647
648  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
649  SourceLocation getLocEnd() const LLVM_READONLY;
650
651  static bool classof(const Stmt *T) {
652    return T->getStmtClass() == CaseStmtClass ||
653           T->getStmtClass() == DefaultStmtClass;
654  }
655};
656
657class CaseStmt : public SwitchCase {
658  enum { LHS, RHS, SUBSTMT, END_EXPR };
659  Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
660                             // GNU "case 1 ... 4" extension
661  SourceLocation EllipsisLoc;
662public:
663  CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
664           SourceLocation ellipsisLoc, SourceLocation colonLoc)
665    : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
666    SubExprs[SUBSTMT] = 0;
667    SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
668    SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
669    EllipsisLoc = ellipsisLoc;
670  }
671
672  /// \brief Build an empty switch case statement.
673  explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
674
675  SourceLocation getCaseLoc() const { return KeywordLoc; }
676  void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
677  SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
678  void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
679  SourceLocation getColonLoc() const { return ColonLoc; }
680  void setColonLoc(SourceLocation L) { ColonLoc = L; }
681
682  Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
683  Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
684  Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
685
686  const Expr *getLHS() const {
687    return reinterpret_cast<const Expr*>(SubExprs[LHS]);
688  }
689  const Expr *getRHS() const {
690    return reinterpret_cast<const Expr*>(SubExprs[RHS]);
691  }
692  const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
693
694  void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
695  void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
696  void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
697
698  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
699  SourceLocation getLocEnd() const LLVM_READONLY {
700    // Handle deeply nested case statements with iteration instead of recursion.
701    const CaseStmt *CS = this;
702    while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
703      CS = CS2;
704
705    return CS->getSubStmt()->getLocEnd();
706  }
707
708  static bool classof(const Stmt *T) {
709    return T->getStmtClass() == CaseStmtClass;
710  }
711
712  // Iterators
713  child_range children() {
714    return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
715  }
716};
717
718class DefaultStmt : public SwitchCase {
719  Stmt* SubStmt;
720public:
721  DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
722    SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
723
724  /// \brief Build an empty default statement.
725  explicit DefaultStmt(EmptyShell Empty)
726    : SwitchCase(DefaultStmtClass, Empty) { }
727
728  Stmt *getSubStmt() { return SubStmt; }
729  const Stmt *getSubStmt() const { return SubStmt; }
730  void setSubStmt(Stmt *S) { SubStmt = S; }
731
732  SourceLocation getDefaultLoc() const { return KeywordLoc; }
733  void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
734  SourceLocation getColonLoc() const { return ColonLoc; }
735  void setColonLoc(SourceLocation L) { ColonLoc = L; }
736
737  SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
738  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
739
740  static bool classof(const Stmt *T) {
741    return T->getStmtClass() == DefaultStmtClass;
742  }
743
744  // Iterators
745  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
746};
747
748inline SourceLocation SwitchCase::getLocEnd() const {
749  if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
750    return CS->getLocEnd();
751  return cast<DefaultStmt>(this)->getLocEnd();
752}
753
754/// LabelStmt - Represents a label, which has a substatement.  For example:
755///    foo: return;
756///
757class LabelStmt : public Stmt {
758  LabelDecl *TheDecl;
759  Stmt *SubStmt;
760  SourceLocation IdentLoc;
761public:
762  LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
763    : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
764  }
765
766  // \brief Build an empty label statement.
767  explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
768
769  SourceLocation getIdentLoc() const { return IdentLoc; }
770  LabelDecl *getDecl() const { return TheDecl; }
771  void setDecl(LabelDecl *D) { TheDecl = D; }
772  const char *getName() const;
773  Stmt *getSubStmt() { return SubStmt; }
774  const Stmt *getSubStmt() const { return SubStmt; }
775  void setIdentLoc(SourceLocation L) { IdentLoc = L; }
776  void setSubStmt(Stmt *SS) { SubStmt = SS; }
777
778  SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
779  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
780
781  child_range children() { return child_range(&SubStmt, &SubStmt+1); }
782
783  static bool classof(const Stmt *T) {
784    return T->getStmtClass() == LabelStmtClass;
785  }
786};
787
788
789/// \brief Represents an attribute applied to a statement.
790///
791/// Represents an attribute applied to a statement. For example:
792///   [[omp::for(...)]] for (...) { ... }
793///
794class AttributedStmt : public Stmt {
795  Stmt *SubStmt;
796  SourceLocation AttrLoc;
797  unsigned NumAttrs;
798  const Attr *Attrs[1];
799
800  friend class ASTStmtReader;
801
802  AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
803    : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
804      NumAttrs(Attrs.size()) {
805    memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
806  }
807
808  explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
809    : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
810    memset(Attrs, 0, NumAttrs * sizeof(Attr*));
811  }
812
813public:
814  static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
815                                ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
816  // \brief Build an empty attributed statement.
817  static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
818
819  SourceLocation getAttrLoc() const { return AttrLoc; }
820  ArrayRef<const Attr*> getAttrs() const {
821    return ArrayRef<const Attr*>(Attrs, NumAttrs);
822  }
823  Stmt *getSubStmt() { return SubStmt; }
824  const Stmt *getSubStmt() const { return SubStmt; }
825
826  SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
827  SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
828
829  child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
830
831  static bool classof(const Stmt *T) {
832    return T->getStmtClass() == AttributedStmtClass;
833  }
834};
835
836
837/// IfStmt - This represents an if/then/else.
838///
839class IfStmt : public Stmt {
840  enum { VAR, COND, THEN, ELSE, END_EXPR };
841  Stmt* SubExprs[END_EXPR];
842
843  SourceLocation IfLoc;
844  SourceLocation ElseLoc;
845
846public:
847  IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
848         Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
849
850  /// \brief Build an empty if/then/else statement
851  explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
852
853  /// \brief Retrieve the variable declared in this "if" statement, if any.
854  ///
855  /// In the following example, "x" is the condition variable.
856  /// \code
857  /// if (int x = foo()) {
858  ///   printf("x is %d", x);
859  /// }
860  /// \endcode
861  VarDecl *getConditionVariable() const;
862  void setConditionVariable(ASTContext &C, VarDecl *V);
863
864  /// If this IfStmt has a condition variable, return the faux DeclStmt
865  /// associated with the creation of that condition variable.
866  const DeclStmt *getConditionVariableDeclStmt() const {
867    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
868  }
869
870  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
871  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
872  const Stmt *getThen() const { return SubExprs[THEN]; }
873  void setThen(Stmt *S) { SubExprs[THEN] = S; }
874  const Stmt *getElse() const { return SubExprs[ELSE]; }
875  void setElse(Stmt *S) { SubExprs[ELSE] = S; }
876
877  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
878  Stmt *getThen() { return SubExprs[THEN]; }
879  Stmt *getElse() { return SubExprs[ELSE]; }
880
881  SourceLocation getIfLoc() const { return IfLoc; }
882  void setIfLoc(SourceLocation L) { IfLoc = L; }
883  SourceLocation getElseLoc() const { return ElseLoc; }
884  void setElseLoc(SourceLocation L) { ElseLoc = L; }
885
886  SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
887  SourceLocation getLocEnd() const LLVM_READONLY {
888    if (SubExprs[ELSE])
889      return SubExprs[ELSE]->getLocEnd();
890    else
891      return SubExprs[THEN]->getLocEnd();
892  }
893
894  // Iterators over subexpressions.  The iterators will include iterating
895  // over the initialization expression referenced by the condition variable.
896  child_range children() {
897    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
898  }
899
900  static bool classof(const Stmt *T) {
901    return T->getStmtClass() == IfStmtClass;
902  }
903};
904
905/// SwitchStmt - This represents a 'switch' stmt.
906///
907class SwitchStmt : public Stmt {
908  enum { VAR, COND, BODY, END_EXPR };
909  Stmt* SubExprs[END_EXPR];
910  // This points to a linked list of case and default statements.
911  SwitchCase *FirstCase;
912  SourceLocation SwitchLoc;
913
914  /// If the SwitchStmt is a switch on an enum value, this records whether
915  /// all the enum values were covered by CaseStmts.  This value is meant to
916  /// be a hint for possible clients.
917  unsigned AllEnumCasesCovered : 1;
918
919public:
920  SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
921
922  /// \brief Build a empty switch statement.
923  explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
924
925  /// \brief Retrieve the variable declared in this "switch" statement, if any.
926  ///
927  /// In the following example, "x" is the condition variable.
928  /// \code
929  /// switch (int x = foo()) {
930  ///   case 0: break;
931  ///   // ...
932  /// }
933  /// \endcode
934  VarDecl *getConditionVariable() const;
935  void setConditionVariable(ASTContext &C, VarDecl *V);
936
937  /// If this SwitchStmt has a condition variable, return the faux DeclStmt
938  /// associated with the creation of that condition variable.
939  const DeclStmt *getConditionVariableDeclStmt() const {
940    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
941  }
942
943  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
944  const Stmt *getBody() const { return SubExprs[BODY]; }
945  const SwitchCase *getSwitchCaseList() const { return FirstCase; }
946
947  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
948  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
949  Stmt *getBody() { return SubExprs[BODY]; }
950  void setBody(Stmt *S) { SubExprs[BODY] = S; }
951  SwitchCase *getSwitchCaseList() { return FirstCase; }
952
953  /// \brief Set the case list for this switch statement.
954  ///
955  /// The caller is responsible for incrementing the retain counts on
956  /// all of the SwitchCase statements in this list.
957  void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
958
959  SourceLocation getSwitchLoc() const { return SwitchLoc; }
960  void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
961
962  void setBody(Stmt *S, SourceLocation SL) {
963    SubExprs[BODY] = S;
964    SwitchLoc = SL;
965  }
966  void addSwitchCase(SwitchCase *SC) {
967    assert(!SC->getNextSwitchCase()
968           && "case/default already added to a switch");
969    SC->setNextSwitchCase(FirstCase);
970    FirstCase = SC;
971  }
972
973  /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
974  /// switch over an enum value then all cases have been explicitly covered.
975  void setAllEnumCasesCovered() {
976    AllEnumCasesCovered = 1;
977  }
978
979  /// Returns true if the SwitchStmt is a switch of an enum value and all cases
980  /// have been explicitly covered.
981  bool isAllEnumCasesCovered() const {
982    return (bool) AllEnumCasesCovered;
983  }
984
985  SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
986  SourceLocation getLocEnd() const LLVM_READONLY {
987    return SubExprs[BODY]->getLocEnd();
988  }
989
990  // Iterators
991  child_range children() {
992    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
993  }
994
995  static bool classof(const Stmt *T) {
996    return T->getStmtClass() == SwitchStmtClass;
997  }
998};
999
1000
1001/// WhileStmt - This represents a 'while' stmt.
1002///
1003class WhileStmt : public Stmt {
1004  enum { VAR, COND, BODY, END_EXPR };
1005  Stmt* SubExprs[END_EXPR];
1006  SourceLocation WhileLoc;
1007public:
1008  WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1009            SourceLocation WL);
1010
1011  /// \brief Build an empty while statement.
1012  explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1013
1014  /// \brief Retrieve the variable declared in this "while" statement, if any.
1015  ///
1016  /// In the following example, "x" is the condition variable.
1017  /// \code
1018  /// while (int x = random()) {
1019  ///   // ...
1020  /// }
1021  /// \endcode
1022  VarDecl *getConditionVariable() const;
1023  void setConditionVariable(ASTContext &C, VarDecl *V);
1024
1025  /// If this WhileStmt has a condition variable, return the faux DeclStmt
1026  /// associated with the creation of that condition variable.
1027  const DeclStmt *getConditionVariableDeclStmt() const {
1028    return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1029  }
1030
1031  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1032  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1033  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1034  Stmt *getBody() { return SubExprs[BODY]; }
1035  const Stmt *getBody() const { return SubExprs[BODY]; }
1036  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1037
1038  SourceLocation getWhileLoc() const { return WhileLoc; }
1039  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1040
1041  SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1042  SourceLocation getLocEnd() const LLVM_READONLY {
1043    return SubExprs[BODY]->getLocEnd();
1044  }
1045
1046  static bool classof(const Stmt *T) {
1047    return T->getStmtClass() == WhileStmtClass;
1048  }
1049
1050  // Iterators
1051  child_range children() {
1052    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1053  }
1054};
1055
1056/// DoStmt - This represents a 'do/while' stmt.
1057///
1058class DoStmt : public Stmt {
1059  enum { BODY, COND, END_EXPR };
1060  Stmt* SubExprs[END_EXPR];
1061  SourceLocation DoLoc;
1062  SourceLocation WhileLoc;
1063  SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
1064
1065public:
1066  DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1067         SourceLocation RP)
1068    : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1069    SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1070    SubExprs[BODY] = body;
1071  }
1072
1073  /// \brief Build an empty do-while statement.
1074  explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1075
1076  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1077  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1078  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1079  Stmt *getBody() { return SubExprs[BODY]; }
1080  const Stmt *getBody() const { return SubExprs[BODY]; }
1081  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1082
1083  SourceLocation getDoLoc() const { return DoLoc; }
1084  void setDoLoc(SourceLocation L) { DoLoc = L; }
1085  SourceLocation getWhileLoc() const { return WhileLoc; }
1086  void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1087
1088  SourceLocation getRParenLoc() const { return RParenLoc; }
1089  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1090
1091  SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1092  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1093
1094  static bool classof(const Stmt *T) {
1095    return T->getStmtClass() == DoStmtClass;
1096  }
1097
1098  // Iterators
1099  child_range children() {
1100    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1101  }
1102};
1103
1104
1105/// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
1106/// the init/cond/inc parts of the ForStmt will be null if they were not
1107/// specified in the source.
1108///
1109class ForStmt : public Stmt {
1110  enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1111  Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1112  SourceLocation ForLoc;
1113  SourceLocation LParenLoc, RParenLoc;
1114
1115public:
1116  ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
1117          Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
1118
1119  /// \brief Build an empty for statement.
1120  explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1121
1122  Stmt *getInit() { return SubExprs[INIT]; }
1123
1124  /// \brief Retrieve the variable declared in this "for" statement, if any.
1125  ///
1126  /// In the following example, "y" is the condition variable.
1127  /// \code
1128  /// for (int x = random(); int y = mangle(x); ++x) {
1129  ///   // ...
1130  /// }
1131  /// \endcode
1132  VarDecl *getConditionVariable() const;
1133  void setConditionVariable(ASTContext &C, VarDecl *V);
1134
1135  /// If this ForStmt has a condition variable, return the faux DeclStmt
1136  /// associated with the creation of that condition variable.
1137  const DeclStmt *getConditionVariableDeclStmt() const {
1138    return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1139  }
1140
1141  Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1142  Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1143  Stmt *getBody() { return SubExprs[BODY]; }
1144
1145  const Stmt *getInit() const { return SubExprs[INIT]; }
1146  const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1147  const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1148  const Stmt *getBody() const { return SubExprs[BODY]; }
1149
1150  void setInit(Stmt *S) { SubExprs[INIT] = S; }
1151  void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1152  void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1153  void setBody(Stmt *S) { SubExprs[BODY] = S; }
1154
1155  SourceLocation getForLoc() const { return ForLoc; }
1156  void setForLoc(SourceLocation L) { ForLoc = L; }
1157  SourceLocation getLParenLoc() const { return LParenLoc; }
1158  void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1159  SourceLocation getRParenLoc() const { return RParenLoc; }
1160  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1161
1162  SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1163  SourceLocation getLocEnd() const LLVM_READONLY {
1164    return SubExprs[BODY]->getLocEnd();
1165  }
1166
1167  static bool classof(const Stmt *T) {
1168    return T->getStmtClass() == ForStmtClass;
1169  }
1170
1171  // Iterators
1172  child_range children() {
1173    return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1174  }
1175};
1176
1177/// GotoStmt - This represents a direct goto.
1178///
1179class GotoStmt : public Stmt {
1180  LabelDecl *Label;
1181  SourceLocation GotoLoc;
1182  SourceLocation LabelLoc;
1183public:
1184  GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1185    : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1186
1187  /// \brief Build an empty goto statement.
1188  explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1189
1190  LabelDecl *getLabel() const { return Label; }
1191  void setLabel(LabelDecl *D) { Label = D; }
1192
1193  SourceLocation getGotoLoc() const { return GotoLoc; }
1194  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1195  SourceLocation getLabelLoc() const { return LabelLoc; }
1196  void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1197
1198  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1199  SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1200
1201  static bool classof(const Stmt *T) {
1202    return T->getStmtClass() == GotoStmtClass;
1203  }
1204
1205  // Iterators
1206  child_range children() { return child_range(); }
1207};
1208
1209/// IndirectGotoStmt - This represents an indirect goto.
1210///
1211class IndirectGotoStmt : public Stmt {
1212  SourceLocation GotoLoc;
1213  SourceLocation StarLoc;
1214  Stmt *Target;
1215public:
1216  IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1217                   Expr *target)
1218    : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1219      Target((Stmt*)target) {}
1220
1221  /// \brief Build an empty indirect goto statement.
1222  explicit IndirectGotoStmt(EmptyShell Empty)
1223    : Stmt(IndirectGotoStmtClass, Empty) { }
1224
1225  void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1226  SourceLocation getGotoLoc() const { return GotoLoc; }
1227  void setStarLoc(SourceLocation L) { StarLoc = L; }
1228  SourceLocation getStarLoc() const { return StarLoc; }
1229
1230  Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1231  const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1232  void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1233
1234  /// getConstantTarget - Returns the fixed target of this indirect
1235  /// goto, if one exists.
1236  LabelDecl *getConstantTarget();
1237  const LabelDecl *getConstantTarget() const {
1238    return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1239  }
1240
1241  SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1242  SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1243
1244  static bool classof(const Stmt *T) {
1245    return T->getStmtClass() == IndirectGotoStmtClass;
1246  }
1247
1248  // Iterators
1249  child_range children() { return child_range(&Target, &Target+1); }
1250};
1251
1252
1253/// ContinueStmt - This represents a continue.
1254///
1255class ContinueStmt : public Stmt {
1256  SourceLocation ContinueLoc;
1257public:
1258  ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1259
1260  /// \brief Build an empty continue statement.
1261  explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1262
1263  SourceLocation getContinueLoc() const { return ContinueLoc; }
1264  void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1265
1266  SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1267  SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1268
1269  static bool classof(const Stmt *T) {
1270    return T->getStmtClass() == ContinueStmtClass;
1271  }
1272
1273  // Iterators
1274  child_range children() { return child_range(); }
1275};
1276
1277/// BreakStmt - This represents a break.
1278///
1279class BreakStmt : public Stmt {
1280  SourceLocation BreakLoc;
1281public:
1282  BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1283
1284  /// \brief Build an empty break statement.
1285  explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1286
1287  SourceLocation getBreakLoc() const { return BreakLoc; }
1288  void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1289
1290  SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1291  SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1292
1293  static bool classof(const Stmt *T) {
1294    return T->getStmtClass() == BreakStmtClass;
1295  }
1296
1297  // Iterators
1298  child_range children() { return child_range(); }
1299};
1300
1301
1302/// ReturnStmt - This represents a return, optionally of an expression:
1303///   return;
1304///   return 4;
1305///
1306/// Note that GCC allows return with no argument in a function declared to
1307/// return a value, and it allows returning a value in functions declared to
1308/// return void.  We explicitly model this in the AST, which means you can't
1309/// depend on the return type of the function and the presence of an argument.
1310///
1311class ReturnStmt : public Stmt {
1312  Stmt *RetExpr;
1313  SourceLocation RetLoc;
1314  const VarDecl *NRVOCandidate;
1315
1316public:
1317  ReturnStmt(SourceLocation RL)
1318    : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1319
1320  ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1321    : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1322      NRVOCandidate(NRVOCandidate) {}
1323
1324  /// \brief Build an empty return expression.
1325  explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1326
1327  const Expr *getRetValue() const;
1328  Expr *getRetValue();
1329  void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1330
1331  SourceLocation getReturnLoc() const { return RetLoc; }
1332  void setReturnLoc(SourceLocation L) { RetLoc = L; }
1333
1334  /// \brief Retrieve the variable that might be used for the named return
1335  /// value optimization.
1336  ///
1337  /// The optimization itself can only be performed if the variable is
1338  /// also marked as an NRVO object.
1339  const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1340  void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1341
1342  SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1343  SourceLocation getLocEnd() const LLVM_READONLY {
1344    return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1345  }
1346
1347  static bool classof(const Stmt *T) {
1348    return T->getStmtClass() == ReturnStmtClass;
1349  }
1350
1351  // Iterators
1352  child_range children() {
1353    if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1354    return child_range();
1355  }
1356};
1357
1358/// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1359///
1360class AsmStmt : public Stmt {
1361protected:
1362  SourceLocation AsmLoc;
1363  /// \brief True if the assembly statement does not have any input or output
1364  /// operands.
1365  bool IsSimple;
1366
1367  /// \brief If true, treat this inline assembly as having side effects.
1368  /// This assembly statement should not be optimized, deleted or moved.
1369  bool IsVolatile;
1370
1371  unsigned NumOutputs;
1372  unsigned NumInputs;
1373  unsigned NumClobbers;
1374
1375  IdentifierInfo **Names;
1376  Stmt **Exprs;
1377
1378  AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1379          unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1380    Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1381    NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1382
1383public:
1384  /// \brief Build an empty inline-assembly statement.
1385  explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1386    Stmt(SC, Empty), Names(0), Exprs(0) { }
1387
1388  SourceLocation getAsmLoc() const { return AsmLoc; }
1389  void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1390
1391  bool isSimple() const { return IsSimple; }
1392  void setSimple(bool V) { IsSimple = V; }
1393
1394  bool isVolatile() const { return IsVolatile; }
1395  void setVolatile(bool V) { IsVolatile = V; }
1396
1397  SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1398  SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1399
1400  //===--- Asm String Analysis ---===//
1401
1402  /// Assemble final IR asm string.
1403  std::string generateAsmString(ASTContext &C) const;
1404
1405  //===--- Output operands ---===//
1406
1407  unsigned getNumOutputs() const { return NumOutputs; }
1408
1409  IdentifierInfo *getOutputIdentifier(unsigned i) const {
1410    return Names[i];
1411  }
1412
1413  StringRef getOutputName(unsigned i) const {
1414    if (IdentifierInfo *II = getOutputIdentifier(i))
1415      return II->getName();
1416
1417    return StringRef();
1418  }
1419
1420  /// getOutputConstraint - Return the constraint string for the specified
1421  /// output operand.  All output constraints are known to be non-empty (either
1422  /// '=' or '+').
1423  StringRef getOutputConstraint(unsigned i) const;
1424
1425  /// isOutputPlusConstraint - Return true if the specified output constraint
1426  /// is a "+" constraint (which is both an input and an output) or false if it
1427  /// is an "=" constraint (just an output).
1428  bool isOutputPlusConstraint(unsigned i) const {
1429    return getOutputConstraint(i)[0] == '+';
1430  }
1431
1432  const Expr *getOutputExpr(unsigned i) const;
1433
1434  /// getNumPlusOperands - Return the number of output operands that have a "+"
1435  /// constraint.
1436  unsigned getNumPlusOperands() const;
1437
1438  //===--- Input operands ---===//
1439
1440  unsigned getNumInputs() const { return NumInputs; }
1441
1442  IdentifierInfo *getInputIdentifier(unsigned i) const {
1443    return Names[i + NumOutputs];
1444  }
1445
1446  StringRef getInputName(unsigned i) const {
1447    if (IdentifierInfo *II = getInputIdentifier(i))
1448      return II->getName();
1449
1450    return StringRef();
1451  }
1452
1453  /// getInputConstraint - Return the specified input constraint.  Unlike output
1454  /// constraints, these can be empty.
1455  StringRef getInputConstraint(unsigned i) const;
1456
1457  const Expr *getInputExpr(unsigned i) const;
1458
1459  //===--- Other ---===//
1460
1461  unsigned getNumClobbers() const { return NumClobbers; }
1462  StringRef getClobber(unsigned i) const;
1463
1464  static bool classof(const Stmt *T) {
1465    return T->getStmtClass() == GCCAsmStmtClass ||
1466      T->getStmtClass() == MSAsmStmtClass;
1467  }
1468
1469  // Input expr iterators.
1470
1471  typedef ExprIterator inputs_iterator;
1472  typedef ConstExprIterator const_inputs_iterator;
1473
1474  inputs_iterator begin_inputs() {
1475    return &Exprs[0] + NumOutputs;
1476  }
1477
1478  inputs_iterator end_inputs() {
1479    return &Exprs[0] + NumOutputs + NumInputs;
1480  }
1481
1482  const_inputs_iterator begin_inputs() const {
1483    return &Exprs[0] + NumOutputs;
1484  }
1485
1486  const_inputs_iterator end_inputs() const {
1487    return &Exprs[0] + NumOutputs + NumInputs;
1488  }
1489
1490  // Output expr iterators.
1491
1492  typedef ExprIterator outputs_iterator;
1493  typedef ConstExprIterator const_outputs_iterator;
1494
1495  outputs_iterator begin_outputs() {
1496    return &Exprs[0];
1497  }
1498  outputs_iterator end_outputs() {
1499    return &Exprs[0] + NumOutputs;
1500  }
1501
1502  const_outputs_iterator begin_outputs() const {
1503    return &Exprs[0];
1504  }
1505  const_outputs_iterator end_outputs() const {
1506    return &Exprs[0] + NumOutputs;
1507  }
1508
1509  child_range children() {
1510    return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1511  }
1512};
1513
1514/// This represents a GCC inline-assembly statement extension.
1515///
1516class GCCAsmStmt : public AsmStmt {
1517  SourceLocation RParenLoc;
1518  StringLiteral *AsmStr;
1519
1520  // FIXME: If we wanted to, we could allocate all of these in one big array.
1521  StringLiteral **Constraints;
1522  StringLiteral **Clobbers;
1523
1524public:
1525  GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1526             bool isvolatile, unsigned numoutputs, unsigned numinputs,
1527             IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1528             StringLiteral *asmstr, unsigned numclobbers,
1529             StringLiteral **clobbers, SourceLocation rparenloc);
1530
1531  /// \brief Build an empty inline-assembly statement.
1532  explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1533    Constraints(0), Clobbers(0) { }
1534
1535  SourceLocation getRParenLoc() const { return RParenLoc; }
1536  void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1537
1538  //===--- Asm String Analysis ---===//
1539
1540  const StringLiteral *getAsmString() const { return AsmStr; }
1541  StringLiteral *getAsmString() { return AsmStr; }
1542  void setAsmString(StringLiteral *E) { AsmStr = E; }
1543
1544  /// AsmStringPiece - this is part of a decomposed asm string specification
1545  /// (for use with the AnalyzeAsmString function below).  An asm string is
1546  /// considered to be a concatenation of these parts.
1547  class AsmStringPiece {
1548  public:
1549    enum Kind {
1550      String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1551      Operand  // Operand reference, with optional modifier %c4.
1552    };
1553  private:
1554    Kind MyKind;
1555    std::string Str;
1556    unsigned OperandNo;
1557  public:
1558    AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1559    AsmStringPiece(unsigned OpNo, char Modifier)
1560      : MyKind(Operand), Str(), OperandNo(OpNo) {
1561      Str += Modifier;
1562    }
1563
1564    bool isString() const { return MyKind == String; }
1565    bool isOperand() const { return MyKind == Operand; }
1566
1567    const std::string &getString() const {
1568      assert(isString());
1569      return Str;
1570    }
1571
1572    unsigned getOperandNo() const {
1573      assert(isOperand());
1574      return OperandNo;
1575    }
1576
1577    /// getModifier - Get the modifier for this operand, if present.  This
1578    /// returns '\0' if there was no modifier.
1579    char getModifier() const {
1580      assert(isOperand());
1581      return Str[0];
1582    }
1583  };
1584
1585  /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1586  /// it into pieces.  If the asm string is erroneous, emit errors and return
1587  /// true, otherwise return false.  This handles canonicalization and
1588  /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1589  //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1590  unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1591                            ASTContext &C, unsigned &DiagOffs) const;
1592
1593  /// Assemble final IR asm string.
1594  std::string generateAsmString(ASTContext &C) const;
1595
1596  //===--- Output operands ---===//
1597
1598  StringRef getOutputConstraint(unsigned i) const;
1599
1600  const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1601    return Constraints[i];
1602  }
1603  StringLiteral *getOutputConstraintLiteral(unsigned i) {
1604    return Constraints[i];
1605  }
1606
1607  Expr *getOutputExpr(unsigned i);
1608
1609  const Expr *getOutputExpr(unsigned i) const {
1610    return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1611  }
1612
1613  //===--- Input operands ---===//
1614
1615  StringRef getInputConstraint(unsigned i) const;
1616
1617  const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1618    return Constraints[i + NumOutputs];
1619  }
1620  StringLiteral *getInputConstraintLiteral(unsigned i) {
1621    return Constraints[i + NumOutputs];
1622  }
1623
1624  Expr *getInputExpr(unsigned i);
1625  void setInputExpr(unsigned i, Expr *E);
1626
1627  const Expr *getInputExpr(unsigned i) const {
1628    return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1629  }
1630
1631  void setOutputsAndInputsAndClobbers(ASTContext &C,
1632                                      IdentifierInfo **Names,
1633                                      StringLiteral **Constraints,
1634                                      Stmt **Exprs,
1635                                      unsigned NumOutputs,
1636                                      unsigned NumInputs,
1637                                      StringLiteral **Clobbers,
1638                                      unsigned NumClobbers);
1639
1640  //===--- Other ---===//
1641
1642  /// getNamedOperand - Given a symbolic operand reference like %[foo],
1643  /// translate this into a numeric value needed to reference the same operand.
1644  /// This returns -1 if the operand name is invalid.
1645  int getNamedOperand(StringRef SymbolicName) const;
1646
1647  StringRef getClobber(unsigned i) const;
1648  StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1649  const StringLiteral *getClobberStringLiteral(unsigned i) const {
1650    return Clobbers[i];
1651  }
1652
1653  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1654  SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1655
1656  static bool classof(const Stmt *T) {
1657    return T->getStmtClass() == GCCAsmStmtClass;
1658  }
1659};
1660
1661/// This represents a Microsoft inline-assembly statement extension.
1662///
1663class MSAsmStmt : public AsmStmt {
1664  SourceLocation AsmLoc, LBraceLoc, EndLoc;
1665  std::string AsmStr;
1666
1667  unsigned NumAsmToks;
1668
1669  Token *AsmToks;
1670  StringRef *Constraints;
1671  StringRef *Clobbers;
1672
1673public:
1674  MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
1675            bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1676            unsigned numoutputs, unsigned numinputs,
1677            ArrayRef<IdentifierInfo*> names, ArrayRef<StringRef> constraints,
1678            ArrayRef<Expr*> exprs, StringRef asmstr,
1679            ArrayRef<StringRef> clobbers, SourceLocation endloc);
1680
1681  /// \brief Build an empty MS-style inline-assembly statement.
1682  explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1683    NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1684
1685  SourceLocation getLBraceLoc() const { return LBraceLoc; }
1686  void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1687  SourceLocation getEndLoc() const { return EndLoc; }
1688  void setEndLoc(SourceLocation L) { EndLoc = L; }
1689
1690  bool hasBraces() const { return LBraceLoc.isValid(); }
1691
1692  unsigned getNumAsmToks() { return NumAsmToks; }
1693  Token *getAsmToks() { return AsmToks; }
1694
1695  //===--- Asm String Analysis ---===//
1696
1697  const std::string *getAsmString() const { return &AsmStr; }
1698  std::string *getAsmString() { return &AsmStr; }
1699  void setAsmString(StringRef &E) { AsmStr = E.str(); }
1700
1701  /// Assemble final IR asm string.
1702  std::string generateAsmString(ASTContext &C) const;
1703
1704  //===--- Output operands ---===//
1705
1706  StringRef getOutputConstraint(unsigned i) const {
1707    return Constraints[i];
1708  }
1709
1710  Expr *getOutputExpr(unsigned i);
1711
1712  const Expr *getOutputExpr(unsigned i) const {
1713    return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1714  }
1715
1716  //===--- Input operands ---===//
1717
1718  StringRef getInputConstraint(unsigned i) const {
1719    return Constraints[i + NumOutputs];
1720  }
1721
1722  Expr *getInputExpr(unsigned i);
1723  void setInputExpr(unsigned i, Expr *E);
1724
1725  const Expr *getInputExpr(unsigned i) const {
1726    return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1727  }
1728
1729  //===--- Other ---===//
1730
1731  StringRef getClobber(unsigned i) const { return Clobbers[i]; }
1732
1733  SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1734  SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1735
1736  static bool classof(const Stmt *T) {
1737    return T->getStmtClass() == MSAsmStmtClass;
1738  }
1739
1740  child_range children() {
1741    return child_range(&Exprs[0], &Exprs[0]);
1742  }
1743};
1744
1745class SEHExceptStmt : public Stmt {
1746  SourceLocation  Loc;
1747  Stmt           *Children[2];
1748
1749  enum { FILTER_EXPR, BLOCK };
1750
1751  SEHExceptStmt(SourceLocation Loc,
1752                Expr *FilterExpr,
1753                Stmt *Block);
1754
1755  friend class ASTReader;
1756  friend class ASTStmtReader;
1757  explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1758
1759public:
1760  static SEHExceptStmt* Create(ASTContext &C,
1761                               SourceLocation ExceptLoc,
1762                               Expr *FilterExpr,
1763                               Stmt *Block);
1764
1765  SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1766  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1767
1768  SourceLocation getExceptLoc() const { return Loc; }
1769  SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1770
1771  Expr *getFilterExpr() const {
1772    return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1773  }
1774
1775  CompoundStmt *getBlock() const {
1776    return cast<CompoundStmt>(Children[BLOCK]);
1777  }
1778
1779  child_range children() {
1780    return child_range(Children,Children+2);
1781  }
1782
1783  static bool classof(const Stmt *T) {
1784    return T->getStmtClass() == SEHExceptStmtClass;
1785  }
1786
1787};
1788
1789class SEHFinallyStmt : public Stmt {
1790  SourceLocation  Loc;
1791  Stmt           *Block;
1792
1793  SEHFinallyStmt(SourceLocation Loc,
1794                 Stmt *Block);
1795
1796  friend class ASTReader;
1797  friend class ASTStmtReader;
1798  explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1799
1800public:
1801  static SEHFinallyStmt* Create(ASTContext &C,
1802                                SourceLocation FinallyLoc,
1803                                Stmt *Block);
1804
1805  SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1806  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1807
1808  SourceLocation getFinallyLoc() const { return Loc; }
1809  SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1810
1811  CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1812
1813  child_range children() {
1814    return child_range(&Block,&Block+1);
1815  }
1816
1817  static bool classof(const Stmt *T) {
1818    return T->getStmtClass() == SEHFinallyStmtClass;
1819  }
1820
1821};
1822
1823class SEHTryStmt : public Stmt {
1824  bool            IsCXXTry;
1825  SourceLocation  TryLoc;
1826  Stmt           *Children[2];
1827
1828  enum { TRY = 0, HANDLER = 1 };
1829
1830  SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1831             SourceLocation TryLoc,
1832             Stmt *TryBlock,
1833             Stmt *Handler);
1834
1835  friend class ASTReader;
1836  friend class ASTStmtReader;
1837  explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1838
1839public:
1840  static SEHTryStmt* Create(ASTContext &C,
1841                            bool isCXXTry,
1842                            SourceLocation TryLoc,
1843                            Stmt *TryBlock,
1844                            Stmt *Handler);
1845
1846  SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1847  SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1848
1849  SourceLocation getTryLoc() const { return TryLoc; }
1850  SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1851
1852  bool getIsCXXTry() const { return IsCXXTry; }
1853
1854  CompoundStmt* getTryBlock() const {
1855    return cast<CompoundStmt>(Children[TRY]);
1856  }
1857
1858  Stmt *getHandler() const { return Children[HANDLER]; }
1859
1860  /// Returns 0 if not defined
1861  SEHExceptStmt  *getExceptHandler() const;
1862  SEHFinallyStmt *getFinallyHandler() const;
1863
1864  child_range children() {
1865    return child_range(Children,Children+2);
1866  }
1867
1868  static bool classof(const Stmt *T) {
1869    return T->getStmtClass() == SEHTryStmtClass;
1870  }
1871};
1872
1873}  // end namespace clang
1874
1875#endif
1876