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;
271 class TypeTraitExprBitfields {
272 friend class TypeTraitExpr;
273 friend class ASTStmtReader;
274 friend class ASTStmtWriter;
276 unsigned : NumExprBits;
278 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
281 /// \brief If this expression is not value-dependent, this indicates whether
282 /// the trait evaluated true or false.
285 /// \brief The number of arguments to this type trait.
286 unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
290 // FIXME: this is wasteful on 64-bit platforms.
293 StmtBitfields StmtBits;
294 CompoundStmtBitfields CompoundStmtBits;
295 ExprBitfields ExprBits;
296 CharacterLiteralBitfields CharacterLiteralBits;
297 FloatingLiteralBitfields FloatingLiteralBits;
298 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
299 DeclRefExprBitfields DeclRefExprBits;
300 CastExprBitfields CastExprBits;
301 CallExprBitfields CallExprBits;
302 ExprWithCleanupsBitfields ExprWithCleanupsBits;
303 PseudoObjectExprBitfields PseudoObjectExprBits;
304 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
305 InitListExprBitfields InitListExprBits;
306 TypeTraitExprBitfields TypeTraitExprBits;
309 friend class ASTStmtReader;
310 friend class ASTStmtWriter;
313 // Only allow allocation of Stmts using the allocator in ASTContext
314 // or by doing a placement new.
315 void* operator new(size_t bytes, const ASTContext& C,
316 unsigned alignment = 8);
318 void* operator new(size_t bytes, const ASTContext* C,
319 unsigned alignment = 8) {
320 return operator new(bytes, *C, alignment);
323 void* operator new(size_t bytes, void* mem) throw() {
327 void operator delete(void*, const ASTContext&, unsigned) throw() { }
328 void operator delete(void*, const ASTContext*, unsigned) throw() { }
329 void operator delete(void*, size_t) throw() { }
330 void operator delete(void*, void*) throw() { }
333 /// \brief A placeholder type used to construct an empty shell of a
334 /// type, that will be filled in later (e.g., by some
335 /// de-serialization).
336 struct EmptyShell { };
339 /// \brief Whether statistic collection is enabled.
340 static bool StatisticsEnabled;
343 /// \brief Construct an empty statement.
344 explicit Stmt(StmtClass SC, EmptyShell) {
345 StmtBits.sClass = SC;
346 if (StatisticsEnabled) Stmt::addStmtClass(SC);
351 StmtBits.sClass = SC;
352 if (StatisticsEnabled) Stmt::addStmtClass(SC);
355 StmtClass getStmtClass() const {
356 return static_cast<StmtClass>(StmtBits.sClass);
358 const char *getStmtClassName() const;
360 /// SourceLocation tokens are not useful in isolation - they are low level
361 /// value objects created/interpreted by SourceManager. We assume AST
362 /// clients will have a pointer to the respective SourceManager.
363 SourceRange getSourceRange() const LLVM_READONLY;
364 SourceLocation getLocStart() const LLVM_READONLY;
365 SourceLocation getLocEnd() const LLVM_READONLY;
367 // global temp stats (until we have a per-module visitor)
368 static void addStmtClass(const StmtClass s);
369 static void EnableStatistics();
370 static void PrintStats();
372 /// \brief Dumps the specified AST fragment and all subtrees to
375 void dump(SourceManager &SM) const;
376 void dump(raw_ostream &OS, SourceManager &SM) const;
378 /// dumpColor - same as dump(), but forces color highlighting.
379 void dumpColor() const;
381 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
382 /// back to its original source language syntax.
383 void dumpPretty(const ASTContext &Context) const;
384 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
385 const PrintingPolicy &Policy,
386 unsigned Indentation = 0) const;
388 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
389 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
390 void viewAST() const;
392 /// Skip past any implicit AST nodes which might surround this
393 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
394 Stmt *IgnoreImplicit();
396 const Stmt *stripLabelLikeStatements() const;
397 Stmt *stripLabelLikeStatements() {
398 return const_cast<Stmt*>(
399 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
402 /// Child Iterators: All subclasses must implement 'children'
403 /// to permit easy iteration over the substatements/subexpessions of an
404 /// AST node. This permits easy iteration over all nodes in the AST.
405 typedef StmtIterator child_iterator;
406 typedef ConstStmtIterator const_child_iterator;
408 typedef StmtRange child_range;
409 typedef ConstStmtRange const_child_range;
411 child_range children();
412 const_child_range children() const {
413 return const_cast<Stmt*>(this)->children();
416 child_iterator child_begin() { return children().first; }
417 child_iterator child_end() { return children().second; }
419 const_child_iterator child_begin() const { return children().first; }
420 const_child_iterator child_end() const { return children().second; }
422 /// \brief Produce a unique representation of the given statement.
424 /// \param ID once the profiling operation is complete, will contain
425 /// the unique representation of the given statement.
427 /// \param Context the AST context in which the statement resides
429 /// \param Canonical whether the profile should be based on the canonical
430 /// representation of this statement (e.g., where non-type template
431 /// parameters are identified by index/level rather than their
432 /// declaration pointers) or the exact representation of the statement as
433 /// written in the source.
434 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
435 bool Canonical) const;
438 /// DeclStmt - Adaptor class for mixing declarations with statements and
439 /// expressions. For example, CompoundStmt mixes statements, expressions
440 /// and declarations (variables, types). Another example is ForStmt, where
441 /// the first statement can be an expression or a declaration.
443 class DeclStmt : public Stmt {
445 SourceLocation StartLoc, EndLoc;
448 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
449 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
450 StartLoc(startLoc), EndLoc(endLoc) {}
452 /// \brief Build an empty declaration statement.
453 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
455 /// isSingleDecl - This method returns true if this DeclStmt refers
456 /// to a single Decl.
457 bool isSingleDecl() const {
458 return DG.isSingleDecl();
461 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
462 Decl *getSingleDecl() { return DG.getSingleDecl(); }
464 const DeclGroupRef getDeclGroup() const { return DG; }
465 DeclGroupRef getDeclGroup() { return DG; }
466 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
468 SourceLocation getStartLoc() const { return StartLoc; }
469 void setStartLoc(SourceLocation L) { StartLoc = L; }
470 SourceLocation getEndLoc() const { return EndLoc; }
471 void setEndLoc(SourceLocation L) { EndLoc = L; }
473 SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
474 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
476 static bool classof(const Stmt *T) {
477 return T->getStmtClass() == DeclStmtClass;
480 // Iterators over subexpressions.
481 child_range children() {
482 return child_range(child_iterator(DG.begin(), DG.end()),
483 child_iterator(DG.end(), DG.end()));
486 typedef DeclGroupRef::iterator decl_iterator;
487 typedef DeclGroupRef::const_iterator const_decl_iterator;
488 typedef llvm::iterator_range<decl_iterator> decl_range;
489 typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
491 decl_range decls() { return decl_range(decl_begin(), decl_end()); }
492 decl_const_range decls() const {
493 return decl_const_range(decl_begin(), decl_end());
495 decl_iterator decl_begin() { return DG.begin(); }
496 decl_iterator decl_end() { return DG.end(); }
497 const_decl_iterator decl_begin() const { return DG.begin(); }
498 const_decl_iterator decl_end() const { return DG.end(); }
500 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
501 reverse_decl_iterator decl_rbegin() {
502 return reverse_decl_iterator(decl_end());
504 reverse_decl_iterator decl_rend() {
505 return reverse_decl_iterator(decl_begin());
509 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
511 class NullStmt : public Stmt {
512 SourceLocation SemiLoc;
514 /// \brief True if the null statement was preceded by an empty macro, e.g:
519 bool HasLeadingEmptyMacro;
521 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
522 : Stmt(NullStmtClass), SemiLoc(L),
523 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
525 /// \brief Build an empty null statement.
526 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
527 HasLeadingEmptyMacro(false) { }
529 SourceLocation getSemiLoc() const { return SemiLoc; }
530 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
532 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
534 SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
535 SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
537 static bool classof(const Stmt *T) {
538 return T->getStmtClass() == NullStmtClass;
541 child_range children() { return child_range(); }
543 friend class ASTStmtReader;
544 friend class ASTStmtWriter;
547 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
549 class CompoundStmt : public Stmt {
551 SourceLocation LBracLoc, RBracLoc;
553 CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
554 SourceLocation LB, SourceLocation RB);
556 // \brief Build an empty compound statement with a location.
557 explicit CompoundStmt(SourceLocation Loc)
558 : Stmt(CompoundStmtClass), Body(0), LBracLoc(Loc), RBracLoc(Loc) {
559 CompoundStmtBits.NumStmts = 0;
562 // \brief Build an empty compound statement.
563 explicit CompoundStmt(EmptyShell Empty)
564 : Stmt(CompoundStmtClass, Empty), Body(0) {
565 CompoundStmtBits.NumStmts = 0;
568 void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts);
570 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
571 unsigned size() const { return CompoundStmtBits.NumStmts; }
573 typedef Stmt** body_iterator;
574 typedef llvm::iterator_range<body_iterator> body_range;
576 body_range body() { return body_range(body_begin(), body_end()); }
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 typedef llvm::iterator_range<const_body_iterator> body_const_range;
589 body_const_range body() const {
590 return body_const_range(body_begin(), body_end());
592 const_body_iterator body_begin() const { return Body; }
593 const_body_iterator body_end() const { return Body + size(); }
594 const Stmt *body_back() const { return !body_empty() ? Body[size()-1] : 0; }
596 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
597 reverse_body_iterator body_rbegin() {
598 return reverse_body_iterator(body_end());
600 reverse_body_iterator body_rend() {
601 return reverse_body_iterator(body_begin());
604 typedef std::reverse_iterator<const_body_iterator>
605 const_reverse_body_iterator;
607 const_reverse_body_iterator body_rbegin() const {
608 return const_reverse_body_iterator(body_end());
611 const_reverse_body_iterator body_rend() const {
612 return const_reverse_body_iterator(body_begin());
615 SourceLocation getLocStart() const LLVM_READONLY { return LBracLoc; }
616 SourceLocation getLocEnd() const LLVM_READONLY { return RBracLoc; }
618 SourceLocation getLBracLoc() const { return LBracLoc; }
619 void setLBracLoc(SourceLocation L) { LBracLoc = L; }
620 SourceLocation getRBracLoc() const { return RBracLoc; }
621 void setRBracLoc(SourceLocation L) { RBracLoc = L; }
623 static bool classof(const Stmt *T) {
624 return T->getStmtClass() == CompoundStmtClass;
628 child_range children() {
629 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
632 const_child_range children() const {
633 return child_range(&Body[0], &Body[0]+CompoundStmtBits.NumStmts);
637 // SwitchCase is the base class for CaseStmt and DefaultStmt,
638 class SwitchCase : public Stmt {
640 // A pointer to the following CaseStmt or DefaultStmt class,
641 // used by SwitchStmt.
642 SwitchCase *NextSwitchCase;
643 SourceLocation KeywordLoc;
644 SourceLocation ColonLoc;
646 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
647 : Stmt(SC), NextSwitchCase(0), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {}
649 SwitchCase(StmtClass SC, EmptyShell)
650 : Stmt(SC), NextSwitchCase(0) {}
653 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
655 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
657 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
659 SourceLocation getKeywordLoc() const { return KeywordLoc; }
660 void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
661 SourceLocation getColonLoc() const { return ColonLoc; }
662 void setColonLoc(SourceLocation L) { ColonLoc = L; }
665 const Stmt *getSubStmt() const {
666 return const_cast<SwitchCase*>(this)->getSubStmt();
669 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
670 SourceLocation getLocEnd() const LLVM_READONLY;
672 static bool classof(const Stmt *T) {
673 return T->getStmtClass() == CaseStmtClass ||
674 T->getStmtClass() == DefaultStmtClass;
678 class CaseStmt : public SwitchCase {
679 enum { LHS, RHS, SUBSTMT, END_EXPR };
680 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
681 // GNU "case 1 ... 4" extension
682 SourceLocation EllipsisLoc;
684 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
685 SourceLocation ellipsisLoc, SourceLocation colonLoc)
686 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
687 SubExprs[SUBSTMT] = 0;
688 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
689 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
690 EllipsisLoc = ellipsisLoc;
693 /// \brief Build an empty switch case statement.
694 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
696 SourceLocation getCaseLoc() const { return KeywordLoc; }
697 void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
698 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
699 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
700 SourceLocation getColonLoc() const { return ColonLoc; }
701 void setColonLoc(SourceLocation L) { ColonLoc = L; }
703 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
704 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
705 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
707 const Expr *getLHS() const {
708 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
710 const Expr *getRHS() const {
711 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
713 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
715 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
716 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
717 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
719 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
720 SourceLocation getLocEnd() const LLVM_READONLY {
721 // Handle deeply nested case statements with iteration instead of recursion.
722 const CaseStmt *CS = this;
723 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
726 return CS->getSubStmt()->getLocEnd();
729 static bool classof(const Stmt *T) {
730 return T->getStmtClass() == CaseStmtClass;
734 child_range children() {
735 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
739 class DefaultStmt : public SwitchCase {
742 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
743 SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
745 /// \brief Build an empty default statement.
746 explicit DefaultStmt(EmptyShell Empty)
747 : SwitchCase(DefaultStmtClass, Empty) { }
749 Stmt *getSubStmt() { return SubStmt; }
750 const Stmt *getSubStmt() const { return SubStmt; }
751 void setSubStmt(Stmt *S) { SubStmt = S; }
753 SourceLocation getDefaultLoc() const { return KeywordLoc; }
754 void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
755 SourceLocation getColonLoc() const { return ColonLoc; }
756 void setColonLoc(SourceLocation L) { ColonLoc = L; }
758 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
759 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
761 static bool classof(const Stmt *T) {
762 return T->getStmtClass() == DefaultStmtClass;
766 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
769 inline SourceLocation SwitchCase::getLocEnd() const {
770 if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
771 return CS->getLocEnd();
772 return cast<DefaultStmt>(this)->getLocEnd();
775 /// LabelStmt - Represents a label, which has a substatement. For example:
778 class LabelStmt : public Stmt {
781 SourceLocation IdentLoc;
783 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
784 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
787 // \brief Build an empty label statement.
788 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
790 SourceLocation getIdentLoc() const { return IdentLoc; }
791 LabelDecl *getDecl() const { return TheDecl; }
792 void setDecl(LabelDecl *D) { TheDecl = D; }
793 const char *getName() const;
794 Stmt *getSubStmt() { return SubStmt; }
795 const Stmt *getSubStmt() const { return SubStmt; }
796 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
797 void setSubStmt(Stmt *SS) { SubStmt = SS; }
799 SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
800 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
802 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
804 static bool classof(const Stmt *T) {
805 return T->getStmtClass() == LabelStmtClass;
810 /// \brief Represents an attribute applied to a statement.
812 /// Represents an attribute applied to a statement. For example:
813 /// [[omp::for(...)]] for (...) { ... }
815 class AttributedStmt : public Stmt {
817 SourceLocation AttrLoc;
819 const Attr *Attrs[1];
821 friend class ASTStmtReader;
823 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
824 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
825 NumAttrs(Attrs.size()) {
826 memcpy(this->Attrs, Attrs.data(), Attrs.size() * sizeof(Attr*));
829 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
830 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
831 memset(Attrs, 0, NumAttrs * sizeof(Attr*));
835 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
836 ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
837 // \brief Build an empty attributed statement.
838 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
840 SourceLocation getAttrLoc() const { return AttrLoc; }
841 ArrayRef<const Attr*> getAttrs() const {
842 return ArrayRef<const Attr*>(Attrs, NumAttrs);
844 Stmt *getSubStmt() { return SubStmt; }
845 const Stmt *getSubStmt() const { return SubStmt; }
847 SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
848 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
850 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
852 static bool classof(const Stmt *T) {
853 return T->getStmtClass() == AttributedStmtClass;
858 /// IfStmt - This represents an if/then/else.
860 class IfStmt : public Stmt {
861 enum { VAR, COND, THEN, ELSE, END_EXPR };
862 Stmt* SubExprs[END_EXPR];
864 SourceLocation IfLoc;
865 SourceLocation ElseLoc;
868 IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
869 Stmt *then, SourceLocation EL = SourceLocation(), Stmt *elsev = 0);
871 /// \brief Build an empty if/then/else statement
872 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
874 /// \brief Retrieve the variable declared in this "if" statement, if any.
876 /// In the following example, "x" is the condition variable.
878 /// if (int x = foo()) {
879 /// printf("x is %d", x);
882 VarDecl *getConditionVariable() const;
883 void setConditionVariable(const ASTContext &C, VarDecl *V);
885 /// If this IfStmt has a condition variable, return the faux DeclStmt
886 /// associated with the creation of that condition variable.
887 const DeclStmt *getConditionVariableDeclStmt() const {
888 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
891 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
892 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
893 const Stmt *getThen() const { return SubExprs[THEN]; }
894 void setThen(Stmt *S) { SubExprs[THEN] = S; }
895 const Stmt *getElse() const { return SubExprs[ELSE]; }
896 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
898 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
899 Stmt *getThen() { return SubExprs[THEN]; }
900 Stmt *getElse() { return SubExprs[ELSE]; }
902 SourceLocation getIfLoc() const { return IfLoc; }
903 void setIfLoc(SourceLocation L) { IfLoc = L; }
904 SourceLocation getElseLoc() const { return ElseLoc; }
905 void setElseLoc(SourceLocation L) { ElseLoc = L; }
907 SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
908 SourceLocation getLocEnd() const LLVM_READONLY {
910 return SubExprs[ELSE]->getLocEnd();
912 return SubExprs[THEN]->getLocEnd();
915 // Iterators over subexpressions. The iterators will include iterating
916 // over the initialization expression referenced by the condition variable.
917 child_range children() {
918 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
921 static bool classof(const Stmt *T) {
922 return T->getStmtClass() == IfStmtClass;
926 /// SwitchStmt - This represents a 'switch' stmt.
928 class SwitchStmt : public Stmt {
929 enum { VAR, COND, BODY, END_EXPR };
930 Stmt* SubExprs[END_EXPR];
931 // This points to a linked list of case and default statements.
932 SwitchCase *FirstCase;
933 SourceLocation SwitchLoc;
935 /// If the SwitchStmt is a switch on an enum value, this records whether
936 /// all the enum values were covered by CaseStmts. This value is meant to
937 /// be a hint for possible clients.
938 unsigned AllEnumCasesCovered : 1;
941 SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond);
943 /// \brief Build a empty switch statement.
944 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
946 /// \brief Retrieve the variable declared in this "switch" statement, if any.
948 /// In the following example, "x" is the condition variable.
950 /// switch (int x = foo()) {
955 VarDecl *getConditionVariable() const;
956 void setConditionVariable(const ASTContext &C, VarDecl *V);
958 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
959 /// associated with the creation of that condition variable.
960 const DeclStmt *getConditionVariableDeclStmt() const {
961 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
964 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
965 const Stmt *getBody() const { return SubExprs[BODY]; }
966 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
968 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
969 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
970 Stmt *getBody() { return SubExprs[BODY]; }
971 void setBody(Stmt *S) { SubExprs[BODY] = S; }
972 SwitchCase *getSwitchCaseList() { return FirstCase; }
974 /// \brief Set the case list for this switch statement.
975 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
977 SourceLocation getSwitchLoc() const { return SwitchLoc; }
978 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
980 void setBody(Stmt *S, SourceLocation SL) {
984 void addSwitchCase(SwitchCase *SC) {
985 assert(!SC->getNextSwitchCase()
986 && "case/default already added to a switch");
987 SC->setNextSwitchCase(FirstCase);
991 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
992 /// switch over an enum value then all cases have been explicitly covered.
993 void setAllEnumCasesCovered() {
994 AllEnumCasesCovered = 1;
997 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
998 /// have been explicitly covered.
999 bool isAllEnumCasesCovered() const {
1000 return (bool) AllEnumCasesCovered;
1003 SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1004 SourceLocation getLocEnd() const LLVM_READONLY {
1005 return SubExprs[BODY]->getLocEnd();
1009 child_range children() {
1010 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1013 static bool classof(const Stmt *T) {
1014 return T->getStmtClass() == SwitchStmtClass;
1019 /// WhileStmt - This represents a 'while' stmt.
1021 class WhileStmt : public Stmt {
1022 enum { VAR, COND, BODY, END_EXPR };
1023 Stmt* SubExprs[END_EXPR];
1024 SourceLocation WhileLoc;
1026 WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1029 /// \brief Build an empty while statement.
1030 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1032 /// \brief Retrieve the variable declared in this "while" statement, if any.
1034 /// In the following example, "x" is the condition variable.
1036 /// while (int x = random()) {
1040 VarDecl *getConditionVariable() const;
1041 void setConditionVariable(const ASTContext &C, VarDecl *V);
1043 /// If this WhileStmt has a condition variable, return the faux DeclStmt
1044 /// associated with the creation of that condition variable.
1045 const DeclStmt *getConditionVariableDeclStmt() const {
1046 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1049 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1050 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1051 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1052 Stmt *getBody() { return SubExprs[BODY]; }
1053 const Stmt *getBody() const { return SubExprs[BODY]; }
1054 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1056 SourceLocation getWhileLoc() const { return WhileLoc; }
1057 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1059 SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1060 SourceLocation getLocEnd() const LLVM_READONLY {
1061 return SubExprs[BODY]->getLocEnd();
1064 static bool classof(const Stmt *T) {
1065 return T->getStmtClass() == WhileStmtClass;
1069 child_range children() {
1070 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1074 /// DoStmt - This represents a 'do/while' stmt.
1076 class DoStmt : public Stmt {
1077 enum { BODY, COND, END_EXPR };
1078 Stmt* SubExprs[END_EXPR];
1079 SourceLocation DoLoc;
1080 SourceLocation WhileLoc;
1081 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
1084 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1086 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1087 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1088 SubExprs[BODY] = body;
1091 /// \brief Build an empty do-while statement.
1092 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1094 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1095 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1096 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1097 Stmt *getBody() { return SubExprs[BODY]; }
1098 const Stmt *getBody() const { return SubExprs[BODY]; }
1099 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1101 SourceLocation getDoLoc() const { return DoLoc; }
1102 void setDoLoc(SourceLocation L) { DoLoc = L; }
1103 SourceLocation getWhileLoc() const { return WhileLoc; }
1104 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1106 SourceLocation getRParenLoc() const { return RParenLoc; }
1107 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1109 SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1110 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1112 static bool classof(const Stmt *T) {
1113 return T->getStmtClass() == DoStmtClass;
1117 child_range children() {
1118 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1123 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
1124 /// the init/cond/inc parts of the ForStmt will be null if they were not
1125 /// specified in the source.
1127 class ForStmt : public Stmt {
1128 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1129 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1130 SourceLocation ForLoc;
1131 SourceLocation LParenLoc, RParenLoc;
1134 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1135 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1138 /// \brief Build an empty for statement.
1139 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1141 Stmt *getInit() { return SubExprs[INIT]; }
1143 /// \brief Retrieve the variable declared in this "for" statement, if any.
1145 /// In the following example, "y" is the condition variable.
1147 /// for (int x = random(); int y = mangle(x); ++x) {
1151 VarDecl *getConditionVariable() const;
1152 void setConditionVariable(const ASTContext &C, VarDecl *V);
1154 /// If this ForStmt has a condition variable, return the faux DeclStmt
1155 /// associated with the creation of that condition variable.
1156 const DeclStmt *getConditionVariableDeclStmt() const {
1157 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1160 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1161 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1162 Stmt *getBody() { return SubExprs[BODY]; }
1164 const Stmt *getInit() const { return SubExprs[INIT]; }
1165 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1166 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1167 const Stmt *getBody() const { return SubExprs[BODY]; }
1169 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1170 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1171 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1172 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1174 SourceLocation getForLoc() const { return ForLoc; }
1175 void setForLoc(SourceLocation L) { ForLoc = L; }
1176 SourceLocation getLParenLoc() const { return LParenLoc; }
1177 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1178 SourceLocation getRParenLoc() const { return RParenLoc; }
1179 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1181 SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1182 SourceLocation getLocEnd() const LLVM_READONLY {
1183 return SubExprs[BODY]->getLocEnd();
1186 static bool classof(const Stmt *T) {
1187 return T->getStmtClass() == ForStmtClass;
1191 child_range children() {
1192 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1196 /// GotoStmt - This represents a direct goto.
1198 class GotoStmt : public Stmt {
1200 SourceLocation GotoLoc;
1201 SourceLocation LabelLoc;
1203 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1204 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1206 /// \brief Build an empty goto statement.
1207 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1209 LabelDecl *getLabel() const { return Label; }
1210 void setLabel(LabelDecl *D) { Label = D; }
1212 SourceLocation getGotoLoc() const { return GotoLoc; }
1213 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1214 SourceLocation getLabelLoc() const { return LabelLoc; }
1215 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1217 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1218 SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1220 static bool classof(const Stmt *T) {
1221 return T->getStmtClass() == GotoStmtClass;
1225 child_range children() { return child_range(); }
1228 /// IndirectGotoStmt - This represents an indirect goto.
1230 class IndirectGotoStmt : public Stmt {
1231 SourceLocation GotoLoc;
1232 SourceLocation StarLoc;
1235 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1237 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1238 Target((Stmt*)target) {}
1240 /// \brief Build an empty indirect goto statement.
1241 explicit IndirectGotoStmt(EmptyShell Empty)
1242 : Stmt(IndirectGotoStmtClass, Empty) { }
1244 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1245 SourceLocation getGotoLoc() const { return GotoLoc; }
1246 void setStarLoc(SourceLocation L) { StarLoc = L; }
1247 SourceLocation getStarLoc() const { return StarLoc; }
1249 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1250 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1251 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1253 /// getConstantTarget - Returns the fixed target of this indirect
1254 /// goto, if one exists.
1255 LabelDecl *getConstantTarget();
1256 const LabelDecl *getConstantTarget() const {
1257 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1260 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1261 SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1263 static bool classof(const Stmt *T) {
1264 return T->getStmtClass() == IndirectGotoStmtClass;
1268 child_range children() { return child_range(&Target, &Target+1); }
1272 /// ContinueStmt - This represents a continue.
1274 class ContinueStmt : public Stmt {
1275 SourceLocation ContinueLoc;
1277 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1279 /// \brief Build an empty continue statement.
1280 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1282 SourceLocation getContinueLoc() const { return ContinueLoc; }
1283 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1285 SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1286 SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1288 static bool classof(const Stmt *T) {
1289 return T->getStmtClass() == ContinueStmtClass;
1293 child_range children() { return child_range(); }
1296 /// BreakStmt - This represents a break.
1298 class BreakStmt : public Stmt {
1299 SourceLocation BreakLoc;
1301 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1303 /// \brief Build an empty break statement.
1304 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1306 SourceLocation getBreakLoc() const { return BreakLoc; }
1307 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1309 SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1310 SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1312 static bool classof(const Stmt *T) {
1313 return T->getStmtClass() == BreakStmtClass;
1317 child_range children() { return child_range(); }
1321 /// ReturnStmt - This represents a return, optionally of an expression:
1325 /// Note that GCC allows return with no argument in a function declared to
1326 /// return a value, and it allows returning a value in functions declared to
1327 /// return void. We explicitly model this in the AST, which means you can't
1328 /// depend on the return type of the function and the presence of an argument.
1330 class ReturnStmt : public Stmt {
1332 SourceLocation RetLoc;
1333 const VarDecl *NRVOCandidate;
1336 ReturnStmt(SourceLocation RL)
1337 : Stmt(ReturnStmtClass), RetExpr(0), RetLoc(RL), NRVOCandidate(0) { }
1339 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1340 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1341 NRVOCandidate(NRVOCandidate) {}
1343 /// \brief Build an empty return expression.
1344 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1346 const Expr *getRetValue() const;
1347 Expr *getRetValue();
1348 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1350 SourceLocation getReturnLoc() const { return RetLoc; }
1351 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1353 /// \brief Retrieve the variable that might be used for the named return
1354 /// value optimization.
1356 /// The optimization itself can only be performed if the variable is
1357 /// also marked as an NRVO object.
1358 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1359 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1361 SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1362 SourceLocation getLocEnd() const LLVM_READONLY {
1363 return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1366 static bool classof(const Stmt *T) {
1367 return T->getStmtClass() == ReturnStmtClass;
1371 child_range children() {
1372 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1373 return child_range();
1377 /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1379 class AsmStmt : public Stmt {
1381 SourceLocation AsmLoc;
1382 /// \brief True if the assembly statement does not have any input or output
1386 /// \brief If true, treat this inline assembly as having side effects.
1387 /// This assembly statement should not be optimized, deleted or moved.
1390 unsigned NumOutputs;
1392 unsigned NumClobbers;
1396 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1397 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1398 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1399 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1401 friend class ASTStmtReader;
1404 /// \brief Build an empty inline-assembly statement.
1405 explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1406 Stmt(SC, Empty), Exprs(0) { }
1408 SourceLocation getAsmLoc() const { return AsmLoc; }
1409 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1411 bool isSimple() const { return IsSimple; }
1412 void setSimple(bool V) { IsSimple = V; }
1414 bool isVolatile() const { return IsVolatile; }
1415 void setVolatile(bool V) { IsVolatile = V; }
1417 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1418 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1420 //===--- Asm String Analysis ---===//
1422 /// Assemble final IR asm string.
1423 std::string generateAsmString(const ASTContext &C) const;
1425 //===--- Output operands ---===//
1427 unsigned getNumOutputs() const { return NumOutputs; }
1429 /// getOutputConstraint - Return the constraint string for the specified
1430 /// output operand. All output constraints are known to be non-empty (either
1432 StringRef getOutputConstraint(unsigned i) const;
1434 /// isOutputPlusConstraint - Return true if the specified output constraint
1435 /// is a "+" constraint (which is both an input and an output) or false if it
1436 /// is an "=" constraint (just an output).
1437 bool isOutputPlusConstraint(unsigned i) const {
1438 return getOutputConstraint(i)[0] == '+';
1441 const Expr *getOutputExpr(unsigned i) const;
1443 /// getNumPlusOperands - Return the number of output operands that have a "+"
1445 unsigned getNumPlusOperands() const;
1447 //===--- Input operands ---===//
1449 unsigned getNumInputs() const { return NumInputs; }
1451 /// getInputConstraint - Return the specified input constraint. Unlike output
1452 /// constraints, these can be empty.
1453 StringRef getInputConstraint(unsigned i) const;
1455 const Expr *getInputExpr(unsigned i) const;
1457 //===--- Other ---===//
1459 unsigned getNumClobbers() const { return NumClobbers; }
1460 StringRef getClobber(unsigned i) const;
1462 static bool classof(const Stmt *T) {
1463 return T->getStmtClass() == GCCAsmStmtClass ||
1464 T->getStmtClass() == MSAsmStmtClass;
1467 // Input expr iterators.
1469 typedef ExprIterator inputs_iterator;
1470 typedef ConstExprIterator const_inputs_iterator;
1472 inputs_iterator begin_inputs() {
1473 return &Exprs[0] + NumOutputs;
1476 inputs_iterator end_inputs() {
1477 return &Exprs[0] + NumOutputs + NumInputs;
1480 const_inputs_iterator begin_inputs() const {
1481 return &Exprs[0] + NumOutputs;
1484 const_inputs_iterator end_inputs() const {
1485 return &Exprs[0] + NumOutputs + NumInputs;
1488 // Output expr iterators.
1490 typedef ExprIterator outputs_iterator;
1491 typedef ConstExprIterator const_outputs_iterator;
1493 outputs_iterator begin_outputs() {
1496 outputs_iterator end_outputs() {
1497 return &Exprs[0] + NumOutputs;
1500 const_outputs_iterator begin_outputs() const {
1503 const_outputs_iterator end_outputs() const {
1504 return &Exprs[0] + NumOutputs;
1507 child_range children() {
1508 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1512 /// This represents a GCC inline-assembly statement extension.
1514 class GCCAsmStmt : public AsmStmt {
1515 SourceLocation RParenLoc;
1516 StringLiteral *AsmStr;
1518 // FIXME: If we wanted to, we could allocate all of these in one big array.
1519 StringLiteral **Constraints;
1520 StringLiteral **Clobbers;
1521 IdentifierInfo **Names;
1523 friend class ASTStmtReader;
1526 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1527 bool isvolatile, unsigned numoutputs, unsigned numinputs,
1528 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1529 StringLiteral *asmstr, unsigned numclobbers,
1530 StringLiteral **clobbers, SourceLocation rparenloc);
1532 /// \brief Build an empty inline-assembly statement.
1533 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1534 Constraints(0), Clobbers(0), Names(0) { }
1536 SourceLocation getRParenLoc() const { return RParenLoc; }
1537 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1539 //===--- Asm String Analysis ---===//
1541 const StringLiteral *getAsmString() const { return AsmStr; }
1542 StringLiteral *getAsmString() { return AsmStr; }
1543 void setAsmString(StringLiteral *E) { AsmStr = E; }
1545 /// AsmStringPiece - this is part of a decomposed asm string specification
1546 /// (for use with the AnalyzeAsmString function below). An asm string is
1547 /// considered to be a concatenation of these parts.
1548 class AsmStringPiece {
1551 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1552 Operand // Operand reference, with optional modifier %c4.
1559 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1560 AsmStringPiece(unsigned OpNo, char Modifier)
1561 : MyKind(Operand), Str(), OperandNo(OpNo) {
1565 bool isString() const { return MyKind == String; }
1566 bool isOperand() const { return MyKind == Operand; }
1568 const std::string &getString() const {
1573 unsigned getOperandNo() const {
1574 assert(isOperand());
1578 /// getModifier - Get the modifier for this operand, if present. This
1579 /// returns '\0' if there was no modifier.
1580 char getModifier() const {
1581 assert(isOperand());
1586 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1587 /// it into pieces. If the asm string is erroneous, emit errors and return
1588 /// true, otherwise return false. This handles canonicalization and
1589 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1590 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1591 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1592 const ASTContext &C, unsigned &DiagOffs) const;
1594 /// Assemble final IR asm string.
1595 std::string generateAsmString(const ASTContext &C) const;
1597 //===--- Output operands ---===//
1599 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1603 StringRef getOutputName(unsigned i) const {
1604 if (IdentifierInfo *II = getOutputIdentifier(i))
1605 return II->getName();
1610 StringRef getOutputConstraint(unsigned i) const;
1612 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1613 return Constraints[i];
1615 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1616 return Constraints[i];
1619 Expr *getOutputExpr(unsigned i);
1621 const Expr *getOutputExpr(unsigned i) const {
1622 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1625 //===--- Input operands ---===//
1627 IdentifierInfo *getInputIdentifier(unsigned i) const {
1628 return Names[i + NumOutputs];
1631 StringRef getInputName(unsigned i) const {
1632 if (IdentifierInfo *II = getInputIdentifier(i))
1633 return II->getName();
1638 StringRef getInputConstraint(unsigned i) const;
1640 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1641 return Constraints[i + NumOutputs];
1643 StringLiteral *getInputConstraintLiteral(unsigned i) {
1644 return Constraints[i + NumOutputs];
1647 Expr *getInputExpr(unsigned i);
1648 void setInputExpr(unsigned i, Expr *E);
1650 const Expr *getInputExpr(unsigned i) const {
1651 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1655 void setOutputsAndInputsAndClobbers(const ASTContext &C,
1656 IdentifierInfo **Names,
1657 StringLiteral **Constraints,
1659 unsigned NumOutputs,
1661 StringLiteral **Clobbers,
1662 unsigned NumClobbers);
1665 //===--- Other ---===//
1667 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1668 /// translate this into a numeric value needed to reference the same operand.
1669 /// This returns -1 if the operand name is invalid.
1670 int getNamedOperand(StringRef SymbolicName) const;
1672 StringRef getClobber(unsigned i) const;
1673 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1674 const StringLiteral *getClobberStringLiteral(unsigned i) const {
1678 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1679 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1681 static bool classof(const Stmt *T) {
1682 return T->getStmtClass() == GCCAsmStmtClass;
1686 /// This represents a Microsoft inline-assembly statement extension.
1688 class MSAsmStmt : public AsmStmt {
1689 SourceLocation LBraceLoc, EndLoc;
1692 unsigned NumAsmToks;
1695 StringRef *Constraints;
1696 StringRef *Clobbers;
1698 friend class ASTStmtReader;
1701 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
1702 SourceLocation lbraceloc, bool issimple, bool isvolatile,
1703 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1704 ArrayRef<StringRef> constraints,
1705 ArrayRef<Expr*> exprs, StringRef asmstr,
1706 ArrayRef<StringRef> clobbers, SourceLocation endloc);
1708 /// \brief Build an empty MS-style inline-assembly statement.
1709 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1710 NumAsmToks(0), AsmToks(0), Constraints(0), Clobbers(0) { }
1712 SourceLocation getLBraceLoc() const { return LBraceLoc; }
1713 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1714 SourceLocation getEndLoc() const { return EndLoc; }
1715 void setEndLoc(SourceLocation L) { EndLoc = L; }
1717 bool hasBraces() const { return LBraceLoc.isValid(); }
1719 unsigned getNumAsmToks() { return NumAsmToks; }
1720 Token *getAsmToks() { return AsmToks; }
1722 //===--- Asm String Analysis ---===//
1723 StringRef getAsmString() const { return AsmStr; }
1725 /// Assemble final IR asm string.
1726 std::string generateAsmString(const ASTContext &C) const;
1728 //===--- Output operands ---===//
1730 StringRef getOutputConstraint(unsigned i) const {
1731 assert(i < NumOutputs);
1732 return Constraints[i];
1735 Expr *getOutputExpr(unsigned i);
1737 const Expr *getOutputExpr(unsigned i) const {
1738 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1741 //===--- Input operands ---===//
1743 StringRef getInputConstraint(unsigned i) const {
1744 assert(i < NumInputs);
1745 return Constraints[i + NumOutputs];
1748 Expr *getInputExpr(unsigned i);
1749 void setInputExpr(unsigned i, Expr *E);
1751 const Expr *getInputExpr(unsigned i) const {
1752 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1755 //===--- Other ---===//
1757 ArrayRef<StringRef> getAllConstraints() const {
1758 return ArrayRef<StringRef>(Constraints, NumInputs + NumOutputs);
1760 ArrayRef<StringRef> getClobbers() const {
1761 return ArrayRef<StringRef>(Clobbers, NumClobbers);
1763 ArrayRef<Expr*> getAllExprs() const {
1764 return ArrayRef<Expr*>(reinterpret_cast<Expr**>(Exprs),
1765 NumInputs + NumOutputs);
1768 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1771 void initialize(const ASTContext &C, StringRef AsmString,
1772 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
1773 ArrayRef<Expr*> Exprs, 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[NumInputs + NumOutputs]);
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(const 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(const 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(const ASTContext &C, bool isCXXTry,
1884 SourceLocation TryLoc, Stmt *TryBlock,
1887 SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1888 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1890 SourceLocation getTryLoc() const { return TryLoc; }
1891 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1893 bool getIsCXXTry() const { return IsCXXTry; }
1895 CompoundStmt* getTryBlock() const {
1896 return cast<CompoundStmt>(Children[TRY]);
1899 Stmt *getHandler() const { return Children[HANDLER]; }
1901 /// Returns 0 if not defined
1902 SEHExceptStmt *getExceptHandler() const;
1903 SEHFinallyStmt *getFinallyHandler() const;
1905 child_range children() {
1906 return child_range(Children,Children+2);
1909 static bool classof(const Stmt *T) {
1910 return T->getStmtClass() == SEHTryStmtClass;
1914 /// \brief This captures a statement into a function. For example, the following
1915 /// pragma annotated compound statement can be represented as a CapturedStmt,
1916 /// and this compound statement is the body of an anonymous outlined function.
1918 /// #pragma omp parallel
1923 class CapturedStmt : public Stmt {
1925 /// \brief The different capture forms: by 'this' or by reference, etc.
1926 enum VariableCaptureKind {
1931 /// \brief Describes the capture of either a variable or 'this'.
1933 llvm::PointerIntPair<VarDecl *, 1, VariableCaptureKind> VarAndKind;
1937 /// \brief Create a new capture.
1939 /// \param Loc The source location associated with this capture.
1941 /// \param Kind The kind of capture (this, ByRef, ...).
1943 /// \param Var The variable being captured, or null if capturing this.
1945 Capture(SourceLocation Loc, VariableCaptureKind Kind, VarDecl *Var = 0)
1946 : VarAndKind(Var, Kind), Loc(Loc) {
1949 assert(Var == 0 && "'this' capture cannot have a variable!");
1952 assert(Var && "capturing by reference must have a variable!");
1957 /// \brief Determine the kind of capture.
1958 VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
1960 /// \brief Retrieve the source location at which the variable or 'this' was
1962 SourceLocation getLocation() const { return Loc; }
1964 /// \brief Determine whether this capture handles the C++ 'this' pointer.
1965 bool capturesThis() const { return getCaptureKind() == VCK_This; }
1967 /// \brief Determine whether this capture handles a variable.
1968 bool capturesVariable() const { return getCaptureKind() != VCK_This; }
1970 /// \brief Retrieve the declaration of the variable being captured.
1972 /// This operation is only valid if this capture does not capture 'this'.
1973 VarDecl *getCapturedVar() const {
1974 assert(!capturesThis() && "No variable available for 'this' capture");
1975 return VarAndKind.getPointer();
1977 friend class ASTStmtReader;
1981 /// \brief The number of variable captured, including 'this'.
1982 unsigned NumCaptures;
1984 /// \brief The pointer part is the implicit the outlined function and the
1985 /// int part is the captured region kind, 'CR_Default' etc.
1986 llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
1988 /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
1989 RecordDecl *TheRecordDecl;
1991 /// \brief Construct a captured statement.
1992 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
1993 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
1995 /// \brief Construct an empty captured statement.
1996 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
1998 Stmt **getStoredStmts() const {
1999 return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2002 Capture *getStoredCaptures() const;
2004 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2007 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
2008 CapturedRegionKind Kind,
2009 ArrayRef<Capture> Captures,
2010 ArrayRef<Expr *> CaptureInits,
2011 CapturedDecl *CD, RecordDecl *RD);
2013 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2014 unsigned NumCaptures);
2016 /// \brief Retrieve the statement being captured.
2017 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2018 const Stmt *getCapturedStmt() const {
2019 return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2022 /// \brief Retrieve the outlined function declaration.
2023 CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
2024 const CapturedDecl *getCapturedDecl() const {
2025 return const_cast<CapturedStmt *>(this)->getCapturedDecl();
2028 /// \brief Set the outlined function declaration.
2029 void setCapturedDecl(CapturedDecl *D) {
2030 assert(D && "null CapturedDecl");
2031 CapDeclAndKind.setPointer(D);
2034 /// \brief Retrieve the captured region kind.
2035 CapturedRegionKind getCapturedRegionKind() const {
2036 return CapDeclAndKind.getInt();
2039 /// \brief Set the captured region kind.
2040 void setCapturedRegionKind(CapturedRegionKind Kind) {
2041 CapDeclAndKind.setInt(Kind);
2044 /// \brief Retrieve the record declaration for captured variables.
2045 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2047 /// \brief Set the record declaration for captured variables.
2048 void setCapturedRecordDecl(RecordDecl *D) {
2049 assert(D && "null RecordDecl");
2053 /// \brief True if this variable has been captured.
2054 bool capturesVariable(const VarDecl *Var) const;
2056 /// \brief An iterator that walks over the captures.
2057 typedef Capture *capture_iterator;
2058 typedef const Capture *const_capture_iterator;
2059 typedef llvm::iterator_range<capture_iterator> capture_range;
2060 typedef llvm::iterator_range<const_capture_iterator> capture_const_range;
2062 capture_range captures() {
2063 return capture_range(capture_begin(), capture_end());
2065 capture_const_range captures() const {
2066 return capture_const_range(capture_begin(), capture_end());
2069 /// \brief Retrieve an iterator pointing to the first capture.
2070 capture_iterator capture_begin() { return getStoredCaptures(); }
2071 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2073 /// \brief Retrieve an iterator pointing past the end of the sequence of
2075 capture_iterator capture_end() const {
2076 return getStoredCaptures() + NumCaptures;
2079 /// \brief Retrieve the number of captures, including 'this'.
2080 unsigned capture_size() const { return NumCaptures; }
2082 /// \brief Iterator that walks over the capture initialization arguments.
2083 typedef Expr **capture_init_iterator;
2084 typedef llvm::iterator_range<capture_init_iterator> capture_init_range;
2086 capture_init_range capture_inits() const {
2087 return capture_init_range(capture_init_begin(), capture_init_end());
2090 /// \brief Retrieve the first initialization argument.
2091 capture_init_iterator capture_init_begin() const {
2092 return reinterpret_cast<Expr **>(getStoredStmts());
2095 /// \brief Retrieve the iterator pointing one past the last initialization
2097 capture_init_iterator capture_init_end() const {
2098 return capture_init_begin() + NumCaptures;
2101 SourceLocation getLocStart() const LLVM_READONLY {
2102 return getCapturedStmt()->getLocStart();
2104 SourceLocation getLocEnd() const LLVM_READONLY {
2105 return getCapturedStmt()->getLocEnd();
2107 SourceRange getSourceRange() const LLVM_READONLY {
2108 return getCapturedStmt()->getSourceRange();
2111 static bool classof(const Stmt *T) {
2112 return T->getStmtClass() == CapturedStmtClass;
2115 child_range children();
2117 friend class ASTStmtReader;
2120 } // end namespace clang