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