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/ADT/iterator.h"
26 #include "llvm/Support/Compiler.h"
27 #include "llvm/Support/ErrorHandling.h"
31 class FoldingSetNodeID;
44 struct PrintingPolicy;
53 //===----------------------------------------------------------------------===//
54 // AST classes for statements.
55 //===----------------------------------------------------------------------===//
57 /// Stmt - This represents one statement.
59 class LLVM_ALIGNAS(LLVM_PTR_SIZE) Stmt {
63 #define STMT(CLASS, PARENT) CLASS##Class,
64 #define STMT_RANGE(BASE, FIRST, LAST) \
65 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
66 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
67 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
68 #define ABSTRACT_STMT(STMT)
69 #include "clang/AST/StmtNodes.inc"
72 // Make vanilla 'new' and 'delete' illegal for Stmts.
74 void *operator new(size_t bytes) LLVM_NOEXCEPT {
75 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
77 void operator delete(void *data) LLVM_NOEXCEPT {
78 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
84 /// \brief The statement class.
87 enum { NumStmtBits = 8 };
89 class CompoundStmtBitfields {
90 friend class CompoundStmt;
91 unsigned : NumStmtBits;
93 unsigned NumStmts : 32 - NumStmtBits;
98 friend class DeclRefExpr; // computeDependence
99 friend class InitListExpr; // ctor
100 friend class DesignatedInitExpr; // ctor
101 friend class BlockDeclRefExpr; // ctor
102 friend class ASTStmtReader; // deserialization
103 friend class CXXNewExpr; // ctor
104 friend class DependentScopeDeclRefExpr; // ctor
105 friend class CXXConstructExpr; // ctor
106 friend class CallExpr; // ctor
107 friend class OffsetOfExpr; // ctor
108 friend class ObjCMessageExpr; // ctor
109 friend class ObjCArrayLiteral; // ctor
110 friend class ObjCDictionaryLiteral; // ctor
111 friend class ShuffleVectorExpr; // ctor
112 friend class ParenListExpr; // ctor
113 friend class CXXUnresolvedConstructExpr; // ctor
114 friend class CXXDependentScopeMemberExpr; // ctor
115 friend class OverloadExpr; // ctor
116 friend class PseudoObjectExpr; // ctor
117 friend class AtomicExpr; // ctor
118 unsigned : NumStmtBits;
120 unsigned ValueKind : 2;
121 unsigned ObjectKind : 2;
122 unsigned TypeDependent : 1;
123 unsigned ValueDependent : 1;
124 unsigned InstantiationDependent : 1;
125 unsigned ContainsUnexpandedParameterPack : 1;
127 enum { NumExprBits = 16 };
129 class CharacterLiteralBitfields {
130 friend class CharacterLiteral;
131 unsigned : NumExprBits;
136 enum APFloatSemantics {
145 class FloatingLiteralBitfields {
146 friend class FloatingLiteral;
147 unsigned : NumExprBits;
149 unsigned Semantics : 3; // Provides semantics for APFloat construction
150 unsigned IsExact : 1;
153 class UnaryExprOrTypeTraitExprBitfields {
154 friend class UnaryExprOrTypeTraitExpr;
155 unsigned : NumExprBits;
158 unsigned IsType : 1; // true if operand is a type, false if an expression.
161 class DeclRefExprBitfields {
162 friend class DeclRefExpr;
163 friend class ASTStmtReader; // deserialization
164 unsigned : NumExprBits;
166 unsigned HasQualifier : 1;
167 unsigned HasTemplateKWAndArgsInfo : 1;
168 unsigned HasFoundDecl : 1;
169 unsigned HadMultipleCandidates : 1;
170 unsigned RefersToEnclosingVariableOrCapture : 1;
173 class CastExprBitfields {
174 friend class CastExpr;
175 unsigned : NumExprBits;
178 unsigned BasePathSize : 32 - 6 - NumExprBits;
181 class CallExprBitfields {
182 friend class CallExpr;
183 unsigned : NumExprBits;
185 unsigned NumPreArgs : 1;
188 class ExprWithCleanupsBitfields {
189 friend class ExprWithCleanups;
190 friend class ASTStmtReader; // deserialization
192 unsigned : NumExprBits;
194 unsigned NumObjects : 32 - NumExprBits;
197 class PseudoObjectExprBitfields {
198 friend class PseudoObjectExpr;
199 friend class ASTStmtReader; // deserialization
201 unsigned : NumExprBits;
203 // These don't need to be particularly wide, because they're
204 // strictly limited by the forms of expressions we permit.
205 unsigned NumSubExprs : 8;
206 unsigned ResultIndex : 32 - 8 - NumExprBits;
209 class ObjCIndirectCopyRestoreExprBitfields {
210 friend class ObjCIndirectCopyRestoreExpr;
211 unsigned : NumExprBits;
213 unsigned ShouldCopy : 1;
216 class InitListExprBitfields {
217 friend class InitListExpr;
219 unsigned : NumExprBits;
221 /// Whether this initializer list originally had a GNU array-range
222 /// designator in it. This is a temporary marker used by CodeGen.
223 unsigned HadArrayRangeDesignator : 1;
226 class TypeTraitExprBitfields {
227 friend class TypeTraitExpr;
228 friend class ASTStmtReader;
229 friend class ASTStmtWriter;
231 unsigned : NumExprBits;
233 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
236 /// \brief If this expression is not value-dependent, this indicates whether
237 /// the trait evaluated true or false.
240 /// \brief The number of arguments to this type trait.
241 unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
245 StmtBitfields StmtBits;
246 CompoundStmtBitfields CompoundStmtBits;
247 ExprBitfields ExprBits;
248 CharacterLiteralBitfields CharacterLiteralBits;
249 FloatingLiteralBitfields FloatingLiteralBits;
250 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
251 DeclRefExprBitfields DeclRefExprBits;
252 CastExprBitfields CastExprBits;
253 CallExprBitfields CallExprBits;
254 ExprWithCleanupsBitfields ExprWithCleanupsBits;
255 PseudoObjectExprBitfields PseudoObjectExprBits;
256 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
257 InitListExprBitfields InitListExprBits;
258 TypeTraitExprBitfields TypeTraitExprBits;
261 friend class ASTStmtReader;
262 friend class ASTStmtWriter;
265 // Only allow allocation of Stmts using the allocator in ASTContext
266 // or by doing a placement new.
267 void* operator new(size_t bytes, const ASTContext& C,
268 unsigned alignment = 8);
270 void* operator new(size_t bytes, const ASTContext* C,
271 unsigned alignment = 8) {
272 return operator new(bytes, *C, alignment);
275 void *operator new(size_t bytes, void *mem) LLVM_NOEXCEPT { return mem; }
277 void operator delete(void *, const ASTContext &, unsigned) LLVM_NOEXCEPT {}
278 void operator delete(void *, const ASTContext *, unsigned) LLVM_NOEXCEPT {}
279 void operator delete(void *, size_t) LLVM_NOEXCEPT {}
280 void operator delete(void *, void *) LLVM_NOEXCEPT {}
283 /// \brief A placeholder type used to construct an empty shell of a
284 /// type, that will be filled in later (e.g., by some
285 /// de-serialization).
286 struct EmptyShell { };
289 /// Iterator for iterating over Stmt * arrays that contain only Expr *
291 /// This is needed because AST nodes use Stmt* arrays to store
292 /// references to children (to be compatible with StmtIterator).
294 : llvm::iterator_adaptor_base<ExprIterator, Stmt **,
295 std::random_access_iterator_tag, Expr *> {
296 ExprIterator() : iterator_adaptor_base(nullptr) {}
297 ExprIterator(Stmt **I) : iterator_adaptor_base(I) {}
299 reference operator*() const {
300 assert((*I)->getStmtClass() >= firstExprConstant &&
301 (*I)->getStmtClass() <= lastExprConstant);
302 return *reinterpret_cast<Expr **>(I);
306 /// Const iterator for iterating over Stmt * arrays that contain only Expr *
307 struct ConstExprIterator
308 : llvm::iterator_adaptor_base<ConstExprIterator, const Stmt *const *,
309 std::random_access_iterator_tag,
311 ConstExprIterator() : iterator_adaptor_base(nullptr) {}
312 ConstExprIterator(const Stmt *const *I) : iterator_adaptor_base(I) {}
314 reference operator*() const {
315 assert((*I)->getStmtClass() >= firstExprConstant &&
316 (*I)->getStmtClass() <= lastExprConstant);
317 return *reinterpret_cast<const Expr *const *>(I);
322 /// \brief Whether statistic collection is enabled.
323 static bool StatisticsEnabled;
326 /// \brief Construct an empty statement.
327 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
331 static_assert(sizeof(*this) % llvm::AlignOf<void *>::Alignment == 0,
332 "Insufficient alignment!");
333 StmtBits.sClass = SC;
334 if (StatisticsEnabled) Stmt::addStmtClass(SC);
337 StmtClass getStmtClass() const {
338 return static_cast<StmtClass>(StmtBits.sClass);
340 const char *getStmtClassName() const;
342 /// SourceLocation tokens are not useful in isolation - they are low level
343 /// value objects created/interpreted by SourceManager. We assume AST
344 /// clients will have a pointer to the respective SourceManager.
345 SourceRange getSourceRange() const LLVM_READONLY;
346 SourceLocation getLocStart() const LLVM_READONLY;
347 SourceLocation getLocEnd() const LLVM_READONLY;
349 // global temp stats (until we have a per-module visitor)
350 static void addStmtClass(const StmtClass s);
351 static void EnableStatistics();
352 static void PrintStats();
354 /// \brief Dumps the specified AST fragment and all subtrees to
357 void dump(SourceManager &SM) const;
358 void dump(raw_ostream &OS, SourceManager &SM) const;
359 void dump(raw_ostream &OS) const;
361 /// dumpColor - same as dump(), but forces color highlighting.
362 void dumpColor() const;
364 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
365 /// back to its original source language syntax.
366 void dumpPretty(const ASTContext &Context) const;
367 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
368 const PrintingPolicy &Policy,
369 unsigned Indentation = 0) const;
371 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
372 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
373 void viewAST() const;
375 /// Skip past any implicit AST nodes which might surround this
376 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
377 Stmt *IgnoreImplicit();
379 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
380 /// stmt at the top, if \a IgnoreCaptured is true.
381 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
383 const Stmt *stripLabelLikeStatements() const;
384 Stmt *stripLabelLikeStatements() {
385 return const_cast<Stmt*>(
386 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
389 /// Child Iterators: All subclasses must implement 'children'
390 /// to permit easy iteration over the substatements/subexpessions of an
391 /// AST node. This permits easy iteration over all nodes in the AST.
392 typedef StmtIterator child_iterator;
393 typedef ConstStmtIterator const_child_iterator;
395 typedef llvm::iterator_range<child_iterator> child_range;
396 typedef llvm::iterator_range<const_child_iterator> const_child_range;
398 child_range children();
399 const_child_range children() const {
400 auto Children = const_cast<Stmt *>(this)->children();
401 return const_child_range(Children.begin(), Children.end());
404 child_iterator child_begin() { return children().begin(); }
405 child_iterator child_end() { return children().end(); }
407 const_child_iterator child_begin() const { return children().begin(); }
408 const_child_iterator child_end() const { return children().end(); }
410 /// \brief Produce a unique representation of the given statement.
412 /// \param ID once the profiling operation is complete, will contain
413 /// the unique representation of the given statement.
415 /// \param Context the AST context in which the statement resides
417 /// \param Canonical whether the profile should be based on the canonical
418 /// representation of this statement (e.g., where non-type template
419 /// parameters are identified by index/level rather than their
420 /// declaration pointers) or the exact representation of the statement as
421 /// written in the source.
422 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
423 bool Canonical) const;
426 /// DeclStmt - Adaptor class for mixing declarations with statements and
427 /// expressions. For example, CompoundStmt mixes statements, expressions
428 /// and declarations (variables, types). Another example is ForStmt, where
429 /// the first statement can be an expression or a declaration.
431 class DeclStmt : public Stmt {
433 SourceLocation StartLoc, EndLoc;
436 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
437 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
438 StartLoc(startLoc), EndLoc(endLoc) {}
440 /// \brief Build an empty declaration statement.
441 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
443 /// isSingleDecl - This method returns true if this DeclStmt refers
444 /// to a single Decl.
445 bool isSingleDecl() const {
446 return DG.isSingleDecl();
449 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
450 Decl *getSingleDecl() { return DG.getSingleDecl(); }
452 const DeclGroupRef getDeclGroup() const { return DG; }
453 DeclGroupRef getDeclGroup() { return DG; }
454 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
456 SourceLocation getStartLoc() const { return StartLoc; }
457 void setStartLoc(SourceLocation L) { StartLoc = L; }
458 SourceLocation getEndLoc() const { return EndLoc; }
459 void setEndLoc(SourceLocation L) { EndLoc = L; }
461 SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
462 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
464 static bool classof(const Stmt *T) {
465 return T->getStmtClass() == DeclStmtClass;
468 // Iterators over subexpressions.
469 child_range children() {
470 return child_range(child_iterator(DG.begin(), DG.end()),
471 child_iterator(DG.end(), DG.end()));
474 typedef DeclGroupRef::iterator decl_iterator;
475 typedef DeclGroupRef::const_iterator const_decl_iterator;
476 typedef llvm::iterator_range<decl_iterator> decl_range;
477 typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
479 decl_range decls() { return decl_range(decl_begin(), decl_end()); }
480 decl_const_range decls() const {
481 return decl_const_range(decl_begin(), decl_end());
483 decl_iterator decl_begin() { return DG.begin(); }
484 decl_iterator decl_end() { return DG.end(); }
485 const_decl_iterator decl_begin() const { return DG.begin(); }
486 const_decl_iterator decl_end() const { return DG.end(); }
488 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
489 reverse_decl_iterator decl_rbegin() {
490 return reverse_decl_iterator(decl_end());
492 reverse_decl_iterator decl_rend() {
493 return reverse_decl_iterator(decl_begin());
497 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
499 class NullStmt : public Stmt {
500 SourceLocation SemiLoc;
502 /// \brief True if the null statement was preceded by an empty macro, e.g:
507 bool HasLeadingEmptyMacro;
509 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
510 : Stmt(NullStmtClass), SemiLoc(L),
511 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
513 /// \brief Build an empty null statement.
514 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
515 HasLeadingEmptyMacro(false) { }
517 SourceLocation getSemiLoc() const { return SemiLoc; }
518 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
520 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
522 SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
523 SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
525 static bool classof(const Stmt *T) {
526 return T->getStmtClass() == NullStmtClass;
529 child_range children() {
530 return child_range(child_iterator(), child_iterator());
533 friend class ASTStmtReader;
534 friend class ASTStmtWriter;
537 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
539 class CompoundStmt : public Stmt {
541 SourceLocation LBraceLoc, RBraceLoc;
543 friend class ASTStmtReader;
546 CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
547 SourceLocation LB, SourceLocation RB);
549 // \brief Build an empty compound statement with a location.
550 explicit CompoundStmt(SourceLocation Loc)
551 : Stmt(CompoundStmtClass), Body(nullptr), LBraceLoc(Loc), RBraceLoc(Loc) {
552 CompoundStmtBits.NumStmts = 0;
555 // \brief Build an empty compound statement.
556 explicit CompoundStmt(EmptyShell Empty)
557 : Stmt(CompoundStmtClass, Empty), Body(nullptr) {
558 CompoundStmtBits.NumStmts = 0;
561 void setStmts(const ASTContext &C, ArrayRef<Stmt *> Stmts);
563 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
564 unsigned size() const { return CompoundStmtBits.NumStmts; }
566 typedef Stmt** body_iterator;
567 typedef llvm::iterator_range<body_iterator> body_range;
569 body_range body() { return body_range(body_begin(), body_end()); }
570 body_iterator body_begin() { return Body; }
571 body_iterator body_end() { return Body + size(); }
572 Stmt *body_front() { return !body_empty() ? Body[0] : nullptr; }
573 Stmt *body_back() { return !body_empty() ? Body[size()-1] : nullptr; }
575 void setLastStmt(Stmt *S) {
576 assert(!body_empty() && "setLastStmt");
580 typedef Stmt* const * const_body_iterator;
581 typedef llvm::iterator_range<const_body_iterator> body_const_range;
583 body_const_range body() const {
584 return body_const_range(body_begin(), body_end());
586 const_body_iterator body_begin() const { return Body; }
587 const_body_iterator body_end() const { return Body + size(); }
588 const Stmt *body_front() const {
589 return !body_empty() ? Body[0] : nullptr;
591 const Stmt *body_back() const {
592 return !body_empty() ? Body[size() - 1] : nullptr;
595 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
596 reverse_body_iterator body_rbegin() {
597 return reverse_body_iterator(body_end());
599 reverse_body_iterator body_rend() {
600 return reverse_body_iterator(body_begin());
603 typedef std::reverse_iterator<const_body_iterator>
604 const_reverse_body_iterator;
606 const_reverse_body_iterator body_rbegin() const {
607 return const_reverse_body_iterator(body_end());
610 const_reverse_body_iterator body_rend() const {
611 return const_reverse_body_iterator(body_begin());
614 SourceLocation getLocStart() const LLVM_READONLY { return LBraceLoc; }
615 SourceLocation getLocEnd() const LLVM_READONLY { return RBraceLoc; }
617 SourceLocation getLBracLoc() const { return LBraceLoc; }
618 SourceLocation getRBracLoc() const { return RBraceLoc; }
620 static bool classof(const Stmt *T) {
621 return T->getStmtClass() == CompoundStmtClass;
625 child_range children() {
626 return child_range(Body, Body + CompoundStmtBits.NumStmts);
629 const_child_range children() const {
630 return const_child_range(child_iterator(Body),
631 child_iterator(Body + CompoundStmtBits.NumStmts));
635 // SwitchCase is the base class for CaseStmt and DefaultStmt,
636 class SwitchCase : public Stmt {
638 // A pointer to the following CaseStmt or DefaultStmt class,
639 // used by SwitchStmt.
640 SwitchCase *NextSwitchCase;
641 SourceLocation KeywordLoc;
642 SourceLocation ColonLoc;
644 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
645 : Stmt(SC), NextSwitchCase(nullptr), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {
648 SwitchCase(StmtClass SC, EmptyShell)
649 : Stmt(SC), NextSwitchCase(nullptr) {}
652 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
654 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
656 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
658 SourceLocation getKeywordLoc() const { return KeywordLoc; }
659 void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
660 SourceLocation getColonLoc() const { return ColonLoc; }
661 void setColonLoc(SourceLocation L) { ColonLoc = L; }
664 const Stmt *getSubStmt() const {
665 return const_cast<SwitchCase*>(this)->getSubStmt();
668 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
669 SourceLocation getLocEnd() const LLVM_READONLY;
671 static bool classof(const Stmt *T) {
672 return T->getStmtClass() == CaseStmtClass ||
673 T->getStmtClass() == DefaultStmtClass;
677 class CaseStmt : public SwitchCase {
678 SourceLocation EllipsisLoc;
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
683 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
684 SourceLocation ellipsisLoc, SourceLocation colonLoc)
685 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
686 SubExprs[SUBSTMT] = nullptr;
687 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
688 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
689 EllipsisLoc = ellipsisLoc;
692 /// \brief Build an empty switch case statement.
693 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
695 SourceLocation getCaseLoc() const { return KeywordLoc; }
696 void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
697 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
698 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
699 SourceLocation getColonLoc() const { return ColonLoc; }
700 void setColonLoc(SourceLocation L) { ColonLoc = L; }
702 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
703 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
704 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
706 const Expr *getLHS() const {
707 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
709 const Expr *getRHS() const {
710 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
712 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
714 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
715 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
716 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
718 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
719 SourceLocation getLocEnd() const LLVM_READONLY {
720 // Handle deeply nested case statements with iteration instead of recursion.
721 const CaseStmt *CS = this;
722 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
725 return CS->getSubStmt()->getLocEnd();
728 static bool classof(const Stmt *T) {
729 return T->getStmtClass() == CaseStmtClass;
733 child_range children() {
734 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
738 class DefaultStmt : public SwitchCase {
741 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
742 SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
744 /// \brief Build an empty default statement.
745 explicit DefaultStmt(EmptyShell Empty)
746 : SwitchCase(DefaultStmtClass, Empty) { }
748 Stmt *getSubStmt() { return SubStmt; }
749 const Stmt *getSubStmt() const { return SubStmt; }
750 void setSubStmt(Stmt *S) { SubStmt = S; }
752 SourceLocation getDefaultLoc() const { return KeywordLoc; }
753 void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
754 SourceLocation getColonLoc() const { return ColonLoc; }
755 void setColonLoc(SourceLocation L) { ColonLoc = L; }
757 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
758 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
760 static bool classof(const Stmt *T) {
761 return T->getStmtClass() == DefaultStmtClass;
765 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
768 inline SourceLocation SwitchCase::getLocEnd() const {
769 if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
770 return CS->getLocEnd();
771 return cast<DefaultStmt>(this)->getLocEnd();
774 /// LabelStmt - Represents a label, which has a substatement. For example:
777 class LabelStmt : public Stmt {
778 SourceLocation IdentLoc;
783 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
784 : Stmt(LabelStmtClass), IdentLoc(IL), TheDecl(D), SubStmt(substmt) {
785 static_assert(sizeof(LabelStmt) ==
786 2 * sizeof(SourceLocation) + 2 * sizeof(void *),
787 "LabelStmt too big");
790 // \brief Build an empty label statement.
791 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
793 SourceLocation getIdentLoc() const { return IdentLoc; }
794 LabelDecl *getDecl() const { return TheDecl; }
795 void setDecl(LabelDecl *D) { TheDecl = D; }
796 const char *getName() const;
797 Stmt *getSubStmt() { return SubStmt; }
798 const Stmt *getSubStmt() const { return SubStmt; }
799 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
800 void setSubStmt(Stmt *SS) { SubStmt = SS; }
802 SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
803 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
805 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
807 static bool classof(const Stmt *T) {
808 return T->getStmtClass() == LabelStmtClass;
813 /// \brief Represents an attribute applied to a statement.
815 /// Represents an attribute applied to a statement. For example:
816 /// [[omp::for(...)]] for (...) { ... }
818 class AttributedStmt : public Stmt {
820 SourceLocation AttrLoc;
823 friend class ASTStmtReader;
825 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
826 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
827 NumAttrs(Attrs.size()) {
828 std::copy(Attrs.begin(), Attrs.end(), getAttrArrayPtr());
831 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
832 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
833 std::fill_n(getAttrArrayPtr(), NumAttrs, nullptr);
836 const Attr *const *getAttrArrayPtr() const {
837 return reinterpret_cast<const Attr *const *>(this + 1);
839 const Attr **getAttrArrayPtr() {
840 return reinterpret_cast<const Attr **>(this + 1);
844 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
845 ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
846 // \brief Build an empty attributed statement.
847 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
849 SourceLocation getAttrLoc() const { return AttrLoc; }
850 ArrayRef<const Attr*> getAttrs() const {
851 return llvm::makeArrayRef(getAttrArrayPtr(), NumAttrs);
853 Stmt *getSubStmt() { return SubStmt; }
854 const Stmt *getSubStmt() const { return SubStmt; }
856 SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
857 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
859 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
861 static bool classof(const Stmt *T) {
862 return T->getStmtClass() == AttributedStmtClass;
867 /// IfStmt - This represents an if/then/else.
869 class IfStmt : public Stmt {
870 enum { VAR, COND, THEN, ELSE, END_EXPR };
871 Stmt* SubExprs[END_EXPR];
873 SourceLocation IfLoc;
874 SourceLocation ElseLoc;
877 IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
878 Stmt *then, SourceLocation EL = SourceLocation(),
879 Stmt *elsev = nullptr);
881 /// \brief Build an empty if/then/else statement
882 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
884 /// \brief Retrieve the variable declared in this "if" statement, if any.
886 /// In the following example, "x" is the condition variable.
888 /// if (int x = foo()) {
889 /// printf("x is %d", x);
892 VarDecl *getConditionVariable() const;
893 void setConditionVariable(const ASTContext &C, VarDecl *V);
895 /// If this IfStmt has a condition variable, return the faux DeclStmt
896 /// associated with the creation of that condition variable.
897 const DeclStmt *getConditionVariableDeclStmt() const {
898 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
901 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
902 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
903 const Stmt *getThen() const { return SubExprs[THEN]; }
904 void setThen(Stmt *S) { SubExprs[THEN] = S; }
905 const Stmt *getElse() const { return SubExprs[ELSE]; }
906 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
908 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
909 Stmt *getThen() { return SubExprs[THEN]; }
910 Stmt *getElse() { return SubExprs[ELSE]; }
912 SourceLocation getIfLoc() const { return IfLoc; }
913 void setIfLoc(SourceLocation L) { IfLoc = L; }
914 SourceLocation getElseLoc() const { return ElseLoc; }
915 void setElseLoc(SourceLocation L) { ElseLoc = L; }
917 SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
918 SourceLocation getLocEnd() const LLVM_READONLY {
920 return SubExprs[ELSE]->getLocEnd();
922 return SubExprs[THEN]->getLocEnd();
925 // Iterators over subexpressions. The iterators will include iterating
926 // over the initialization expression referenced by the condition variable.
927 child_range children() {
928 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
931 static bool classof(const Stmt *T) {
932 return T->getStmtClass() == IfStmtClass;
936 /// SwitchStmt - This represents a 'switch' stmt.
938 class SwitchStmt : public Stmt {
939 SourceLocation SwitchLoc;
940 enum { VAR, COND, BODY, END_EXPR };
941 Stmt* SubExprs[END_EXPR];
942 // This points to a linked list of case and default statements and, if the
943 // SwitchStmt is a switch on an enum value, records whether all the enum
944 // values were covered by CaseStmts. The coverage information value is meant
945 // to be a hint for possible clients.
946 llvm::PointerIntPair<SwitchCase *, 1, bool> FirstCase;
949 SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond);
951 /// \brief Build a empty switch statement.
952 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
954 /// \brief Retrieve the variable declared in this "switch" statement, if any.
956 /// In the following example, "x" is the condition variable.
958 /// switch (int x = foo()) {
963 VarDecl *getConditionVariable() const;
964 void setConditionVariable(const ASTContext &C, VarDecl *V);
966 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
967 /// associated with the creation of that condition variable.
968 const DeclStmt *getConditionVariableDeclStmt() const {
969 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
972 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
973 const Stmt *getBody() const { return SubExprs[BODY]; }
974 const SwitchCase *getSwitchCaseList() const { return FirstCase.getPointer(); }
976 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
977 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
978 Stmt *getBody() { return SubExprs[BODY]; }
979 void setBody(Stmt *S) { SubExprs[BODY] = S; }
980 SwitchCase *getSwitchCaseList() { return FirstCase.getPointer(); }
982 /// \brief Set the case list for this switch statement.
983 void setSwitchCaseList(SwitchCase *SC) { FirstCase.setPointer(SC); }
985 SourceLocation getSwitchLoc() const { return SwitchLoc; }
986 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
988 void setBody(Stmt *S, SourceLocation SL) {
992 void addSwitchCase(SwitchCase *SC) {
993 assert(!SC->getNextSwitchCase()
994 && "case/default already added to a switch");
995 SC->setNextSwitchCase(FirstCase.getPointer());
996 FirstCase.setPointer(SC);
999 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
1000 /// switch over an enum value then all cases have been explicitly covered.
1001 void setAllEnumCasesCovered() { FirstCase.setInt(true); }
1003 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
1004 /// have been explicitly covered.
1005 bool isAllEnumCasesCovered() const { return FirstCase.getInt(); }
1007 SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1008 SourceLocation getLocEnd() const LLVM_READONLY {
1009 return SubExprs[BODY] ? SubExprs[BODY]->getLocEnd() : SubExprs[COND]->getLocEnd();
1013 child_range children() {
1014 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1017 static bool classof(const Stmt *T) {
1018 return T->getStmtClass() == SwitchStmtClass;
1023 /// WhileStmt - This represents a 'while' stmt.
1025 class WhileStmt : public Stmt {
1026 SourceLocation WhileLoc;
1027 enum { VAR, COND, BODY, END_EXPR };
1028 Stmt* SubExprs[END_EXPR];
1030 WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1033 /// \brief Build an empty while statement.
1034 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1036 /// \brief Retrieve the variable declared in this "while" statement, if any.
1038 /// In the following example, "x" is the condition variable.
1040 /// while (int x = random()) {
1044 VarDecl *getConditionVariable() const;
1045 void setConditionVariable(const ASTContext &C, VarDecl *V);
1047 /// If this WhileStmt has a condition variable, return the faux DeclStmt
1048 /// associated with the creation of that condition variable.
1049 const DeclStmt *getConditionVariableDeclStmt() const {
1050 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1053 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1054 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1055 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1056 Stmt *getBody() { return SubExprs[BODY]; }
1057 const Stmt *getBody() const { return SubExprs[BODY]; }
1058 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1060 SourceLocation getWhileLoc() const { return WhileLoc; }
1061 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1063 SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1064 SourceLocation getLocEnd() const LLVM_READONLY {
1065 return SubExprs[BODY]->getLocEnd();
1068 static bool classof(const Stmt *T) {
1069 return T->getStmtClass() == WhileStmtClass;
1073 child_range children() {
1074 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1078 /// DoStmt - This represents a 'do/while' stmt.
1080 class DoStmt : public Stmt {
1081 SourceLocation DoLoc;
1082 enum { BODY, COND, END_EXPR };
1083 Stmt* SubExprs[END_EXPR];
1084 SourceLocation WhileLoc;
1085 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
1088 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1090 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1091 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1092 SubExprs[BODY] = body;
1095 /// \brief Build an empty do-while statement.
1096 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1098 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1099 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1100 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1101 Stmt *getBody() { return SubExprs[BODY]; }
1102 const Stmt *getBody() const { return SubExprs[BODY]; }
1103 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1105 SourceLocation getDoLoc() const { return DoLoc; }
1106 void setDoLoc(SourceLocation L) { DoLoc = L; }
1107 SourceLocation getWhileLoc() const { return WhileLoc; }
1108 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1110 SourceLocation getRParenLoc() const { return RParenLoc; }
1111 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1113 SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1114 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1116 static bool classof(const Stmt *T) {
1117 return T->getStmtClass() == DoStmtClass;
1121 child_range children() {
1122 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1127 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
1128 /// the init/cond/inc parts of the ForStmt will be null if they were not
1129 /// specified in the source.
1131 class ForStmt : public Stmt {
1132 SourceLocation ForLoc;
1133 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1134 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1135 SourceLocation LParenLoc, RParenLoc;
1138 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1139 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1142 /// \brief Build an empty for statement.
1143 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1145 Stmt *getInit() { return SubExprs[INIT]; }
1147 /// \brief Retrieve the variable declared in this "for" statement, if any.
1149 /// In the following example, "y" is the condition variable.
1151 /// for (int x = random(); int y = mangle(x); ++x) {
1155 VarDecl *getConditionVariable() const;
1156 void setConditionVariable(const ASTContext &C, VarDecl *V);
1158 /// If this ForStmt has a condition variable, return the faux DeclStmt
1159 /// associated with the creation of that condition variable.
1160 const DeclStmt *getConditionVariableDeclStmt() const {
1161 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1164 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1165 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1166 Stmt *getBody() { return SubExprs[BODY]; }
1168 const Stmt *getInit() const { return SubExprs[INIT]; }
1169 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1170 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1171 const Stmt *getBody() const { return SubExprs[BODY]; }
1173 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1174 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1175 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1176 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1178 SourceLocation getForLoc() const { return ForLoc; }
1179 void setForLoc(SourceLocation L) { ForLoc = L; }
1180 SourceLocation getLParenLoc() const { return LParenLoc; }
1181 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1182 SourceLocation getRParenLoc() const { return RParenLoc; }
1183 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1185 SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1186 SourceLocation getLocEnd() const LLVM_READONLY {
1187 return SubExprs[BODY]->getLocEnd();
1190 static bool classof(const Stmt *T) {
1191 return T->getStmtClass() == ForStmtClass;
1195 child_range children() {
1196 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1200 /// GotoStmt - This represents a direct goto.
1202 class GotoStmt : public Stmt {
1204 SourceLocation GotoLoc;
1205 SourceLocation LabelLoc;
1207 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1208 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1210 /// \brief Build an empty goto statement.
1211 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1213 LabelDecl *getLabel() const { return Label; }
1214 void setLabel(LabelDecl *D) { Label = D; }
1216 SourceLocation getGotoLoc() const { return GotoLoc; }
1217 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1218 SourceLocation getLabelLoc() const { return LabelLoc; }
1219 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1221 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1222 SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1224 static bool classof(const Stmt *T) {
1225 return T->getStmtClass() == GotoStmtClass;
1229 child_range children() {
1230 return child_range(child_iterator(), child_iterator());
1234 /// IndirectGotoStmt - This represents an indirect goto.
1236 class IndirectGotoStmt : public Stmt {
1237 SourceLocation GotoLoc;
1238 SourceLocation StarLoc;
1241 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1243 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1244 Target((Stmt*)target) {}
1246 /// \brief Build an empty indirect goto statement.
1247 explicit IndirectGotoStmt(EmptyShell Empty)
1248 : Stmt(IndirectGotoStmtClass, Empty) { }
1250 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1251 SourceLocation getGotoLoc() const { return GotoLoc; }
1252 void setStarLoc(SourceLocation L) { StarLoc = L; }
1253 SourceLocation getStarLoc() const { return StarLoc; }
1255 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1256 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1257 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1259 /// getConstantTarget - Returns the fixed target of this indirect
1260 /// goto, if one exists.
1261 LabelDecl *getConstantTarget();
1262 const LabelDecl *getConstantTarget() const {
1263 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1266 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1267 SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1269 static bool classof(const Stmt *T) {
1270 return T->getStmtClass() == IndirectGotoStmtClass;
1274 child_range children() { return child_range(&Target, &Target+1); }
1278 /// ContinueStmt - This represents a continue.
1280 class ContinueStmt : public Stmt {
1281 SourceLocation ContinueLoc;
1283 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1285 /// \brief Build an empty continue statement.
1286 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1288 SourceLocation getContinueLoc() const { return ContinueLoc; }
1289 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1291 SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1292 SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1294 static bool classof(const Stmt *T) {
1295 return T->getStmtClass() == ContinueStmtClass;
1299 child_range children() {
1300 return child_range(child_iterator(), child_iterator());
1304 /// BreakStmt - This represents a break.
1306 class BreakStmt : public Stmt {
1307 SourceLocation BreakLoc;
1310 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {
1311 static_assert(sizeof(BreakStmt) == 2 * sizeof(SourceLocation),
1312 "BreakStmt too large");
1315 /// \brief Build an empty break statement.
1316 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1318 SourceLocation getBreakLoc() const { return BreakLoc; }
1319 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1321 SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1322 SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1324 static bool classof(const Stmt *T) {
1325 return T->getStmtClass() == BreakStmtClass;
1329 child_range children() {
1330 return child_range(child_iterator(), child_iterator());
1335 /// ReturnStmt - This represents a return, optionally of an expression:
1339 /// Note that GCC allows return with no argument in a function declared to
1340 /// return a value, and it allows returning a value in functions declared to
1341 /// return void. We explicitly model this in the AST, which means you can't
1342 /// depend on the return type of the function and the presence of an argument.
1344 class ReturnStmt : public Stmt {
1345 SourceLocation RetLoc;
1347 const VarDecl *NRVOCandidate;
1350 explicit ReturnStmt(SourceLocation RL) : ReturnStmt(RL, nullptr, nullptr) {}
1352 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1353 : Stmt(ReturnStmtClass), RetLoc(RL), RetExpr((Stmt *)E),
1354 NRVOCandidate(NRVOCandidate) {}
1356 /// \brief Build an empty return expression.
1357 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1359 const Expr *getRetValue() const;
1360 Expr *getRetValue();
1361 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1363 SourceLocation getReturnLoc() const { return RetLoc; }
1364 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1366 /// \brief Retrieve the variable that might be used for the named return
1367 /// value optimization.
1369 /// The optimization itself can only be performed if the variable is
1370 /// also marked as an NRVO object.
1371 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1372 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1374 SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1375 SourceLocation getLocEnd() const LLVM_READONLY {
1376 return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1379 static bool classof(const Stmt *T) {
1380 return T->getStmtClass() == ReturnStmtClass;
1384 child_range children() {
1385 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1386 return child_range(child_iterator(), child_iterator());
1390 /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1392 class AsmStmt : public Stmt {
1394 SourceLocation AsmLoc;
1395 /// \brief True if the assembly statement does not have any input or output
1399 /// \brief If true, treat this inline assembly as having side effects.
1400 /// This assembly statement should not be optimized, deleted or moved.
1403 unsigned NumOutputs;
1405 unsigned NumClobbers;
1409 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1410 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1411 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1412 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1414 friend class ASTStmtReader;
1417 /// \brief Build an empty inline-assembly statement.
1418 explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1419 Stmt(SC, Empty), Exprs(nullptr) { }
1421 SourceLocation getAsmLoc() const { return AsmLoc; }
1422 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1424 bool isSimple() const { return IsSimple; }
1425 void setSimple(bool V) { IsSimple = V; }
1427 bool isVolatile() const { return IsVolatile; }
1428 void setVolatile(bool V) { IsVolatile = V; }
1430 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1431 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1433 //===--- Asm String Analysis ---===//
1435 /// Assemble final IR asm string.
1436 std::string generateAsmString(const ASTContext &C) const;
1438 //===--- Output operands ---===//
1440 unsigned getNumOutputs() const { return NumOutputs; }
1442 /// getOutputConstraint - Return the constraint string for the specified
1443 /// output operand. All output constraints are known to be non-empty (either
1445 StringRef getOutputConstraint(unsigned i) const;
1447 /// isOutputPlusConstraint - Return true if the specified output constraint
1448 /// is a "+" constraint (which is both an input and an output) or false if it
1449 /// is an "=" constraint (just an output).
1450 bool isOutputPlusConstraint(unsigned i) const {
1451 return getOutputConstraint(i)[0] == '+';
1454 const Expr *getOutputExpr(unsigned i) const;
1456 /// getNumPlusOperands - Return the number of output operands that have a "+"
1458 unsigned getNumPlusOperands() const;
1460 //===--- Input operands ---===//
1462 unsigned getNumInputs() const { return NumInputs; }
1464 /// getInputConstraint - Return the specified input constraint. Unlike output
1465 /// constraints, these can be empty.
1466 StringRef getInputConstraint(unsigned i) const;
1468 const Expr *getInputExpr(unsigned i) const;
1470 //===--- Other ---===//
1472 unsigned getNumClobbers() const { return NumClobbers; }
1473 StringRef getClobber(unsigned i) const;
1475 static bool classof(const Stmt *T) {
1476 return T->getStmtClass() == GCCAsmStmtClass ||
1477 T->getStmtClass() == MSAsmStmtClass;
1480 // Input expr iterators.
1482 typedef ExprIterator inputs_iterator;
1483 typedef ConstExprIterator const_inputs_iterator;
1484 typedef llvm::iterator_range<inputs_iterator> inputs_range;
1485 typedef llvm::iterator_range<const_inputs_iterator> inputs_const_range;
1487 inputs_iterator begin_inputs() {
1488 return &Exprs[0] + NumOutputs;
1491 inputs_iterator end_inputs() {
1492 return &Exprs[0] + NumOutputs + NumInputs;
1495 inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
1497 const_inputs_iterator begin_inputs() const {
1498 return &Exprs[0] + NumOutputs;
1501 const_inputs_iterator end_inputs() const {
1502 return &Exprs[0] + NumOutputs + NumInputs;
1505 inputs_const_range inputs() const {
1506 return inputs_const_range(begin_inputs(), end_inputs());
1509 // Output expr iterators.
1511 typedef ExprIterator outputs_iterator;
1512 typedef ConstExprIterator const_outputs_iterator;
1513 typedef llvm::iterator_range<outputs_iterator> outputs_range;
1514 typedef llvm::iterator_range<const_outputs_iterator> outputs_const_range;
1516 outputs_iterator begin_outputs() {
1519 outputs_iterator end_outputs() {
1520 return &Exprs[0] + NumOutputs;
1522 outputs_range outputs() {
1523 return outputs_range(begin_outputs(), end_outputs());
1526 const_outputs_iterator begin_outputs() const {
1529 const_outputs_iterator end_outputs() const {
1530 return &Exprs[0] + NumOutputs;
1532 outputs_const_range outputs() const {
1533 return outputs_const_range(begin_outputs(), end_outputs());
1536 child_range children() {
1537 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1541 /// This represents a GCC inline-assembly statement extension.
1543 class GCCAsmStmt : public AsmStmt {
1544 SourceLocation RParenLoc;
1545 StringLiteral *AsmStr;
1547 // FIXME: If we wanted to, we could allocate all of these in one big array.
1548 StringLiteral **Constraints;
1549 StringLiteral **Clobbers;
1550 IdentifierInfo **Names;
1552 friend class ASTStmtReader;
1555 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1556 bool isvolatile, unsigned numoutputs, unsigned numinputs,
1557 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1558 StringLiteral *asmstr, unsigned numclobbers,
1559 StringLiteral **clobbers, SourceLocation rparenloc);
1561 /// \brief Build an empty inline-assembly statement.
1562 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1563 Constraints(nullptr), Clobbers(nullptr), Names(nullptr) { }
1565 SourceLocation getRParenLoc() const { return RParenLoc; }
1566 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1568 //===--- Asm String Analysis ---===//
1570 const StringLiteral *getAsmString() const { return AsmStr; }
1571 StringLiteral *getAsmString() { return AsmStr; }
1572 void setAsmString(StringLiteral *E) { AsmStr = E; }
1574 /// AsmStringPiece - this is part of a decomposed asm string specification
1575 /// (for use with the AnalyzeAsmString function below). An asm string is
1576 /// considered to be a concatenation of these parts.
1577 class AsmStringPiece {
1580 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1581 Operand // Operand reference, with optional modifier %c4.
1588 // Source range for operand references.
1589 CharSourceRange Range;
1591 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1592 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
1594 : MyKind(Operand), Str(S), OperandNo(OpNo),
1595 Range(CharSourceRange::getCharRange(Begin, End)) {
1598 bool isString() const { return MyKind == String; }
1599 bool isOperand() const { return MyKind == Operand; }
1601 const std::string &getString() const {
1605 unsigned getOperandNo() const {
1606 assert(isOperand());
1610 CharSourceRange getRange() const {
1611 assert(isOperand() && "Range is currently used only for Operands.");
1615 /// getModifier - Get the modifier for this operand, if present. This
1616 /// returns '\0' if there was no modifier.
1617 char getModifier() const;
1620 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1621 /// it into pieces. If the asm string is erroneous, emit errors and return
1622 /// true, otherwise return false. This handles canonicalization and
1623 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1624 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1625 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1626 const ASTContext &C, unsigned &DiagOffs) const;
1628 /// Assemble final IR asm string.
1629 std::string generateAsmString(const ASTContext &C) const;
1631 //===--- Output operands ---===//
1633 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1637 StringRef getOutputName(unsigned i) const {
1638 if (IdentifierInfo *II = getOutputIdentifier(i))
1639 return II->getName();
1644 StringRef getOutputConstraint(unsigned i) const;
1646 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1647 return Constraints[i];
1649 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1650 return Constraints[i];
1653 Expr *getOutputExpr(unsigned i);
1655 const Expr *getOutputExpr(unsigned i) const {
1656 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1659 //===--- Input operands ---===//
1661 IdentifierInfo *getInputIdentifier(unsigned i) const {
1662 return Names[i + NumOutputs];
1665 StringRef getInputName(unsigned i) const {
1666 if (IdentifierInfo *II = getInputIdentifier(i))
1667 return II->getName();
1672 StringRef getInputConstraint(unsigned i) const;
1674 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1675 return Constraints[i + NumOutputs];
1677 StringLiteral *getInputConstraintLiteral(unsigned i) {
1678 return Constraints[i + NumOutputs];
1681 Expr *getInputExpr(unsigned i);
1682 void setInputExpr(unsigned i, Expr *E);
1684 const Expr *getInputExpr(unsigned i) const {
1685 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1689 void setOutputsAndInputsAndClobbers(const ASTContext &C,
1690 IdentifierInfo **Names,
1691 StringLiteral **Constraints,
1693 unsigned NumOutputs,
1695 StringLiteral **Clobbers,
1696 unsigned NumClobbers);
1699 //===--- Other ---===//
1701 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1702 /// translate this into a numeric value needed to reference the same operand.
1703 /// This returns -1 if the operand name is invalid.
1704 int getNamedOperand(StringRef SymbolicName) const;
1706 StringRef getClobber(unsigned i) const;
1707 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1708 const StringLiteral *getClobberStringLiteral(unsigned i) const {
1712 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1713 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1715 static bool classof(const Stmt *T) {
1716 return T->getStmtClass() == GCCAsmStmtClass;
1720 /// This represents a Microsoft inline-assembly statement extension.
1722 class MSAsmStmt : public AsmStmt {
1723 SourceLocation LBraceLoc, EndLoc;
1726 unsigned NumAsmToks;
1729 StringRef *Constraints;
1730 StringRef *Clobbers;
1732 friend class ASTStmtReader;
1735 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
1736 SourceLocation lbraceloc, bool issimple, bool isvolatile,
1737 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1738 ArrayRef<StringRef> constraints,
1739 ArrayRef<Expr*> exprs, StringRef asmstr,
1740 ArrayRef<StringRef> clobbers, SourceLocation endloc);
1742 /// \brief Build an empty MS-style inline-assembly statement.
1743 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1744 NumAsmToks(0), AsmToks(nullptr), Constraints(nullptr), Clobbers(nullptr) { }
1746 SourceLocation getLBraceLoc() const { return LBraceLoc; }
1747 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1748 SourceLocation getEndLoc() const { return EndLoc; }
1749 void setEndLoc(SourceLocation L) { EndLoc = L; }
1751 bool hasBraces() const { return LBraceLoc.isValid(); }
1753 unsigned getNumAsmToks() { return NumAsmToks; }
1754 Token *getAsmToks() { return AsmToks; }
1756 //===--- Asm String Analysis ---===//
1757 StringRef getAsmString() const { return AsmStr; }
1759 /// Assemble final IR asm string.
1760 std::string generateAsmString(const ASTContext &C) const;
1762 //===--- Output operands ---===//
1764 StringRef getOutputConstraint(unsigned i) const {
1765 assert(i < NumOutputs);
1766 return Constraints[i];
1769 Expr *getOutputExpr(unsigned i);
1771 const Expr *getOutputExpr(unsigned i) const {
1772 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1775 //===--- Input operands ---===//
1777 StringRef getInputConstraint(unsigned i) const {
1778 assert(i < NumInputs);
1779 return Constraints[i + NumOutputs];
1782 Expr *getInputExpr(unsigned i);
1783 void setInputExpr(unsigned i, Expr *E);
1785 const Expr *getInputExpr(unsigned i) const {
1786 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1789 //===--- Other ---===//
1791 ArrayRef<StringRef> getAllConstraints() const {
1792 return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
1794 ArrayRef<StringRef> getClobbers() const {
1795 return llvm::makeArrayRef(Clobbers, NumClobbers);
1797 ArrayRef<Expr*> getAllExprs() const {
1798 return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
1799 NumInputs + NumOutputs);
1802 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1805 void initialize(const ASTContext &C, StringRef AsmString,
1806 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
1807 ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
1810 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1811 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1813 static bool classof(const Stmt *T) {
1814 return T->getStmtClass() == MSAsmStmtClass;
1817 child_range children() {
1818 return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
1822 class SEHExceptStmt : public Stmt {
1826 enum { FILTER_EXPR, BLOCK };
1828 SEHExceptStmt(SourceLocation Loc,
1832 friend class ASTReader;
1833 friend class ASTStmtReader;
1834 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1837 static SEHExceptStmt* Create(const ASTContext &C,
1838 SourceLocation ExceptLoc,
1842 SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1843 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1845 SourceLocation getExceptLoc() const { return Loc; }
1846 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1848 Expr *getFilterExpr() const {
1849 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1852 CompoundStmt *getBlock() const {
1853 return cast<CompoundStmt>(Children[BLOCK]);
1856 child_range children() {
1857 return child_range(Children,Children+2);
1860 static bool classof(const Stmt *T) {
1861 return T->getStmtClass() == SEHExceptStmtClass;
1866 class SEHFinallyStmt : public Stmt {
1870 SEHFinallyStmt(SourceLocation Loc,
1873 friend class ASTReader;
1874 friend class ASTStmtReader;
1875 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1878 static SEHFinallyStmt* Create(const ASTContext &C,
1879 SourceLocation FinallyLoc,
1882 SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1883 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1885 SourceLocation getFinallyLoc() const { return Loc; }
1886 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1888 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1890 child_range children() {
1891 return child_range(&Block,&Block+1);
1894 static bool classof(const Stmt *T) {
1895 return T->getStmtClass() == SEHFinallyStmtClass;
1900 class SEHTryStmt : public Stmt {
1902 SourceLocation TryLoc;
1905 enum { TRY = 0, HANDLER = 1 };
1907 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1908 SourceLocation TryLoc,
1912 friend class ASTReader;
1913 friend class ASTStmtReader;
1914 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1917 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
1918 SourceLocation TryLoc, Stmt *TryBlock,
1921 SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1922 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1924 SourceLocation getTryLoc() const { return TryLoc; }
1925 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1927 bool getIsCXXTry() const { return IsCXXTry; }
1929 CompoundStmt* getTryBlock() const {
1930 return cast<CompoundStmt>(Children[TRY]);
1933 Stmt *getHandler() const { return Children[HANDLER]; }
1935 /// Returns 0 if not defined
1936 SEHExceptStmt *getExceptHandler() const;
1937 SEHFinallyStmt *getFinallyHandler() const;
1939 child_range children() {
1940 return child_range(Children,Children+2);
1943 static bool classof(const Stmt *T) {
1944 return T->getStmtClass() == SEHTryStmtClass;
1948 /// Represents a __leave statement.
1950 class SEHLeaveStmt : public Stmt {
1951 SourceLocation LeaveLoc;
1953 explicit SEHLeaveStmt(SourceLocation LL)
1954 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
1956 /// \brief Build an empty __leave statement.
1957 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) { }
1959 SourceLocation getLeaveLoc() const { return LeaveLoc; }
1960 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
1962 SourceLocation getLocStart() const LLVM_READONLY { return LeaveLoc; }
1963 SourceLocation getLocEnd() const LLVM_READONLY { return LeaveLoc; }
1965 static bool classof(const Stmt *T) {
1966 return T->getStmtClass() == SEHLeaveStmtClass;
1970 child_range children() {
1971 return child_range(child_iterator(), child_iterator());
1975 /// \brief This captures a statement into a function. For example, the following
1976 /// pragma annotated compound statement can be represented as a CapturedStmt,
1977 /// and this compound statement is the body of an anonymous outlined function.
1979 /// #pragma omp parallel
1984 class CapturedStmt : public Stmt {
1986 /// \brief The different capture forms: by 'this', by reference, capture for
1987 /// variable-length array type etc.
1988 enum VariableCaptureKind {
1995 /// \brief Describes the capture of either a variable, or 'this', or
1996 /// variable-length array type.
1998 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
2002 /// \brief Create a new capture.
2004 /// \param Loc The source location associated with this capture.
2006 /// \param Kind The kind of capture (this, ByRef, ...).
2008 /// \param Var The variable being captured, or null if capturing this.
2010 Capture(SourceLocation Loc, VariableCaptureKind Kind,
2011 VarDecl *Var = nullptr);
2013 /// \brief Determine the kind of capture.
2014 VariableCaptureKind getCaptureKind() const;
2016 /// \brief Retrieve the source location at which the variable or 'this' was
2018 SourceLocation getLocation() const { return Loc; }
2020 /// \brief Determine whether this capture handles the C++ 'this' pointer.
2021 bool capturesThis() const { return getCaptureKind() == VCK_This; }
2023 /// \brief Determine whether this capture handles a variable (by reference).
2024 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
2026 /// \brief Determine whether this capture handles a variable by copy.
2027 bool capturesVariableByCopy() const {
2028 return getCaptureKind() == VCK_ByCopy;
2031 /// \brief Determine whether this capture handles a variable-length array
2033 bool capturesVariableArrayType() const {
2034 return getCaptureKind() == VCK_VLAType;
2037 /// \brief Retrieve the declaration of the variable being captured.
2039 /// This operation is only valid if this capture captures a variable.
2040 VarDecl *getCapturedVar() const;
2042 friend class ASTStmtReader;
2046 /// \brief The number of variable captured, including 'this'.
2047 unsigned NumCaptures;
2049 /// \brief The pointer part is the implicit the outlined function and the
2050 /// int part is the captured region kind, 'CR_Default' etc.
2051 llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
2053 /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
2054 RecordDecl *TheRecordDecl;
2056 /// \brief Construct a captured statement.
2057 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
2058 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
2060 /// \brief Construct an empty captured statement.
2061 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2063 Stmt **getStoredStmts() { return reinterpret_cast<Stmt **>(this + 1); }
2065 Stmt *const *getStoredStmts() const {
2066 return reinterpret_cast<Stmt *const *>(this + 1);
2069 Capture *getStoredCaptures() const;
2071 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2074 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
2075 CapturedRegionKind Kind,
2076 ArrayRef<Capture> Captures,
2077 ArrayRef<Expr *> CaptureInits,
2078 CapturedDecl *CD, RecordDecl *RD);
2080 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2081 unsigned NumCaptures);
2083 /// \brief Retrieve the statement being captured.
2084 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2085 const Stmt *getCapturedStmt() const { return getStoredStmts()[NumCaptures]; }
2087 /// \brief Retrieve the outlined function declaration.
2088 CapturedDecl *getCapturedDecl();
2089 const CapturedDecl *getCapturedDecl() const;
2091 /// \brief Set the outlined function declaration.
2092 void setCapturedDecl(CapturedDecl *D);
2094 /// \brief Retrieve the captured region kind.
2095 CapturedRegionKind getCapturedRegionKind() const;
2097 /// \brief Set the captured region kind.
2098 void setCapturedRegionKind(CapturedRegionKind Kind);
2100 /// \brief Retrieve the record declaration for captured variables.
2101 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2103 /// \brief Set the record declaration for captured variables.
2104 void setCapturedRecordDecl(RecordDecl *D) {
2105 assert(D && "null RecordDecl");
2109 /// \brief True if this variable has been captured.
2110 bool capturesVariable(const VarDecl *Var) const;
2112 /// \brief An iterator that walks over the captures.
2113 typedef Capture *capture_iterator;
2114 typedef const Capture *const_capture_iterator;
2115 typedef llvm::iterator_range<capture_iterator> capture_range;
2116 typedef llvm::iterator_range<const_capture_iterator> capture_const_range;
2118 capture_range captures() {
2119 return capture_range(capture_begin(), capture_end());
2121 capture_const_range captures() const {
2122 return capture_const_range(capture_begin(), capture_end());
2125 /// \brief Retrieve an iterator pointing to the first capture.
2126 capture_iterator capture_begin() { return getStoredCaptures(); }
2127 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2129 /// \brief Retrieve an iterator pointing past the end of the sequence of
2131 capture_iterator capture_end() const {
2132 return getStoredCaptures() + NumCaptures;
2135 /// \brief Retrieve the number of captures, including 'this'.
2136 unsigned capture_size() const { return NumCaptures; }
2138 /// \brief Iterator that walks over the capture initialization arguments.
2139 typedef Expr **capture_init_iterator;
2140 typedef llvm::iterator_range<capture_init_iterator> capture_init_range;
2142 /// \brief Const iterator that walks over the capture initialization
2144 typedef Expr *const *const_capture_init_iterator;
2145 typedef llvm::iterator_range<const_capture_init_iterator>
2146 const_capture_init_range;
2148 capture_init_range capture_inits() {
2149 return capture_init_range(capture_init_begin(), capture_init_end());
2152 const_capture_init_range capture_inits() const {
2153 return const_capture_init_range(capture_init_begin(), capture_init_end());
2156 /// \brief Retrieve the first initialization argument.
2157 capture_init_iterator capture_init_begin() {
2158 return reinterpret_cast<Expr **>(getStoredStmts());
2161 const_capture_init_iterator capture_init_begin() const {
2162 return reinterpret_cast<Expr *const *>(getStoredStmts());
2165 /// \brief Retrieve the iterator pointing one past the last initialization
2167 capture_init_iterator capture_init_end() {
2168 return capture_init_begin() + NumCaptures;
2171 const_capture_init_iterator capture_init_end() const {
2172 return capture_init_begin() + NumCaptures;
2175 SourceLocation getLocStart() const LLVM_READONLY {
2176 return getCapturedStmt()->getLocStart();
2178 SourceLocation getLocEnd() const LLVM_READONLY {
2179 return getCapturedStmt()->getLocEnd();
2181 SourceRange getSourceRange() const LLVM_READONLY {
2182 return getCapturedStmt()->getSourceRange();
2185 static bool classof(const Stmt *T) {
2186 return T->getStmtClass() == CapturedStmtClass;
2189 child_range children();
2191 friend class ASTStmtReader;
2194 } // end namespace clang