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/AST/DeclGroup.h"
18 #include "clang/AST/StmtIterator.h"
19 #include "clang/Basic/CapturedStmt.h"
20 #include "clang/Basic/IdentifierTable.h"
21 #include "clang/Basic/LLVM.h"
22 #include "clang/Basic/SourceLocation.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/PointerIntPair.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/ErrorHandling.h"
30 class FoldingSetNodeID;
43 struct PrintingPolicy;
52 //===--------------------------------------------------------------------===//
53 // ExprIterator - Iterators for iterating over Stmt* arrays that contain
54 // only Expr*. This is needed because AST nodes use Stmt* arrays to store
55 // references to children (to be compatible with StmtIterator).
56 //===--------------------------------------------------------------------===//
64 ExprIterator(Stmt** i) : I(i) {}
65 ExprIterator() : I(0) {}
66 ExprIterator& operator++() { ++I; return *this; }
67 ExprIterator operator-(size_t i) { return I-i; }
68 ExprIterator operator+(size_t i) { return I+i; }
69 Expr* operator[](size_t idx);
70 // FIXME: Verify that this will correctly return a signed distance.
71 signed operator-(const ExprIterator& R) const { return I - R.I; }
72 Expr* operator*() const;
73 Expr* operator->() const;
74 bool operator==(const ExprIterator& R) const { return I == R.I; }
75 bool operator!=(const ExprIterator& R) const { return I != R.I; }
76 bool operator>(const ExprIterator& R) const { return I > R.I; }
77 bool operator>=(const ExprIterator& R) const { return I >= R.I; }
80 class ConstExprIterator {
81 const Stmt * const *I;
83 ConstExprIterator(const Stmt * const *i) : I(i) {}
84 ConstExprIterator() : I(0) {}
85 ConstExprIterator& operator++() { ++I; return *this; }
86 ConstExprIterator operator+(size_t i) const { return I+i; }
87 ConstExprIterator operator-(size_t i) const { return I-i; }
88 const Expr * operator[](size_t idx) const;
89 signed operator-(const ConstExprIterator& R) const { return I - R.I; }
90 const Expr * operator*() const;
91 const Expr * operator->() const;
92 bool operator==(const ConstExprIterator& R) const { return I == R.I; }
93 bool operator!=(const ConstExprIterator& R) const { return I != R.I; }
94 bool operator>(const ConstExprIterator& R) const { return I > R.I; }
95 bool operator>=(const ConstExprIterator& R) const { return I >= R.I; }
98 //===----------------------------------------------------------------------===//
99 // AST classes for statements.
100 //===----------------------------------------------------------------------===//
102 /// Stmt - This represents one statement.
108 #define STMT(CLASS, PARENT) CLASS##Class,
109 #define STMT_RANGE(BASE, FIRST, LAST) \
110 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
111 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
112 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
113 #define ABSTRACT_STMT(STMT)
114 #include "clang/AST/StmtNodes.inc"
117 // Make vanilla 'new' and 'delete' illegal for Stmts.
119 void* operator new(size_t bytes) throw() {
120 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
122 void operator delete(void* data) throw() {
123 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
126 class StmtBitfields {
129 /// \brief The statement class.
132 enum { NumStmtBits = 8 };
134 class CompoundStmtBitfields {
135 friend class CompoundStmt;
136 unsigned : NumStmtBits;
138 unsigned NumStmts : 32 - NumStmtBits;
141 class ExprBitfields {
143 friend class DeclRefExpr; // computeDependence
144 friend class InitListExpr; // ctor
145 friend class DesignatedInitExpr; // ctor
146 friend class BlockDeclRefExpr; // ctor
147 friend class ASTStmtReader; // deserialization
148 friend class CXXNewExpr; // ctor
149 friend class DependentScopeDeclRefExpr; // ctor
150 friend class CXXConstructExpr; // ctor
151 friend class CallExpr; // ctor
152 friend class OffsetOfExpr; // ctor
153 friend class ObjCMessageExpr; // ctor
154 friend class ObjCArrayLiteral; // ctor
155 friend class ObjCDictionaryLiteral; // ctor
156 friend class ShuffleVectorExpr; // ctor
157 friend class ParenListExpr; // ctor
158 friend class CXXUnresolvedConstructExpr; // ctor
159 friend class CXXDependentScopeMemberExpr; // ctor
160 friend class OverloadExpr; // ctor
161 friend class PseudoObjectExpr; // ctor
162 friend class AtomicExpr; // ctor
163 unsigned : NumStmtBits;
165 unsigned ValueKind : 2;
166 unsigned ObjectKind : 2;
167 unsigned TypeDependent : 1;
168 unsigned ValueDependent : 1;
169 unsigned InstantiationDependent : 1;
170 unsigned ContainsUnexpandedParameterPack : 1;
172 enum { NumExprBits = 16 };
174 class CharacterLiteralBitfields {
175 friend class CharacterLiteral;
176 unsigned : NumExprBits;
181 enum APFloatSemantics {
190 class FloatingLiteralBitfields {
191 friend class FloatingLiteral;
192 unsigned : NumExprBits;
194 unsigned Semantics : 3; // Provides semantics for APFloat construction
195 unsigned IsExact : 1;
198 class UnaryExprOrTypeTraitExprBitfields {
199 friend class UnaryExprOrTypeTraitExpr;
200 unsigned : NumExprBits;
203 unsigned IsType : 1; // true if operand is a type, false if an expression.
206 class DeclRefExprBitfields {
207 friend class DeclRefExpr;
208 friend class ASTStmtReader; // deserialization
209 unsigned : NumExprBits;
211 unsigned HasQualifier : 1;
212 unsigned HasTemplateKWAndArgsInfo : 1;
213 unsigned HasFoundDecl : 1;
214 unsigned HadMultipleCandidates : 1;
215 unsigned RefersToEnclosingLocal : 1;
218 class CastExprBitfields {
219 friend class CastExpr;
220 unsigned : NumExprBits;
223 unsigned BasePathSize : 32 - 6 - NumExprBits;
226 class CallExprBitfields {
227 friend class CallExpr;
228 unsigned : NumExprBits;
230 unsigned NumPreArgs : 1;
233 class ExprWithCleanupsBitfields {
234 friend class ExprWithCleanups;
235 friend class ASTStmtReader; // deserialization
237 unsigned : NumExprBits;
239 unsigned NumObjects : 32 - NumExprBits;
242 class PseudoObjectExprBitfields {
243 friend class PseudoObjectExpr;
244 friend class ASTStmtReader; // deserialization
246 unsigned : NumExprBits;
248 // These don't need to be particularly wide, because they're
249 // strictly limited by the forms of expressions we permit.
250 unsigned NumSubExprs : 8;
251 unsigned ResultIndex : 32 - 8 - NumExprBits;
254 class ObjCIndirectCopyRestoreExprBitfields {
255 friend class ObjCIndirectCopyRestoreExpr;
256 unsigned : NumExprBits;
258 unsigned ShouldCopy : 1;
261 class InitListExprBitfields {
262 friend class InitListExpr;
264 unsigned : NumExprBits;
266 /// Whether this initializer list originally had a GNU array-range
267 /// designator in it. This is a temporary marker used by CodeGen.
268 unsigned HadArrayRangeDesignator : 1;
270 /// Whether this initializer list initializes a std::initializer_list
272 unsigned InitializesStdInitializerList : 1;
275 class TypeTraitExprBitfields {
276 friend class TypeTraitExpr;
277 friend class ASTStmtReader;
278 friend class ASTStmtWriter;
280 unsigned : NumExprBits;
282 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
285 /// \brief If this expression is not value-dependent, this indicates whether
286 /// the trait evaluated true or false.
289 /// \brief The number of arguments to this type trait.
290 unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
294 // FIXME: this is wasteful on 64-bit platforms.
297 StmtBitfields StmtBits;
298 CompoundStmtBitfields CompoundStmtBits;
299 ExprBitfields ExprBits;
300 CharacterLiteralBitfields CharacterLiteralBits;
301 FloatingLiteralBitfields FloatingLiteralBits;
302 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
303 DeclRefExprBitfields DeclRefExprBits;
304 CastExprBitfields CastExprBits;
305 CallExprBitfields CallExprBits;
306 ExprWithCleanupsBitfields ExprWithCleanupsBits;
307 PseudoObjectExprBitfields PseudoObjectExprBits;
308 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
309 InitListExprBitfields InitListExprBits;
310 TypeTraitExprBitfields TypeTraitExprBits;
313 friend class ASTStmtReader;
314 friend class ASTStmtWriter;
317 // Only allow allocation of Stmts using the allocator in ASTContext
318 // or by doing a placement new.
319 void* operator new(size_t bytes, ASTContext& C,
320 unsigned alignment = 8) throw();
322 void* operator new(size_t bytes, ASTContext* C,
323 unsigned alignment = 8) throw();
325 void* operator new(size_t bytes, void* mem) throw() {
329 void operator delete(void*, ASTContext&, unsigned) throw() { }
330 void operator delete(void*, ASTContext*, unsigned) throw() { }
331 void operator delete(void*, std::size_t) throw() { }
332 void operator delete(void*, void*) throw() { }
335 /// \brief A placeholder type used to construct an empty shell of a
336 /// type, that will be filled in later (e.g., by some
337 /// de-serialization).
338 struct EmptyShell { };
341 /// \brief Whether statistic collection is enabled.
342 static bool StatisticsEnabled;
345 /// \brief Construct an empty statement.
346 explicit Stmt(StmtClass SC, EmptyShell) {
347 StmtBits.sClass = SC;
348 if (StatisticsEnabled) Stmt::addStmtClass(SC);
353 StmtBits.sClass = SC;
354 if (StatisticsEnabled) Stmt::addStmtClass(SC);
357 StmtClass getStmtClass() const {
358 return static_cast<StmtClass>(StmtBits.sClass);
360 const char *getStmtClassName() const;
362 /// SourceLocation tokens are not useful in isolation - they are low level
363 /// value objects created/interpreted by SourceManager. We assume AST
364 /// clients will have a pointer to the respective SourceManager.
365 SourceRange getSourceRange() const LLVM_READONLY;
366 SourceLocation getLocStart() const LLVM_READONLY;
367 SourceLocation getLocEnd() const LLVM_READONLY;
369 // global temp stats (until we have a per-module visitor)
370 static void addStmtClass(const StmtClass s);
371 static void EnableStatistics();
372 static void PrintStats();
374 /// \brief Dumps the specified AST fragment and all subtrees to
376 LLVM_ATTRIBUTE_USED void dump() const;
377 LLVM_ATTRIBUTE_USED void dump(SourceManager &SM) const;
378 void dump(raw_ostream &OS, SourceManager &SM) const;
380 /// dumpColor - same as dump(), but forces color highlighting.
381 LLVM_ATTRIBUTE_USED void dumpColor() const;
383 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
384 /// back to its original source language syntax.
385 void dumpPretty(ASTContext &Context) const;
386 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
387 const PrintingPolicy &Policy,
388 unsigned Indentation = 0) const;
390 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
391 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
392 void viewAST() const;
394 /// Skip past any implicit AST nodes which might surround this
395 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
396 Stmt *IgnoreImplicit();
398 const Stmt *stripLabelLikeStatements() const;
399 Stmt *stripLabelLikeStatements() {
400 return const_cast<Stmt*>(
401 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
404 /// hasImplicitControlFlow - Some statements (e.g. short circuited operations)
405 /// contain implicit control-flow in the order their subexpressions
406 /// are evaluated. This predicate returns true if this statement has
407 /// such implicit control-flow. Such statements are also specially handled
409 bool hasImplicitControlFlow() const;
411 /// Child Iterators: All subclasses must implement 'children'
412 /// to permit easy iteration over the substatements/subexpessions of an
413 /// AST node. This permits easy iteration over all nodes in the AST.
414 typedef StmtIterator child_iterator;
415 typedef ConstStmtIterator const_child_iterator;
417 typedef StmtRange child_range;
418 typedef ConstStmtRange const_child_range;
420 child_range children();
421 const_child_range children() const {
422 return const_cast<Stmt*>(this)->children();
425 child_iterator child_begin() { return children().first; }
426 child_iterator child_end() { return children().second; }
428 const_child_iterator child_begin() const { return children().first; }
429 const_child_iterator child_end() const { return children().second; }
431 /// \brief Produce a unique representation of the given statement.
433 /// \param ID once the profiling operation is complete, will contain
434 /// the unique representation of the given statement.
436 /// \param Context the AST context in which the statement resides
438 /// \param Canonical whether the profile should be based on the canonical
439 /// representation of this statement (e.g., where non-type template
440 /// parameters are identified by index/level rather than their
441 /// declaration pointers) or the exact representation of the statement as
442 /// written in the source.
443 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
444 bool Canonical) const;
447 /// DeclStmt - Adaptor class for mixing declarations with statements and
448 /// expressions. For example, CompoundStmt mixes statements, expressions
449 /// and declarations (variables, types). Another example is ForStmt, where
450 /// the first statement can be an expression or a declaration.
452 class DeclStmt : public Stmt {
454 SourceLocation StartLoc, EndLoc;
457 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
458 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
459 StartLoc(startLoc), EndLoc(endLoc) {}
461 /// \brief Build an empty declaration statement.
462 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
464 /// isSingleDecl - This method returns true if this DeclStmt refers
465 /// to a single Decl.
466 bool isSingleDecl() const {
467 return DG.isSingleDecl();
470 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
471 Decl *getSingleDecl() { return DG.getSingleDecl(); }
473 const DeclGroupRef getDeclGroup() const { return DG; }
474 DeclGroupRef getDeclGroup() { return DG; }
475 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
477 SourceLocation getStartLoc() const { return StartLoc; }
478 void setStartLoc(SourceLocation L) { StartLoc = L; }
479 SourceLocation getEndLoc() const { return EndLoc; }
480 void setEndLoc(SourceLocation L) { EndLoc = L; }
482 SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
483 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
485 static bool classof(const Stmt *T) {
486 return T->getStmtClass() == DeclStmtClass;
489 // Iterators over subexpressions.
490 child_range children() {
491 return child_range(child_iterator(DG.begin(), DG.end()),
492 child_iterator(DG.end(), DG.end()));
495 typedef DeclGroupRef::iterator decl_iterator;
496 typedef DeclGroupRef::const_iterator const_decl_iterator;
498 decl_iterator decl_begin() { return DG.begin(); }
499 decl_iterator decl_end() { return DG.end(); }
500 const_decl_iterator decl_begin() const { return DG.begin(); }
501 const_decl_iterator decl_end() const { return DG.end(); }
503 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
504 reverse_decl_iterator decl_rbegin() {
505 return reverse_decl_iterator(decl_end());
507 reverse_decl_iterator decl_rend() {
508 return reverse_decl_iterator(decl_begin());
512 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
514 class NullStmt : public Stmt {
515 SourceLocation SemiLoc;
517 /// \brief True if the null statement was preceded by an empty macro, e.g:
522 bool HasLeadingEmptyMacro;
524 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
525 : Stmt(NullStmtClass), SemiLoc(L),
526 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
528 /// \brief Build an empty null statement.
529 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
530 HasLeadingEmptyMacro(false) { }
532 SourceLocation getSemiLoc() const { return SemiLoc; }
533 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
535 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
537 SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
538 SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
540 static bool classof(const Stmt *T) {
541 return T->getStmtClass() == NullStmtClass;
544 child_range children() { return child_range(); }
546 friend class ASTStmtReader;
547 friend class ASTStmtWriter;
550 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
552 class CompoundStmt : public Stmt {
554 SourceLocation LBracLoc, RBracLoc;
556 CompoundStmt(ASTContext &C, ArrayRef<Stmt*> Stmts,
557 SourceLocation LB, SourceLocation RB);
559 // \brief Build an empty compound statment with a location.
560 explicit CompoundStmt(SourceLocation Loc)
561 : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
562 CompoundStmtBits.NumStmts = 0;
565 // \brief Build an empty compound statement.
566 explicit CompoundStmt(EmptyShell Empty)
567 : Stmt(CompoundStmtClass, Empty), Body(0) {
568 CompoundStmtBits.NumStmts = 0;
571 void setStmts(ASTContext &C, Stmt **Stmts, unsigned NumStmts);
573 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
574 unsigned size() const { return CompoundStmtBits.NumStmts; }
576 typedef Stmt** body_iterator;
577 body_iterator body_begin() { return Body; }
578 body_iterator body_end() { return Body + size(); }
579 Stmt *body_back() { return !body_empty() ? Body[size()-1] : 0; }
581 void setLastStmt(Stmt *S) {
582 assert(!body_empty() && "setLastStmt");
586 typedef Stmt* const * const_body_iterator;
587 const_body_iterator body_begin() const { return Body; }
588 const_body_iterator body_end() const { return Body + size(); }
589 const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
591 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
592 reverse_body_iterator body_rbegin() {
593 return reverse_body_iterator(body_end());
595 reverse_body_iterator body_rend() {
596 return reverse_body_iterator(body_begin());
599 typedef std::reverse_iterator<const_body_iterator>
600 const_reverse_body_iterator;
602 const_reverse_body_iterator body_rbegin() const {
603 return const_reverse_body_iterator(body_end());
606 const_reverse_body_iterator body_rend() const {
607 return const_reverse_body_iterator(body_begin());
610 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
611 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
613 SourceLocation getLBracLoc() const { return LBracLoc; }
614 void setLBracLoc(SourceLocation L) { LBracLoc = L; }
615 SourceLocation getRBracLoc() const { return RBracLoc; }
616 void setRBracLoc(SourceLocation L) { RBracLoc = L; }
618 static bool classof(const Stmt *T) {
619 return T->getStmtClass() == CompoundStmtClass;
623 child_range children() {
624 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
627 const_child_range children() const {
628 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
632 // SwitchCase is the base class for CaseStmt and DefaultStmt,
633 class SwitchCase : public Stmt {
635 // A pointer to the following CaseStmt or DefaultStmt class,
636 // used by SwitchStmt.
637 SwitchCase *NextSwitchCase;
638 SourceLocation KeywordLoc;
639 SourceLocation ColonLoc;
641 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
642 : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
644 SwitchCase(StmtClass SC, EmptyShell)
645 : Stmt(SC), NextSwitchCase(0) {}
648 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
650 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
652 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
654 SourceLocation getKeywordLoc() const { return KeywordLoc; }
655 void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
656 SourceLocation getColonLoc() const { return ColonLoc; }
657 void setColonLoc(SourceLocation L) { ColonLoc = L; }
660 const Stmt *getSubStmt() const {
661 return const_cast<SwitchCase*>(this)->getSubStmt();
664 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
665 SourceLocation getLocEnd() const LLVM_READONLY;
667 static bool classof(const Stmt *T) {
668 return T->getStmtClass() == CaseStmtClass ||
669 T->getStmtClass() == DefaultStmtClass;
673 class CaseStmt : public SwitchCase {
674 enum { LHS, RHS, SUBSTMT, END_EXPR };
675 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
676 // GNU "case 1 ... 4" extension
677 SourceLocation EllipsisLoc;
679 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
680 SourceLocation ellipsisLoc, SourceLocation colonLoc)
681 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
682 SubExprs[SUBSTMT] = 0;
683 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
684 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
685 EllipsisLoc = ellipsisLoc;
688 /// \brief Build an empty switch case statement.
689 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
691 SourceLocation getCaseLoc() const { return KeywordLoc; }
692 void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
693 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
694 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
695 SourceLocation getColonLoc() const { return ColonLoc; }
696 void setColonLoc(SourceLocation L) { ColonLoc = L; }
698 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
699 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
700 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
702 const Expr *getLHS() const {
703 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
705 const Expr *getRHS() const {
706 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
708 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
710 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
711 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
712 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
714 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
715 SourceLocation getLocEnd() const LLVM_READONLY {
716 // Handle deeply nested case statements with iteration instead of recursion.
717 const CaseStmt *CS = this;
718 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
721 return CS->getSubStmt()->getLocEnd();
724 static bool classof(const Stmt *T) {
725 return T->getStmtClass() == CaseStmtClass;
729 child_range children() {
730 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
734 class DefaultStmt : public SwitchCase {
737 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
738 SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
740 /// \brief Build an empty default statement.
741 explicit DefaultStmt(EmptyShell Empty)
742 : SwitchCase(DefaultStmtClass, Empty) { }
744 Stmt *getSubStmt() { return SubStmt; }
745 const Stmt *getSubStmt() const { return SubStmt; }
746 void setSubStmt(Stmt *S) { SubStmt = S; }
748 SourceLocation getDefaultLoc() const { return KeywordLoc; }
749 void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
750 SourceLocation getColonLoc() const { return ColonLoc; }
751 void setColonLoc(SourceLocation L) { ColonLoc = L; }
753 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
754 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
756 static bool classof(const Stmt *T) {
757 return T->getStmtClass() == DefaultStmtClass;
761 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
764 inline SourceLocation SwitchCase::getLocEnd() const {
765 if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
766 return CS->getLocEnd();
767 return cast<DefaultStmt>(this)->getLocEnd();
770 /// LabelStmt - Represents a label, which has a substatement. For example:
773 class LabelStmt : public Stmt {
776 SourceLocation IdentLoc;
778 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
779 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
782 // \brief Build an empty label statement.
783 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
785 SourceLocation getIdentLoc() const { return IdentLoc; }
786 LabelDecl *getDecl() const { return TheDecl; }
787 void setDecl(LabelDecl *D) { TheDecl = D; }
788 const char *getName() const;
789 Stmt *getSubStmt() { return SubStmt; }
790 const Stmt *getSubStmt() const { return SubStmt; }
791 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
792 void setSubStmt(Stmt *SS) { SubStmt = SS; }
794 SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
795 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
797 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
799 static bool classof(const Stmt *T) {
800 return T->getStmtClass() == LabelStmtClass;
805 /// \brief Represents an attribute applied to a statement.
807 /// Represents an attribute applied to a statement. For example:
808 /// [[omp::for(...)]] for (...) { ... }
810 class AttributedStmt : public Stmt {
812 SourceLocation AttrLoc;
814 const Attr *Attrs[1];
816 friend class ASTStmtReader;
818 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
819 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
820 NumAttrs(Attrs.size()) {
821 memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
824 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
825 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
826 memset(Attrs, 0, NumAttrs * sizeof(Attr*));
830 static AttributedStmt *Create(ASTContext &C, SourceLocation Loc,
831 ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
832 // \brief Build an empty attributed statement.
833 static AttributedStmt *CreateEmpty(ASTContext &C, unsigned NumAttrs);
835 SourceLocation getAttrLoc() const { return AttrLoc; }
836 ArrayRef<const Attr*> getAttrs() const {
837 return ArrayRef<const Attr*>(Attrs, NumAttrs);
839 Stmt *getSubStmt() { return SubStmt; }
840 const Stmt *getSubStmt() const { return SubStmt; }
842 SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
843 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
845 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
847 static bool classof(const Stmt *T) {
848 return T->getStmtClass() == AttributedStmtClass;
853 /// IfStmt - This represents an if/then/else.
855 class IfStmt : public Stmt {
856 enum { VAR, COND, THEN, ELSE, END_EXPR };
857 Stmt* SubExprs[END_EXPR];
859 SourceLocation IfLoc;
860 SourceLocation ElseLoc;
863 IfStmt(ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
864 Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
866 /// \brief Build an empty if/then/else statement
867 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
869 /// \brief Retrieve the variable declared in this "if" statement, if any.
871 /// In the following example, "x" is the condition variable.
873 /// if (int x = foo()) {
874 /// printf("x is %d", x);
877 VarDecl *getConditionVariable() const;
878 void setConditionVariable(ASTContext &C, VarDecl *V);
880 /// If this IfStmt has a condition variable, return the faux DeclStmt
881 /// associated with the creation of that condition variable.
882 const DeclStmt *getConditionVariableDeclStmt() const {
883 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
886 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
887 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
888 const Stmt *getThen() const { return SubExprs[THEN]; }
889 void setThen(Stmt *S) { SubExprs[THEN] = S; }
890 const Stmt *getElse() const { return SubExprs[ELSE]; }
891 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
893 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
894 Stmt *getThen() { return SubExprs[THEN]; }
895 Stmt *getElse() { return SubExprs[ELSE]; }
897 SourceLocation getIfLoc() const { return IfLoc; }
898 void setIfLoc(SourceLocation L) { IfLoc = L; }
899 SourceLocation getElseLoc() const { return ElseLoc; }
900 void setElseLoc(SourceLocation L) { ElseLoc = L; }
902 SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
903 SourceLocation getLocEnd() const LLVM_READONLY {
905 return SubExprs[ELSE]->getLocEnd();
907 return SubExprs[THEN]->getLocEnd();
910 // Iterators over subexpressions. The iterators will include iterating
911 // over the initialization expression referenced by the condition variable.
912 child_range children() {
913 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
916 static bool classof(const Stmt *T) {
917 return T->getStmtClass() == IfStmtClass;
921 /// SwitchStmt - This represents a 'switch' stmt.
923 class SwitchStmt : public Stmt {
924 enum { VAR, COND, BODY, END_EXPR };
925 Stmt* SubExprs[END_EXPR];
926 // This points to a linked list of case and default statements.
927 SwitchCase *FirstCase;
928 SourceLocation SwitchLoc;
930 /// If the SwitchStmt is a switch on an enum value, this records whether
931 /// all the enum values were covered by CaseStmts. This value is meant to
932 /// be a hint for possible clients.
933 unsigned AllEnumCasesCovered : 1;
936 SwitchStmt(ASTContext &C, VarDecl *Var, Expr *cond);
938 /// \brief Build a empty switch statement.
939 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
941 /// \brief Retrieve the variable declared in this "switch" statement, if any.
943 /// In the following example, "x" is the condition variable.
945 /// switch (int x = foo()) {
950 VarDecl *getConditionVariable() const;
951 void setConditionVariable(ASTContext &C, VarDecl *V);
953 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
954 /// associated with the creation of that condition variable.
955 const DeclStmt *getConditionVariableDeclStmt() const {
956 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
959 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
960 const Stmt *getBody() const { return SubExprs[BODY]; }
961 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
963 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
964 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
965 Stmt *getBody() { return SubExprs[BODY]; }
966 void setBody(Stmt *S) { SubExprs[BODY] = S; }
967 SwitchCase *getSwitchCaseList() { return FirstCase; }
969 /// \brief Set the case list for this switch statement.
971 /// The caller is responsible for incrementing the retain counts on
972 /// all of the SwitchCase statements in this list.
973 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
975 SourceLocation getSwitchLoc() const { return SwitchLoc; }
976 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
978 void setBody(Stmt *S, SourceLocation SL) {
982 void addSwitchCase(SwitchCase *SC) {
983 assert(!SC->getNextSwitchCase()
984 && "case/default already added to a switch");
985 SC->setNextSwitchCase(FirstCase);
989 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
990 /// switch over an enum value then all cases have been explicitly covered.
991 void setAllEnumCasesCovered() {
992 AllEnumCasesCovered = 1;
995 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
996 /// have been explicitly covered.
997 bool isAllEnumCasesCovered() const {
998 return (bool) AllEnumCasesCovered;
1001 SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1002 SourceLocation getLocEnd() const LLVM_READONLY {
1003 return SubExprs[BODY]->getLocEnd();
1007 child_range children() {
1008 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1011 static bool classof(const Stmt *T) {
1012 return T->getStmtClass() == SwitchStmtClass;
1017 /// WhileStmt - This represents a 'while' stmt.
1019 class WhileStmt : public Stmt {
1020 enum { VAR, COND, BODY, END_EXPR };
1021 Stmt* SubExprs[END_EXPR];
1022 SourceLocation WhileLoc;
1024 WhileStmt(ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1027 /// \brief Build an empty while statement.
1028 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1030 /// \brief Retrieve the variable declared in this "while" statement, if any.
1032 /// In the following example, "x" is the condition variable.
1034 /// while (int x = random()) {
1038 VarDecl *getConditionVariable() const;
1039 void setConditionVariable(ASTContext &C, VarDecl *V);
1041 /// If this WhileStmt has a condition variable, return the faux DeclStmt
1042 /// associated with the creation of that condition variable.
1043 const DeclStmt *getConditionVariableDeclStmt() const {
1044 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1047 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1048 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1049 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1050 Stmt *getBody() { return SubExprs[BODY]; }
1051 const Stmt *getBody() const { return SubExprs[BODY]; }
1052 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1054 SourceLocation getWhileLoc() const { return WhileLoc; }
1055 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1057 SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1058 SourceLocation getLocEnd() const LLVM_READONLY {
1059 return SubExprs[BODY]->getLocEnd();
1062 static bool classof(const Stmt *T) {
1063 return T->getStmtClass() == WhileStmtClass;
1067 child_range children() {
1068 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1072 /// DoStmt - This represents a 'do/while' stmt.
1074 class DoStmt : public Stmt {
1075 enum { BODY, COND, END_EXPR };
1076 Stmt* SubExprs[END_EXPR];
1077 SourceLocation DoLoc;
1078 SourceLocation WhileLoc;
1079 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
1082 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1084 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1085 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1086 SubExprs[BODY] = body;
1089 /// \brief Build an empty do-while statement.
1090 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1092 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1093 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1094 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1095 Stmt *getBody() { return SubExprs[BODY]; }
1096 const Stmt *getBody() const { return SubExprs[BODY]; }
1097 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1099 SourceLocation getDoLoc() const { return DoLoc; }
1100 void setDoLoc(SourceLocation L) { DoLoc = L; }
1101 SourceLocation getWhileLoc() const { return WhileLoc; }
1102 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1104 SourceLocation getRParenLoc() const { return RParenLoc; }
1105 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1107 SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1108 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1110 static bool classof(const Stmt *T) {
1111 return T->getStmtClass() == DoStmtClass;
1115 child_range children() {
1116 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1121 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
1122 /// the init/cond/inc parts of the ForStmt will be null if they were not
1123 /// specified in the source.
1125 class ForStmt : public Stmt {
1126 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1127 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1128 SourceLocation ForLoc;
1129 SourceLocation LParenLoc, RParenLoc;
1132 ForStmt(ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, Expr *Inc,
1133 Stmt *Body, SourceLocation FL, SourceLocation LP, SourceLocation RP);
1135 /// \brief Build an empty for statement.
1136 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1138 Stmt *getInit() { return SubExprs[INIT]; }
1140 /// \brief Retrieve the variable declared in this "for" statement, if any.
1142 /// In the following example, "y" is the condition variable.
1144 /// for (int x = random(); int y = mangle(x); ++x) {
1148 VarDecl *getConditionVariable() const;
1149 void setConditionVariable(ASTContext &C, VarDecl *V);
1151 /// If this ForStmt has a condition variable, return the faux DeclStmt
1152 /// associated with the creation of that condition variable.
1153 const DeclStmt *getConditionVariableDeclStmt() const {
1154 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1157 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1158 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1159 Stmt *getBody() { return SubExprs[BODY]; }
1161 const Stmt *getInit() const { return SubExprs[INIT]; }
1162 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1163 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1164 const Stmt *getBody() const { return SubExprs[BODY]; }
1166 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1167 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1168 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1169 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1171 SourceLocation getForLoc() const { return ForLoc; }
1172 void setForLoc(SourceLocation L) { ForLoc = L; }
1173 SourceLocation getLParenLoc() const { return LParenLoc; }
1174 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1175 SourceLocation getRParenLoc() const { return RParenLoc; }
1176 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1178 SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1179 SourceLocation getLocEnd() const LLVM_READONLY {
1180 return SubExprs[BODY]->getLocEnd();
1183 static bool classof(const Stmt *T) {
1184 return T->getStmtClass() == ForStmtClass;
1188 child_range children() {
1189 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1193 /// GotoStmt - This represents a direct goto.
1195 class GotoStmt : public Stmt {
1197 SourceLocation GotoLoc;
1198 SourceLocation LabelLoc;
1200 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1201 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1203 /// \brief Build an empty goto statement.
1204 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1206 LabelDecl *getLabel() const { return Label; }
1207 void setLabel(LabelDecl *D) { Label = D; }
1209 SourceLocation getGotoLoc() const { return GotoLoc; }
1210 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1211 SourceLocation getLabelLoc() const { return LabelLoc; }
1212 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1214 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1215 SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1217 static bool classof(const Stmt *T) {
1218 return T->getStmtClass() == GotoStmtClass;
1222 child_range children() { return child_range(); }
1225 /// IndirectGotoStmt - This represents an indirect goto.
1227 class IndirectGotoStmt : public Stmt {
1228 SourceLocation GotoLoc;
1229 SourceLocation StarLoc;
1232 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1234 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1235 Target((Stmt*)target) {}
1237 /// \brief Build an empty indirect goto statement.
1238 explicit IndirectGotoStmt(EmptyShell Empty)
1239 : Stmt(IndirectGotoStmtClass, Empty) { }
1241 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1242 SourceLocation getGotoLoc() const { return GotoLoc; }
1243 void setStarLoc(SourceLocation L) { StarLoc = L; }
1244 SourceLocation getStarLoc() const { return StarLoc; }
1246 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1247 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1248 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1250 /// getConstantTarget - Returns the fixed target of this indirect
1251 /// goto, if one exists.
1252 LabelDecl *getConstantTarget();
1253 const LabelDecl *getConstantTarget() const {
1254 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1257 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1258 SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1260 static bool classof(const Stmt *T) {
1261 return T->getStmtClass() == IndirectGotoStmtClass;
1265 child_range children() { return child_range(&Target, &Target+1); }
1269 /// ContinueStmt - This represents a continue.
1271 class ContinueStmt : public Stmt {
1272 SourceLocation ContinueLoc;
1274 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1276 /// \brief Build an empty continue statement.
1277 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1279 SourceLocation getContinueLoc() const { return ContinueLoc; }
1280 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1282 SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1283 SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1285 static bool classof(const Stmt *T) {
1286 return T->getStmtClass() == ContinueStmtClass;
1290 child_range children() { return child_range(); }
1293 /// BreakStmt - This represents a break.
1295 class BreakStmt : public Stmt {
1296 SourceLocation BreakLoc;
1298 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1300 /// \brief Build an empty break statement.
1301 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1303 SourceLocation getBreakLoc() const { return BreakLoc; }
1304 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1306 SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1307 SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1309 static bool classof(const Stmt *T) {
1310 return T->getStmtClass() == BreakStmtClass;
1314 child_range children() { return child_range(); }
1318 /// ReturnStmt - This represents a return, optionally of an expression:
1322 /// Note that GCC allows return with no argument in a function declared to
1323 /// return a value, and it allows returning a value in functions declared to
1324 /// return void. We explicitly model this in the AST, which means you can't
1325 /// depend on the return type of the function and the presence of an argument.
1327 class ReturnStmt : public Stmt {
1329 SourceLocation RetLoc;
1330 const VarDecl *NRVOCandidate;
1333 ReturnStmt(SourceLocation RL)
1334 : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1336 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1337 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1338 NRVOCandidate(NRVOCandidate) {}
1340 /// \brief Build an empty return expression.
1341 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1343 const Expr *getRetValue() const;
1344 Expr *getRetValue();
1345 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1347 SourceLocation getReturnLoc() const { return RetLoc; }
1348 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1350 /// \brief Retrieve the variable that might be used for the named return
1351 /// value optimization.
1353 /// The optimization itself can only be performed if the variable is
1354 /// also marked as an NRVO object.
1355 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1356 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1358 SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1359 SourceLocation getLocEnd() const LLVM_READONLY {
1360 return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1363 static bool classof(const Stmt *T) {
1364 return T->getStmtClass() == ReturnStmtClass;
1368 child_range children() {
1369 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1370 return child_range();
1374 /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1376 class AsmStmt : public Stmt {
1378 SourceLocation AsmLoc;
1379 /// \brief True if the assembly statement does not have any input or output
1383 /// \brief If true, treat this inline assembly as having side effects.
1384 /// This assembly statement should not be optimized, deleted or moved.
1387 unsigned NumOutputs;
1389 unsigned NumClobbers;
1393 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1394 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1395 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1396 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1398 friend class ASTStmtReader;
1401 /// \brief Build an empty inline-assembly statement.
1402 explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1403 Stmt(SC, Empty), Exprs(0) { }
1405 SourceLocation getAsmLoc() const { return AsmLoc; }
1406 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1408 bool isSimple() const { return IsSimple; }
1409 void setSimple(bool V) { IsSimple = V; }
1411 bool isVolatile() const { return IsVolatile; }
1412 void setVolatile(bool V) { IsVolatile = V; }
1414 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1415 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1417 //===--- Asm String Analysis ---===//
1419 /// Assemble final IR asm string.
1420 std::string generateAsmString(ASTContext &C) const;
1422 //===--- Output operands ---===//
1424 unsigned getNumOutputs() const { return NumOutputs; }
1426 /// getOutputConstraint - Return the constraint string for the specified
1427 /// output operand. All output constraints are known to be non-empty (either
1429 StringRef getOutputConstraint(unsigned i) const;
1431 /// isOutputPlusConstraint - Return true if the specified output constraint
1432 /// is a "+" constraint (which is both an input and an output) or false if it
1433 /// is an "=" constraint (just an output).
1434 bool isOutputPlusConstraint(unsigned i) const {
1435 return getOutputConstraint(i)[0] == '+';
1438 const Expr *getOutputExpr(unsigned i) const;
1440 /// getNumPlusOperands - Return the number of output operands that have a "+"
1442 unsigned getNumPlusOperands() const;
1444 //===--- Input operands ---===//
1446 unsigned getNumInputs() const { return NumInputs; }
1448 /// getInputConstraint - Return the specified input constraint. Unlike output
1449 /// constraints, these can be empty.
1450 StringRef getInputConstraint(unsigned i) const;
1452 const Expr *getInputExpr(unsigned i) const;
1454 //===--- Other ---===//
1456 unsigned getNumClobbers() const { return NumClobbers; }
1457 StringRef getClobber(unsigned i) const;
1459 static bool classof(const Stmt *T) {
1460 return T->getStmtClass() == GCCAsmStmtClass ||
1461 T->getStmtClass() == MSAsmStmtClass;
1464 // Input expr iterators.
1466 typedef ExprIterator inputs_iterator;
1467 typedef ConstExprIterator const_inputs_iterator;
1469 inputs_iterator begin_inputs() {
1470 return &Exprs[0] + NumOutputs;
1473 inputs_iterator end_inputs() {
1474 return &Exprs[0] + NumOutputs + NumInputs;
1477 const_inputs_iterator begin_inputs() const {
1478 return &Exprs[0] + NumOutputs;
1481 const_inputs_iterator end_inputs() const {
1482 return &Exprs[0] + NumOutputs + NumInputs;
1485 // Output expr iterators.
1487 typedef ExprIterator outputs_iterator;
1488 typedef ConstExprIterator const_outputs_iterator;
1490 outputs_iterator begin_outputs() {
1493 outputs_iterator end_outputs() {
1494 return &Exprs[0] + NumOutputs;
1497 const_outputs_iterator begin_outputs() const {
1500 const_outputs_iterator end_outputs() const {
1501 return &Exprs[0] + NumOutputs;
1504 child_range children() {
1505 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1509 /// This represents a GCC inline-assembly statement extension.
1511 class GCCAsmStmt : public AsmStmt {
1512 SourceLocation RParenLoc;
1513 StringLiteral *AsmStr;
1515 // FIXME: If we wanted to, we could allocate all of these in one big array.
1516 StringLiteral **Constraints;
1517 StringLiteral **Clobbers;
1518 IdentifierInfo **Names;
1520 friend class ASTStmtReader;
1523 GCCAsmStmt(ASTContext &C, SourceLocation asmloc, bool issimple,
1524 bool isvolatile, unsigned numoutputs, unsigned numinputs,
1525 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1526 StringLiteral *asmstr, unsigned numclobbers,
1527 StringLiteral **clobbers, SourceLocation rparenloc);
1529 /// \brief Build an empty inline-assembly statement.
1530 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1531 Constraints(0), Clobbers(0), Names(0) { }
1533 SourceLocation getRParenLoc() const { return RParenLoc; }
1534 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1536 //===--- Asm String Analysis ---===//
1538 const StringLiteral *getAsmString() const { return AsmStr; }
1539 StringLiteral *getAsmString() { return AsmStr; }
1540 void setAsmString(StringLiteral *E) { AsmStr = E; }
1542 /// AsmStringPiece - this is part of a decomposed asm string specification
1543 /// (for use with the AnalyzeAsmString function below). An asm string is
1544 /// considered to be a concatenation of these parts.
1545 class AsmStringPiece {
1548 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1549 Operand // Operand reference, with optional modifier %c4.
1556 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1557 AsmStringPiece(unsigned OpNo, char Modifier)
1558 : MyKind(Operand), Str(), OperandNo(OpNo) {
1562 bool isString() const { return MyKind == String; }
1563 bool isOperand() const { return MyKind == Operand; }
1565 const std::string &getString() const {
1570 unsigned getOperandNo() const {
1571 assert(isOperand());
1575 /// getModifier - Get the modifier for this operand, if present. This
1576 /// returns '\0' if there was no modifier.
1577 char getModifier() const {
1578 assert(isOperand());
1583 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1584 /// it into pieces. If the asm string is erroneous, emit errors and return
1585 /// true, otherwise return false. This handles canonicalization and
1586 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1587 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1588 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1589 ASTContext &C, unsigned &DiagOffs) const;
1591 /// Assemble final IR asm string.
1592 std::string generateAsmString(ASTContext &C) const;
1594 //===--- Output operands ---===//
1596 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1600 StringRef getOutputName(unsigned i) const {
1601 if (IdentifierInfo *II = getOutputIdentifier(i))
1602 return II->getName();
1607 StringRef getOutputConstraint(unsigned i) const;
1609 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1610 return Constraints[i];
1612 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1613 return Constraints[i];
1616 Expr *getOutputExpr(unsigned i);
1618 const Expr *getOutputExpr(unsigned i) const {
1619 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1622 //===--- Input operands ---===//
1624 IdentifierInfo *getInputIdentifier(unsigned i) const {
1625 return Names[i + NumOutputs];
1628 StringRef getInputName(unsigned i) const {
1629 if (IdentifierInfo *II = getInputIdentifier(i))
1630 return II->getName();
1635 StringRef getInputConstraint(unsigned i) const;
1637 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1638 return Constraints[i + NumOutputs];
1640 StringLiteral *getInputConstraintLiteral(unsigned i) {
1641 return Constraints[i + NumOutputs];
1644 Expr *getInputExpr(unsigned i);
1645 void setInputExpr(unsigned i, Expr *E);
1647 const Expr *getInputExpr(unsigned i) const {
1648 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1652 void setOutputsAndInputsAndClobbers(ASTContext &C,
1653 IdentifierInfo **Names,
1654 StringLiteral **Constraints,
1656 unsigned NumOutputs,
1658 StringLiteral **Clobbers,
1659 unsigned NumClobbers);
1662 //===--- Other ---===//
1664 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1665 /// translate this into a numeric value needed to reference the same operand.
1666 /// This returns -1 if the operand name is invalid.
1667 int getNamedOperand(StringRef SymbolicName) const;
1669 StringRef getClobber(unsigned i) const;
1670 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1671 const StringLiteral *getClobberStringLiteral(unsigned i) const {
1675 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1676 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1678 static bool classof(const Stmt *T) {
1679 return T->getStmtClass() == GCCAsmStmtClass;
1683 /// This represents a Microsoft inline-assembly statement extension.
1685 class MSAsmStmt : public AsmStmt {
1686 SourceLocation LBraceLoc, EndLoc;
1689 unsigned NumAsmToks;
1692 StringRef *Constraints;
1693 StringRef *Clobbers;
1695 friend class ASTStmtReader;
1698 MSAsmStmt(ASTContext &C, SourceLocation asmloc, SourceLocation lbraceloc,
1699 bool issimple, bool isvolatile, ArrayRef<Token> asmtoks,
1700 unsigned numoutputs, unsigned numinputs,
1701 ArrayRef<StringRef> constraints,
1702 ArrayRef<Expr*> exprs, StringRef asmstr,
1703 ArrayRef<StringRef> clobbers, SourceLocation endloc);
1705 /// \brief Build an empty MS-style inline-assembly statement.
1706 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1707 NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1709 SourceLocation getLBraceLoc() const { return LBraceLoc; }
1710 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1711 SourceLocation getEndLoc() const { return EndLoc; }
1712 void setEndLoc(SourceLocation L) { EndLoc = L; }
1714 bool hasBraces() const { return LBraceLoc.isValid(); }
1716 unsigned getNumAsmToks() { return NumAsmToks; }
1717 Token *getAsmToks() { return AsmToks; }
1719 //===--- Asm String Analysis ---===//
1720 StringRef getAsmString() const { return AsmStr; }
1722 /// Assemble final IR asm string.
1723 std::string generateAsmString(ASTContext &C) const;
1725 //===--- Output operands ---===//
1727 StringRef getOutputConstraint(unsigned i) const {
1728 assert(i < NumOutputs);
1729 return Constraints[i];
1732 Expr *getOutputExpr(unsigned i);
1734 const Expr *getOutputExpr(unsigned i) const {
1735 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1738 //===--- Input operands ---===//
1740 StringRef getInputConstraint(unsigned i) const {
1741 assert(i < NumInputs);
1742 return Constraints[i + NumOutputs];
1745 Expr *getInputExpr(unsigned i);
1746 void setInputExpr(unsigned i, Expr *E);
1748 const Expr *getInputExpr(unsigned i) const {
1749 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1752 //===--- Other ---===//
1754 ArrayRef<StringRef> getAllConstraints() const {
1755 return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs);
1757 ArrayRef<StringRef> getClobbers() const {
1758 return ArrayRef<StringRef>(Clobbers, NumClobbers);
1760 ArrayRef<Expr*> getAllExprs() const {
1761 return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs),
1762 NumInputs + NumOutputs);
1765 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1768 void initialize(ASTContext &C,
1769 StringRef AsmString,
1770 ArrayRef<Token> AsmToks,
1771 ArrayRef<StringRef> Constraints,
1772 ArrayRef<Expr*> Exprs,
1773 ArrayRef<StringRef> Clobbers);
1776 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1777 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1779 static bool classof(const Stmt *T) {
1780 return T->getStmtClass() == MSAsmStmtClass;
1783 child_range children() {
1784 return child_range(&Exprs[0], &Exprs[0]);
1788 class SEHExceptStmt : public Stmt {
1792 enum { FILTER_EXPR, BLOCK };
1794 SEHExceptStmt(SourceLocation Loc,
1798 friend class ASTReader;
1799 friend class ASTStmtReader;
1800 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1803 static SEHExceptStmt* Create(ASTContext &C,
1804 SourceLocation ExceptLoc,
1808 SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1809 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1811 SourceLocation getExceptLoc() const { return Loc; }
1812 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1814 Expr *getFilterExpr() const {
1815 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1818 CompoundStmt *getBlock() const {
1819 return cast<CompoundStmt>(Children[BLOCK]);
1822 child_range children() {
1823 return child_range(Children,Children+2);
1826 static bool classof(const Stmt *T) {
1827 return T->getStmtClass() == SEHExceptStmtClass;
1832 class SEHFinallyStmt : public Stmt {
1836 SEHFinallyStmt(SourceLocation Loc,
1839 friend class ASTReader;
1840 friend class ASTStmtReader;
1841 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1844 static SEHFinallyStmt* Create(ASTContext &C,
1845 SourceLocation FinallyLoc,
1848 SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1849 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1851 SourceLocation getFinallyLoc() const { return Loc; }
1852 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1854 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1856 child_range children() {
1857 return child_range(&Block,&Block+1);
1860 static bool classof(const Stmt *T) {
1861 return T->getStmtClass() == SEHFinallyStmtClass;
1866 class SEHTryStmt : public Stmt {
1868 SourceLocation TryLoc;
1871 enum { TRY = 0, HANDLER = 1 };
1873 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1874 SourceLocation TryLoc,
1878 friend class ASTReader;
1879 friend class ASTStmtReader;
1880 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1883 static SEHTryStmt* Create(ASTContext &C,
1885 SourceLocation TryLoc,
1889 SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1890 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1892 SourceLocation getTryLoc() const { return TryLoc; }
1893 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1895 bool getIsCXXTry() const { return IsCXXTry; }
1897 CompoundStmt* getTryBlock() const {
1898 return cast<CompoundStmt>(Children[TRY]);
1901 Stmt *getHandler() const { return Children[HANDLER]; }
1903 /// Returns 0 if not defined
1904 SEHExceptStmt *getExceptHandler() const;
1905 SEHFinallyStmt *getFinallyHandler() const;
1907 child_range children() {
1908 return child_range(Children,Children+2);
1911 static bool classof(const Stmt *T) {
1912 return T->getStmtClass() == SEHTryStmtClass;
1916 /// \brief This captures a statement into a function. For example, the following
1917 /// pragma annotated compound statement can be represented as a CapturedStmt,
1918 /// and this compound statement is the body of an anonymous outlined function.
1920 /// #pragma omp parallel
1925 class CapturedStmt : public Stmt {
1927 /// \brief The different capture forms: by 'this' or by reference, etc.
1928 enum VariableCaptureKind {
1933 /// \brief Describes the capture of either a variable or 'this'.
1935 llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind;
1939 /// \brief Create a new capture.
1941 /// \param Loc The source location associated with this capture.
1943 /// \param Kind The kind of capture (this, ByRef, ...).
1945 /// \param Var The variable being captured, or null if capturing this.
1947 Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0)
1948 : VarAndKind(Var, Kind), Loc(Loc) {
1951 assert(Var == 0 && "'this' capture cannot have a variable!");
1954 assert(Var && "capturing by reference must have a variable!");
1959 /// \brief Determine the kind of capture.
1960 VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
1962 /// \brief Retrieve the source location at which the variable or 'this' was
1964 SourceLocation getLocation() const { return Loc; }
1966 /// \brief Determine whether this capture handles the C++ 'this' pointer.
1967 bool capturesThis() const { return getCaptureKind() == VCK_This; }
1969 /// \brief Determine whether this capture handles a variable.
1970 bool capturesVariable() const { return getCaptureKind() != VCK_This; }
1972 /// \brief Retrieve the declaration of the variable being captured.
1974 /// This operation is only valid if this capture does not capture 'this'.
1975 VarDecl *getCapturedVar() const {
1976 assert(!capturesThis() && "No variable available for 'this' capture");
1977 return VarAndKind.getPointer();
1979 friend class ASTStmtReader;
1983 /// \brief The number of variable captured, including 'this'.
1984 unsigned NumCaptures;
1986 /// \brief The pointer part is the implicit the outlined function and the
1987 /// int part is the captured region kind, 'CR_Default' etc.
1988 llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
1990 /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
1991 RecordDecl *TheRecordDecl;
1993 /// \brief Construct a captured statement.
1994 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
1995 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
1997 /// \brief Construct an empty captured statement.
1998 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2000 Stmt **getStoredStmts() const {
2001 return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2004 Capture *getStoredCaptures() const;
2006 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2009 static CapturedStmt *Create(ASTContext &Context, Stmt *S,
2010 CapturedRegionKind Kind,
2011 ArrayRef<Capture> Captures,
2012 ArrayRef<Expr *> CaptureInits,
2013 CapturedDecl *CD, RecordDecl *RD);
2015 static CapturedStmt *CreateDeserialized(ASTContext &Context,
2016 unsigned NumCaptures);
2018 /// \brief Retrieve the statement being captured.
2019 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2020 const Stmt *getCapturedStmt() const {
2021 return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2024 /// \brief Retrieve the outlined function declaration.
2025 CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
2026 const CapturedDecl *getCapturedDecl() const {
2027 return const_cast<CapturedStmt *>(this)->getCapturedDecl();
2030 /// \brief Set the outlined function declaration.
2031 void setCapturedDecl(CapturedDecl *D) {
2032 assert(D && "null CapturedDecl");
2033 CapDeclAndKind.setPointer(D);
2036 /// \brief Retrieve the captured region kind.
2037 CapturedRegionKind getCapturedRegionKind() const {
2038 return CapDeclAndKind.getInt();
2041 /// \brief Set the captured region kind.
2042 void setCapturedRegionKind(CapturedRegionKind Kind) {
2043 CapDeclAndKind.setInt(Kind);
2046 /// \brief Retrieve the record declaration for captured variables.
2047 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2049 /// \brief Set the record declaration for captured variables.
2050 void setCapturedRecordDecl(RecordDecl *D) {
2051 assert(D && "null RecordDecl");
2055 /// \brief True if this variable has been captured.
2056 bool capturesVariable(const VarDecl *Var) const;
2058 /// \brief An iterator that walks over the captures.
2059 typedef Capture *capture_iterator;
2060 typedef const Capture *const_capture_iterator;
2062 /// \brief Retrieve an iterator pointing to the first capture.
2063 capture_iterator capture_begin() { return getStoredCaptures(); }
2064 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2066 /// \brief Retrieve an iterator pointing past the end of the sequence of
2068 capture_iterator capture_end() const {
2069 return getStoredCaptures() + NumCaptures;
2072 /// \brief Retrieve the number of captures, including 'this'.
2073 unsigned capture_size() const { return NumCaptures; }
2075 /// \brief Iterator that walks over the capture initialization arguments.
2076 typedef Expr **capture_init_iterator;
2078 /// \brief Retrieve the first initialization argument.
2079 capture_init_iterator capture_init_begin() const {
2080 return reinterpret_cast<Expr **>(getStoredStmts());
2083 /// \brief Retrieve the iterator pointing one past the last initialization
2085 capture_init_iterator capture_init_end() const {
2086 return capture_init_begin() + NumCaptures;
2089 SourceLocation getLocStart() const LLVM_READONLY {
2090 return getCapturedStmt()->getLocStart();
2092 SourceLocation getLocEnd() const LLVM_READONLY {
2093 return getCapturedStmt()->getLocEnd();
2095 SourceRange getSourceRange() const LLVM_READONLY {
2096 return getCapturedStmt()->getSourceRange();
2099 static bool classof(const Stmt *T) {
2100 return T->getStmtClass() == CapturedStmtClass;
2103 child_range children();
2105 friend class ASTStmtReader;
2108 } // end namespace clang