]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/AST/Stmt.h
Update clang to r90226.
[FreeBSD/FreeBSD.git] / 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 "llvm/Support/Casting.h"
18 #include "llvm/Support/raw_ostream.h"
19 #include "clang/Basic/SourceLocation.h"
20 #include "clang/AST/PrettyPrinter.h"
21 #include "clang/AST/StmtIterator.h"
22 #include "clang/AST/DeclGroup.h"
23 #include "llvm/ADT/SmallVector.h"
24 #include "clang/AST/ASTContext.h"
25 #include <string>
26 using llvm::dyn_cast_or_null;
27
28 namespace llvm {
29   class FoldingSetNodeID;
30 }
31
32 namespace clang {
33   class ASTContext;
34   class Expr;
35   class Decl;
36   class ParmVarDecl;
37   class QualType;
38   class IdentifierInfo;
39   class SourceManager;
40   class StringLiteral;
41   class SwitchStmt;
42
43   //===----------------------------------------------------------------------===//
44   // ExprIterator - Iterators for iterating over Stmt* arrays that contain
45   //  only Expr*.  This is needed because AST nodes use Stmt* arrays to store
46   //  references to children (to be compatible with StmtIterator).
47   //===----------------------------------------------------------------------===//
48
49   class Stmt;
50   class Expr;
51
52   class ExprIterator {
53     Stmt** I;
54   public:
55     ExprIterator(Stmt** i) : I(i) {}
56     ExprIterator() : I(0) {}
57     ExprIterator& operator++() { ++I; return *this; }
58     ExprIterator operator-(size_t i) { return I-i; }
59     ExprIterator operator+(size_t i) { return I+i; }
60     Expr* operator[](size_t idx);
61     // FIXME: Verify that this will correctly return a signed distance.
62     signed operator-(const ExprIterator& R) const { return I - R.I; }
63     Expr* operator*() const;
64     Expr* operator->() const;
65     bool operator==(const ExprIterator& R) const { return I == R.I; }
66     bool operator!=(const ExprIterator& R) const { return I != R.I; }
67     bool operator>(const ExprIterator& R) const { return I > R.I; }
68     bool operator>=(const ExprIterator& R) const { return I >= R.I; }
69   };
70
71   class ConstExprIterator {
72     Stmt* const * I;
73   public:
74     ConstExprIterator(Stmt* const* i) : I(i) {}
75     ConstExprIterator() : I(0) {}
76     ConstExprIterator& operator++() { ++I; return *this; }
77     ConstExprIterator operator+(size_t i) { return I+i; }
78     ConstExprIterator operator-(size_t i) { return I-i; }
79     const Expr * operator[](size_t idx) const;
80     signed operator-(const ConstExprIterator& R) const { return I - R.I; }
81     const Expr * operator*() const;
82     const Expr * operator->() const;
83     bool operator==(const ConstExprIterator& R) const { return I == R.I; }
84     bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
85     bool operator>(const ConstExprIterator& R) const { return I > R.I; }
86     bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
87   };
88
89 //===----------------------------------------------------------------------===//
90 // AST classes for statements.
91 //===----------------------------------------------------------------------===//
92
93 /// Stmt - This represents one statement.
94 ///
95 class Stmt {
96 public:
97   enum StmtClass {
98     NoStmtClass = 0,
99 #define STMT(CLASS, PARENT) CLASS##Class,
100 #define FIRST_STMT(CLASS) firstStmtConstant = CLASS##Class,
101 #define LAST_STMT(CLASS) lastStmtConstant = CLASS##Class,
102 #define FIRST_EXPR(CLASS) firstExprConstant = CLASS##Class,
103 #define LAST_EXPR(CLASS) lastExprConstant = CLASS##Class
104 #include "clang/AST/StmtNodes.def"
105 };
106 private:
107   /// \brief The statement class.
108   const unsigned sClass : 8;
109
110   /// \brief The reference count for this statement.
111   unsigned RefCount : 24;
112
113   // Make vanilla 'new' and 'delete' illegal for Stmts.
114 protected:
115   void* operator new(size_t bytes) throw() {
116     assert(0 && "Stmts cannot be allocated with regular 'new'.");
117     return 0;
118   }
119   void operator delete(void* data) throw() {
120     assert(0 && "Stmts cannot be released with regular 'delete'.");
121   }
122
123 public:
124   // Only allow allocation of Stmts using the allocator in ASTContext
125   // or by doing a placement new.
126   void* operator new(size_t bytes, ASTContext& C,
127                      unsigned alignment = 16) throw() {
128     return ::operator new(bytes, C, alignment);
129   }
130
131   void* operator new(size_t bytes, ASTContext* C,
132                      unsigned alignment = 16) throw() {
133     return ::operator new(bytes, *C, alignment);
134   }
135
136   void* operator new(size_t bytes, void* mem) throw() {
137     return mem;
138   }
139
140   void operator delete(void*, ASTContext&, unsigned) throw() { }
141   void operator delete(void*, ASTContext*, unsigned) throw() { }
142   void operator delete(void*, std::size_t) throw() { }
143   void operator delete(void*, void*) throw() { }
144
145 public:
146   /// \brief A placeholder type used to construct an empty shell of a
147   /// type, that will be filled in later (e.g., by some
148   /// de-serialization).
149   struct EmptyShell { };
150
151 protected:
152   /// DestroyChildren - Invoked by destructors of subclasses of Stmt to
153   ///  recursively release child AST nodes.
154   void DestroyChildren(ASTContext& Ctx);
155
156   /// \brief Construct an empty statement.
157   explicit Stmt(StmtClass SC, EmptyShell) : sClass(SC), RefCount(1) {
158     if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
159   }
160
161   /// \brief Virtual method that performs the actual destruction of
162   /// this statement.
163   ///
164   /// Subclasses should override this method (not Destroy()) to
165   /// provide class-specific destruction.
166   virtual void DoDestroy(ASTContext &Ctx);
167
168 public:
169   Stmt(StmtClass SC) : sClass(SC), RefCount(1) {
170     if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
171   }
172   virtual ~Stmt() {}
173
174 #ifndef NDEBUG
175   /// \brief True if this statement's refcount is in a valid state.
176   /// Should be used only in assertions.
177   bool isRetained() const {
178     return (RefCount >= 1);
179   }
180 #endif
181
182   /// \brief Destroy the current statement and its children.
183   void Destroy(ASTContext &Ctx) {
184     assert(RefCount >= 1);
185     if (--RefCount == 0)
186       DoDestroy(Ctx);
187   }
188
189   /// \brief Increases the reference count for this statement.
190   ///
191   /// Invoke the Retain() operation when this statement or expression
192   /// is being shared by another owner.
193   Stmt *Retain() {
194     assert(RefCount >= 1);
195     ++RefCount;
196     return this;
197   }
198
199   StmtClass getStmtClass() const { 
200     assert(RefCount >= 1 && "Referencing already-destroyed statement!");
201     return (StmtClass)sClass; 
202   }
203   const char *getStmtClassName() const;
204
205   /// SourceLocation tokens are not useful in isolation - they are low level
206   /// value objects created/interpreted by SourceManager. We assume AST
207   /// clients will have a pointer to the respective SourceManager.
208   virtual SourceRange getSourceRange() const = 0;
209   SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
210   SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
211
212   // global temp stats (until we have a per-module visitor)
213   static void addStmtClass(const StmtClass s);
214   static bool CollectingStats(bool Enable = false);
215   static void PrintStats();
216
217   /// dump - This does a local dump of the specified AST fragment.  It dumps the
218   /// specified node and a few nodes underneath it, but not the whole subtree.
219   /// This is useful in a debugger.
220   void dump() const;
221   void dump(SourceManager &SM) const;
222
223   /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
224   void dumpAll() const;
225   void dumpAll(SourceManager &SM) const;
226
227   /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
228   /// back to its original source language syntax.
229   void dumpPretty(ASTContext& Context) const;
230   void printPretty(llvm::raw_ostream &OS, PrinterHelper *Helper,
231                    const PrintingPolicy &Policy,
232                    unsigned Indentation = 0) const {
233     printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
234   }
235   void printPretty(llvm::raw_ostream &OS, ASTContext &Context,
236                    PrinterHelper *Helper,
237                    const PrintingPolicy &Policy,
238                    unsigned Indentation = 0) const;
239
240   /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz.  Only
241   ///   works on systems with GraphViz (Mac OS X) or dot+gv installed.
242   void viewAST() const;
243
244   // Implement isa<T> support.
245   static bool classof(const Stmt *) { return true; }
246
247   /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
248   ///  contain implicit control-flow in the order their subexpressions
249   ///  are evaluated.  This predicate returns true if this statement has
250   ///  such implicit control-flow.  Such statements are also specially handled
251   ///  within CFGs.
252   bool hasImplicitControlFlow() const;
253
254   /// Child Iterators: All subclasses must implement child_begin and child_end
255   ///  to permit easy iteration over the substatements/subexpessions of an
256   ///  AST node.  This permits easy iteration over all nodes in the AST.
257   typedef StmtIterator       child_iterator;
258   typedef ConstStmtIterator  const_child_iterator;
259
260   virtual child_iterator child_begin() = 0;
261   virtual child_iterator child_end()   = 0;
262
263   const_child_iterator child_begin() const {
264     return const_child_iterator(const_cast<Stmt*>(this)->child_begin());
265   }
266
267   const_child_iterator child_end() const {
268     return const_child_iterator(const_cast<Stmt*>(this)->child_end());
269   }
270
271   /// \brief Produce a unique representation of the given statement.
272   ///
273   /// \brief ID once the profiling operation is complete, will contain
274   /// the unique representation of the given statement.
275   ///
276   /// \brief Context the AST context in which the statement resides
277   ///
278   /// \brief Canonical whether the profile should be based on the canonical
279   /// representation of this statement (e.g., where non-type template
280   /// parameters are identified by index/level rather than their
281   /// declaration pointers) or the exact representation of the statement as
282   /// written in the source.
283   void Profile(llvm::FoldingSetNodeID &ID, ASTContext &Context,
284                bool Canonical);
285 };
286
287 /// DeclStmt - Adaptor class for mixing declarations with statements and
288 /// expressions. For example, CompoundStmt mixes statements, expressions
289 /// and declarations (variables, types). Another example is ForStmt, where
290 /// the first statement can be an expression or a declaration.
291 ///
292 class DeclStmt : public Stmt {
293   DeclGroupRef DG;
294   SourceLocation StartLoc, EndLoc;
295
296 public:
297   DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
298            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
299                                     StartLoc(startLoc), EndLoc(endLoc) {}
300
301   /// \brief Build an empty declaration statement.
302   explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
303
304   /// isSingleDecl - This method returns true if this DeclStmt refers
305   /// to a single Decl.
306   bool isSingleDecl() const {
307     return DG.isSingleDecl();
308   }
309
310   const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
311   Decl *getSingleDecl() { return DG.getSingleDecl(); }
312
313   const DeclGroupRef getDeclGroup() const { return DG; }
314   DeclGroupRef getDeclGroup() { return DG; }
315   void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
316
317   SourceLocation getStartLoc() const { return StartLoc; }
318   void setStartLoc(SourceLocation L) { StartLoc = L; }
319   SourceLocation getEndLoc() const { return EndLoc; }
320   void setEndLoc(SourceLocation L) { EndLoc = L; }
321
322   SourceRange getSourceRange() const {
323     return SourceRange(StartLoc, EndLoc);
324   }
325
326   static bool classof(const Stmt *T) {
327     return T->getStmtClass() == DeclStmtClass;
328   }
329   static bool classof(const DeclStmt *) { return true; }
330
331   // Iterators over subexpressions.
332   virtual child_iterator child_begin();
333   virtual child_iterator child_end();
334
335   typedef DeclGroupRef::iterator decl_iterator;
336   typedef DeclGroupRef::const_iterator const_decl_iterator;
337
338   decl_iterator decl_begin() { return DG.begin(); }
339   decl_iterator decl_end() { return DG.end(); }
340   const_decl_iterator decl_begin() const { return DG.begin(); }
341   const_decl_iterator decl_end() const { return DG.end(); }
342 };
343
344 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
345 ///
346 class NullStmt : public Stmt {
347   SourceLocation SemiLoc;
348 public:
349   NullStmt(SourceLocation L) : Stmt(NullStmtClass), SemiLoc(L) {}
350
351   /// \brief Build an empty null statement.
352   explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { }
353
354   SourceLocation getSemiLoc() const { return SemiLoc; }
355   void setSemiLoc(SourceLocation L) { SemiLoc = L; }
356
357   virtual SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
358
359   static bool classof(const Stmt *T) {
360     return T->getStmtClass() == NullStmtClass;
361   }
362   static bool classof(const NullStmt *) { return true; }
363
364   // Iterators
365   virtual child_iterator child_begin();
366   virtual child_iterator child_end();
367 };
368
369 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
370 ///
371 class CompoundStmt : public Stmt {
372   Stmt** Body;
373   unsigned NumStmts;
374   SourceLocation LBracLoc, RBracLoc;
375 public:
376   CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned numStmts,
377                              SourceLocation LB, SourceLocation RB)
378   : Stmt(CompoundStmtClass), NumStmts(numStmts), LBracLoc(LB), RBracLoc(RB) {
379     if (NumStmts == 0) {
380       Body = 0;
381       return;
382     }
383
384     Body = new (C) Stmt*[NumStmts];
385     memcpy(Body, StmtStart, numStmts * sizeof(*Body));
386   }
387
388   // \brief Build an empty compound statement.
389   explicit CompoundStmt(EmptyShell Empty)
390     : Stmt(CompoundStmtClass, Empty), Body(0), NumStmts(0) { }
391
392   void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
393
394   bool body_empty() const { return NumStmts == 0; }
395   unsigned size() const { return NumStmts; }
396
397   typedef Stmt** body_iterator;
398   body_iterator body_begin() { return Body; }
399   body_iterator body_end() { return Body + NumStmts; }
400   Stmt *body_back() { return NumStmts ? Body[NumStmts-1] : 0; }
401
402   typedef Stmt* const * const_body_iterator;
403   const_body_iterator body_begin() const { return Body; }
404   const_body_iterator body_end() const { return Body + NumStmts; }
405   const Stmt *body_back() const { return NumStmts ? Body[NumStmts-1] : 0; }
406
407   typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
408   reverse_body_iterator body_rbegin() {
409     return reverse_body_iterator(body_end());
410   }
411   reverse_body_iterator body_rend() {
412     return reverse_body_iterator(body_begin());
413   }
414
415   typedef std::reverse_iterator<const_body_iterator>
416           const_reverse_body_iterator;
417
418   const_reverse_body_iterator body_rbegin() const {
419     return const_reverse_body_iterator(body_end());
420   }
421
422   const_reverse_body_iterator body_rend() const {
423     return const_reverse_body_iterator(body_begin());
424   }
425
426   virtual SourceRange getSourceRange() const {
427     return SourceRange(LBracLoc, RBracLoc);
428   }
429
430   SourceLocation getLBracLoc() const { return LBracLoc; }
431   void setLBracLoc(SourceLocation L) { LBracLoc = L; }
432   SourceLocation getRBracLoc() const { return RBracLoc; }
433   void setRBracLoc(SourceLocation L) { RBracLoc = L; }
434
435   static bool classof(const Stmt *T) {
436     return T->getStmtClass() == CompoundStmtClass;
437   }
438   static bool classof(const CompoundStmt *) { return true; }
439
440   // Iterators
441   virtual child_iterator child_begin();
442   virtual child_iterator child_end();
443 };
444
445 // SwitchCase is the base class for CaseStmt and DefaultStmt,
446 class SwitchCase : public Stmt {
447 protected:
448   // A pointer to the following CaseStmt or DefaultStmt class,
449   // used by SwitchStmt.
450   SwitchCase *NextSwitchCase;
451
452   SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
453
454 public:
455   const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
456
457   SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
458
459   void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
460
461   Stmt *getSubStmt() { return v_getSubStmt(); }
462
463   virtual SourceRange getSourceRange() const { return SourceRange(); }
464
465   static bool classof(const Stmt *T) {
466     return T->getStmtClass() == CaseStmtClass ||
467     T->getStmtClass() == DefaultStmtClass;
468   }
469   static bool classof(const SwitchCase *) { return true; }
470 protected:
471   virtual Stmt* v_getSubStmt() = 0;
472 };
473
474 class CaseStmt : public SwitchCase {
475   enum { SUBSTMT, LHS, RHS, END_EXPR };
476   Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
477                              // GNU "case 1 ... 4" extension
478   SourceLocation CaseLoc;
479   SourceLocation EllipsisLoc;
480   SourceLocation ColonLoc;
481
482   virtual Stmt* v_getSubStmt() { return getSubStmt(); }
483 public:
484   CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
485            SourceLocation ellipsisLoc, SourceLocation colonLoc)
486     : SwitchCase(CaseStmtClass) {
487     SubExprs[SUBSTMT] = 0;
488     SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
489     SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
490     CaseLoc = caseLoc;
491     EllipsisLoc = ellipsisLoc;
492     ColonLoc = colonLoc;
493   }
494
495   /// \brief Build an empty switch case statement.
496   explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
497
498   SourceLocation getCaseLoc() const { return CaseLoc; }
499   void setCaseLoc(SourceLocation L) { CaseLoc = L; }
500   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
501   void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
502   SourceLocation getColonLoc() const { return ColonLoc; }
503   void setColonLoc(SourceLocation L) { ColonLoc = L; }
504
505   Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
506   Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
507   Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
508
509   const Expr *getLHS() const {
510     return reinterpret_cast<const Expr*>(SubExprs[LHS]);
511   }
512   const Expr *getRHS() const {
513     return reinterpret_cast<const Expr*>(SubExprs[RHS]);
514   }
515   const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
516
517   void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
518   void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
519   void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
520
521
522   virtual SourceRange getSourceRange() const {
523     // Handle deeply nested case statements with iteration instead of recursion.
524     const CaseStmt *CS = this;
525     while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
526       CS = CS2;
527
528     return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
529   }
530   static bool classof(const Stmt *T) {
531     return T->getStmtClass() == CaseStmtClass;
532   }
533   static bool classof(const CaseStmt *) { return true; }
534
535   // Iterators
536   virtual child_iterator child_begin();
537   virtual child_iterator child_end();
538 };
539
540 class DefaultStmt : public SwitchCase {
541   Stmt* SubStmt;
542   SourceLocation DefaultLoc;
543   SourceLocation ColonLoc;
544   virtual Stmt* v_getSubStmt() { return getSubStmt(); }
545 public:
546   DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
547     SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
548     ColonLoc(CL) {}
549
550   /// \brief Build an empty default statement.
551   explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
552
553   Stmt *getSubStmt() { return SubStmt; }
554   const Stmt *getSubStmt() const { return SubStmt; }
555   void setSubStmt(Stmt *S) { SubStmt = S; }
556
557   SourceLocation getDefaultLoc() const { return DefaultLoc; }
558   void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
559   SourceLocation getColonLoc() const { return ColonLoc; }
560   void setColonLoc(SourceLocation L) { ColonLoc = L; }
561
562   virtual SourceRange getSourceRange() const {
563     return SourceRange(DefaultLoc, SubStmt->getLocEnd());
564   }
565   static bool classof(const Stmt *T) {
566     return T->getStmtClass() == DefaultStmtClass;
567   }
568   static bool classof(const DefaultStmt *) { return true; }
569
570   // Iterators
571   virtual child_iterator child_begin();
572   virtual child_iterator child_end();
573 };
574
575 class LabelStmt : public Stmt {
576   IdentifierInfo *Label;
577   Stmt *SubStmt;
578   SourceLocation IdentLoc;
579 public:
580   LabelStmt(SourceLocation IL, IdentifierInfo *label, Stmt *substmt)
581     : Stmt(LabelStmtClass), Label(label),
582       SubStmt(substmt), IdentLoc(IL) {}
583
584   // \brief Build an empty label statement.
585   explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
586
587   SourceLocation getIdentLoc() const { return IdentLoc; }
588   IdentifierInfo *getID() const { return Label; }
589   void setID(IdentifierInfo *II) { Label = II; }
590   const char *getName() const;
591   Stmt *getSubStmt() { return SubStmt; }
592   const Stmt *getSubStmt() const { return SubStmt; }
593   void setIdentLoc(SourceLocation L) { IdentLoc = L; }
594   void setSubStmt(Stmt *SS) { SubStmt = SS; }
595
596   virtual SourceRange getSourceRange() const {
597     return SourceRange(IdentLoc, SubStmt->getLocEnd());
598   }
599   static bool classof(const Stmt *T) {
600     return T->getStmtClass() == LabelStmtClass;
601   }
602   static bool classof(const LabelStmt *) { return true; }
603
604   // Iterators
605   virtual child_iterator child_begin();
606   virtual child_iterator child_end();
607 };
608
609
610 /// IfStmt - This represents an if/then/else.
611 ///
612 class IfStmt : public Stmt {
613   enum { COND, THEN, ELSE, END_EXPR };
614   Stmt* SubExprs[END_EXPR];
615
616   /// \brief If non-NULL, the declaration in the "if" statement.
617   VarDecl *Var;
618   
619   SourceLocation IfLoc;
620   SourceLocation ElseLoc;
621   
622 public:
623   IfStmt(SourceLocation IL, VarDecl *Var, Expr *cond, Stmt *then,
624          SourceLocation EL = SourceLocation(), Stmt *elsev = 0)
625     : Stmt(IfStmtClass), Var(Var), IfLoc(IL), ElseLoc(EL)  {
626     SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
627     SubExprs[THEN] = then;
628     SubExprs[ELSE] = elsev;
629   }
630
631   /// \brief Build an empty if/then/else statement
632   explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
633
634   /// \brief Retrieve the variable declared in this "if" statement, if any.
635   ///
636   /// In the following example, "x" is the condition variable.
637   /// \code
638   /// if (int x = foo()) {
639   ///   printf("x is %d", x);
640   /// }
641   /// \endcode
642   VarDecl *getConditionVariable() const { return Var; }
643   void setConditionVariable(VarDecl *V) { Var = V; }
644   
645   const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
646   void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
647   const Stmt *getThen() const { return SubExprs[THEN]; }
648   void setThen(Stmt *S) { SubExprs[THEN] = S; }
649   const Stmt *getElse() const { return SubExprs[ELSE]; }
650   void setElse(Stmt *S) { SubExprs[ELSE] = S; }
651
652   Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
653   Stmt *getThen() { return SubExprs[THEN]; }
654   Stmt *getElse() { return SubExprs[ELSE]; }
655
656   SourceLocation getIfLoc() const { return IfLoc; }
657   void setIfLoc(SourceLocation L) { IfLoc = L; }
658   SourceLocation getElseLoc() const { return ElseLoc; }
659   void setElseLoc(SourceLocation L) { ElseLoc = L; }
660
661   virtual SourceRange getSourceRange() const {
662     if (SubExprs[ELSE])
663       return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
664     else
665       return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
666   }
667
668   static bool classof(const Stmt *T) {
669     return T->getStmtClass() == IfStmtClass;
670   }
671   static bool classof(const IfStmt *) { return true; }
672
673   // Iterators
674   virtual child_iterator child_begin();
675   virtual child_iterator child_end();
676 };
677
678 /// SwitchStmt - This represents a 'switch' stmt.
679 ///
680 class SwitchStmt : public Stmt {
681   enum { COND, BODY, END_EXPR };
682   Stmt* SubExprs[END_EXPR];
683   VarDecl *Var;
684   // This points to a linked list of case and default statements.
685   SwitchCase *FirstCase;
686   SourceLocation SwitchLoc;
687
688 protected:
689   virtual void DoDestroy(ASTContext &Ctx);
690
691 public:
692   SwitchStmt(VarDecl *Var, Expr *cond) 
693     : Stmt(SwitchStmtClass), Var(Var), FirstCase(0) 
694   {
695     SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
696     SubExprs[BODY] = NULL;
697   }
698
699   /// \brief Build a empty switch statement.
700   explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
701
702   /// \brief Retrieve the variable declared in this "switch" statement, if any.
703   ///
704   /// In the following example, "x" is the condition variable.
705   /// \code
706   /// switch (int x = foo()) {
707   ///   case 0: break;
708   ///   // ...
709   /// }
710   /// \endcode
711   VarDecl *getConditionVariable() const { return Var; }
712   void setConditionVariable(VarDecl *V) { Var = V; }
713
714   const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
715   const Stmt *getBody() const { return SubExprs[BODY]; }
716   const SwitchCase *getSwitchCaseList() const { return FirstCase; }
717
718   Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
719   void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
720   Stmt *getBody() { return SubExprs[BODY]; }
721   void setBody(Stmt *S) { SubExprs[BODY] = S; }
722   SwitchCase *getSwitchCaseList() { return FirstCase; }
723
724   /// \brief Set the case list for this switch statement.
725   ///
726   /// The caller is responsible for incrementing the retain counts on
727   /// all of the SwitchCase statements in this list.
728   void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
729
730   SourceLocation getSwitchLoc() const { return SwitchLoc; }
731   void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
732
733   void setBody(Stmt *S, SourceLocation SL) {
734     SubExprs[BODY] = S;
735     SwitchLoc = SL;
736   }
737   void addSwitchCase(SwitchCase *SC) {
738     assert(!SC->getNextSwitchCase() && "case/default already added to a switch");
739     SC->Retain();
740     SC->setNextSwitchCase(FirstCase);
741     FirstCase = SC;
742   }
743   virtual SourceRange getSourceRange() const {
744     return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
745   }
746   static bool classof(const Stmt *T) {
747     return T->getStmtClass() == SwitchStmtClass;
748   }
749   static bool classof(const SwitchStmt *) { return true; }
750
751   // Iterators
752   virtual child_iterator child_begin();
753   virtual child_iterator child_end();
754 };
755
756
757 /// WhileStmt - This represents a 'while' stmt.
758 ///
759 class WhileStmt : public Stmt {
760   enum { COND, BODY, END_EXPR };
761   VarDecl *Var;
762   Stmt* SubExprs[END_EXPR];
763   SourceLocation WhileLoc;
764 public:
765   WhileStmt(VarDecl *Var, Expr *cond, Stmt *body, SourceLocation WL)
766     : Stmt(WhileStmtClass), Var(Var) 
767   {
768     SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
769     SubExprs[BODY] = body;
770     WhileLoc = WL;
771   }
772
773   /// \brief Build an empty while statement.
774   explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
775
776   /// \brief Retrieve the variable declared in this "while" statement, if any.
777   ///
778   /// In the following example, "x" is the condition variable.
779   /// \code
780   /// while (int x = random()) {
781   ///   // ...
782   /// }
783   /// \endcode
784   VarDecl *getConditionVariable() const { return Var; }
785   void setConditionVariable(VarDecl *V) { Var = V; }
786
787   Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
788   const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
789   void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
790   Stmt *getBody() { return SubExprs[BODY]; }
791   const Stmt *getBody() const { return SubExprs[BODY]; }
792   void setBody(Stmt *S) { SubExprs[BODY] = S; }
793
794   SourceLocation getWhileLoc() const { return WhileLoc; }
795   void setWhileLoc(SourceLocation L) { WhileLoc = L; }
796
797   virtual SourceRange getSourceRange() const {
798     return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
799   }
800   static bool classof(const Stmt *T) {
801     return T->getStmtClass() == WhileStmtClass;
802   }
803   static bool classof(const WhileStmt *) { return true; }
804
805   // Iterators
806   virtual child_iterator child_begin();
807   virtual child_iterator child_end();
808 };
809
810 /// DoStmt - This represents a 'do/while' stmt.
811 ///
812 class DoStmt : public Stmt {
813   enum { COND, BODY, END_EXPR };
814   Stmt* SubExprs[END_EXPR];
815   SourceLocation DoLoc;
816   SourceLocation WhileLoc;
817   SourceLocation RParenLoc;  // Location of final ')' in do stmt condition.
818
819 public:
820   DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
821          SourceLocation RP)
822     : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
823     SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
824     SubExprs[BODY] = body;
825   }
826
827   /// \brief Build an empty do-while statement.
828   explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
829
830   Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
831   const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
832   void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
833   Stmt *getBody() { return SubExprs[BODY]; }
834   const Stmt *getBody() const { return SubExprs[BODY]; }
835   void setBody(Stmt *S) { SubExprs[BODY] = S; }
836
837   SourceLocation getDoLoc() const { return DoLoc; }
838   void setDoLoc(SourceLocation L) { DoLoc = L; }
839   SourceLocation getWhileLoc() const { return WhileLoc; }
840   void setWhileLoc(SourceLocation L) { WhileLoc = L; }
841
842   SourceLocation getRParenLoc() const { return RParenLoc; }
843   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
844
845   virtual SourceRange getSourceRange() const {
846     return SourceRange(DoLoc, RParenLoc);
847   }
848   static bool classof(const Stmt *T) {
849     return T->getStmtClass() == DoStmtClass;
850   }
851   static bool classof(const DoStmt *) { return true; }
852
853   // Iterators
854   virtual child_iterator child_begin();
855   virtual child_iterator child_end();
856 };
857
858
859 /// ForStmt - This represents a 'for (init;cond;inc)' stmt.  Note that any of
860 /// the init/cond/inc parts of the ForStmt will be null if they were not
861 /// specified in the source.
862 ///
863 class ForStmt : public Stmt {
864   enum { INIT, COND, INC, BODY, END_EXPR };
865   Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
866   VarDecl *CondVar;
867   SourceLocation ForLoc;
868   SourceLocation LParenLoc, RParenLoc;
869
870 public:
871   ForStmt(Stmt *Init, Expr *Cond, VarDecl *CondVar, Expr *Inc, Stmt *Body, 
872           SourceLocation FL, SourceLocation LP, SourceLocation RP)
873     : Stmt(ForStmtClass), CondVar(CondVar), ForLoc(FL), LParenLoc(LP), 
874       RParenLoc(RP) 
875   {
876     SubExprs[INIT] = Init;
877     SubExprs[COND] = reinterpret_cast<Stmt*>(Cond);
878     SubExprs[INC] = reinterpret_cast<Stmt*>(Inc);
879     SubExprs[BODY] = Body;
880   }
881
882   /// \brief Build an empty for statement.
883   explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
884
885   Stmt *getInit() { return SubExprs[INIT]; }
886   
887   /// \brief Retrieve the variable declared in this "for" statement, if any.
888   ///
889   /// In the following example, "y" is the condition variable.
890   /// \code
891   /// for (int x = random(); int y = mangle(x); ++x) {
892   ///   // ...
893   /// }
894   /// \endcode
895   VarDecl *getConditionVariable() const { return CondVar; }
896   void setConditionVariable(VarDecl *V) { CondVar = V; }
897   
898   Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
899   Expr *getInc()  { return reinterpret_cast<Expr*>(SubExprs[INC]); }
900   Stmt *getBody() { return SubExprs[BODY]; }
901
902   const Stmt *getInit() const { return SubExprs[INIT]; }
903   const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
904   const Expr *getInc()  const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
905   const Stmt *getBody() const { return SubExprs[BODY]; }
906
907   void setInit(Stmt *S) { SubExprs[INIT] = S; }
908   void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
909   void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
910   void setBody(Stmt *S) { SubExprs[BODY] = S; }
911
912   SourceLocation getForLoc() const { return ForLoc; }
913   void setForLoc(SourceLocation L) { ForLoc = L; }
914   SourceLocation getLParenLoc() const { return LParenLoc; }
915   void setLParenLoc(SourceLocation L) { LParenLoc = L; }
916   SourceLocation getRParenLoc() const { return RParenLoc; }
917   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
918
919   virtual SourceRange getSourceRange() const {
920     return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
921   }
922   static bool classof(const Stmt *T) {
923     return T->getStmtClass() == ForStmtClass;
924   }
925   static bool classof(const ForStmt *) { return true; }
926
927   // Iterators
928   virtual child_iterator child_begin();
929   virtual child_iterator child_end();
930 };
931
932 /// GotoStmt - This represents a direct goto.
933 ///
934 class GotoStmt : public Stmt {
935   LabelStmt *Label;
936   SourceLocation GotoLoc;
937   SourceLocation LabelLoc;
938 public:
939   GotoStmt(LabelStmt *label, SourceLocation GL, SourceLocation LL)
940     : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
941
942   /// \brief Build an empty goto statement.
943   explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
944
945   LabelStmt *getLabel() const { return Label; }
946   void setLabel(LabelStmt *S) { Label = S; }
947
948   SourceLocation getGotoLoc() const { return GotoLoc; }
949   void setGotoLoc(SourceLocation L) { GotoLoc = L; }
950   SourceLocation getLabelLoc() const { return LabelLoc; }
951   void setLabelLoc(SourceLocation L) { LabelLoc = L; }
952
953   virtual SourceRange getSourceRange() const {
954     return SourceRange(GotoLoc, LabelLoc);
955   }
956   static bool classof(const Stmt *T) {
957     return T->getStmtClass() == GotoStmtClass;
958   }
959   static bool classof(const GotoStmt *) { return true; }
960
961   // Iterators
962   virtual child_iterator child_begin();
963   virtual child_iterator child_end();
964 };
965
966 /// IndirectGotoStmt - This represents an indirect goto.
967 ///
968 class IndirectGotoStmt : public Stmt {
969   SourceLocation GotoLoc;
970   SourceLocation StarLoc;
971   Stmt *Target;
972 public:
973   IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
974                    Expr *target)
975     : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
976       Target((Stmt*)target) {}
977
978   /// \brief Build an empty indirect goto statement.
979   explicit IndirectGotoStmt(EmptyShell Empty)
980     : Stmt(IndirectGotoStmtClass, Empty) { }
981
982   void setGotoLoc(SourceLocation L) { GotoLoc = L; }
983   SourceLocation getGotoLoc() const { return GotoLoc; }
984   void setStarLoc(SourceLocation L) { StarLoc = L; }
985   SourceLocation getStarLoc() const { return StarLoc; }
986
987   Expr *getTarget();
988   const Expr *getTarget() const;
989   void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
990
991   virtual SourceRange getSourceRange() const {
992     return SourceRange(GotoLoc, Target->getLocEnd());
993   }
994
995   static bool classof(const Stmt *T) {
996     return T->getStmtClass() == IndirectGotoStmtClass;
997   }
998   static bool classof(const IndirectGotoStmt *) { return true; }
999
1000   // Iterators
1001   virtual child_iterator child_begin();
1002   virtual child_iterator child_end();
1003 };
1004
1005
1006 /// ContinueStmt - This represents a continue.
1007 ///
1008 class ContinueStmt : public Stmt {
1009   SourceLocation ContinueLoc;
1010 public:
1011   ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1012
1013   /// \brief Build an empty continue statement.
1014   explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1015
1016   SourceLocation getContinueLoc() const { return ContinueLoc; }
1017   void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1018
1019   virtual SourceRange getSourceRange() const {
1020     return SourceRange(ContinueLoc);
1021   }
1022
1023   static bool classof(const Stmt *T) {
1024     return T->getStmtClass() == ContinueStmtClass;
1025   }
1026   static bool classof(const ContinueStmt *) { return true; }
1027
1028   // Iterators
1029   virtual child_iterator child_begin();
1030   virtual child_iterator child_end();
1031 };
1032
1033 /// BreakStmt - This represents a break.
1034 ///
1035 class BreakStmt : public Stmt {
1036   SourceLocation BreakLoc;
1037 public:
1038   BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1039
1040   /// \brief Build an empty break statement.
1041   explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1042
1043   SourceLocation getBreakLoc() const { return BreakLoc; }
1044   void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1045
1046   virtual SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
1047
1048   static bool classof(const Stmt *T) {
1049     return T->getStmtClass() == BreakStmtClass;
1050   }
1051   static bool classof(const BreakStmt *) { return true; }
1052
1053   // Iterators
1054   virtual child_iterator child_begin();
1055   virtual child_iterator child_end();
1056 };
1057
1058
1059 /// ReturnStmt - This represents a return, optionally of an expression:
1060 ///   return;
1061 ///   return 4;
1062 ///
1063 /// Note that GCC allows return with no argument in a function declared to
1064 /// return a value, and it allows returning a value in functions declared to
1065 /// return void.  We explicitly model this in the AST, which means you can't
1066 /// depend on the return type of the function and the presence of an argument.
1067 ///
1068 class ReturnStmt : public Stmt {
1069   Stmt *RetExpr;
1070   SourceLocation RetLoc;
1071 public:
1072   ReturnStmt(SourceLocation RL, Expr *E = 0) : Stmt(ReturnStmtClass),
1073     RetExpr((Stmt*) E), RetLoc(RL) {}
1074
1075   /// \brief Build an empty return expression.
1076   explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1077
1078   const Expr *getRetValue() const;
1079   Expr *getRetValue();
1080   void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1081
1082   SourceLocation getReturnLoc() const { return RetLoc; }
1083   void setReturnLoc(SourceLocation L) { RetLoc = L; }
1084
1085   virtual SourceRange getSourceRange() const;
1086
1087   static bool classof(const Stmt *T) {
1088     return T->getStmtClass() == ReturnStmtClass;
1089   }
1090   static bool classof(const ReturnStmt *) { return true; }
1091
1092   // Iterators
1093   virtual child_iterator child_begin();
1094   virtual child_iterator child_end();
1095 };
1096
1097 /// AsmStmt - This represents a GNU inline-assembly statement extension.
1098 ///
1099 class AsmStmt : public Stmt {
1100   SourceLocation AsmLoc, RParenLoc;
1101   StringLiteral *AsmStr;
1102
1103   bool IsSimple;
1104   bool IsVolatile;
1105
1106   unsigned NumOutputs;
1107   unsigned NumInputs;
1108
1109   llvm::SmallVector<std::string, 4> Names;
1110   llvm::SmallVector<StringLiteral*, 4> Constraints;
1111   llvm::SmallVector<Stmt*, 4> Exprs;
1112
1113   llvm::SmallVector<StringLiteral*, 4> Clobbers;
1114 public:
1115   AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile,
1116           unsigned numoutputs, unsigned numinputs,
1117           std::string *names, StringLiteral **constraints,
1118           Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1119           StringLiteral **clobbers, SourceLocation rparenloc);
1120
1121   /// \brief Build an empty inline-assembly statement.
1122   explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty) { }
1123
1124   SourceLocation getAsmLoc() const { return AsmLoc; }
1125   void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1126   SourceLocation getRParenLoc() const { return RParenLoc; }
1127   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1128
1129   bool isVolatile() const { return IsVolatile; }
1130   void setVolatile(bool V) { IsVolatile = V; }
1131   bool isSimple() const { return IsSimple; }
1132   void setSimple(bool V) { IsSimple = false; }
1133
1134   //===--- Asm String Analysis ---===//
1135
1136   const StringLiteral *getAsmString() const { return AsmStr; }
1137   StringLiteral *getAsmString() { return AsmStr; }
1138   void setAsmString(StringLiteral *E) { AsmStr = E; }
1139
1140   /// AsmStringPiece - this is part of a decomposed asm string specification
1141   /// (for use with the AnalyzeAsmString function below).  An asm string is
1142   /// considered to be a concatenation of these parts.
1143   class AsmStringPiece {
1144   public:
1145     enum Kind {
1146       String,  // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1147       Operand  // Operand reference, with optional modifier %c4.
1148     };
1149   private:
1150     Kind MyKind;
1151     std::string Str;
1152     unsigned OperandNo;
1153   public:
1154     AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1155     AsmStringPiece(unsigned OpNo, char Modifier)
1156       : MyKind(Operand), Str(), OperandNo(OpNo) {
1157       Str += Modifier;
1158     }
1159
1160     bool isString() const { return MyKind == String; }
1161     bool isOperand() const { return MyKind == Operand; }
1162
1163     const std::string &getString() const {
1164       assert(isString());
1165       return Str;
1166     }
1167
1168     unsigned getOperandNo() const {
1169       assert(isOperand());
1170       return OperandNo;
1171     }
1172
1173     /// getModifier - Get the modifier for this operand, if present.  This
1174     /// returns '\0' if there was no modifier.
1175     char getModifier() const {
1176       assert(isOperand());
1177       return Str[0];
1178     }
1179   };
1180
1181   /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1182   /// it into pieces.  If the asm string is erroneous, emit errors and return
1183   /// true, otherwise return false.  This handles canonicalization and
1184   /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1185   //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1186   unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces,
1187                             ASTContext &C, unsigned &DiagOffs) const;
1188
1189
1190   //===--- Output operands ---===//
1191
1192   unsigned getNumOutputs() const { return NumOutputs; }
1193
1194   const std::string &getOutputName(unsigned i) const {
1195     return Names[i];
1196   }
1197
1198   /// getOutputConstraint - Return the constraint string for the specified
1199   /// output operand.  All output constraints are known to be non-empty (either
1200   /// '=' or '+').
1201   std::string getOutputConstraint(unsigned i) const;
1202
1203   const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1204     return Constraints[i];
1205   }
1206   StringLiteral *getOutputConstraintLiteral(unsigned i) {
1207     return Constraints[i];
1208   }
1209
1210
1211   Expr *getOutputExpr(unsigned i);
1212
1213   const Expr *getOutputExpr(unsigned i) const {
1214     return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1215   }
1216
1217   /// isOutputPlusConstraint - Return true if the specified output constraint
1218   /// is a "+" constraint (which is both an input and an output) or false if it
1219   /// is an "=" constraint (just an output).
1220   bool isOutputPlusConstraint(unsigned i) const {
1221     return getOutputConstraint(i)[0] == '+';
1222   }
1223
1224   /// getNumPlusOperands - Return the number of output operands that have a "+"
1225   /// constraint.
1226   unsigned getNumPlusOperands() const;
1227
1228   //===--- Input operands ---===//
1229
1230   unsigned getNumInputs() const { return NumInputs; }
1231
1232   const std::string &getInputName(unsigned i) const {
1233     return Names[i + NumOutputs];
1234   }
1235
1236   /// getInputConstraint - Return the specified input constraint.  Unlike output
1237   /// constraints, these can be empty.
1238   std::string getInputConstraint(unsigned i) const;
1239
1240   const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1241     return Constraints[i + NumOutputs];
1242   }
1243   StringLiteral *getInputConstraintLiteral(unsigned i) {
1244     return Constraints[i + NumOutputs];
1245   }
1246
1247
1248   Expr *getInputExpr(unsigned i);
1249
1250   const Expr *getInputExpr(unsigned i) const {
1251     return const_cast<AsmStmt*>(this)->getInputExpr(i);
1252   }
1253
1254   void setOutputsAndInputs(unsigned NumOutputs,
1255                            unsigned NumInputs,
1256                            const std::string *Names,
1257                            StringLiteral **Constraints,
1258                            Stmt **Exprs);
1259
1260   //===--- Other ---===//
1261
1262   /// getNamedOperand - Given a symbolic operand reference like %[foo],
1263   /// translate this into a numeric value needed to reference the same operand.
1264   /// This returns -1 if the operand name is invalid.
1265   int getNamedOperand(const std::string &SymbolicName) const;
1266
1267
1268
1269   unsigned getNumClobbers() const { return Clobbers.size(); }
1270   StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1271   const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1272   void setClobbers(StringLiteral **Clobbers, unsigned NumClobbers);
1273
1274   virtual SourceRange getSourceRange() const {
1275     return SourceRange(AsmLoc, RParenLoc);
1276   }
1277
1278   static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1279   static bool classof(const AsmStmt *) { return true; }
1280
1281   // Input expr iterators.
1282
1283   typedef ExprIterator inputs_iterator;
1284   typedef ConstExprIterator const_inputs_iterator;
1285
1286   inputs_iterator begin_inputs() {
1287     return Exprs.data() + NumOutputs;
1288   }
1289
1290   inputs_iterator end_inputs() {
1291     return Exprs.data() + NumOutputs + NumInputs;
1292   }
1293
1294   const_inputs_iterator begin_inputs() const {
1295     return Exprs.data() + NumOutputs;
1296   }
1297
1298   const_inputs_iterator end_inputs() const {
1299     return Exprs.data() + NumOutputs + NumInputs;
1300   }
1301
1302   // Output expr iterators.
1303
1304   typedef ExprIterator outputs_iterator;
1305   typedef ConstExprIterator const_outputs_iterator;
1306
1307   outputs_iterator begin_outputs() {
1308     return Exprs.data();
1309   }
1310   outputs_iterator end_outputs() {
1311     return Exprs.data() + NumOutputs;
1312   }
1313
1314   const_outputs_iterator begin_outputs() const {
1315     return Exprs.data();
1316   }
1317   const_outputs_iterator end_outputs() const {
1318     return Exprs.data() + NumOutputs;
1319   }
1320
1321   // Input name iterator.
1322
1323   const std::string *begin_output_names() const {
1324     return &Names[0];
1325   }
1326
1327   const std::string *end_output_names() const {
1328     return &Names[0] + NumOutputs;
1329   }
1330
1331   // Child iterators
1332
1333   virtual child_iterator child_begin();
1334   virtual child_iterator child_end();
1335 };
1336
1337 }  // end namespace clang
1338
1339 #endif