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 "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"
26 using llvm::dyn_cast_or_null;
29 class FoldingSetNodeID;
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 //===----------------------------------------------------------------------===//
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; }
71 class ConstExprIterator {
72 const Stmt * const *I;
74 ConstExprIterator(const Stmt * const *i) : I(i) {}
75 ConstExprIterator() : I(0) {}
76 ConstExprIterator& operator++() { ++I; return *this; }
77 ConstExprIterator operator+(size_t i) const { return I+i; }
78 ConstExprIterator operator-(size_t i) const { 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; }
89 //===----------------------------------------------------------------------===//
90 // AST classes for statements.
91 //===----------------------------------------------------------------------===//
93 /// Stmt - This represents one statement.
99 #define STMT(CLASS, PARENT) CLASS##Class,
100 #define STMT_RANGE(BASE, FIRST, LAST) \
101 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
102 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
103 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
104 #define ABSTRACT_STMT(STMT)
105 #include "clang/AST/StmtNodes.inc"
108 // Make vanilla 'new' and 'delete' illegal for Stmts.
110 void* operator new(size_t bytes) throw() {
111 assert(0 && "Stmts cannot be allocated with regular 'new'.");
114 void operator delete(void* data) throw() {
115 assert(0 && "Stmts cannot be released with regular 'delete'.");
118 class StmtBitfields {
121 /// \brief The statement class.
124 enum { NumStmtBits = 8 };
126 class CompoundStmtBitfields {
127 friend class CompoundStmt;
128 unsigned : NumStmtBits;
130 unsigned NumStmts : 32 - NumStmtBits;
133 class ExprBitfields {
135 friend class DeclRefExpr; // computeDependence
136 friend class InitListExpr; // ctor
137 friend class DesignatedInitExpr; // ctor
138 friend class BlockDeclRefExpr; // ctor
139 friend class ASTStmtReader; // deserialization
140 friend class CXXNewExpr; // ctor
141 friend class DependentScopeDeclRefExpr; // ctor
142 friend class CXXConstructExpr; // ctor
143 friend class CallExpr; // ctor
144 friend class OffsetOfExpr; // ctor
145 friend class ObjCMessageExpr; // ctor
146 friend class ShuffleVectorExpr; // ctor
147 friend class ParenListExpr; // ctor
148 friend class CXXUnresolvedConstructExpr; // ctor
149 friend class CXXDependentScopeMemberExpr; // ctor
150 friend class OverloadExpr; // ctor
151 unsigned : NumStmtBits;
153 unsigned ValueKind : 2;
154 unsigned ObjectKind : 2;
155 unsigned TypeDependent : 1;
156 unsigned ValueDependent : 1;
157 unsigned InstantiationDependent : 1;
158 unsigned ContainsUnexpandedParameterPack : 1;
160 enum { NumExprBits = 16 };
162 class DeclRefExprBitfields {
163 friend class DeclRefExpr;
164 friend class ASTStmtReader; // deserialization
165 unsigned : NumExprBits;
167 unsigned HasQualifier : 1;
168 unsigned HasExplicitTemplateArgs : 1;
169 unsigned HasFoundDecl : 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(llvm::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(llvm::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(llvm::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 // Implement isa<T> support.
301 static bool classof(const Stmt *) { return true; }
303 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
304 /// contain implicit control-flow in the order their subexpressions
305 /// are evaluated. This predicate returns true if this statement has
306 /// such implicit control-flow. Such statements are also specially handled
308 bool hasImplicitControlFlow() const;
310 /// Child Iterators: All subclasses must implement 'children'
311 /// to permit easy iteration over the substatements/subexpessions of an
312 /// AST node. This permits easy iteration over all nodes in the AST.
313 typedef StmtIterator child_iterator;
314 typedef ConstStmtIterator const_child_iterator;
316 typedef StmtRange child_range;
317 typedef ConstStmtRange const_child_range;
319 child_range children();
320 const_child_range children() const {
321 return const_cast<Stmt*>(this)->children();
324 child_iterator child_begin() { return children().first; }
325 child_iterator child_end() { return children().second; }
327 const_child_iterator child_begin() const { return children().first; }
328 const_child_iterator child_end() const { return children().second; }
330 /// \brief Produce a unique representation of the given statement.
332 /// \brief ID once the profiling operation is complete, will contain
333 /// the unique representation of the given statement.
335 /// \brief Context the AST context in which the statement resides
337 /// \brief Canonical whether the profile should be based on the canonical
338 /// representation of this statement (e.g., where non-type template
339 /// parameters are identified by index/level rather than their
340 /// declaration pointers) or the exact representation of the statement as
341 /// written in the source.
342 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
343 bool Canonical) const;
346 /// DeclStmt - Adaptor class for mixing declarations with statements and
347 /// expressions. For example, CompoundStmt mixes statements, expressions
348 /// and declarations (variables, types). Another example is ForStmt, where
349 /// the first statement can be an expression or a declaration.
351 class DeclStmt : public Stmt {
353 SourceLocation StartLoc, EndLoc;
356 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
357 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
358 StartLoc(startLoc), EndLoc(endLoc) {}
360 /// \brief Build an empty declaration statement.
361 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
363 /// isSingleDecl - This method returns true if this DeclStmt refers
364 /// to a single Decl.
365 bool isSingleDecl() const {
366 return DG.isSingleDecl();
369 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
370 Decl *getSingleDecl() { return DG.getSingleDecl(); }
372 const DeclGroupRef getDeclGroup() const { return DG; }
373 DeclGroupRef getDeclGroup() { return DG; }
374 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
376 SourceLocation getStartLoc() const { return StartLoc; }
377 void setStartLoc(SourceLocation L) { StartLoc = L; }
378 SourceLocation getEndLoc() const { return EndLoc; }
379 void setEndLoc(SourceLocation L) { EndLoc = L; }
381 SourceRange getSourceRange() const {
382 return SourceRange(StartLoc, EndLoc);
385 static bool classof(const Stmt *T) {
386 return T->getStmtClass() == DeclStmtClass;
388 static bool classof(const DeclStmt *) { return true; }
390 // Iterators over subexpressions.
391 child_range children() {
392 return child_range(child_iterator(DG.begin(), DG.end()),
393 child_iterator(DG.end(), DG.end()));
396 typedef DeclGroupRef::iterator decl_iterator;
397 typedef DeclGroupRef::const_iterator const_decl_iterator;
399 decl_iterator decl_begin() { return DG.begin(); }
400 decl_iterator decl_end() { return DG.end(); }
401 const_decl_iterator decl_begin() const { return DG.begin(); }
402 const_decl_iterator decl_end() const { return DG.end(); }
405 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
407 class NullStmt : public Stmt {
408 SourceLocation SemiLoc;
410 /// \brief If the null statement was preceded by an empty macro this is
411 /// its instantiation source location, e.g:
416 SourceLocation LeadingEmptyMacro;
418 NullStmt(SourceLocation L, SourceLocation LeadingEmptyMacro =SourceLocation())
419 : Stmt(NullStmtClass), SemiLoc(L), LeadingEmptyMacro(LeadingEmptyMacro) {}
421 /// \brief Build an empty null statement.
422 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty) { }
424 SourceLocation getSemiLoc() const { return SemiLoc; }
425 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
427 bool hasLeadingEmptyMacro() const { return LeadingEmptyMacro.isValid(); }
428 SourceLocation getLeadingEmptyMacroLoc() const { return LeadingEmptyMacro; }
430 SourceRange getSourceRange() const { return SourceRange(SemiLoc); }
432 static bool classof(const Stmt *T) {
433 return T->getStmtClass() == NullStmtClass;
435 static bool classof(const NullStmt *) { return true; }
437 child_range children() { return child_range(); }
439 friend class ASTStmtReader;
440 friend class ASTStmtWriter;
443 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
445 class CompoundStmt : public Stmt {
447 SourceLocation LBracLoc, RBracLoc;
449 CompoundStmt(ASTContext& C, Stmt **StmtStart, unsigned NumStmts,
450 SourceLocation LB, SourceLocation RB)
451 : Stmt(CompoundStmtClass), LBracLoc(LB), RBracLoc(RB) {
452 CompoundStmtBits.NumStmts = NumStmts;
453 assert(CompoundStmtBits.NumStmts == NumStmts &&
454 "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!");
461 Body = new (C) Stmt*[NumStmts];
462 memcpy(Body, StmtStart, NumStmts * sizeof(*Body));
465 // \brief Build an empty compound statement.
466 explicit CompoundStmt(EmptyShell Empty)
467 : Stmt(CompoundStmtClass, Empty), Body(0) {
468 CompoundStmtBits.NumStmts = 0;
471 void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
473 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
474 unsigned size() const { return CompoundStmtBits.NumStmts; }
476 typedef Stmt** body_iterator;
477 body_iterator body_begin() { return Body; }
478 body_iterator body_end() { return Body + size(); }
479 Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
481 void setLastStmt(Stmt *S) {
482 assert(!body_empty() && "setLastStmt");
486 typedef Stmt* const * const_body_iterator;
487 const_body_iterator body_begin() const { return Body; }
488 const_body_iterator body_end() const { return Body + size(); }
489 const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
491 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
492 reverse_body_iterator body_rbegin() {
493 return reverse_body_iterator(body_end());
495 reverse_body_iterator body_rend() {
496 return reverse_body_iterator(body_begin());
499 typedef std::reverse_iterator<const_body_iterator>
500 const_reverse_body_iterator;
502 const_reverse_body_iterator body_rbegin() const {
503 return const_reverse_body_iterator(body_end());
506 const_reverse_body_iterator body_rend() const {
507 return const_reverse_body_iterator(body_begin());
510 SourceRange getSourceRange() const {
511 return SourceRange(LBracLoc, RBracLoc);
514 SourceLocation getLBracLoc() const { return LBracLoc; }
515 void setLBracLoc(SourceLocation L) { LBracLoc = L; }
516 SourceLocation getRBracLoc() const { return RBracLoc; }
517 void setRBracLoc(SourceLocation L) { RBracLoc = L; }
519 static bool classof(const Stmt *T) {
520 return T->getStmtClass() == CompoundStmtClass;
522 static bool classof(const CompoundStmt *) { return true; }
525 child_range children() {
526 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
530 // SwitchCase is the base class for CaseStmt and DefaultStmt,
531 class SwitchCase : public Stmt {
533 // A pointer to the following CaseStmt or DefaultStmt class,
534 // used by SwitchStmt.
535 SwitchCase *NextSwitchCase;
537 SwitchCase(StmtClass SC) : Stmt(SC), NextSwitchCase(0) {}
540 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
542 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
544 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
547 const Stmt *getSubStmt() const {
548 return const_cast<SwitchCase*>(this)->getSubStmt();
551 SourceRange getSourceRange() const { return SourceRange(); }
553 static bool classof(const Stmt *T) {
554 return T->getStmtClass() == CaseStmtClass ||
555 T->getStmtClass() == DefaultStmtClass;
557 static bool classof(const SwitchCase *) { return true; }
560 class CaseStmt : public SwitchCase {
561 enum { LHS, RHS, SUBSTMT, END_EXPR };
562 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
563 // GNU "case 1 ... 4" extension
564 SourceLocation CaseLoc;
565 SourceLocation EllipsisLoc;
566 SourceLocation ColonLoc;
568 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
569 SourceLocation ellipsisLoc, SourceLocation colonLoc)
570 : SwitchCase(CaseStmtClass) {
571 SubExprs[SUBSTMT] = 0;
572 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
573 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
575 EllipsisLoc = ellipsisLoc;
579 /// \brief Build an empty switch case statement.
580 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass) { }
582 SourceLocation getCaseLoc() const { return CaseLoc; }
583 void setCaseLoc(SourceLocation L) { CaseLoc = L; }
584 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
585 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
586 SourceLocation getColonLoc() const { return ColonLoc; }
587 void setColonLoc(SourceLocation L) { ColonLoc = L; }
589 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
590 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
591 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
593 const Expr *getLHS() const {
594 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
596 const Expr *getRHS() const {
597 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
599 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
601 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
602 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
603 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
606 SourceRange getSourceRange() const {
607 // Handle deeply nested case statements with iteration instead of recursion.
608 const CaseStmt *CS = this;
609 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
612 return SourceRange(CaseLoc, CS->getSubStmt()->getLocEnd());
614 static bool classof(const Stmt *T) {
615 return T->getStmtClass() == CaseStmtClass;
617 static bool classof(const CaseStmt *) { return true; }
620 child_range children() {
621 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
625 class DefaultStmt : public SwitchCase {
627 SourceLocation DefaultLoc;
628 SourceLocation ColonLoc;
630 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
631 SwitchCase(DefaultStmtClass), SubStmt(substmt), DefaultLoc(DL),
634 /// \brief Build an empty default statement.
635 explicit DefaultStmt(EmptyShell) : SwitchCase(DefaultStmtClass) { }
637 Stmt *getSubStmt() { return SubStmt; }
638 const Stmt *getSubStmt() const { return SubStmt; }
639 void setSubStmt(Stmt *S) { SubStmt = S; }
641 SourceLocation getDefaultLoc() const { return DefaultLoc; }
642 void setDefaultLoc(SourceLocation L) { DefaultLoc = L; }
643 SourceLocation getColonLoc() const { return ColonLoc; }
644 void setColonLoc(SourceLocation L) { ColonLoc = L; }
646 SourceRange getSourceRange() const {
647 return SourceRange(DefaultLoc, SubStmt->getLocEnd());
649 static bool classof(const Stmt *T) {
650 return T->getStmtClass() == DefaultStmtClass;
652 static bool classof(const DefaultStmt *) { return true; }
655 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
659 /// LabelStmt - Represents a label, which has a substatement. For example:
662 class LabelStmt : public Stmt {
665 SourceLocation IdentLoc;
667 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
668 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
671 // \brief Build an empty label statement.
672 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
674 SourceLocation getIdentLoc() const { return IdentLoc; }
675 LabelDecl *getDecl() const { return TheDecl; }
676 void setDecl(LabelDecl *D) { TheDecl = D; }
677 const char *getName() const;
678 Stmt *getSubStmt() { return SubStmt; }
679 const Stmt *getSubStmt() const { return SubStmt; }
680 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
681 void setSubStmt(Stmt *SS) { SubStmt = SS; }
683 SourceRange getSourceRange() const {
684 return SourceRange(IdentLoc, SubStmt->getLocEnd());
686 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
688 static bool classof(const Stmt *T) {
689 return T->getStmtClass() == LabelStmtClass;
691 static bool classof(const LabelStmt *) { return true; }
695 /// IfStmt - This represents an if/then/else.
697 class IfStmt : public Stmt {
698 enum { VAR, COND, THEN, ELSE, END_EXPR };
699 Stmt* SubExprs[END_EXPR];
701 SourceLocation IfLoc;
702 SourceLocation ElseLoc;
705 IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
706 Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
708 /// \brief Build an empty if/then/else statement
709 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
711 /// \brief Retrieve the variable declared in this "if" statement, if any.
713 /// In the following example, "x" is the condition variable.
715 /// if (int x = foo()) {
716 /// printf("x is %d", x);
719 VarDecl *getConditionVariable() const;
720 void setConditionVariable(ASTContext &C, VarDecl *V);
722 /// If this IfStmt has a condition variable, return the faux DeclStmt
723 /// associated with the creation of that condition variable.
724 const DeclStmt *getConditionVariableDeclStmt() const {
725 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
728 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
729 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
730 const Stmt *getThen() const { return SubExprs[THEN]; }
731 void setThen(Stmt *S) { SubExprs[THEN] = S; }
732 const Stmt *getElse() const { return SubExprs[ELSE]; }
733 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
735 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
736 Stmt *getThen() { return SubExprs[THEN]; }
737 Stmt *getElse() { return SubExprs[ELSE]; }
739 SourceLocation getIfLoc() const { return IfLoc; }
740 void setIfLoc(SourceLocation L) { IfLoc = L; }
741 SourceLocation getElseLoc() const { return ElseLoc; }
742 void setElseLoc(SourceLocation L) { ElseLoc = L; }
744 SourceRange getSourceRange() const {
746 return SourceRange(IfLoc, SubExprs[ELSE]->getLocEnd());
748 return SourceRange(IfLoc, SubExprs[THEN]->getLocEnd());
751 // Iterators over subexpressions. The iterators will include iterating
752 // over the initialization expression referenced by the condition variable.
753 child_range children() {
754 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
757 static bool classof(const Stmt *T) {
758 return T->getStmtClass() == IfStmtClass;
760 static bool classof(const IfStmt *) { return true; }
763 /// SwitchStmt - This represents a 'switch' stmt.
765 class SwitchStmt : public Stmt {
766 enum { VAR, COND, BODY, END_EXPR };
767 Stmt* SubExprs[END_EXPR];
768 // This points to a linked list of case and default statements.
769 SwitchCase *FirstCase;
770 SourceLocation SwitchLoc;
772 /// If the SwitchStmt is a switch on an enum value, this records whether
773 /// all the enum values were covered by CaseStmts. This value is meant to
774 /// be a hint for possible clients.
775 unsigned AllEnumCasesCovered : 1;
778 SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
780 /// \brief Build a empty switch statement.
781 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
783 /// \brief Retrieve the variable declared in this "switch" statement, if any.
785 /// In the following example, "x" is the condition variable.
787 /// switch (int x = foo()) {
792 VarDecl *getConditionVariable() const;
793 void setConditionVariable(ASTContext &C, VarDecl *V);
795 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
796 /// associated with the creation of that condition variable.
797 const DeclStmt *getConditionVariableDeclStmt() const {
798 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
801 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
802 const Stmt *getBody() const { return SubExprs[BODY]; }
803 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
805 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
806 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
807 Stmt *getBody() { return SubExprs[BODY]; }
808 void setBody(Stmt *S) { SubExprs[BODY] = S; }
809 SwitchCase *getSwitchCaseList() { return FirstCase; }
811 /// \brief Set the case list for this switch statement.
813 /// The caller is responsible for incrementing the retain counts on
814 /// all of the SwitchCase statements in this list.
815 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
817 SourceLocation getSwitchLoc() const { return SwitchLoc; }
818 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
820 void setBody(Stmt *S, SourceLocation SL) {
824 void addSwitchCase(SwitchCase *SC) {
825 assert(!SC->getNextSwitchCase() && "case/default already added to a switch");
826 SC->setNextSwitchCase(FirstCase);
830 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
831 /// switch over an enum value then all cases have been explicitly covered.
832 void setAllEnumCasesCovered() {
833 AllEnumCasesCovered = 1;
836 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
837 /// have been explicitly covered.
838 bool isAllEnumCasesCovered() const {
839 return (bool) AllEnumCasesCovered;
842 SourceRange getSourceRange() const {
843 return SourceRange(SwitchLoc, SubExprs[BODY]->getLocEnd());
846 child_range children() {
847 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
850 static bool classof(const Stmt *T) {
851 return T->getStmtClass() == SwitchStmtClass;
853 static bool classof(const SwitchStmt *) { return true; }
857 /// WhileStmt - This represents a 'while' stmt.
859 class WhileStmt : public Stmt {
860 enum { VAR, COND, BODY, END_EXPR };
861 Stmt* SubExprs[END_EXPR];
862 SourceLocation WhileLoc;
864 WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
867 /// \brief Build an empty while statement.
868 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
870 /// \brief Retrieve the variable declared in this "while" statement, if any.
872 /// In the following example, "x" is the condition variable.
874 /// while (int x = random()) {
878 VarDecl *getConditionVariable() const;
879 void setConditionVariable(ASTContext &C, VarDecl *V);
881 /// If this WhileStmt has a condition variable, return the faux DeclStmt
882 /// associated with the creation of that condition variable.
883 const DeclStmt *getConditionVariableDeclStmt() const {
884 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
887 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
888 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
889 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
890 Stmt *getBody() { return SubExprs[BODY]; }
891 const Stmt *getBody() const { return SubExprs[BODY]; }
892 void setBody(Stmt *S) { SubExprs[BODY] = S; }
894 SourceLocation getWhileLoc() const { return WhileLoc; }
895 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
897 SourceRange getSourceRange() const {
898 return SourceRange(WhileLoc, SubExprs[BODY]->getLocEnd());
900 static bool classof(const Stmt *T) {
901 return T->getStmtClass() == WhileStmtClass;
903 static bool classof(const WhileStmt *) { return true; }
906 child_range children() {
907 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
911 /// DoStmt - This represents a 'do/while' stmt.
913 class DoStmt : public Stmt {
914 enum { BODY, COND, END_EXPR };
915 Stmt* SubExprs[END_EXPR];
916 SourceLocation DoLoc;
917 SourceLocation WhileLoc;
918 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
921 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
923 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
924 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
925 SubExprs[BODY] = body;
928 /// \brief Build an empty do-while statement.
929 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
931 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
932 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
933 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
934 Stmt *getBody() { return SubExprs[BODY]; }
935 const Stmt *getBody() const { return SubExprs[BODY]; }
936 void setBody(Stmt *S) { SubExprs[BODY] = S; }
938 SourceLocation getDoLoc() const { return DoLoc; }
939 void setDoLoc(SourceLocation L) { DoLoc = L; }
940 SourceLocation getWhileLoc() const { return WhileLoc; }
941 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
943 SourceLocation getRParenLoc() const { return RParenLoc; }
944 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
946 SourceRange getSourceRange() const {
947 return SourceRange(DoLoc, RParenLoc);
949 static bool classof(const Stmt *T) {
950 return T->getStmtClass() == DoStmtClass;
952 static bool classof(const DoStmt *) { return true; }
955 child_range children() {
956 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
961 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
962 /// the init/cond/inc parts of the ForStmt will be null if they were not
963 /// specified in the source.
965 class ForStmt : public Stmt {
966 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
967 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
968 SourceLocation ForLoc;
969 SourceLocation LParenLoc, RParenLoc;
972 ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
973 Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
975 /// \brief Build an empty for statement.
976 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
978 Stmt *getInit() { return SubExprs[INIT]; }
980 /// \brief Retrieve the variable declared in this "for" statement, if any.
982 /// In the following example, "y" is the condition variable.
984 /// for (int x = random(); int y = mangle(x); ++x) {
988 VarDecl *getConditionVariable() const;
989 void setConditionVariable(ASTContext &C, VarDecl *V);
991 /// If this ForStmt has a condition variable, return the faux DeclStmt
992 /// associated with the creation of that condition variable.
993 const DeclStmt *getConditionVariableDeclStmt() const {
994 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
997 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
998 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
999 Stmt *getBody() { return SubExprs[BODY]; }
1001 const Stmt *getInit() const { return SubExprs[INIT]; }
1002 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1003 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1004 const Stmt *getBody() const { return SubExprs[BODY]; }
1006 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1007 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1008 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1009 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1011 SourceLocation getForLoc() const { return ForLoc; }
1012 void setForLoc(SourceLocation L) { ForLoc = L; }
1013 SourceLocation getLParenLoc() const { return LParenLoc; }
1014 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1015 SourceLocation getRParenLoc() const { return RParenLoc; }
1016 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1018 SourceRange getSourceRange() const {
1019 return SourceRange(ForLoc, SubExprs[BODY]->getLocEnd());
1021 static bool classof(const Stmt *T) {
1022 return T->getStmtClass() == ForStmtClass;
1024 static bool classof(const ForStmt *) { return true; }
1027 child_range children() {
1028 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1032 /// GotoStmt - This represents a direct goto.
1034 class GotoStmt : public Stmt {
1036 SourceLocation GotoLoc;
1037 SourceLocation LabelLoc;
1039 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1040 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1042 /// \brief Build an empty goto statement.
1043 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1045 LabelDecl *getLabel() const { return Label; }
1046 void setLabel(LabelDecl *D) { Label = D; }
1048 SourceLocation getGotoLoc() const { return GotoLoc; }
1049 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1050 SourceLocation getLabelLoc() const { return LabelLoc; }
1051 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1053 SourceRange getSourceRange() const {
1054 return SourceRange(GotoLoc, LabelLoc);
1056 static bool classof(const Stmt *T) {
1057 return T->getStmtClass() == GotoStmtClass;
1059 static bool classof(const GotoStmt *) { return true; }
1062 child_range children() { return child_range(); }
1065 /// IndirectGotoStmt - This represents an indirect goto.
1067 class IndirectGotoStmt : public Stmt {
1068 SourceLocation GotoLoc;
1069 SourceLocation StarLoc;
1072 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1074 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1075 Target((Stmt*)target) {}
1077 /// \brief Build an empty indirect goto statement.
1078 explicit IndirectGotoStmt(EmptyShell Empty)
1079 : Stmt(IndirectGotoStmtClass, Empty) { }
1081 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1082 SourceLocation getGotoLoc() const { return GotoLoc; }
1083 void setStarLoc(SourceLocation L) { StarLoc = L; }
1084 SourceLocation getStarLoc() const { return StarLoc; }
1086 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1087 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1088 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1090 /// getConstantTarget - Returns the fixed target of this indirect
1091 /// goto, if one exists.
1092 LabelDecl *getConstantTarget();
1093 const LabelDecl *getConstantTarget() const {
1094 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1097 SourceRange getSourceRange() const {
1098 return SourceRange(GotoLoc, Target->getLocEnd());
1101 static bool classof(const Stmt *T) {
1102 return T->getStmtClass() == IndirectGotoStmtClass;
1104 static bool classof(const IndirectGotoStmt *) { return true; }
1107 child_range children() { return child_range(&Target, &Target+1); }
1111 /// ContinueStmt - This represents a continue.
1113 class ContinueStmt : public Stmt {
1114 SourceLocation ContinueLoc;
1116 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1118 /// \brief Build an empty continue statement.
1119 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1121 SourceLocation getContinueLoc() const { return ContinueLoc; }
1122 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1124 SourceRange getSourceRange() const {
1125 return SourceRange(ContinueLoc);
1128 static bool classof(const Stmt *T) {
1129 return T->getStmtClass() == ContinueStmtClass;
1131 static bool classof(const ContinueStmt *) { return true; }
1134 child_range children() { return child_range(); }
1137 /// BreakStmt - This represents a break.
1139 class BreakStmt : public Stmt {
1140 SourceLocation BreakLoc;
1142 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1144 /// \brief Build an empty break statement.
1145 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1147 SourceLocation getBreakLoc() const { return BreakLoc; }
1148 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1150 SourceRange getSourceRange() const { return SourceRange(BreakLoc); }
1152 static bool classof(const Stmt *T) {
1153 return T->getStmtClass() == BreakStmtClass;
1155 static bool classof(const BreakStmt *) { return true; }
1158 child_range children() { return child_range(); }
1162 /// ReturnStmt - This represents a return, optionally of an expression:
1166 /// Note that GCC allows return with no argument in a function declared to
1167 /// return a value, and it allows returning a value in functions declared to
1168 /// return void. We explicitly model this in the AST, which means you can't
1169 /// depend on the return type of the function and the presence of an argument.
1171 class ReturnStmt : public Stmt {
1173 SourceLocation RetLoc;
1174 const VarDecl *NRVOCandidate;
1177 ReturnStmt(SourceLocation RL)
1178 : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1180 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1181 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1182 NRVOCandidate(NRVOCandidate) {}
1184 /// \brief Build an empty return expression.
1185 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1187 const Expr *getRetValue() const;
1188 Expr *getRetValue();
1189 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1191 SourceLocation getReturnLoc() const { return RetLoc; }
1192 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1194 /// \brief Retrieve the variable that might be used for the named return
1195 /// value optimization.
1197 /// The optimization itself can only be performed if the variable is
1198 /// also marked as an NRVO object.
1199 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1200 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1202 SourceRange getSourceRange() const;
1204 static bool classof(const Stmt *T) {
1205 return T->getStmtClass() == ReturnStmtClass;
1207 static bool classof(const ReturnStmt *) { return true; }
1210 child_range children() {
1211 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1212 return child_range();
1216 /// AsmStmt - This represents a GNU inline-assembly statement extension.
1218 class AsmStmt : public Stmt {
1219 SourceLocation AsmLoc, RParenLoc;
1220 StringLiteral *AsmStr;
1226 unsigned NumOutputs;
1228 unsigned NumClobbers;
1230 // FIXME: If we wanted to, we could allocate all of these in one big array.
1231 IdentifierInfo **Names;
1232 StringLiteral **Constraints;
1234 StringLiteral **Clobbers;
1237 AsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple, bool isvolatile,
1238 bool msasm, unsigned numoutputs, unsigned numinputs,
1239 IdentifierInfo **names, StringLiteral **constraints,
1240 Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
1241 StringLiteral **clobbers, SourceLocation rparenloc);
1243 /// \brief Build an empty inline-assembly statement.
1244 explicit AsmStmt(EmptyShell Empty) : Stmt(AsmStmtClass, Empty),
1245 Names(0), Constraints(0), Exprs(0), Clobbers(0) { }
1247 SourceLocation getAsmLoc() const { return AsmLoc; }
1248 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1249 SourceLocation getRParenLoc() const { return RParenLoc; }
1250 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1252 bool isVolatile() const { return IsVolatile; }
1253 void setVolatile(bool V) { IsVolatile = V; }
1254 bool isSimple() const { return IsSimple; }
1255 void setSimple(bool V) { IsSimple = V; }
1256 bool isMSAsm() const { return MSAsm; }
1257 void setMSAsm(bool V) { MSAsm = V; }
1259 //===--- Asm String Analysis ---===//
1261 const StringLiteral *getAsmString() const { return AsmStr; }
1262 StringLiteral *getAsmString() { return AsmStr; }
1263 void setAsmString(StringLiteral *E) { AsmStr = E; }
1265 /// AsmStringPiece - this is part of a decomposed asm string specification
1266 /// (for use with the AnalyzeAsmString function below). An asm string is
1267 /// considered to be a concatenation of these parts.
1268 class AsmStringPiece {
1271 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1272 Operand // Operand reference, with optional modifier %c4.
1279 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1280 AsmStringPiece(unsigned OpNo, char Modifier)
1281 : MyKind(Operand), Str(), OperandNo(OpNo) {
1285 bool isString() const { return MyKind == String; }
1286 bool isOperand() const { return MyKind == Operand; }
1288 const std::string &getString() const {
1293 unsigned getOperandNo() const {
1294 assert(isOperand());
1298 /// getModifier - Get the modifier for this operand, if present. This
1299 /// returns '\0' if there was no modifier.
1300 char getModifier() const {
1301 assert(isOperand());
1306 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1307 /// it into pieces. If the asm string is erroneous, emit errors and return
1308 /// true, otherwise return false. This handles canonicalization and
1309 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1310 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1311 unsigned AnalyzeAsmString(llvm::SmallVectorImpl<AsmStringPiece> &Pieces,
1312 ASTContext &C, unsigned &DiagOffs) const;
1315 //===--- Output operands ---===//
1317 unsigned getNumOutputs() const { return NumOutputs; }
1319 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1323 llvm::StringRef getOutputName(unsigned i) const {
1324 if (IdentifierInfo *II = getOutputIdentifier(i))
1325 return II->getName();
1327 return llvm::StringRef();
1330 /// getOutputConstraint - Return the constraint string for the specified
1331 /// output operand. All output constraints are known to be non-empty (either
1333 llvm::StringRef getOutputConstraint(unsigned i) const;
1335 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1336 return Constraints[i];
1338 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1339 return Constraints[i];
1342 Expr *getOutputExpr(unsigned i);
1344 const Expr *getOutputExpr(unsigned i) const {
1345 return const_cast<AsmStmt*>(this)->getOutputExpr(i);
1348 /// isOutputPlusConstraint - Return true if the specified output constraint
1349 /// is a "+" constraint (which is both an input and an output) or false if it
1350 /// is an "=" constraint (just an output).
1351 bool isOutputPlusConstraint(unsigned i) const {
1352 return getOutputConstraint(i)[0] == '+';
1355 /// getNumPlusOperands - Return the number of output operands that have a "+"
1357 unsigned getNumPlusOperands() const;
1359 //===--- Input operands ---===//
1361 unsigned getNumInputs() const { return NumInputs; }
1363 IdentifierInfo *getInputIdentifier(unsigned i) const {
1364 return Names[i + NumOutputs];
1367 llvm::StringRef getInputName(unsigned i) const {
1368 if (IdentifierInfo *II = getInputIdentifier(i))
1369 return II->getName();
1371 return llvm::StringRef();
1374 /// getInputConstraint - Return the specified input constraint. Unlike output
1375 /// constraints, these can be empty.
1376 llvm::StringRef getInputConstraint(unsigned i) const;
1378 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1379 return Constraints[i + NumOutputs];
1381 StringLiteral *getInputConstraintLiteral(unsigned i) {
1382 return Constraints[i + NumOutputs];
1385 Expr *getInputExpr(unsigned i);
1386 void setInputExpr(unsigned i, Expr *E);
1388 const Expr *getInputExpr(unsigned i) const {
1389 return const_cast<AsmStmt*>(this)->getInputExpr(i);
1392 void setOutputsAndInputsAndClobbers(ASTContext &C,
1393 IdentifierInfo **Names,
1394 StringLiteral **Constraints,
1396 unsigned NumOutputs,
1398 StringLiteral **Clobbers,
1399 unsigned NumClobbers);
1401 //===--- Other ---===//
1403 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1404 /// translate this into a numeric value needed to reference the same operand.
1405 /// This returns -1 if the operand name is invalid.
1406 int getNamedOperand(llvm::StringRef SymbolicName) const;
1408 unsigned getNumClobbers() const { return NumClobbers; }
1409 StringLiteral *getClobber(unsigned i) { return Clobbers[i]; }
1410 const StringLiteral *getClobber(unsigned i) const { return Clobbers[i]; }
1412 SourceRange getSourceRange() const {
1413 return SourceRange(AsmLoc, RParenLoc);
1416 static bool classof(const Stmt *T) {return T->getStmtClass() == AsmStmtClass;}
1417 static bool classof(const AsmStmt *) { return true; }
1419 // Input expr iterators.
1421 typedef ExprIterator inputs_iterator;
1422 typedef ConstExprIterator const_inputs_iterator;
1424 inputs_iterator begin_inputs() {
1425 return &Exprs[0] + NumOutputs;
1428 inputs_iterator end_inputs() {
1429 return &Exprs[0] + NumOutputs + NumInputs;
1432 const_inputs_iterator begin_inputs() const {
1433 return &Exprs[0] + NumOutputs;
1436 const_inputs_iterator end_inputs() const {
1437 return &Exprs[0] + NumOutputs + NumInputs;
1440 // Output expr iterators.
1442 typedef ExprIterator outputs_iterator;
1443 typedef ConstExprIterator const_outputs_iterator;
1445 outputs_iterator begin_outputs() {
1448 outputs_iterator end_outputs() {
1449 return &Exprs[0] + NumOutputs;
1452 const_outputs_iterator begin_outputs() const {
1455 const_outputs_iterator end_outputs() const {
1456 return &Exprs[0] + NumOutputs;
1459 child_range children() {
1460 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1464 class SEHExceptStmt : public Stmt {
1468 enum { FILTER_EXPR, BLOCK };
1470 SEHExceptStmt(SourceLocation Loc,
1474 friend class ASTReader;
1475 friend class ASTStmtReader;
1476 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1479 static SEHExceptStmt* Create(ASTContext &C,
1480 SourceLocation ExceptLoc,
1483 SourceRange getSourceRange() const {
1484 return SourceRange(getExceptLoc(), getEndLoc());
1487 SourceLocation getExceptLoc() const { return Loc; }
1488 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1490 Expr *getFilterExpr() const { return reinterpret_cast<Expr*>(Children[FILTER_EXPR]); }
1491 CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Children[BLOCK]); }
1493 child_range children() {
1494 return child_range(Children,Children+2);
1497 static bool classof(const Stmt *T) {
1498 return T->getStmtClass() == SEHExceptStmtClass;
1501 static bool classof(SEHExceptStmt *) { return true; }
1505 class SEHFinallyStmt : public Stmt {
1509 SEHFinallyStmt(SourceLocation Loc,
1512 friend class ASTReader;
1513 friend class ASTStmtReader;
1514 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1517 static SEHFinallyStmt* Create(ASTContext &C,
1518 SourceLocation FinallyLoc,
1521 SourceRange getSourceRange() const {
1522 return SourceRange(getFinallyLoc(), getEndLoc());
1525 SourceLocation getFinallyLoc() const { return Loc; }
1526 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1528 CompoundStmt *getBlock() const { return llvm::cast<CompoundStmt>(Block); }
1530 child_range children() {
1531 return child_range(&Block,&Block+1);
1534 static bool classof(const Stmt *T) {
1535 return T->getStmtClass() == SEHFinallyStmtClass;
1538 static bool classof(SEHFinallyStmt *) { return true; }
1542 class SEHTryStmt : public Stmt {
1544 SourceLocation TryLoc;
1547 enum { TRY = 0, HANDLER = 1 };
1549 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1550 SourceLocation TryLoc,
1554 friend class ASTReader;
1555 friend class ASTStmtReader;
1556 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1559 static SEHTryStmt* Create(ASTContext &C,
1561 SourceLocation TryLoc,
1565 SourceRange getSourceRange() const {
1566 return SourceRange(getTryLoc(), getEndLoc());
1569 SourceLocation getTryLoc() const { return TryLoc; }
1570 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1572 bool getIsCXXTry() const { return IsCXXTry; }
1573 CompoundStmt* getTryBlock() const { return llvm::cast<CompoundStmt>(Children[TRY]); }
1574 Stmt *getHandler() const { return Children[HANDLER]; }
1576 /// Returns 0 if not defined
1577 SEHExceptStmt *getExceptHandler() const;
1578 SEHFinallyStmt *getFinallyHandler() const;
1580 child_range children() {
1581 return child_range(Children,Children+2);
1584 static bool classof(const Stmt *T) {
1585 return T->getStmtClass() == SEHTryStmtClass;
1588 static bool classof(SEHTryStmt *) { return true; }
1592 } // end namespace clang