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