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(nullptr) {}
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(nullptr) {}
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.
104 #if !defined(_MSC_VER) || LLVM_MSC_PREREQ(1900)
105 class LLVM_ALIGNAS(sizeof(void *)) Stmt {
107 // Old MSVC has issues to align this. Drop when we retire MSVC 2013. When GCC
108 // 4.7 is also gone this can be just alignof(void *).
114 #define STMT(CLASS, PARENT) CLASS##Class,
115 #define STMT_RANGE(BASE, FIRST, LAST) \
116 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
117 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
118 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
119 #define ABSTRACT_STMT(STMT)
120 #include "clang/AST/StmtNodes.inc"
123 // Make vanilla 'new' and 'delete' illegal for Stmts.
125 void* operator new(size_t bytes) throw() {
126 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
128 void operator delete(void* data) throw() {
129 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
132 class StmtBitfields {
135 /// \brief The statement class.
138 enum { NumStmtBits = 8 };
140 class CompoundStmtBitfields {
141 friend class CompoundStmt;
142 unsigned : NumStmtBits;
144 unsigned NumStmts : 32 - NumStmtBits;
147 class ExprBitfields {
149 friend class DeclRefExpr; // computeDependence
150 friend class InitListExpr; // ctor
151 friend class DesignatedInitExpr; // ctor
152 friend class BlockDeclRefExpr; // ctor
153 friend class ASTStmtReader; // deserialization
154 friend class CXXNewExpr; // ctor
155 friend class DependentScopeDeclRefExpr; // ctor
156 friend class CXXConstructExpr; // ctor
157 friend class CallExpr; // ctor
158 friend class OffsetOfExpr; // ctor
159 friend class ObjCMessageExpr; // ctor
160 friend class ObjCArrayLiteral; // ctor
161 friend class ObjCDictionaryLiteral; // ctor
162 friend class ShuffleVectorExpr; // ctor
163 friend class ParenListExpr; // ctor
164 friend class CXXUnresolvedConstructExpr; // ctor
165 friend class CXXDependentScopeMemberExpr; // ctor
166 friend class OverloadExpr; // ctor
167 friend class PseudoObjectExpr; // ctor
168 friend class AtomicExpr; // ctor
169 unsigned : NumStmtBits;
171 unsigned ValueKind : 2;
172 unsigned ObjectKind : 2;
173 unsigned TypeDependent : 1;
174 unsigned ValueDependent : 1;
175 unsigned InstantiationDependent : 1;
176 unsigned ContainsUnexpandedParameterPack : 1;
178 enum { NumExprBits = 16 };
180 class CharacterLiteralBitfields {
181 friend class CharacterLiteral;
182 unsigned : NumExprBits;
187 enum APFloatSemantics {
196 class FloatingLiteralBitfields {
197 friend class FloatingLiteral;
198 unsigned : NumExprBits;
200 unsigned Semantics : 3; // Provides semantics for APFloat construction
201 unsigned IsExact : 1;
204 class UnaryExprOrTypeTraitExprBitfields {
205 friend class UnaryExprOrTypeTraitExpr;
206 unsigned : NumExprBits;
209 unsigned IsType : 1; // true if operand is a type, false if an expression.
212 class DeclRefExprBitfields {
213 friend class DeclRefExpr;
214 friend class ASTStmtReader; // deserialization
215 unsigned : NumExprBits;
217 unsigned HasQualifier : 1;
218 unsigned HasTemplateKWAndArgsInfo : 1;
219 unsigned HasFoundDecl : 1;
220 unsigned HadMultipleCandidates : 1;
221 unsigned RefersToEnclosingVariableOrCapture : 1;
224 class CastExprBitfields {
225 friend class CastExpr;
226 unsigned : NumExprBits;
229 unsigned BasePathSize : 32 - 6 - NumExprBits;
232 class CallExprBitfields {
233 friend class CallExpr;
234 unsigned : NumExprBits;
236 unsigned NumPreArgs : 1;
239 class ExprWithCleanupsBitfields {
240 friend class ExprWithCleanups;
241 friend class ASTStmtReader; // deserialization
243 unsigned : NumExprBits;
245 unsigned NumObjects : 32 - NumExprBits;
248 class PseudoObjectExprBitfields {
249 friend class PseudoObjectExpr;
250 friend class ASTStmtReader; // deserialization
252 unsigned : NumExprBits;
254 // These don't need to be particularly wide, because they're
255 // strictly limited by the forms of expressions we permit.
256 unsigned NumSubExprs : 8;
257 unsigned ResultIndex : 32 - 8 - NumExprBits;
260 class ObjCIndirectCopyRestoreExprBitfields {
261 friend class ObjCIndirectCopyRestoreExpr;
262 unsigned : NumExprBits;
264 unsigned ShouldCopy : 1;
267 class InitListExprBitfields {
268 friend class InitListExpr;
270 unsigned : NumExprBits;
272 /// Whether this initializer list originally had a GNU array-range
273 /// designator in it. This is a temporary marker used by CodeGen.
274 unsigned HadArrayRangeDesignator : 1;
277 class TypeTraitExprBitfields {
278 friend class TypeTraitExpr;
279 friend class ASTStmtReader;
280 friend class ASTStmtWriter;
282 unsigned : NumExprBits;
284 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
287 /// \brief If this expression is not value-dependent, this indicates whether
288 /// the trait evaluated true or false.
291 /// \brief The number of arguments to this type trait.
292 unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
296 #if !(!defined(_MSC_VER) || LLVM_MSC_PREREQ(1900))
297 // FIXME: this is wasteful on 64-bit platforms.
301 StmtBitfields StmtBits;
302 CompoundStmtBitfields CompoundStmtBits;
303 ExprBitfields ExprBits;
304 CharacterLiteralBitfields CharacterLiteralBits;
305 FloatingLiteralBitfields FloatingLiteralBits;
306 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
307 DeclRefExprBitfields DeclRefExprBits;
308 CastExprBitfields CastExprBits;
309 CallExprBitfields CallExprBits;
310 ExprWithCleanupsBitfields ExprWithCleanupsBits;
311 PseudoObjectExprBitfields PseudoObjectExprBits;
312 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
313 InitListExprBitfields InitListExprBits;
314 TypeTraitExprBitfields TypeTraitExprBits;
317 friend class ASTStmtReader;
318 friend class ASTStmtWriter;
321 // Only allow allocation of Stmts using the allocator in ASTContext
322 // or by doing a placement new.
323 void* operator new(size_t bytes, const ASTContext& C,
324 unsigned alignment = 8);
326 void* operator new(size_t bytes, const ASTContext* C,
327 unsigned alignment = 8) {
328 return operator new(bytes, *C, alignment);
331 void* operator new(size_t bytes, void* mem) throw() {
335 void operator delete(void*, const ASTContext&, unsigned) throw() { }
336 void operator delete(void*, const ASTContext*, unsigned) throw() { }
337 void operator delete(void*, size_t) throw() { }
338 void operator delete(void*, void*) throw() { }
341 /// \brief A placeholder type used to construct an empty shell of a
342 /// type, that will be filled in later (e.g., by some
343 /// de-serialization).
344 struct EmptyShell { };
347 /// \brief Whether statistic collection is enabled.
348 static bool StatisticsEnabled;
351 /// \brief Construct an empty statement.
352 explicit Stmt(StmtClass SC, EmptyShell) : Stmt(SC) {}
356 static_assert(sizeof(*this) % llvm::AlignOf<void *>::Alignment == 0,
357 "Insufficient alignment!");
358 StmtBits.sClass = SC;
359 if (StatisticsEnabled) Stmt::addStmtClass(SC);
362 StmtClass getStmtClass() const {
363 return static_cast<StmtClass>(StmtBits.sClass);
365 const char *getStmtClassName() const;
367 /// SourceLocation tokens are not useful in isolation - they are low level
368 /// value objects created/interpreted by SourceManager. We assume AST
369 /// clients will have a pointer to the respective SourceManager.
370 SourceRange getSourceRange() const LLVM_READONLY;
371 SourceLocation getLocStart() const LLVM_READONLY;
372 SourceLocation getLocEnd() const LLVM_READONLY;
374 // global temp stats (until we have a per-module visitor)
375 static void addStmtClass(const StmtClass s);
376 static void EnableStatistics();
377 static void PrintStats();
379 /// \brief Dumps the specified AST fragment and all subtrees to
382 void dump(SourceManager &SM) const;
383 void dump(raw_ostream &OS, SourceManager &SM) const;
384 void dump(raw_ostream &OS) const;
386 /// dumpColor - same as dump(), but forces color highlighting.
387 void dumpColor() const;
389 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
390 /// back to its original source language syntax.
391 void dumpPretty(const ASTContext &Context) const;
392 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
393 const PrintingPolicy &Policy,
394 unsigned Indentation = 0) const;
396 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
397 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
398 void viewAST() const;
400 /// Skip past any implicit AST nodes which might surround this
401 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
402 Stmt *IgnoreImplicit();
404 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
405 /// stmt at the top, if \a IgnoreCaptured is true.
406 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
408 const Stmt *stripLabelLikeStatements() const;
409 Stmt *stripLabelLikeStatements() {
410 return const_cast<Stmt*>(
411 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
414 /// Child Iterators: All subclasses must implement 'children'
415 /// to permit easy iteration over the substatements/subexpessions of an
416 /// AST node. This permits easy iteration over all nodes in the AST.
417 typedef StmtIterator child_iterator;
418 typedef ConstStmtIterator const_child_iterator;
420 typedef StmtRange child_range;
421 typedef ConstStmtRange const_child_range;
423 child_range children();
424 const_child_range children() const {
425 return const_cast<Stmt*>(this)->children();
428 child_iterator child_begin() { return children().first; }
429 child_iterator child_end() { return children().second; }
431 const_child_iterator child_begin() const { return children().first; }
432 const_child_iterator child_end() const { return children().second; }
434 /// \brief Produce a unique representation of the given statement.
436 /// \param ID once the profiling operation is complete, will contain
437 /// the unique representation of the given statement.
439 /// \param Context the AST context in which the statement resides
441 /// \param Canonical whether the profile should be based on the canonical
442 /// representation of this statement (e.g., where non-type template
443 /// parameters are identified by index/level rather than their
444 /// declaration pointers) or the exact representation of the statement as
445 /// written in the source.
446 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
447 bool Canonical) const;
450 /// DeclStmt - Adaptor class for mixing declarations with statements and
451 /// expressions. For example, CompoundStmt mixes statements, expressions
452 /// and declarations (variables, types). Another example is ForStmt, where
453 /// the first statement can be an expression or a declaration.
455 class DeclStmt : public Stmt {
457 SourceLocation StartLoc, EndLoc;
460 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
461 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
462 StartLoc(startLoc), EndLoc(endLoc) {}
464 /// \brief Build an empty declaration statement.
465 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
467 /// isSingleDecl - This method returns true if this DeclStmt refers
468 /// to a single Decl.
469 bool isSingleDecl() const {
470 return DG.isSingleDecl();
473 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
474 Decl *getSingleDecl() { return DG.getSingleDecl(); }
476 const DeclGroupRef getDeclGroup() const { return DG; }
477 DeclGroupRef getDeclGroup() { return DG; }
478 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
480 SourceLocation getStartLoc() const { return StartLoc; }
481 void setStartLoc(SourceLocation L) { StartLoc = L; }
482 SourceLocation getEndLoc() const { return EndLoc; }
483 void setEndLoc(SourceLocation L) { EndLoc = L; }
485 SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
486 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
488 static bool classof(const Stmt *T) {
489 return T->getStmtClass() == DeclStmtClass;
492 // Iterators over subexpressions.
493 child_range children() {
494 return child_range(child_iterator(DG.begin(), DG.end()),
495 child_iterator(DG.end(), DG.end()));
498 typedef DeclGroupRef::iterator decl_iterator;
499 typedef DeclGroupRef::const_iterator const_decl_iterator;
500 typedef llvm::iterator_range<decl_iterator> decl_range;
501 typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
503 decl_range decls() { return decl_range(decl_begin(), decl_end()); }
504 decl_const_range decls() const {
505 return decl_const_range(decl_begin(), decl_end());
507 decl_iterator decl_begin() { return DG.begin(); }
508 decl_iterator decl_end() { return DG.end(); }
509 const_decl_iterator decl_begin() const { return DG.begin(); }
510 const_decl_iterator decl_end() const { return DG.end(); }
512 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
513 reverse_decl_iterator decl_rbegin() {
514 return reverse_decl_iterator(decl_end());
516 reverse_decl_iterator decl_rend() {
517 return reverse_decl_iterator(decl_begin());
521 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
523 class NullStmt : public Stmt {
524 SourceLocation SemiLoc;
526 /// \brief True if the null statement was preceded by an empty macro, e.g:
531 bool HasLeadingEmptyMacro;
533 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
534 : Stmt(NullStmtClass), SemiLoc(L),
535 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
537 /// \brief Build an empty null statement.
538 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
539 HasLeadingEmptyMacro(false) { }
541 SourceLocation getSemiLoc() const { return SemiLoc; }
542 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
544 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
546 SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
547 SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
549 static bool classof(const Stmt *T) {
550 return T->getStmtClass() == NullStmtClass;
553 child_range children() { return child_range(); }
555 friend class ASTStmtReader;
556 friend class ASTStmtWriter;
559 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
561 class CompoundStmt : public Stmt {
563 SourceLocation LBraceLoc, RBraceLoc;
565 friend class ASTStmtReader;
568 CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
569 SourceLocation LB, SourceLocation RB);
571 // \brief Build an empty compound statement with a location.
572 explicit CompoundStmt(SourceLocation Loc)
573 : Stmt(CompoundStmtClass), Body(nullptr), LBraceLoc(Loc), RBraceLoc(Loc) {
574 CompoundStmtBits.NumStmts = 0;
577 // \brief Build an empty compound statement.
578 explicit CompoundStmt(EmptyShell Empty)
579 : Stmt(CompoundStmtClass, Empty), Body(nullptr) {
580 CompoundStmtBits.NumStmts = 0;
583 void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts);
585 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
586 unsigned size() const { return CompoundStmtBits.NumStmts; }
588 typedef Stmt** body_iterator;
589 typedef llvm::iterator_range<body_iterator> body_range;
591 body_range body() { return body_range(body_begin(), body_end()); }
592 body_iterator body_begin() { return Body; }
593 body_iterator body_end() { return Body + size(); }
594 Stmt *body_front() { return !body_empty() ? Body[0] : nullptr; }
595 Stmt *body_back() { return !body_empty() ? Body[size()-1] : nullptr; }
597 void setLastStmt(Stmt *S) {
598 assert(!body_empty() && "setLastStmt");
602 typedef Stmt* const * const_body_iterator;
603 typedef llvm::iterator_range<const_body_iterator> body_const_range;
605 body_const_range body() const {
606 return body_const_range(body_begin(), body_end());
608 const_body_iterator body_begin() const { return Body; }
609 const_body_iterator body_end() const { return Body + size(); }
610 const Stmt *body_front() const {
611 return !body_empty() ? Body[0] : nullptr;
613 const Stmt *body_back() const {
614 return !body_empty() ? Body[size() - 1] : nullptr;
617 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
618 reverse_body_iterator body_rbegin() {
619 return reverse_body_iterator(body_end());
621 reverse_body_iterator body_rend() {
622 return reverse_body_iterator(body_begin());
625 typedef std::reverse_iterator<const_body_iterator>
626 const_reverse_body_iterator;
628 const_reverse_body_iterator body_rbegin() const {
629 return const_reverse_body_iterator(body_end());
632 const_reverse_body_iterator body_rend() const {
633 return const_reverse_body_iterator(body_begin());
636 SourceLocation getLocStart() const LLVM_READONLY { return LBraceLoc; }
637 SourceLocation getLocEnd() const LLVM_READONLY { return RBraceLoc; }
639 SourceLocation getLBracLoc() const { return LBraceLoc; }
640 SourceLocation getRBracLoc() const { return RBraceLoc; }
642 static bool classof(const Stmt *T) {
643 return T->getStmtClass() == CompoundStmtClass;
647 child_range children() {
648 return child_range(Body, Body + CompoundStmtBits.NumStmts);
651 const_child_range children() const {
652 return child_range(Body, Body + CompoundStmtBits.NumStmts);
656 // SwitchCase is the base class for CaseStmt and DefaultStmt,
657 class SwitchCase : public Stmt {
659 // A pointer to the following CaseStmt or DefaultStmt class,
660 // used by SwitchStmt.
661 SwitchCase *NextSwitchCase;
662 SourceLocation KeywordLoc;
663 SourceLocation ColonLoc;
665 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
666 : Stmt(SC), NextSwitchCase(nullptr), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {
669 SwitchCase(StmtClass SC, EmptyShell)
670 : Stmt(SC), NextSwitchCase(nullptr) {}
673 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
675 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
677 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
679 SourceLocation getKeywordLoc() const { return KeywordLoc; }
680 void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
681 SourceLocation getColonLoc() const { return ColonLoc; }
682 void setColonLoc(SourceLocation L) { ColonLoc = L; }
685 const Stmt *getSubStmt() const {
686 return const_cast<SwitchCase*>(this)->getSubStmt();
689 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
690 SourceLocation getLocEnd() const LLVM_READONLY;
692 static bool classof(const Stmt *T) {
693 return T->getStmtClass() == CaseStmtClass ||
694 T->getStmtClass() == DefaultStmtClass;
698 class CaseStmt : public SwitchCase {
699 SourceLocation EllipsisLoc;
700 enum { LHS, RHS, SUBSTMT, END_EXPR };
701 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
702 // GNU "case 1 ... 4" extension
704 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
705 SourceLocation ellipsisLoc, SourceLocation colonLoc)
706 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
707 SubExprs[SUBSTMT] = nullptr;
708 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
709 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
710 EllipsisLoc = ellipsisLoc;
713 /// \brief Build an empty switch case statement.
714 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
716 SourceLocation getCaseLoc() const { return KeywordLoc; }
717 void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
718 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
719 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
720 SourceLocation getColonLoc() const { return ColonLoc; }
721 void setColonLoc(SourceLocation L) { ColonLoc = L; }
723 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
724 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
725 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
727 const Expr *getLHS() const {
728 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
730 const Expr *getRHS() const {
731 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
733 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
735 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
736 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
737 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
739 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
740 SourceLocation getLocEnd() const LLVM_READONLY {
741 // Handle deeply nested case statements with iteration instead of recursion.
742 const CaseStmt *CS = this;
743 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
746 return CS->getSubStmt()->getLocEnd();
749 static bool classof(const Stmt *T) {
750 return T->getStmtClass() == CaseStmtClass;
754 child_range children() {
755 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
759 class DefaultStmt : public SwitchCase {
762 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
763 SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
765 /// \brief Build an empty default statement.
766 explicit DefaultStmt(EmptyShell Empty)
767 : SwitchCase(DefaultStmtClass, Empty) { }
769 Stmt *getSubStmt() { return SubStmt; }
770 const Stmt *getSubStmt() const { return SubStmt; }
771 void setSubStmt(Stmt *S) { SubStmt = S; }
773 SourceLocation getDefaultLoc() const { return KeywordLoc; }
774 void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
775 SourceLocation getColonLoc() const { return ColonLoc; }
776 void setColonLoc(SourceLocation L) { ColonLoc = L; }
778 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
779 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
781 static bool classof(const Stmt *T) {
782 return T->getStmtClass() == DefaultStmtClass;
786 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
789 inline SourceLocation SwitchCase::getLocEnd() const {
790 if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
791 return CS->getLocEnd();
792 return cast<DefaultStmt>(this)->getLocEnd();
795 /// LabelStmt - Represents a label, which has a substatement. For example:
798 class LabelStmt : public Stmt {
799 SourceLocation IdentLoc;
804 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
805 : Stmt(LabelStmtClass), IdentLoc(IL), TheDecl(D), SubStmt(substmt) {}
807 // \brief Build an empty label statement.
808 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
810 SourceLocation getIdentLoc() const { return IdentLoc; }
811 LabelDecl *getDecl() const { return TheDecl; }
812 void setDecl(LabelDecl *D) { TheDecl = D; }
813 const char *getName() const;
814 Stmt *getSubStmt() { return SubStmt; }
815 const Stmt *getSubStmt() const { return SubStmt; }
816 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
817 void setSubStmt(Stmt *SS) { SubStmt = SS; }
819 SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
820 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
822 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
824 static bool classof(const Stmt *T) {
825 return T->getStmtClass() == LabelStmtClass;
830 /// \brief Represents an attribute applied to a statement.
832 /// Represents an attribute applied to a statement. For example:
833 /// [[omp::for(...)]] for (...) { ... }
835 class AttributedStmt : public Stmt {
837 SourceLocation AttrLoc;
840 friend class ASTStmtReader;
842 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
843 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
844 NumAttrs(Attrs.size()) {
845 memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *));
848 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
849 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
850 memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *));
853 Attr *const *getAttrArrayPtr() const {
854 return reinterpret_cast<Attr *const *>(this + 1);
856 Attr **getAttrArrayPtr() { return reinterpret_cast<Attr **>(this + 1); }
859 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
860 ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
861 // \brief Build an empty attributed statement.
862 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
864 SourceLocation getAttrLoc() const { return AttrLoc; }
865 ArrayRef<const Attr*> getAttrs() const {
866 return llvm::makeArrayRef(getAttrArrayPtr(), NumAttrs);
868 Stmt *getSubStmt() { return SubStmt; }
869 const Stmt *getSubStmt() const { return SubStmt; }
871 SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
872 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
874 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
876 static bool classof(const Stmt *T) {
877 return T->getStmtClass() == AttributedStmtClass;
882 /// IfStmt - This represents an if/then/else.
884 class IfStmt : public Stmt {
885 enum { VAR, COND, THEN, ELSE, END_EXPR };
886 Stmt* SubExprs[END_EXPR];
888 SourceLocation IfLoc;
889 SourceLocation ElseLoc;
892 IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
893 Stmt *then, SourceLocation EL = SourceLocation(),
894 Stmt *elsev = nullptr);
896 /// \brief Build an empty if/then/else statement
897 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
899 /// \brief Retrieve the variable declared in this "if" statement, if any.
901 /// In the following example, "x" is the condition variable.
903 /// if (int x = foo()) {
904 /// printf("x is %d", x);
907 VarDecl *getConditionVariable() const;
908 void setConditionVariable(const ASTContext &C, VarDecl *V);
910 /// If this IfStmt has a condition variable, return the faux DeclStmt
911 /// associated with the creation of that condition variable.
912 const DeclStmt *getConditionVariableDeclStmt() const {
913 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
916 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
917 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
918 const Stmt *getThen() const { return SubExprs[THEN]; }
919 void setThen(Stmt *S) { SubExprs[THEN] = S; }
920 const Stmt *getElse() const { return SubExprs[ELSE]; }
921 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
923 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
924 Stmt *getThen() { return SubExprs[THEN]; }
925 Stmt *getElse() { return SubExprs[ELSE]; }
927 SourceLocation getIfLoc() const { return IfLoc; }
928 void setIfLoc(SourceLocation L) { IfLoc = L; }
929 SourceLocation getElseLoc() const { return ElseLoc; }
930 void setElseLoc(SourceLocation L) { ElseLoc = L; }
932 SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
933 SourceLocation getLocEnd() const LLVM_READONLY {
935 return SubExprs[ELSE]->getLocEnd();
937 return SubExprs[THEN]->getLocEnd();
940 // Iterators over subexpressions. The iterators will include iterating
941 // over the initialization expression referenced by the condition variable.
942 child_range children() {
943 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
946 static bool classof(const Stmt *T) {
947 return T->getStmtClass() == IfStmtClass;
951 /// SwitchStmt - This represents a 'switch' stmt.
953 class SwitchStmt : public Stmt {
954 SourceLocation SwitchLoc;
955 enum { VAR, COND, BODY, END_EXPR };
956 Stmt* SubExprs[END_EXPR];
957 // This points to a linked list of case and default statements and, if the
958 // SwitchStmt is a switch on an enum value, records whether all the enum
959 // values were covered by CaseStmts. The coverage information value is meant
960 // to be a hint for possible clients.
961 llvm::PointerIntPair<SwitchCase *, 1, bool> FirstCase;
964 SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond);
966 /// \brief Build a empty switch statement.
967 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
969 /// \brief Retrieve the variable declared in this "switch" statement, if any.
971 /// In the following example, "x" is the condition variable.
973 /// switch (int x = foo()) {
978 VarDecl *getConditionVariable() const;
979 void setConditionVariable(const ASTContext &C, VarDecl *V);
981 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
982 /// associated with the creation of that condition variable.
983 const DeclStmt *getConditionVariableDeclStmt() const {
984 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
987 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
988 const Stmt *getBody() const { return SubExprs[BODY]; }
989 const SwitchCase *getSwitchCaseList() const { return FirstCase.getPointer(); }
991 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
992 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
993 Stmt *getBody() { return SubExprs[BODY]; }
994 void setBody(Stmt *S) { SubExprs[BODY] = S; }
995 SwitchCase *getSwitchCaseList() { return FirstCase.getPointer(); }
997 /// \brief Set the case list for this switch statement.
998 void setSwitchCaseList(SwitchCase *SC) { FirstCase.setPointer(SC); }
1000 SourceLocation getSwitchLoc() const { return SwitchLoc; }
1001 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
1003 void setBody(Stmt *S, SourceLocation SL) {
1007 void addSwitchCase(SwitchCase *SC) {
1008 assert(!SC->getNextSwitchCase()
1009 && "case/default already added to a switch");
1010 SC->setNextSwitchCase(FirstCase.getPointer());
1011 FirstCase.setPointer(SC);
1014 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
1015 /// switch over an enum value then all cases have been explicitly covered.
1016 void setAllEnumCasesCovered() { FirstCase.setInt(true); }
1018 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
1019 /// have been explicitly covered.
1020 bool isAllEnumCasesCovered() const { return FirstCase.getInt(); }
1022 SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1023 SourceLocation getLocEnd() const LLVM_READONLY {
1024 return SubExprs[BODY] ? SubExprs[BODY]->getLocEnd() : SubExprs[COND]->getLocEnd();
1028 child_range children() {
1029 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1032 static bool classof(const Stmt *T) {
1033 return T->getStmtClass() == SwitchStmtClass;
1038 /// WhileStmt - This represents a 'while' stmt.
1040 class WhileStmt : public Stmt {
1041 SourceLocation WhileLoc;
1042 enum { VAR, COND, BODY, END_EXPR };
1043 Stmt* SubExprs[END_EXPR];
1045 WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1048 /// \brief Build an empty while statement.
1049 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1051 /// \brief Retrieve the variable declared in this "while" statement, if any.
1053 /// In the following example, "x" is the condition variable.
1055 /// while (int x = random()) {
1059 VarDecl *getConditionVariable() const;
1060 void setConditionVariable(const ASTContext &C, VarDecl *V);
1062 /// If this WhileStmt has a condition variable, return the faux DeclStmt
1063 /// associated with the creation of that condition variable.
1064 const DeclStmt *getConditionVariableDeclStmt() const {
1065 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1068 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1069 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1070 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1071 Stmt *getBody() { return SubExprs[BODY]; }
1072 const Stmt *getBody() const { return SubExprs[BODY]; }
1073 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1075 SourceLocation getWhileLoc() const { return WhileLoc; }
1076 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1078 SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1079 SourceLocation getLocEnd() const LLVM_READONLY {
1080 return SubExprs[BODY]->getLocEnd();
1083 static bool classof(const Stmt *T) {
1084 return T->getStmtClass() == WhileStmtClass;
1088 child_range children() {
1089 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1093 /// DoStmt - This represents a 'do/while' stmt.
1095 class DoStmt : public Stmt {
1096 SourceLocation DoLoc;
1097 enum { BODY, COND, END_EXPR };
1098 Stmt* SubExprs[END_EXPR];
1099 SourceLocation WhileLoc;
1100 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
1103 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1105 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1106 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1107 SubExprs[BODY] = body;
1110 /// \brief Build an empty do-while statement.
1111 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1113 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1114 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1115 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1116 Stmt *getBody() { return SubExprs[BODY]; }
1117 const Stmt *getBody() const { return SubExprs[BODY]; }
1118 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1120 SourceLocation getDoLoc() const { return DoLoc; }
1121 void setDoLoc(SourceLocation L) { DoLoc = L; }
1122 SourceLocation getWhileLoc() const { return WhileLoc; }
1123 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1125 SourceLocation getRParenLoc() const { return RParenLoc; }
1126 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1128 SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1129 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1131 static bool classof(const Stmt *T) {
1132 return T->getStmtClass() == DoStmtClass;
1136 child_range children() {
1137 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1142 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
1143 /// the init/cond/inc parts of the ForStmt will be null if they were not
1144 /// specified in the source.
1146 class ForStmt : public Stmt {
1147 SourceLocation ForLoc;
1148 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1149 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1150 SourceLocation LParenLoc, RParenLoc;
1153 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1154 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1157 /// \brief Build an empty for statement.
1158 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1160 Stmt *getInit() { return SubExprs[INIT]; }
1162 /// \brief Retrieve the variable declared in this "for" statement, if any.
1164 /// In the following example, "y" is the condition variable.
1166 /// for (int x = random(); int y = mangle(x); ++x) {
1170 VarDecl *getConditionVariable() const;
1171 void setConditionVariable(const ASTContext &C, VarDecl *V);
1173 /// If this ForStmt has a condition variable, return the faux DeclStmt
1174 /// associated with the creation of that condition variable.
1175 const DeclStmt *getConditionVariableDeclStmt() const {
1176 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1179 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1180 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1181 Stmt *getBody() { return SubExprs[BODY]; }
1183 const Stmt *getInit() const { return SubExprs[INIT]; }
1184 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1185 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1186 const Stmt *getBody() const { return SubExprs[BODY]; }
1188 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1189 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1190 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1191 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1193 SourceLocation getForLoc() const { return ForLoc; }
1194 void setForLoc(SourceLocation L) { ForLoc = L; }
1195 SourceLocation getLParenLoc() const { return LParenLoc; }
1196 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1197 SourceLocation getRParenLoc() const { return RParenLoc; }
1198 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1200 SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1201 SourceLocation getLocEnd() const LLVM_READONLY {
1202 return SubExprs[BODY]->getLocEnd();
1205 static bool classof(const Stmt *T) {
1206 return T->getStmtClass() == ForStmtClass;
1210 child_range children() {
1211 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1215 /// GotoStmt - This represents a direct goto.
1217 class GotoStmt : public Stmt {
1219 SourceLocation GotoLoc;
1220 SourceLocation LabelLoc;
1222 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1223 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1225 /// \brief Build an empty goto statement.
1226 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1228 LabelDecl *getLabel() const { return Label; }
1229 void setLabel(LabelDecl *D) { Label = D; }
1231 SourceLocation getGotoLoc() const { return GotoLoc; }
1232 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1233 SourceLocation getLabelLoc() const { return LabelLoc; }
1234 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1236 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1237 SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1239 static bool classof(const Stmt *T) {
1240 return T->getStmtClass() == GotoStmtClass;
1244 child_range children() { return child_range(); }
1247 /// IndirectGotoStmt - This represents an indirect goto.
1249 class IndirectGotoStmt : public Stmt {
1250 SourceLocation GotoLoc;
1251 SourceLocation StarLoc;
1254 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1256 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1257 Target((Stmt*)target) {}
1259 /// \brief Build an empty indirect goto statement.
1260 explicit IndirectGotoStmt(EmptyShell Empty)
1261 : Stmt(IndirectGotoStmtClass, Empty) { }
1263 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1264 SourceLocation getGotoLoc() const { return GotoLoc; }
1265 void setStarLoc(SourceLocation L) { StarLoc = L; }
1266 SourceLocation getStarLoc() const { return StarLoc; }
1268 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1269 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1270 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1272 /// getConstantTarget - Returns the fixed target of this indirect
1273 /// goto, if one exists.
1274 LabelDecl *getConstantTarget();
1275 const LabelDecl *getConstantTarget() const {
1276 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1279 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1280 SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1282 static bool classof(const Stmt *T) {
1283 return T->getStmtClass() == IndirectGotoStmtClass;
1287 child_range children() { return child_range(&Target, &Target+1); }
1291 /// ContinueStmt - This represents a continue.
1293 class ContinueStmt : public Stmt {
1294 SourceLocation ContinueLoc;
1296 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1298 /// \brief Build an empty continue statement.
1299 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1301 SourceLocation getContinueLoc() const { return ContinueLoc; }
1302 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1304 SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1305 SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1307 static bool classof(const Stmt *T) {
1308 return T->getStmtClass() == ContinueStmtClass;
1312 child_range children() { return child_range(); }
1315 /// BreakStmt - This represents a break.
1317 class BreakStmt : public Stmt {
1318 SourceLocation BreakLoc;
1320 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1322 /// \brief Build an empty break statement.
1323 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1325 SourceLocation getBreakLoc() const { return BreakLoc; }
1326 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1328 SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1329 SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1331 static bool classof(const Stmt *T) {
1332 return T->getStmtClass() == BreakStmtClass;
1336 child_range children() { return child_range(); }
1340 /// ReturnStmt - This represents a return, optionally of an expression:
1344 /// Note that GCC allows return with no argument in a function declared to
1345 /// return a value, and it allows returning a value in functions declared to
1346 /// return void. We explicitly model this in the AST, which means you can't
1347 /// depend on the return type of the function and the presence of an argument.
1349 class ReturnStmt : public Stmt {
1350 SourceLocation RetLoc;
1352 const VarDecl *NRVOCandidate;
1355 explicit ReturnStmt(SourceLocation RL) : ReturnStmt(RL, nullptr, nullptr) {}
1357 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1358 : Stmt(ReturnStmtClass), RetLoc(RL), RetExpr((Stmt *)E),
1359 NRVOCandidate(NRVOCandidate) {}
1361 /// \brief Build an empty return expression.
1362 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1364 const Expr *getRetValue() const;
1365 Expr *getRetValue();
1366 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1368 SourceLocation getReturnLoc() const { return RetLoc; }
1369 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1371 /// \brief Retrieve the variable that might be used for the named return
1372 /// value optimization.
1374 /// The optimization itself can only be performed if the variable is
1375 /// also marked as an NRVO object.
1376 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1377 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1379 SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1380 SourceLocation getLocEnd() const LLVM_READONLY {
1381 return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1384 static bool classof(const Stmt *T) {
1385 return T->getStmtClass() == ReturnStmtClass;
1389 child_range children() {
1390 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1391 return child_range();
1395 /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1397 class AsmStmt : public Stmt {
1399 SourceLocation AsmLoc;
1400 /// \brief True if the assembly statement does not have any input or output
1404 /// \brief If true, treat this inline assembly as having side effects.
1405 /// This assembly statement should not be optimized, deleted or moved.
1408 unsigned NumOutputs;
1410 unsigned NumClobbers;
1414 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1415 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1416 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1417 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1419 friend class ASTStmtReader;
1422 /// \brief Build an empty inline-assembly statement.
1423 explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1424 Stmt(SC, Empty), Exprs(nullptr) { }
1426 SourceLocation getAsmLoc() const { return AsmLoc; }
1427 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1429 bool isSimple() const { return IsSimple; }
1430 void setSimple(bool V) { IsSimple = V; }
1432 bool isVolatile() const { return IsVolatile; }
1433 void setVolatile(bool V) { IsVolatile = V; }
1435 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1436 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1438 //===--- Asm String Analysis ---===//
1440 /// Assemble final IR asm string.
1441 std::string generateAsmString(const ASTContext &C) const;
1443 //===--- Output operands ---===//
1445 unsigned getNumOutputs() const { return NumOutputs; }
1447 /// getOutputConstraint - Return the constraint string for the specified
1448 /// output operand. All output constraints are known to be non-empty (either
1450 StringRef getOutputConstraint(unsigned i) const;
1452 /// isOutputPlusConstraint - Return true if the specified output constraint
1453 /// is a "+" constraint (which is both an input and an output) or false if it
1454 /// is an "=" constraint (just an output).
1455 bool isOutputPlusConstraint(unsigned i) const {
1456 return getOutputConstraint(i)[0] == '+';
1459 const Expr *getOutputExpr(unsigned i) const;
1461 /// getNumPlusOperands - Return the number of output operands that have a "+"
1463 unsigned getNumPlusOperands() const;
1465 //===--- Input operands ---===//
1467 unsigned getNumInputs() const { return NumInputs; }
1469 /// getInputConstraint - Return the specified input constraint. Unlike output
1470 /// constraints, these can be empty.
1471 StringRef getInputConstraint(unsigned i) const;
1473 const Expr *getInputExpr(unsigned i) const;
1475 //===--- Other ---===//
1477 unsigned getNumClobbers() const { return NumClobbers; }
1478 StringRef getClobber(unsigned i) const;
1480 static bool classof(const Stmt *T) {
1481 return T->getStmtClass() == GCCAsmStmtClass ||
1482 T->getStmtClass() == MSAsmStmtClass;
1485 // Input expr iterators.
1487 typedef ExprIterator inputs_iterator;
1488 typedef ConstExprIterator const_inputs_iterator;
1489 typedef llvm::iterator_range<inputs_iterator> inputs_range;
1490 typedef llvm::iterator_range<const_inputs_iterator> inputs_const_range;
1492 inputs_iterator begin_inputs() {
1493 return &Exprs[0] + NumOutputs;
1496 inputs_iterator end_inputs() {
1497 return &Exprs[0] + NumOutputs + NumInputs;
1500 inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
1502 const_inputs_iterator begin_inputs() const {
1503 return &Exprs[0] + NumOutputs;
1506 const_inputs_iterator end_inputs() const {
1507 return &Exprs[0] + NumOutputs + NumInputs;
1510 inputs_const_range inputs() const {
1511 return inputs_const_range(begin_inputs(), end_inputs());
1514 // Output expr iterators.
1516 typedef ExprIterator outputs_iterator;
1517 typedef ConstExprIterator const_outputs_iterator;
1518 typedef llvm::iterator_range<outputs_iterator> outputs_range;
1519 typedef llvm::iterator_range<const_outputs_iterator> outputs_const_range;
1521 outputs_iterator begin_outputs() {
1524 outputs_iterator end_outputs() {
1525 return &Exprs[0] + NumOutputs;
1527 outputs_range outputs() {
1528 return outputs_range(begin_outputs(), end_outputs());
1531 const_outputs_iterator begin_outputs() const {
1534 const_outputs_iterator end_outputs() const {
1535 return &Exprs[0] + NumOutputs;
1537 outputs_const_range outputs() const {
1538 return outputs_const_range(begin_outputs(), end_outputs());
1541 child_range children() {
1542 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1546 /// This represents a GCC inline-assembly statement extension.
1548 class GCCAsmStmt : public AsmStmt {
1549 SourceLocation RParenLoc;
1550 StringLiteral *AsmStr;
1552 // FIXME: If we wanted to, we could allocate all of these in one big array.
1553 StringLiteral **Constraints;
1554 StringLiteral **Clobbers;
1555 IdentifierInfo **Names;
1557 friend class ASTStmtReader;
1560 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1561 bool isvolatile, unsigned numoutputs, unsigned numinputs,
1562 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1563 StringLiteral *asmstr, unsigned numclobbers,
1564 StringLiteral **clobbers, SourceLocation rparenloc);
1566 /// \brief Build an empty inline-assembly statement.
1567 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1568 Constraints(nullptr), Clobbers(nullptr), Names(nullptr) { }
1570 SourceLocation getRParenLoc() const { return RParenLoc; }
1571 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1573 //===--- Asm String Analysis ---===//
1575 const StringLiteral *getAsmString() const { return AsmStr; }
1576 StringLiteral *getAsmString() { return AsmStr; }
1577 void setAsmString(StringLiteral *E) { AsmStr = E; }
1579 /// AsmStringPiece - this is part of a decomposed asm string specification
1580 /// (for use with the AnalyzeAsmString function below). An asm string is
1581 /// considered to be a concatenation of these parts.
1582 class AsmStringPiece {
1585 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1586 Operand // Operand reference, with optional modifier %c4.
1593 // Source range for operand references.
1594 CharSourceRange Range;
1596 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1597 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
1599 : MyKind(Operand), Str(S), OperandNo(OpNo),
1600 Range(CharSourceRange::getCharRange(Begin, End)) {
1603 bool isString() const { return MyKind == String; }
1604 bool isOperand() const { return MyKind == Operand; }
1606 const std::string &getString() const {
1610 unsigned getOperandNo() const {
1611 assert(isOperand());
1615 CharSourceRange getRange() const {
1616 assert(isOperand() && "Range is currently used only for Operands.");
1620 /// getModifier - Get the modifier for this operand, if present. This
1621 /// returns '\0' if there was no modifier.
1622 char getModifier() const;
1625 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1626 /// it into pieces. If the asm string is erroneous, emit errors and return
1627 /// true, otherwise return false. This handles canonicalization and
1628 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1629 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1630 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1631 const ASTContext &C, unsigned &DiagOffs) const;
1633 /// Assemble final IR asm string.
1634 std::string generateAsmString(const ASTContext &C) const;
1636 //===--- Output operands ---===//
1638 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1642 StringRef getOutputName(unsigned i) const {
1643 if (IdentifierInfo *II = getOutputIdentifier(i))
1644 return II->getName();
1649 StringRef getOutputConstraint(unsigned i) const;
1651 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1652 return Constraints[i];
1654 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1655 return Constraints[i];
1658 Expr *getOutputExpr(unsigned i);
1660 const Expr *getOutputExpr(unsigned i) const {
1661 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1664 //===--- Input operands ---===//
1666 IdentifierInfo *getInputIdentifier(unsigned i) const {
1667 return Names[i + NumOutputs];
1670 StringRef getInputName(unsigned i) const {
1671 if (IdentifierInfo *II = getInputIdentifier(i))
1672 return II->getName();
1677 StringRef getInputConstraint(unsigned i) const;
1679 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1680 return Constraints[i + NumOutputs];
1682 StringLiteral *getInputConstraintLiteral(unsigned i) {
1683 return Constraints[i + NumOutputs];
1686 Expr *getInputExpr(unsigned i);
1687 void setInputExpr(unsigned i, Expr *E);
1689 const Expr *getInputExpr(unsigned i) const {
1690 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1694 void setOutputsAndInputsAndClobbers(const ASTContext &C,
1695 IdentifierInfo **Names,
1696 StringLiteral **Constraints,
1698 unsigned NumOutputs,
1700 StringLiteral **Clobbers,
1701 unsigned NumClobbers);
1704 //===--- Other ---===//
1706 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1707 /// translate this into a numeric value needed to reference the same operand.
1708 /// This returns -1 if the operand name is invalid.
1709 int getNamedOperand(StringRef SymbolicName) const;
1711 StringRef getClobber(unsigned i) const;
1712 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1713 const StringLiteral *getClobberStringLiteral(unsigned i) const {
1717 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1718 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1720 static bool classof(const Stmt *T) {
1721 return T->getStmtClass() == GCCAsmStmtClass;
1725 /// This represents a Microsoft inline-assembly statement extension.
1727 class MSAsmStmt : public AsmStmt {
1728 SourceLocation LBraceLoc, EndLoc;
1731 unsigned NumAsmToks;
1734 StringRef *Constraints;
1735 StringRef *Clobbers;
1737 friend class ASTStmtReader;
1740 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
1741 SourceLocation lbraceloc, bool issimple, bool isvolatile,
1742 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1743 ArrayRef<StringRef> constraints,
1744 ArrayRef<Expr*> exprs, StringRef asmstr,
1745 ArrayRef<StringRef> clobbers, SourceLocation endloc);
1747 /// \brief Build an empty MS-style inline-assembly statement.
1748 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1749 NumAsmToks(0), AsmToks(nullptr), Constraints(nullptr), Clobbers(nullptr) { }
1751 SourceLocation getLBraceLoc() const { return LBraceLoc; }
1752 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1753 SourceLocation getEndLoc() const { return EndLoc; }
1754 void setEndLoc(SourceLocation L) { EndLoc = L; }
1756 bool hasBraces() const { return LBraceLoc.isValid(); }
1758 unsigned getNumAsmToks() { return NumAsmToks; }
1759 Token *getAsmToks() { return AsmToks; }
1761 //===--- Asm String Analysis ---===//
1762 StringRef getAsmString() const { return AsmStr; }
1764 /// Assemble final IR asm string.
1765 std::string generateAsmString(const ASTContext &C) const;
1767 //===--- Output operands ---===//
1769 StringRef getOutputConstraint(unsigned i) const {
1770 assert(i < NumOutputs);
1771 return Constraints[i];
1774 Expr *getOutputExpr(unsigned i);
1776 const Expr *getOutputExpr(unsigned i) const {
1777 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1780 //===--- Input operands ---===//
1782 StringRef getInputConstraint(unsigned i) const {
1783 assert(i < NumInputs);
1784 return Constraints[i + NumOutputs];
1787 Expr *getInputExpr(unsigned i);
1788 void setInputExpr(unsigned i, Expr *E);
1790 const Expr *getInputExpr(unsigned i) const {
1791 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1794 //===--- Other ---===//
1796 ArrayRef<StringRef> getAllConstraints() const {
1797 return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
1799 ArrayRef<StringRef> getClobbers() const {
1800 return llvm::makeArrayRef(Clobbers, NumClobbers);
1802 ArrayRef<Expr*> getAllExprs() const {
1803 return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
1804 NumInputs + NumOutputs);
1807 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1810 void initialize(const ASTContext &C, StringRef AsmString,
1811 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
1812 ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
1815 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1816 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1818 static bool classof(const Stmt *T) {
1819 return T->getStmtClass() == MSAsmStmtClass;
1822 child_range children() {
1823 return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
1827 class SEHExceptStmt : public Stmt {
1831 enum { FILTER_EXPR, BLOCK };
1833 SEHExceptStmt(SourceLocation Loc,
1837 friend class ASTReader;
1838 friend class ASTStmtReader;
1839 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1842 static SEHExceptStmt* Create(const ASTContext &C,
1843 SourceLocation ExceptLoc,
1847 SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1848 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1850 SourceLocation getExceptLoc() const { return Loc; }
1851 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1853 Expr *getFilterExpr() const {
1854 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1857 CompoundStmt *getBlock() const {
1858 return cast<CompoundStmt>(Children[BLOCK]);
1861 child_range children() {
1862 return child_range(Children,Children+2);
1865 static bool classof(const Stmt *T) {
1866 return T->getStmtClass() == SEHExceptStmtClass;
1871 class SEHFinallyStmt : public Stmt {
1875 SEHFinallyStmt(SourceLocation Loc,
1878 friend class ASTReader;
1879 friend class ASTStmtReader;
1880 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1883 static SEHFinallyStmt* Create(const ASTContext &C,
1884 SourceLocation FinallyLoc,
1887 SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1888 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1890 SourceLocation getFinallyLoc() const { return Loc; }
1891 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1893 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1895 child_range children() {
1896 return child_range(&Block,&Block+1);
1899 static bool classof(const Stmt *T) {
1900 return T->getStmtClass() == SEHFinallyStmtClass;
1905 class SEHTryStmt : public Stmt {
1907 SourceLocation TryLoc;
1910 enum { TRY = 0, HANDLER = 1 };
1912 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1913 SourceLocation TryLoc,
1917 friend class ASTReader;
1918 friend class ASTStmtReader;
1919 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1922 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
1923 SourceLocation TryLoc, Stmt *TryBlock,
1926 SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1927 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1929 SourceLocation getTryLoc() const { return TryLoc; }
1930 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1932 bool getIsCXXTry() const { return IsCXXTry; }
1934 CompoundStmt* getTryBlock() const {
1935 return cast<CompoundStmt>(Children[TRY]);
1938 Stmt *getHandler() const { return Children[HANDLER]; }
1940 /// Returns 0 if not defined
1941 SEHExceptStmt *getExceptHandler() const;
1942 SEHFinallyStmt *getFinallyHandler() const;
1944 child_range children() {
1945 return child_range(Children,Children+2);
1948 static bool classof(const Stmt *T) {
1949 return T->getStmtClass() == SEHTryStmtClass;
1953 /// Represents a __leave statement.
1955 class SEHLeaveStmt : public Stmt {
1956 SourceLocation LeaveLoc;
1958 explicit SEHLeaveStmt(SourceLocation LL)
1959 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
1961 /// \brief Build an empty __leave statement.
1962 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) { }
1964 SourceLocation getLeaveLoc() const { return LeaveLoc; }
1965 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
1967 SourceLocation getLocStart() const LLVM_READONLY { return LeaveLoc; }
1968 SourceLocation getLocEnd() const LLVM_READONLY { return LeaveLoc; }
1970 static bool classof(const Stmt *T) {
1971 return T->getStmtClass() == SEHLeaveStmtClass;
1975 child_range children() { return child_range(); }
1978 /// \brief This captures a statement into a function. For example, the following
1979 /// pragma annotated compound statement can be represented as a CapturedStmt,
1980 /// and this compound statement is the body of an anonymous outlined function.
1982 /// #pragma omp parallel
1987 class CapturedStmt : public Stmt {
1989 /// \brief The different capture forms: by 'this', by reference, capture for
1990 /// variable-length array type etc.
1991 enum VariableCaptureKind {
1997 /// \brief Describes the capture of either a variable, or 'this', or
1998 /// variable-length array type.
2000 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
2004 /// \brief Create a new capture.
2006 /// \param Loc The source location associated with this capture.
2008 /// \param Kind The kind of capture (this, ByRef, ...).
2010 /// \param Var The variable being captured, or null if capturing this.
2012 Capture(SourceLocation Loc, VariableCaptureKind Kind,
2013 VarDecl *Var = nullptr)
2014 : VarAndKind(Var, Kind), Loc(Loc) {
2017 assert(!Var && "'this' capture cannot have a variable!");
2020 assert(Var && "capturing by reference must have a variable!");
2024 "Variable-length array type capture cannot have a variable!");
2029 /// \brief Determine the kind of capture.
2030 VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
2032 /// \brief Retrieve the source location at which the variable or 'this' was
2034 SourceLocation getLocation() const { return Loc; }
2036 /// \brief Determine whether this capture handles the C++ 'this' pointer.
2037 bool capturesThis() const { return getCaptureKind() == VCK_This; }
2039 /// \brief Determine whether this capture handles a variable.
2040 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
2042 /// \brief Determine whether this capture handles a variable-length array
2044 bool capturesVariableArrayType() const {
2045 return getCaptureKind() == VCK_VLAType;
2048 /// \brief Retrieve the declaration of the variable being captured.
2050 /// This operation is only valid if this capture captures a variable.
2051 VarDecl *getCapturedVar() const {
2052 assert(capturesVariable() &&
2053 "No variable available for 'this' or VAT capture");
2054 return VarAndKind.getPointer();
2056 friend class ASTStmtReader;
2060 /// \brief The number of variable captured, including 'this'.
2061 unsigned NumCaptures;
2063 /// \brief The pointer part is the implicit the outlined function and the
2064 /// int part is the captured region kind, 'CR_Default' etc.
2065 llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
2067 /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
2068 RecordDecl *TheRecordDecl;
2070 /// \brief Construct a captured statement.
2071 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
2072 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
2074 /// \brief Construct an empty captured statement.
2075 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2077 Stmt **getStoredStmts() const {
2078 return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2081 Capture *getStoredCaptures() const;
2083 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2086 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
2087 CapturedRegionKind Kind,
2088 ArrayRef<Capture> Captures,
2089 ArrayRef<Expr *> CaptureInits,
2090 CapturedDecl *CD, RecordDecl *RD);
2092 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2093 unsigned NumCaptures);
2095 /// \brief Retrieve the statement being captured.
2096 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2097 const Stmt *getCapturedStmt() const {
2098 return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2101 /// \brief Retrieve the outlined function declaration.
2102 CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
2103 const CapturedDecl *getCapturedDecl() const {
2104 return const_cast<CapturedStmt *>(this)->getCapturedDecl();
2107 /// \brief Set the outlined function declaration.
2108 void setCapturedDecl(CapturedDecl *D) {
2109 assert(D && "null CapturedDecl");
2110 CapDeclAndKind.setPointer(D);
2113 /// \brief Retrieve the captured region kind.
2114 CapturedRegionKind getCapturedRegionKind() const {
2115 return CapDeclAndKind.getInt();
2118 /// \brief Set the captured region kind.
2119 void setCapturedRegionKind(CapturedRegionKind Kind) {
2120 CapDeclAndKind.setInt(Kind);
2123 /// \brief Retrieve the record declaration for captured variables.
2124 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2126 /// \brief Set the record declaration for captured variables.
2127 void setCapturedRecordDecl(RecordDecl *D) {
2128 assert(D && "null RecordDecl");
2132 /// \brief True if this variable has been captured.
2133 bool capturesVariable(const VarDecl *Var) const;
2135 /// \brief An iterator that walks over the captures.
2136 typedef Capture *capture_iterator;
2137 typedef const Capture *const_capture_iterator;
2138 typedef llvm::iterator_range<capture_iterator> capture_range;
2139 typedef llvm::iterator_range<const_capture_iterator> capture_const_range;
2141 capture_range captures() {
2142 return capture_range(capture_begin(), capture_end());
2144 capture_const_range captures() const {
2145 return capture_const_range(capture_begin(), capture_end());
2148 /// \brief Retrieve an iterator pointing to the first capture.
2149 capture_iterator capture_begin() { return getStoredCaptures(); }
2150 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2152 /// \brief Retrieve an iterator pointing past the end of the sequence of
2154 capture_iterator capture_end() const {
2155 return getStoredCaptures() + NumCaptures;
2158 /// \brief Retrieve the number of captures, including 'this'.
2159 unsigned capture_size() const { return NumCaptures; }
2161 /// \brief Iterator that walks over the capture initialization arguments.
2162 typedef Expr **capture_init_iterator;
2163 typedef llvm::iterator_range<capture_init_iterator> capture_init_range;
2165 capture_init_range capture_inits() const {
2166 return capture_init_range(capture_init_begin(), capture_init_end());
2169 /// \brief Retrieve the first initialization argument.
2170 capture_init_iterator capture_init_begin() const {
2171 return reinterpret_cast<Expr **>(getStoredStmts());
2174 /// \brief Retrieve the iterator pointing one past the last initialization
2176 capture_init_iterator capture_init_end() const {
2177 return capture_init_begin() + NumCaptures;
2180 SourceLocation getLocStart() const LLVM_READONLY {
2181 return getCapturedStmt()->getLocStart();
2183 SourceLocation getLocEnd() const LLVM_READONLY {
2184 return getCapturedStmt()->getLocEnd();
2186 SourceRange getSourceRange() const LLVM_READONLY {
2187 return getCapturedStmt()->getSourceRange();
2190 static bool classof(const Stmt *T) {
2191 return T->getStmtClass() == CapturedStmtClass;
2194 child_range children();
2196 friend class ASTStmtReader;
2199 } // end namespace clang