1 //===--- Stmt.h - Classes for representing statements -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Stmt interface and subclasses.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_AST_STMT_H
15 #define LLVM_CLANG_AST_STMT_H
17 #include "clang/Basic/LLVM.h"
18 #include "clang/Basic/SourceLocation.h"
19 #include "clang/AST/PrettyPrinter.h"
20 #include "clang/AST/StmtIterator.h"
21 #include "clang/AST/DeclGroup.h"
22 #include "clang/AST/ASTContext.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/ADT/SmallVector.h"
28 class FoldingSetNodeID;
42 //===----------------------------------------------------------------------===//
43 // ExprIterator - Iterators for iterating over Stmt* arrays that contain
44 // only Expr*. This is needed because AST nodes use Stmt* arrays to store
45 // references to children (to be compatible with StmtIterator).
46 //===----------------------------------------------------------------------===//
54 ExprIterator(Stmt** i) : I(i) {}
55 ExprIterator() : I(0) {}
56 ExprIterator& operator++() { ++I; return *this; }
57 ExprIterator operator-(size_t i) { return I-i; }
58 ExprIterator operator+(size_t i) { return I+i; }
59 Expr* operator[](size_t idx);
60 // FIXME: Verify that this will correctly return a signed distance.
61 signed operator-(const ExprIterator& R) const { return I - R.I; }
62 Expr* operator*() const;
63 Expr* operator->() const;
64 bool operator==(const ExprIterator& R) const { return I == R.I; }
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; }
70 class ConstExprIterator {
71 const Stmt * const *I;
73 ConstExprIterator(const Stmt * const *i) : I(i) {}
74 ConstExprIterator() : I(0) {}
75 ConstExprIterator& operator++() { ++I; return *this; }
76 ConstExprIterator operator+(size_t i) const { return I+i; }
77 ConstExprIterator operator-(size_t i) const { return I-i; }
78 const Expr * operator[](size_t idx) const;
79 signed operator-(const ConstExprIterator& R) const { return I - R.I; }
80 const Expr * operator*() const;
81 const Expr * operator->() const;
82 bool operator==(const ConstExprIterator& R) const { return I == R.I; }
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; }
88 //===----------------------------------------------------------------------===//
89 // AST classes for statements.
90 //===----------------------------------------------------------------------===//
92 /// Stmt - This represents one statement.
98 #define STMT(CLASS, PARENT) CLASS##Class,
99 #define STMT_RANGE(BASE, FIRST, LAST) \
100 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
101 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
102 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
103 #define ABSTRACT_STMT(STMT)
104 #include "clang/AST/StmtNodes.inc"
107 // Make vanilla 'new' and 'delete' illegal for Stmts.
109 void* operator new(size_t bytes) throw() {
110 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
112 void operator delete(void* data) throw() {
113 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
116 class StmtBitfields {
119 /// \brief The statement class.
122 enum { NumStmtBits = 8 };
124 class CompoundStmtBitfields {
125 friend class CompoundStmt;
126 unsigned : NumStmtBits;
128 unsigned NumStmts : 32 - NumStmtBits;
131 class ExprBitfields {
133 friend class DeclRefExpr; // computeDependence
134 friend class InitListExpr; // ctor
135 friend class DesignatedInitExpr; // ctor
136 friend class BlockDeclRefExpr; // ctor
137 friend class ASTStmtReader; // deserialization
138 friend class CXXNewExpr; // ctor
139 friend class DependentScopeDeclRefExpr; // ctor
140 friend class CXXConstructExpr; // ctor
141 friend class CallExpr; // ctor
142 friend class OffsetOfExpr; // ctor
143 friend class ObjCMessageExpr; // ctor
144 friend class ShuffleVectorExpr; // ctor
145 friend class ParenListExpr; // ctor
146 friend class CXXUnresolvedConstructExpr; // ctor
147 friend class CXXDependentScopeMemberExpr; // ctor
148 friend class OverloadExpr; // ctor
149 friend class AtomicExpr; // ctor
150 unsigned : NumStmtBits;
152 unsigned ValueKind : 2;
153 unsigned ObjectKind : 2;
154 unsigned TypeDependent : 1;
155 unsigned ValueDependent : 1;
156 unsigned InstantiationDependent : 1;
157 unsigned ContainsUnexpandedParameterPack : 1;
159 enum { NumExprBits = 16 };
161 class DeclRefExprBitfields {
162 friend class DeclRefExpr;
163 friend class ASTStmtReader; // deserialization
164 unsigned : NumExprBits;
166 unsigned HasQualifier : 1;
167 unsigned HasExplicitTemplateArgs : 1;
168 unsigned HasFoundDecl : 1;
169 unsigned HadMultipleCandidates : 1;
172 class CastExprBitfields {
173 friend class CastExpr;
174 unsigned : NumExprBits;
177 unsigned BasePathSize : 32 - 6 - NumExprBits;
180 class CallExprBitfields {
181 friend class CallExpr;
182 unsigned : NumExprBits;
184 unsigned NumPreArgs : 1;
187 class ObjCIndirectCopyRestoreExprBitfields {
188 friend class ObjCIndirectCopyRestoreExpr;
189 unsigned : NumExprBits;
191 unsigned ShouldCopy : 1;
195 // FIXME: this is wasteful on 64-bit platforms.
198 StmtBitfields StmtBits;
199 CompoundStmtBitfields CompoundStmtBits;
200 ExprBitfields ExprBits;
201 DeclRefExprBitfields DeclRefExprBits;
202 CastExprBitfields CastExprBits;
203 CallExprBitfields CallExprBits;
204 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
207 friend class ASTStmtReader;
210 // Only allow allocation of Stmts using the allocator in ASTContext
211 // or by doing a placement new.
212 void* operator new(size_t bytes, ASTContext& C,
213 unsigned alignment = 8) throw() {
214 return ::operator new(bytes, C, alignment);
217 void* operator new(size_t bytes, ASTContext* C,
218 unsigned alignment = 8) throw() {
219 return ::operator new(bytes, *C, alignment);
222 void* operator new(size_t bytes, void* mem) throw() {
226 void operator delete(void*, ASTContext&, unsigned) throw() { }
227 void operator delete(void*, ASTContext*, unsigned) throw() { }
228 void operator delete(void*, std::size_t) throw() { }
229 void operator delete(void*, void*) throw() { }
232 /// \brief A placeholder type used to construct an empty shell of a
233 /// type, that will be filled in later (e.g., by some
234 /// de-serialization).
235 struct EmptyShell { };
238 /// \brief Construct an empty statement.
239 explicit Stmt(StmtClass SC, EmptyShell) {
240 StmtBits.sClass = SC;
241 if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
246 StmtBits.sClass = SC;
247 if (Stmt::CollectingStats()) Stmt::addStmtClass(SC);
250 StmtClass getStmtClass() const {
251 return static_cast<StmtClass>(StmtBits.sClass);
253 const char *getStmtClassName() const;
255 /// SourceLocation tokens are not useful in isolation - they are low level
256 /// value objects created/interpreted by SourceManager. We assume AST
257 /// clients will have a pointer to the respective SourceManager.
258 SourceRange getSourceRange() const;
260 SourceLocation getLocStart() const { return getSourceRange().getBegin(); }
261 SourceLocation getLocEnd() const { return getSourceRange().getEnd(); }
263 // global temp stats (until we have a per-module visitor)
264 static void addStmtClass(const StmtClass s);
265 static bool CollectingStats(bool Enable = false);
266 static void PrintStats();
268 /// dump - This does a local dump of the specified AST fragment. It dumps the
269 /// specified node and a few nodes underneath it, but not the whole subtree.
270 /// This is useful in a debugger.
272 void dump(SourceManager &SM) const;
273 void dump(raw_ostream &OS, SourceManager &SM) const;
275 /// dumpAll - This does a dump of the specified AST fragment and all subtrees.
276 void dumpAll() const;
277 void dumpAll(SourceManager &SM) const;
279 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
280 /// back to its original source language syntax.
281 void dumpPretty(ASTContext& Context) const;
282 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
283 const PrintingPolicy &Policy,
284 unsigned Indentation = 0) const {
285 printPretty(OS, *(ASTContext*)0, Helper, Policy, Indentation);
287 void printPretty(raw_ostream &OS, ASTContext &Context,
288 PrinterHelper *Helper,
289 const PrintingPolicy &Policy,
290 unsigned Indentation = 0) const;
292 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
293 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
294 void viewAST() const;
296 /// Skip past any implicit AST nodes which might surround this
297 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
298 Stmt *IgnoreImplicit();
300 const Stmt *stripLabelLikeStatements() const;
301 Stmt *stripLabelLikeStatements() {
302 return const_cast<Stmt*>(
303 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
306 // Implement isa<T> support.
307 static bool classof(const Stmt *) { return true; }
309 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
310 /// contain implicit control-flow in the order their subexpressions
311 /// are evaluated. This predicate returns true if this statement has
312 /// such implicit control-flow. Such statements are also specially handled
314 bool hasImplicitControlFlow() const;
316 /// Child Iterators: All subclasses must implement 'children'
317 /// to permit easy iteration over the substatements/subexpessions of an
318 /// AST node. This permits easy iteration over all nodes in the AST.
319 typedef StmtIterator child_iterator;
320 typedef ConstStmtIterator const_child_iterator;
322 typedef StmtRange child_range;
323 typedef ConstStmtRange const_child_range;
325 child_range children();
326 const_child_range children() const {
327 return const_cast<Stmt*>(this)->children();
330 child_iterator child_begin() { return children().first; }
331 child_iterator child_end() { return children().second; }
333 const_child_iterator child_begin() const { return children().first; }
334 const_child_iterator child_end() const { return children().second; }
336 /// \brief Produce a unique representation of the given statement.
338 /// \brief ID once the profiling operation is complete, will contain
339 /// the unique representation of the given statement.
341 /// \brief Context the AST context in which the statement resides
343 /// \brief Canonical whether the profile should be based on the canonical
344 /// representation of this statement (e.g., where non-type template
345 /// parameters are identified by index/level rather than their
346 /// declaration pointers) or the exact representation of the statement as
347 /// written in the source.
348 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
349 bool Canonical) const;
352 /// DeclStmt - Adaptor class for mixing declarations with statements and
353 /// expressions. For example, CompoundStmt mixes statements, expressions
354 /// and declarations (variables, types). Another example is ForStmt, where
355 /// the first statement can be an expression or a declaration.
357 class DeclStmt : public Stmt {
359 SourceLocation StartLoc, EndLoc;
362 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
363 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
364 StartLoc(startLoc), EndLoc(endLoc) {}
366 /// \brief Build an empty declaration statement.
367 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
369 /// isSingleDecl - This method returns true if this DeclStmt refers
370 /// to a single Decl.
371 bool isSingleDecl() const {
372 return DG.isSingleDecl();
375 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
376 Decl *getSingleDecl() { return DG.getSingleDecl(); }
378 const DeclGroupRef getDeclGroup() const { return DG; }
379 DeclGroupRef getDeclGroup() { return DG; }
380 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
382 SourceLocation getStartLoc() const { return StartLoc; }
383 void setStartLoc(SourceLocation L) { StartLoc = L; }
384 SourceLocation getEndLoc() const { return EndLoc; }
385 void setEndLoc(SourceLocation L) { EndLoc = L; }
387 SourceRange getSourceRange() const {
388 return SourceRange(StartLoc, EndLoc);
391 static bool classof(const Stmt *T) {
392 return T->getStmtClass() == DeclStmtClass;
394 static bool classof(const DeclStmt *) { return true; }
396 // Iterators over subexpressions.
397 child_range children() {
398 return child_range(child_iterator(DG.begin(), DG.end()),
399 child_iterator(DG.end(), DG.end()));
402 typedef DeclGroupRef::iterator decl_iterator;
403 typedef DeclGroupRef::const_iterator const_decl_iterator;
405 decl_iterator decl_begin() { return DG.begin(); }
406 decl_iterator decl_end() { return DG.end(); }
407 const_decl_iterator decl_begin() const { return DG.begin(); }
408 const_decl_iterator decl_end() const { return DG.end(); }
411 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
413 class NullStmt : public Stmt {
414 SourceLocation SemiLoc;
416 /// \brief True if the null statement was preceded by an empty macro, e.g:
421 bool HasLeadingEmptyMacro;
423 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
424 : Stmt(NullStmtClass), SemiLoc(L),
425 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
427 /// \brief Build an empty null statement.
428 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
429 HasLeadingEmptyMacro(false) { }
431 SourceLocation getSemiLoc() const { return SemiLoc; }
432 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
434 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
436 SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
438 static bool classof(const Stmt *T) {
439 return T->getStmtClass() == NullStmtClass;
441 static bool classof(const NullStmt *) { return true; }
443 child_range children() { return child_range(); }
445 friend class ASTStmtReader;
446 friend class ASTStmtWriter;
449 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
451 class CompoundStmt : public Stmt {
453 SourceLocation LBracLoc, RBracLoc;
455 CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts,
456 SourceLocation LB, SourceLocation RB)
457 : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
458 CompoundStmtBits.NumStmts = NumStmts;
459 assert(CompoundStmtBits.NumStmts == NumStmts &&
460 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
467 Body = new (C) Stmt*[NumStmts];
468 memcpy(Body, StmtStart, NumStmts * sizeof(*Body));
471 // \brief Build an empty compound statement.
472 explicit CompoundStmt(EmptyShell Empty)
473 : Stmt(CompoundStmtClass, Empty), Body(0) {
474 CompoundStmtBits.NumStmts = 0;
477 void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
479 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
480 unsigned size() const { return CompoundStmtBits.NumStmts; }
482 typedef Stmt** body_iterator;
483 body_iterator body_begin() { return Body; }
484 body_iterator body_end() { return Body + size(); }
485 Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
487 void setLastStmt(Stmt *S) {
488 assert(!body_empty() && "setLastStmt");
492 typedef Stmt* const * const_body_iterator;
493 const_body_iterator body_begin() const { return Body; }
494 const_body_iterator body_end() const { return Body + size(); }
495 const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
497 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
498 reverse_body_iterator body_rbegin() {
499 return reverse_body_iterator(body_end());
501 reverse_body_iterator body_rend() {
502 return reverse_body_iterator(body_begin());
505 typedef std::reverse_iterator<const_body_iterator>
506 const_reverse_body_iterator;
508 const_reverse_body_iterator body_rbegin() const {
509 return const_reverse_body_iterator(body_end());
512 const_reverse_body_iterator body_rend() const {
513 return const_reverse_body_iterator(body_begin());
516 SourceRange getSourceRange() const {
517 return SourceRange(LBracLoc, RBracLoc);
520 SourceLocation getLBracLoc() const { return LBracLoc; }
521 void setLBracLoc(SourceLocation L) { LBracLoc = L; }
522 SourceLocation getRBracLoc() const { return RBracLoc; }
523 void setRBracLoc(SourceLocation L) { RBracLoc = L; }
525 static bool classof(const Stmt *T) {
526 return T->getStmtClass() == CompoundStmtClass;
528 static bool classof(const CompoundStmt *) { return true; }
531 child_range children() {
532 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
535 const_child_range children() const {
536 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
540 // SwitchCase is the base class for CaseStmt and DefaultStmt,
541 class SwitchCase : public Stmt {
543 // A pointer to the following CaseStmt or DefaultStmt class,
544 // used by SwitchStmt.
545 SwitchCase *NextSwitchCase;
547 SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
550 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
552 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
554 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
557 const Stmt *getSubStmt() const {
558 return const_cast<SwitchCase*>(this)->getSubStmt();
561 SourceRange getSourceRange() const { return SourceRange(); }
563 static bool classof(const Stmt *T) {
564 return T->getStmtClass() == CaseStmtClass ||
565 T->getStmtClass() == DefaultStmtClass;
567 static bool classof(const SwitchCase *) { return true; }
570 class CaseStmt : public SwitchCase {
571 enum { LHS, RHS, SUBSTMT, END_EXPR };
572 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
573 // GNU "case 1 ... 4" extension
574 SourceLocation CaseLoc;
575 SourceLocation EllipsisLoc;
576 SourceLocation ColonLoc;
578 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
579 SourceLocation ellipsisLoc, SourceLocation colonLoc)
580 : SwitchCase(CaseStmtClass) {
581 SubExprs[SUBSTMT] = 0;
582 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
583 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
585 EllipsisLoc = ellipsisLoc;
589 /// \brief Build an empty switch case statement.
590 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
592 SourceLocation getCaseLoc() const { return CaseLoc; }
593 void setCaseLoc(SourceLocation L) { CaseLoc = L; }
594 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
595 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
596 SourceLocation getColonLoc() const { return ColonLoc; }
597 void setColonLoc(SourceLocation L) { ColonLoc = L; }
599 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
600 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
601 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
603 const Expr *getLHS() const {
604 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
606 const Expr *getRHS() const {
607 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
609 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
611 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
612 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
613 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
616 SourceRange getSourceRange() const {
617 // Handle deeply nested case statements with iteration instead of recursion.
618 const CaseStmt *CS = this;
619 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
622 return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
624 static bool classof(const Stmt *T) {
625 return T->getStmtClass() == CaseStmtClass;
627 static bool classof(const CaseStmt *) { return true; }
630 child_range children() {
631 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
635 class DefaultStmt : public SwitchCase {
637 SourceLocation DefaultLoc;
638 SourceLocation ColonLoc;
640 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
641 SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
644 /// \brief Build an empty default statement.
645 explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
647 Stmt *getSubStmt() { return SubStmt; }
648 const Stmt *getSubStmt() const { return SubStmt; }
649 void setSubStmt(Stmt *S) { SubStmt = S; }
651 SourceLocation getDefaultLoc() const { return DefaultLoc; }
652 void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
653 SourceLocation getColonLoc() const { return ColonLoc; }
654 void setColonLoc(SourceLocation L) { ColonLoc = L; }
656 SourceRange getSourceRange() const {
657 return SourceRange(DefaultLoc, SubStmt->getLocEnd());
659 static bool classof(const Stmt *T) {
660 return T->getStmtClass() == DefaultStmtClass;
662 static bool classof(const DefaultStmt *) { return true; }
665 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
669 /// LabelStmt - Represents a label, which has a substatement. For example:
672 class LabelStmt : public Stmt {
675 SourceLocation IdentLoc;
677 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
678 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
681 // \brief Build an empty label statement.
682 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
684 SourceLocation getIdentLoc() const { return IdentLoc; }
685 LabelDecl *getDecl() const { return TheDecl; }
686 void setDecl(LabelDecl *D) { TheDecl = D; }
687 const char *getName() const;
688 Stmt *getSubStmt() { return SubStmt; }
689 const Stmt *getSubStmt() const { return SubStmt; }
690 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
691 void setSubStmt(Stmt *SS) { SubStmt = SS; }
693 SourceRange getSourceRange() const {
694 return SourceRange(IdentLoc, SubStmt->getLocEnd());
696 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
698 static bool classof(const Stmt *T) {
699 return T->getStmtClass() == LabelStmtClass;
701 static bool classof(const LabelStmt *) { return true; }
705 /// IfStmt - This represents an if/then/else.
707 class IfStmt : public Stmt {
708 enum { VAR, COND, THEN, ELSE, END_EXPR };
709 Stmt* SubExprs[END_EXPR];
711 SourceLocation IfLoc;
712 SourceLocation ElseLoc;
715 IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
716 Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
718 /// \brief Build an empty if/then/else statement
719 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
721 /// \brief Retrieve the variable declared in this "if" statement, if any.
723 /// In the following example, "x" is the condition variable.
725 /// if (int x = foo()) {
726 /// printf("x is %d", x);
729 VarDecl *getConditionVariable() const;
730 void setConditionVariable(ASTContext &C, VarDecl *V);
732 /// If this IfStmt has a condition variable, return the faux DeclStmt
733 /// associated with the creation of that condition variable.
734 const DeclStmt *getConditionVariableDeclStmt() const {
735 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
738 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
739 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
740 const Stmt *getThen() const { return SubExprs[THEN]; }
741 void setThen(Stmt *S) { SubExprs[THEN] = S; }
742 const Stmt *getElse() const { return SubExprs[ELSE]; }
743 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
745 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
746 Stmt *getThen() { return SubExprs[THEN]; }
747 Stmt *getElse() { return SubExprs[ELSE]; }
749 SourceLocation getIfLoc() const { return IfLoc; }
750 void setIfLoc(SourceLocation L) { IfLoc = L; }
751 SourceLocation getElseLoc() const { return ElseLoc; }
752 void setElseLoc(SourceLocation L) { ElseLoc = L; }
754 SourceRange getSourceRange() const {
756 return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
758 return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
761 // Iterators over subexpressions. The iterators will include iterating
762 // over the initialization expression referenced by the condition variable.
763 child_range children() {
764 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
767 static bool classof(const Stmt *T) {
768 return T->getStmtClass() == IfStmtClass;
770 static bool classof(const IfStmt *) { return true; }
773 /// SwitchStmt - This represents a 'switch' stmt.
775 class SwitchStmt : public Stmt {
776 enum { VAR, COND, BODY, END_EXPR };
777 Stmt* SubExprs[END_EXPR];
778 // This points to a linked list of case and default statements.
779 SwitchCase *FirstCase;
780 SourceLocation SwitchLoc;
782 /// If the SwitchStmt is a switch on an enum value, this records whether
783 /// all the enum values were covered by CaseStmts. This value is meant to
784 /// be a hint for possible clients.
785 unsigned AllEnumCasesCovered : 1;
788 SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
790 /// \brief Build a empty switch statement.
791 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
793 /// \brief Retrieve the variable declared in this "switch" statement, if any.
795 /// In the following example, "x" is the condition variable.
797 /// switch (int x = foo()) {
802 VarDecl *getConditionVariable() const;
803 void setConditionVariable(ASTContext &C, VarDecl *V);
805 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
806 /// associated with the creation of that condition variable.
807 const DeclStmt *getConditionVariableDeclStmt() const {
808 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
811 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
812 const Stmt *getBody() const { return SubExprs[BODY]; }
813 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
815 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
816 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
817 Stmt *getBody() { return SubExprs[BODY]; }
818 void setBody(Stmt *S) { SubExprs[BODY] = S; }
819 SwitchCase *getSwitchCaseList() { return FirstCase; }
821 /// \brief Set the case list for this switch statement.
823 /// The caller is responsible for incrementing the retain counts on
824 /// all of the SwitchCase statements in this list.
825 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
827 SourceLocation getSwitchLoc() const { return SwitchLoc; }
828 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
830 void setBody(Stmt *S, SourceLocation SL) {
834 void addSwitchCase(SwitchCase *SC) {
835 assert(!SC->getNextSwitchCase() && "case/default already added to a switch");
836 SC->setNextSwitchCase(FirstCase);
840 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
841 /// switch over an enum value then all cases have been explicitly covered.
842 void setAllEnumCasesCovered() {
843 AllEnumCasesCovered = 1;
846 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
847 /// have been explicitly covered.
848 bool isAllEnumCasesCovered() const {
849 return (bool) AllEnumCasesCovered;
852 SourceRange getSourceRange() const {
853 return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
856 child_range children() {
857 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
860 static bool classof(const Stmt *T) {
861 return T->getStmtClass() == SwitchStmtClass;
863 static bool classof(const SwitchStmt *) { return true; }
867 /// WhileStmt - This represents a 'while' stmt.
869 class WhileStmt : public Stmt {
870 enum { VAR, COND, BODY, END_EXPR };
871 Stmt* SubExprs[END_EXPR];
872 SourceLocation WhileLoc;
874 WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
877 /// \brief Build an empty while statement.
878 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
880 /// \brief Retrieve the variable declared in this "while" statement, if any.
882 /// In the following example, "x" is the condition variable.
884 /// while (int x = random()) {
888 VarDecl *getConditionVariable() const;
889 void setConditionVariable(ASTContext &C, VarDecl *V);
891 /// If this WhileStmt has a condition variable, return the faux DeclStmt
892 /// associated with the creation of that condition variable.
893 const DeclStmt *getConditionVariableDeclStmt() const {
894 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
897 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
898 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
899 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
900 Stmt *getBody() { return SubExprs[BODY]; }
901 const Stmt *getBody() const { return SubExprs[BODY]; }
902 void setBody(Stmt *S) { SubExprs[BODY] = S; }
904 SourceLocation getWhileLoc() const { return WhileLoc; }
905 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
907 SourceRange getSourceRange() const {
908 return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
910 static bool classof(const Stmt *T) {
911 return T->getStmtClass() == WhileStmtClass;
913 static bool classof(const WhileStmt *) { return true; }
916 child_range children() {
917 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
921 /// DoStmt - This represents a 'do/while' stmt.
923 class DoStmt : public Stmt {
924 enum { BODY, COND, END_EXPR };
925 Stmt* SubExprs[END_EXPR];
926 SourceLocation DoLoc;
927 SourceLocation WhileLoc;
928 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
931 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
933 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
934 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
935 SubExprs[BODY] = body;
938 /// \brief Build an empty do-while statement.
939 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
941 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
942 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
943 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
944 Stmt *getBody() { return SubExprs[BODY]; }
945 const Stmt *getBody() const { return SubExprs[BODY]; }
946 void setBody(Stmt *S) { SubExprs[BODY] = S; }
948 SourceLocation getDoLoc() const { return DoLoc; }
949 void setDoLoc(SourceLocation L) { DoLoc = L; }
950 SourceLocation getWhileLoc() const { return WhileLoc; }
951 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
953 SourceLocation getRParenLoc() const { return RParenLoc; }
954 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
956 SourceRange getSourceRange() const {
957 return SourceRange(DoLoc, RParenLoc);
959 static bool classof(const Stmt *T) {
960 return T->getStmtClass() == DoStmtClass;
962 static bool classof(const DoStmt *) { return true; }
965 child_range children() {
966 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
971 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
972 /// the init/cond/inc parts of the ForStmt will be null if they were not
973 /// specified in the source.
975 class ForStmt : public Stmt {
976 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
977 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
978 SourceLocation ForLoc;
979 SourceLocation LParenLoc, RParenLoc;
982 ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
983 Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
985 /// \brief Build an empty for statement.
986 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
988 Stmt *getInit() { return SubExprs[INIT]; }
990 /// \brief Retrieve the variable declared in this "for" statement, if any.
992 /// In the following example, "y" is the condition variable.
994 /// for (int x = random(); int y = mangle(x); ++x) {
998 VarDecl *getConditionVariable() const;
999 void setConditionVariable(ASTContext &C, VarDecl *V);
1001 /// If this ForStmt has a condition variable, return the faux DeclStmt
1002 /// associated with the creation of that condition variable.
1003 const DeclStmt *getConditionVariableDeclStmt() const {
1004 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1007 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1008 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1009 Stmt *getBody() { return SubExprs[BODY]; }
1011 const Stmt *getInit() const { return SubExprs[INIT]; }
1012 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1013 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1014 const Stmt *getBody() const { return SubExprs[BODY]; }
1016 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1017 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1018 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1019 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1021 SourceLocation getForLoc() const { return ForLoc; }
1022 void setForLoc(SourceLocation L) { ForLoc = L; }
1023 SourceLocation getLParenLoc() const { return LParenLoc; }
1024 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1025 SourceLocation getRParenLoc() const { return RParenLoc; }
1026 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1028 SourceRange getSourceRange() const {
1029 return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1031 static bool classof(const Stmt *T) {
1032 return T->getStmtClass() == ForStmtClass;
1034 static bool classof(const ForStmt *) { return true; }
1037 child_range children() {
1038 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1042 /// GotoStmt - This represents a direct goto.
1044 class GotoStmt : public Stmt {
1046 SourceLocation GotoLoc;
1047 SourceLocation LabelLoc;
1049 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1050 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1052 /// \brief Build an empty goto statement.
1053 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1055 LabelDecl *getLabel() const { return Label; }
1056 void setLabel(LabelDecl *D) { Label = D; }
1058 SourceLocation getGotoLoc() const { return GotoLoc; }
1059 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1060 SourceLocation getLabelLoc() const { return LabelLoc; }
1061 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1063 SourceRange getSourceRange() const {
1064 return SourceRange(GotoLoc, LabelLoc);
1066 static bool classof(const Stmt *T) {
1067 return T->getStmtClass() == GotoStmtClass;
1069 static bool classof(const GotoStmt *) { return true; }
1072 child_range children() { return child_range(); }
1075 /// IndirectGotoStmt - This represents an indirect goto.
1077 class IndirectGotoStmt : public Stmt {
1078 SourceLocation GotoLoc;
1079 SourceLocation StarLoc;
1082 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1084 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1085 Target((Stmt*)target) {}
1087 /// \brief Build an empty indirect goto statement.
1088 explicit IndirectGotoStmt(EmptyShell Empty)
1089 : Stmt(IndirectGotoStmtClass, Empty) { }
1091 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1092 SourceLocation getGotoLoc() const { return GotoLoc; }
1093 void setStarLoc(SourceLocation L) { StarLoc = L; }
1094 SourceLocation getStarLoc() const { return StarLoc; }
1096 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1097 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1098 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1100 /// getConstantTarget - Returns the fixed target of this indirect
1101 /// goto, if one exists.
1102 LabelDecl *getConstantTarget();
1103 const LabelDecl *getConstantTarget() const {
1104 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1107 SourceRange getSourceRange() const {
1108 return SourceRange(GotoLoc, Target->getLocEnd());
1111 static bool classof(const Stmt *T) {
1112 return T->getStmtClass() == IndirectGotoStmtClass;
1114 static bool classof(const IndirectGotoStmt *) { return true; }
1117 child_range children() { return child_range(&Target, &Target+1); }
1121 /// ContinueStmt - This represents a continue.
1123 class ContinueStmt : public Stmt {
1124 SourceLocation ContinueLoc;
1126 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1128 /// \brief Build an empty continue statement.
1129 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1131 SourceLocation getContinueLoc() const { return ContinueLoc; }
1132 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1134 SourceRange getSourceRange() const {
1135 return SourceRange(ContinueLoc);
1138 static bool classof(const Stmt *T) {
1139 return T->getStmtClass() == ContinueStmtClass;
1141 static bool classof(const ContinueStmt *) { return true; }
1144 child_range children() { return child_range(); }
1147 /// BreakStmt - This represents a break.
1149 class BreakStmt : public Stmt {
1150 SourceLocation BreakLoc;
1152 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1154 /// \brief Build an empty break statement.
1155 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1157 SourceLocation getBreakLoc() const { return BreakLoc; }
1158 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1160 SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
1162 static bool classof(const Stmt *T) {
1163 return T->getStmtClass() == BreakStmtClass;
1165 static bool classof(const BreakStmt *) { return true; }
1168 child_range children() { return child_range(); }
1172 /// ReturnStmt - This represents a return, optionally of an expression:
1176 /// Note that GCC allows return with no argument in a function declared to
1177 /// return a value, and it allows returning a value in functions declared to
1178 /// return void. We explicitly model this in the AST, which means you can't
1179 /// depend on the return type of the function and the presence of an argument.
1181 class ReturnStmt : public Stmt {
1183 SourceLocation RetLoc;
1184 const VarDecl *NRVOCandidate;
1187 ReturnStmt(SourceLocation RL)
1188 : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1190 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1191 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1192 NRVOCandidate(NRVOCandidate) {}
1194 /// \brief Build an empty return expression.
1195 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1197 const Expr *getRetValue() const;
1198 Expr *getRetValue();
1199 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1201 SourceLocation getReturnLoc() const { return RetLoc; }
1202 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1204 /// \brief Retrieve the variable that might be used for the named return
1205 /// value optimization.
1207 /// The optimization itself can only be performed if the variable is
1208 /// also marked as an NRVO object.
1209 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1210 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1212 SourceRange getSourceRange() const;
1214 static bool classof(const Stmt *T) {
1215 return T->getStmtClass() == ReturnStmtClass;
1217 static bool classof(const ReturnStmt *) { return true; }
1220 child_range children() {
1221 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1222 return child_range();
1226 /// AsmStmt - This represents a GNU inline-assembly statement extension.
1228 class AsmStmt : public Stmt {
1229 SourceLocation AsmLoc, RParenLoc;
1230 StringLiteral *AsmStr;
1236 unsigned NumOutputs;
1238 unsigned NumClobbers;
1240 // FIXME: If we wanted to, we could allocate all of these in one big array.
1241 IdentifierInfo **Names;
1242 StringLiteral **Constraints;
1244 StringLiteral **Clobbers;
1247 AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
1248 bool msasm, unsigned numoutputs, unsigned numinputs,
1249 IdentifierInfo **names, StringLiteral **constraints,
1250 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1251 StringLiteral **clobbers, SourceLocation rparenloc);
1253 /// \brief Build an empty inline-assembly statement.
1254 explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
1255 Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
1257 SourceLocation getAsmLoc() const { return AsmLoc; }
1258 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1259 SourceLocation getRParenLoc() const { return RParenLoc; }
1260 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1262 bool isVolatile() const { return IsVolatile; }
1263 void setVolatile(bool V) { IsVolatile = V; }
1264 bool isSimple() const { return IsSimple; }
1265 void setSimple(bool V) { IsSimple = V; }
1266 bool isMSAsm() const { return MSAsm; }
1267 void setMSAsm(bool V) { MSAsm = V; }
1269 //===--- Asm String Analysis ---===//
1271 const StringLiteral *getAsmString() const { return AsmStr; }
1272 StringLiteral *getAsmString() { return AsmStr; }
1273 void setAsmString(StringLiteral *E) { AsmStr = E; }
1275 /// AsmStringPiece - this is part of a decomposed asm string specification
1276 /// (for use with the AnalyzeAsmString function below). An asm string is
1277 /// considered to be a concatenation of these parts.
1278 class AsmStringPiece {
1281 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1282 Operand // Operand reference, with optional modifier %c4.
1289 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1290 AsmStringPiece(unsigned OpNo, char Modifier)
1291 : MyKind(Operand), Str(), OperandNo(OpNo) {
1295 bool isString() const { return MyKind == String; }
1296 bool isOperand() const { return MyKind == Operand; }
1298 const std::string &getString() const {
1303 unsigned getOperandNo() const {
1304 assert(isOperand());
1308 /// getModifier - Get the modifier for this operand, if present. This
1309 /// returns '\0' if there was no modifier.
1310 char getModifier() const {
1311 assert(isOperand());
1316 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1317 /// it into pieces. If the asm string is erroneous, emit errors and return
1318 /// true, otherwise return false. This handles canonicalization and
1319 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1320 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1321 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1322 ASTContext &C, unsigned &DiagOffs) const;
1325 //===--- Output operands ---===//
1327 unsigned getNumOutputs() const { return NumOutputs; }
1329 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1333 StringRef getOutputName(unsigned i) const {
1334 if (IdentifierInfo *II = getOutputIdentifier(i))
1335 return II->getName();
1340 /// getOutputConstraint - Return the constraint string for the specified
1341 /// output operand. All output constraints are known to be non-empty (either
1343 StringRef getOutputConstraint(unsigned i) const;
1345 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1346 return Constraints[i];
1348 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1349 return Constraints[i];
1352 Expr *getOutputExpr(unsigned i);
1354 const Expr *getOutputExpr(unsigned i) const {
1355 return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1358 /// isOutputPlusConstraint - Return true if the specified output constraint
1359 /// is a "+" constraint (which is both an input and an output) or false if it
1360 /// is an "=" constraint (just an output).
1361 bool isOutputPlusConstraint(unsigned i) const {
1362 return getOutputConstraint(i)[0] == '+';
1365 /// getNumPlusOperands - Return the number of output operands that have a "+"
1367 unsigned getNumPlusOperands() const;
1369 //===--- Input operands ---===//
1371 unsigned getNumInputs() const { return NumInputs; }
1373 IdentifierInfo *getInputIdentifier(unsigned i) const {
1374 return Names[i + NumOutputs];
1377 StringRef getInputName(unsigned i) const {
1378 if (IdentifierInfo *II = getInputIdentifier(i))
1379 return II->getName();
1384 /// getInputConstraint - Return the specified input constraint. Unlike output
1385 /// constraints, these can be empty.
1386 StringRef getInputConstraint(unsigned i) const;
1388 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1389 return Constraints[i + NumOutputs];
1391 StringLiteral *getInputConstraintLiteral(unsigned i) {
1392 return Constraints[i + NumOutputs];
1395 Expr *getInputExpr(unsigned i);
1396 void setInputExpr(unsigned i, Expr *E);
1398 const Expr *getInputExpr(unsigned i) const {
1399 return const_cast<AsmStmt*>(this)->getInputExpr(i);
1402 void setOutputsAndInputsAndClobbers(ASTContext &C,
1403 IdentifierInfo **Names,
1404 StringLiteral **Constraints,
1406 unsigned NumOutputs,
1408 StringLiteral **Clobbers,
1409 unsigned NumClobbers);
1411 //===--- Other ---===//
1413 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1414 /// translate this into a numeric value needed to reference the same operand.
1415 /// This returns -1 if the operand name is invalid.
1416 int getNamedOperand(StringRef SymbolicName) const;
1418 unsigned getNumClobbers() const { return NumClobbers; }
1419 StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1420 const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1422 SourceRange getSourceRange() const {
1423 return SourceRange(AsmLoc, RParenLoc);
1426 static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1427 static bool classof(const AsmStmt *) { return true; }
1429 // Input expr iterators.
1431 typedef ExprIterator inputs_iterator;
1432 typedef ConstExprIterator const_inputs_iterator;
1434 inputs_iterator begin_inputs() {
1435 return &Exprs[0] + NumOutputs;
1438 inputs_iterator end_inputs() {
1439 return &Exprs[0] + NumOutputs + NumInputs;
1442 const_inputs_iterator begin_inputs() const {
1443 return &Exprs[0] + NumOutputs;
1446 const_inputs_iterator end_inputs() const {
1447 return &Exprs[0] + NumOutputs + NumInputs;
1450 // Output expr iterators.
1452 typedef ExprIterator outputs_iterator;
1453 typedef ConstExprIterator const_outputs_iterator;
1455 outputs_iterator begin_outputs() {
1458 outputs_iterator end_outputs() {
1459 return &Exprs[0] + NumOutputs;
1462 const_outputs_iterator begin_outputs() const {
1465 const_outputs_iterator end_outputs() const {
1466 return &Exprs[0] + NumOutputs;
1469 child_range children() {
1470 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1474 class SEHExceptStmt : public Stmt {
1478 enum { FILTER_EXPR, BLOCK };
1480 SEHExceptStmt(SourceLocation Loc,
1484 friend class ASTReader;
1485 friend class ASTStmtReader;
1486 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1489 static SEHExceptStmt* Create(ASTContext &C,
1490 SourceLocation ExceptLoc,
1493 SourceRange getSourceRange() const {
1494 return SourceRange(getExceptLoc(), getEndLoc());
1497 SourceLocation getExceptLoc() const { return Loc; }
1498 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1500 Expr *getFilterExpr() const { return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); }
1501 CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Children[BLOCK]); }
1503 child_range children() {
1504 return child_range(Children,Children+2);
1507 static bool classof(const Stmt *T) {
1508 return T->getStmtClass() == SEHExceptStmtClass;
1511 static bool classof(SEHExceptStmt *) { return true; }
1515 class SEHFinallyStmt : public Stmt {
1519 SEHFinallyStmt(SourceLocation Loc,
1522 friend class ASTReader;
1523 friend class ASTStmtReader;
1524 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1527 static SEHFinallyStmt* Create(ASTContext &C,
1528 SourceLocation FinallyLoc,
1531 SourceRange getSourceRange() const {
1532 return SourceRange(getFinallyLoc(), getEndLoc());
1535 SourceLocation getFinallyLoc() const { return Loc; }
1536 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1538 CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
1540 child_range children() {
1541 return child_range(&Block,&Block+1);
1544 static bool classof(const Stmt *T) {
1545 return T->getStmtClass() == SEHFinallyStmtClass;
1548 static bool classof(SEHFinallyStmt *) { return true; }
1552 class SEHTryStmt : public Stmt {
1554 SourceLocation TryLoc;
1557 enum { TRY = 0, HANDLER = 1 };
1559 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1560 SourceLocation TryLoc,
1564 friend class ASTReader;
1565 friend class ASTStmtReader;
1566 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1569 static SEHTryStmt* Create(ASTContext &C,
1571 SourceLocation TryLoc,
1575 SourceRange getSourceRange() const {
1576 return SourceRange(getTryLoc(), getEndLoc());
1579 SourceLocation getTryLoc() const { return TryLoc; }
1580 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1582 bool getIsCXXTry() const { return IsCXXTry; }
1583 CompoundStmt* getTryBlock() const { return llvm::cast<CompoundStmt>(Children[TRY]); }
1584 Stmt *getHandler() const { return Children[HANDLER]; }
1586 /// Returns 0 if not defined
1587 SEHExceptStmt *getExceptHandler() const;
1588 SEHFinallyStmt *getFinallyHandler() const;
1590 child_range children() {
1591 return child_range(Children,Children+2);
1594 static bool classof(const Stmt *T) {
1595 return T->getStmtClass() == SEHTryStmtClass;
1598 static bool classof(SEHTryStmt *) { return true; }
1602 } // end namespace clang