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