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