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