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