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.
108 #define STMT(CLASS, PARENT) CLASS##Class,
109 #define STMT_RANGE(BASE, FIRST, LAST) \
110 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class,
111 #define LAST_STMT_RANGE(BASE, FIRST, LAST) \
112 first##BASE##Constant=FIRST##Class, last##BASE##Constant=LAST##Class
113 #define ABSTRACT_STMT(STMT)
114 #include "clang/AST/StmtNodes.inc"
117 // Make vanilla 'new' and 'delete' illegal for Stmts.
119 void* operator new(size_t bytes) throw() {
120 llvm_unreachable("Stmts cannot be allocated with regular 'new'.");
122 void operator delete(void* data) throw() {
123 llvm_unreachable("Stmts cannot be released with regular 'delete'.");
126 class StmtBitfields {
129 /// \brief The statement class.
132 enum { NumStmtBits = 8 };
134 class CompoundStmtBitfields {
135 friend class CompoundStmt;
136 unsigned : NumStmtBits;
138 unsigned NumStmts : 32 - NumStmtBits;
141 class ExprBitfields {
143 friend class DeclRefExpr; // computeDependence
144 friend class InitListExpr; // ctor
145 friend class DesignatedInitExpr; // ctor
146 friend class BlockDeclRefExpr; // ctor
147 friend class ASTStmtReader; // deserialization
148 friend class CXXNewExpr; // ctor
149 friend class DependentScopeDeclRefExpr; // ctor
150 friend class CXXConstructExpr; // ctor
151 friend class CallExpr; // ctor
152 friend class OffsetOfExpr; // ctor
153 friend class ObjCMessageExpr; // ctor
154 friend class ObjCArrayLiteral; // ctor
155 friend class ObjCDictionaryLiteral; // ctor
156 friend class ShuffleVectorExpr; // ctor
157 friend class ParenListExpr; // ctor
158 friend class CXXUnresolvedConstructExpr; // ctor
159 friend class CXXDependentScopeMemberExpr; // ctor
160 friend class OverloadExpr; // ctor
161 friend class PseudoObjectExpr; // ctor
162 friend class AtomicExpr; // ctor
163 unsigned : NumStmtBits;
165 unsigned ValueKind : 2;
166 unsigned ObjectKind : 2;
167 unsigned TypeDependent : 1;
168 unsigned ValueDependent : 1;
169 unsigned InstantiationDependent : 1;
170 unsigned ContainsUnexpandedParameterPack : 1;
172 enum { NumExprBits = 16 };
174 class CharacterLiteralBitfields {
175 friend class CharacterLiteral;
176 unsigned : NumExprBits;
181 enum APFloatSemantics {
190 class FloatingLiteralBitfields {
191 friend class FloatingLiteral;
192 unsigned : NumExprBits;
194 unsigned Semantics : 3; // Provides semantics for APFloat construction
195 unsigned IsExact : 1;
198 class UnaryExprOrTypeTraitExprBitfields {
199 friend class UnaryExprOrTypeTraitExpr;
200 unsigned : NumExprBits;
203 unsigned IsType : 1; // true if operand is a type, false if an expression.
206 class DeclRefExprBitfields {
207 friend class DeclRefExpr;
208 friend class ASTStmtReader; // deserialization
209 unsigned : NumExprBits;
211 unsigned HasQualifier : 1;
212 unsigned HasTemplateKWAndArgsInfo : 1;
213 unsigned HasFoundDecl : 1;
214 unsigned HadMultipleCandidates : 1;
215 unsigned RefersToEnclosingVariableOrCapture : 1;
218 class CastExprBitfields {
219 friend class CastExpr;
220 unsigned : NumExprBits;
223 unsigned BasePathSize : 32 - 6 - NumExprBits;
226 class CallExprBitfields {
227 friend class CallExpr;
228 unsigned : NumExprBits;
230 unsigned NumPreArgs : 1;
233 class ExprWithCleanupsBitfields {
234 friend class ExprWithCleanups;
235 friend class ASTStmtReader; // deserialization
237 unsigned : NumExprBits;
239 unsigned NumObjects : 32 - NumExprBits;
242 class PseudoObjectExprBitfields {
243 friend class PseudoObjectExpr;
244 friend class ASTStmtReader; // deserialization
246 unsigned : NumExprBits;
248 // These don't need to be particularly wide, because they're
249 // strictly limited by the forms of expressions we permit.
250 unsigned NumSubExprs : 8;
251 unsigned ResultIndex : 32 - 8 - NumExprBits;
254 class ObjCIndirectCopyRestoreExprBitfields {
255 friend class ObjCIndirectCopyRestoreExpr;
256 unsigned : NumExprBits;
258 unsigned ShouldCopy : 1;
261 class InitListExprBitfields {
262 friend class InitListExpr;
264 unsigned : NumExprBits;
266 /// Whether this initializer list originally had a GNU array-range
267 /// designator in it. This is a temporary marker used by CodeGen.
268 unsigned HadArrayRangeDesignator : 1;
271 class TypeTraitExprBitfields {
272 friend class TypeTraitExpr;
273 friend class ASTStmtReader;
274 friend class ASTStmtWriter;
276 unsigned : NumExprBits;
278 /// \brief The kind of type trait, which is a value of a TypeTrait enumerator.
281 /// \brief If this expression is not value-dependent, this indicates whether
282 /// the trait evaluated true or false.
285 /// \brief The number of arguments to this type trait.
286 unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
290 // FIXME: this is wasteful on 64-bit platforms.
293 StmtBitfields StmtBits;
294 CompoundStmtBitfields CompoundStmtBits;
295 ExprBitfields ExprBits;
296 CharacterLiteralBitfields CharacterLiteralBits;
297 FloatingLiteralBitfields FloatingLiteralBits;
298 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
299 DeclRefExprBitfields DeclRefExprBits;
300 CastExprBitfields CastExprBits;
301 CallExprBitfields CallExprBits;
302 ExprWithCleanupsBitfields ExprWithCleanupsBits;
303 PseudoObjectExprBitfields PseudoObjectExprBits;
304 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
305 InitListExprBitfields InitListExprBits;
306 TypeTraitExprBitfields TypeTraitExprBits;
309 friend class ASTStmtReader;
310 friend class ASTStmtWriter;
313 // Only allow allocation of Stmts using the allocator in ASTContext
314 // or by doing a placement new.
315 void* operator new(size_t bytes, const ASTContext& C,
316 unsigned alignment = 8);
318 void* operator new(size_t bytes, const ASTContext* C,
319 unsigned alignment = 8) {
320 return operator new(bytes, *C, alignment);
323 void* operator new(size_t bytes, void* mem) throw() {
327 void operator delete(void*, const ASTContext&, unsigned) throw() { }
328 void operator delete(void*, const ASTContext*, unsigned) throw() { }
329 void operator delete(void*, size_t) throw() { }
330 void operator delete(void*, void*) throw() { }
333 /// \brief A placeholder type used to construct an empty shell of a
334 /// type, that will be filled in later (e.g., by some
335 /// de-serialization).
336 struct EmptyShell { };
339 /// \brief Whether statistic collection is enabled.
340 static bool StatisticsEnabled;
343 /// \brief Construct an empty statement.
344 explicit Stmt(StmtClass SC, EmptyShell) {
345 StmtBits.sClass = SC;
346 if (StatisticsEnabled) Stmt::addStmtClass(SC);
351 StmtBits.sClass = SC;
352 if (StatisticsEnabled) Stmt::addStmtClass(SC);
355 StmtClass getStmtClass() const {
356 return static_cast<StmtClass>(StmtBits.sClass);
358 const char *getStmtClassName() const;
360 /// SourceLocation tokens are not useful in isolation - they are low level
361 /// value objects created/interpreted by SourceManager. We assume AST
362 /// clients will have a pointer to the respective SourceManager.
363 SourceRange getSourceRange() const LLVM_READONLY;
364 SourceLocation getLocStart() const LLVM_READONLY;
365 SourceLocation getLocEnd() const LLVM_READONLY;
367 // global temp stats (until we have a per-module visitor)
368 static void addStmtClass(const StmtClass s);
369 static void EnableStatistics();
370 static void PrintStats();
372 /// \brief Dumps the specified AST fragment and all subtrees to
375 void dump(SourceManager &SM) const;
376 void dump(raw_ostream &OS, SourceManager &SM) const;
378 /// dumpColor - same as dump(), but forces color highlighting.
379 void dumpColor() const;
381 /// dumpPretty/printPretty - These two methods do a "pretty print" of the AST
382 /// back to its original source language syntax.
383 void dumpPretty(const ASTContext &Context) const;
384 void printPretty(raw_ostream &OS, PrinterHelper *Helper,
385 const PrintingPolicy &Policy,
386 unsigned Indentation = 0) const;
388 /// viewAST - Visualize an AST rooted at this Stmt* using GraphViz. Only
389 /// works on systems with GraphViz (Mac OS X) or dot+gv installed.
390 void viewAST() const;
392 /// Skip past any implicit AST nodes which might surround this
393 /// statement, such as ExprWithCleanups or ImplicitCastExpr nodes.
394 Stmt *IgnoreImplicit();
396 /// \brief Skip no-op (attributed, compound) container stmts and skip captured
397 /// stmt at the top, if \a IgnoreCaptured is true.
398 Stmt *IgnoreContainers(bool IgnoreCaptured = false);
400 const Stmt *stripLabelLikeStatements() const;
401 Stmt *stripLabelLikeStatements() {
402 return const_cast<Stmt*>(
403 const_cast<const Stmt*>(this)->stripLabelLikeStatements());
406 /// Child Iterators: All subclasses must implement 'children'
407 /// to permit easy iteration over the substatements/subexpessions of an
408 /// AST node. This permits easy iteration over all nodes in the AST.
409 typedef StmtIterator child_iterator;
410 typedef ConstStmtIterator const_child_iterator;
412 typedef StmtRange child_range;
413 typedef ConstStmtRange const_child_range;
415 child_range children();
416 const_child_range children() const {
417 return const_cast<Stmt*>(this)->children();
420 child_iterator child_begin() { return children().first; }
421 child_iterator child_end() { return children().second; }
423 const_child_iterator child_begin() const { return children().first; }
424 const_child_iterator child_end() const { return children().second; }
426 /// \brief Produce a unique representation of the given statement.
428 /// \param ID once the profiling operation is complete, will contain
429 /// the unique representation of the given statement.
431 /// \param Context the AST context in which the statement resides
433 /// \param Canonical whether the profile should be based on the canonical
434 /// representation of this statement (e.g., where non-type template
435 /// parameters are identified by index/level rather than their
436 /// declaration pointers) or the exact representation of the statement as
437 /// written in the source.
438 void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
439 bool Canonical) const;
442 /// DeclStmt - Adaptor class for mixing declarations with statements and
443 /// expressions. For example, CompoundStmt mixes statements, expressions
444 /// and declarations (variables, types). Another example is ForStmt, where
445 /// the first statement can be an expression or a declaration.
447 class DeclStmt : public Stmt {
449 SourceLocation StartLoc, EndLoc;
452 DeclStmt(DeclGroupRef dg, SourceLocation startLoc,
453 SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
454 StartLoc(startLoc), EndLoc(endLoc) {}
456 /// \brief Build an empty declaration statement.
457 explicit DeclStmt(EmptyShell Empty) : Stmt(DeclStmtClass, Empty) { }
459 /// isSingleDecl - This method returns true if this DeclStmt refers
460 /// to a single Decl.
461 bool isSingleDecl() const {
462 return DG.isSingleDecl();
465 const Decl *getSingleDecl() const { return DG.getSingleDecl(); }
466 Decl *getSingleDecl() { return DG.getSingleDecl(); }
468 const DeclGroupRef getDeclGroup() const { return DG; }
469 DeclGroupRef getDeclGroup() { return DG; }
470 void setDeclGroup(DeclGroupRef DGR) { DG = DGR; }
472 SourceLocation getStartLoc() const { return StartLoc; }
473 void setStartLoc(SourceLocation L) { StartLoc = L; }
474 SourceLocation getEndLoc() const { return EndLoc; }
475 void setEndLoc(SourceLocation L) { EndLoc = L; }
477 SourceLocation getLocStart() const LLVM_READONLY { return StartLoc; }
478 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
480 static bool classof(const Stmt *T) {
481 return T->getStmtClass() == DeclStmtClass;
484 // Iterators over subexpressions.
485 child_range children() {
486 return child_range(child_iterator(DG.begin(), DG.end()),
487 child_iterator(DG.end(), DG.end()));
490 typedef DeclGroupRef::iterator decl_iterator;
491 typedef DeclGroupRef::const_iterator const_decl_iterator;
492 typedef llvm::iterator_range<decl_iterator> decl_range;
493 typedef llvm::iterator_range<const_decl_iterator> decl_const_range;
495 decl_range decls() { return decl_range(decl_begin(), decl_end()); }
496 decl_const_range decls() const {
497 return decl_const_range(decl_begin(), decl_end());
499 decl_iterator decl_begin() { return DG.begin(); }
500 decl_iterator decl_end() { return DG.end(); }
501 const_decl_iterator decl_begin() const { return DG.begin(); }
502 const_decl_iterator decl_end() const { return DG.end(); }
504 typedef std::reverse_iterator<decl_iterator> reverse_decl_iterator;
505 reverse_decl_iterator decl_rbegin() {
506 return reverse_decl_iterator(decl_end());
508 reverse_decl_iterator decl_rend() {
509 return reverse_decl_iterator(decl_begin());
513 /// NullStmt - This is the null statement ";": C99 6.8.3p3.
515 class NullStmt : public Stmt {
516 SourceLocation SemiLoc;
518 /// \brief True if the null statement was preceded by an empty macro, e.g:
523 bool HasLeadingEmptyMacro;
525 NullStmt(SourceLocation L, bool hasLeadingEmptyMacro = false)
526 : Stmt(NullStmtClass), SemiLoc(L),
527 HasLeadingEmptyMacro(hasLeadingEmptyMacro) {}
529 /// \brief Build an empty null statement.
530 explicit NullStmt(EmptyShell Empty) : Stmt(NullStmtClass, Empty),
531 HasLeadingEmptyMacro(false) { }
533 SourceLocation getSemiLoc() const { return SemiLoc; }
534 void setSemiLoc(SourceLocation L) { SemiLoc = L; }
536 bool hasLeadingEmptyMacro() const { return HasLeadingEmptyMacro; }
538 SourceLocation getLocStart() const LLVM_READONLY { return SemiLoc; }
539 SourceLocation getLocEnd() const LLVM_READONLY { return SemiLoc; }
541 static bool classof(const Stmt *T) {
542 return T->getStmtClass() == NullStmtClass;
545 child_range children() { return child_range(); }
547 friend class ASTStmtReader;
548 friend class ASTStmtWriter;
551 /// CompoundStmt - This represents a group of statements like { stmt stmt }.
553 class CompoundStmt : public Stmt {
555 SourceLocation LBraceLoc, RBraceLoc;
557 friend class ASTStmtReader;
560 CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts,
561 SourceLocation LB, SourceLocation RB);
563 // \brief Build an empty compound statement with a location.
564 explicit CompoundStmt(SourceLocation Loc)
565 : Stmt(CompoundStmtClass), Body(nullptr), LBraceLoc(Loc), RBraceLoc(Loc) {
566 CompoundStmtBits.NumStmts = 0;
569 // \brief Build an empty compound statement.
570 explicit CompoundStmt(EmptyShell Empty)
571 : Stmt(CompoundStmtClass, Empty), Body(nullptr) {
572 CompoundStmtBits.NumStmts = 0;
575 void setStmts(const ASTContext &C, Stmt **Stmts, unsigned NumStmts);
577 bool body_empty() const { return CompoundStmtBits.NumStmts == 0; }
578 unsigned size() const { return CompoundStmtBits.NumStmts; }
580 typedef Stmt** body_iterator;
581 typedef llvm::iterator_range<body_iterator> body_range;
583 body_range body() { return body_range(body_begin(), body_end()); }
584 body_iterator body_begin() { return Body; }
585 body_iterator body_end() { return Body + size(); }
586 Stmt *body_back() { return !body_empty() ? Body[size()-1] : nullptr; }
588 void setLastStmt(Stmt *S) {
589 assert(!body_empty() && "setLastStmt");
593 typedef Stmt* const * const_body_iterator;
594 typedef llvm::iterator_range<const_body_iterator> body_const_range;
596 body_const_range body() const {
597 return body_const_range(body_begin(), body_end());
599 const_body_iterator body_begin() const { return Body; }
600 const_body_iterator body_end() const { return Body + size(); }
601 const Stmt *body_back() const {
602 return !body_empty() ? Body[size() - 1] : nullptr;
605 typedef std::reverse_iterator<body_iterator> reverse_body_iterator;
606 reverse_body_iterator body_rbegin() {
607 return reverse_body_iterator(body_end());
609 reverse_body_iterator body_rend() {
610 return reverse_body_iterator(body_begin());
613 typedef std::reverse_iterator<const_body_iterator>
614 const_reverse_body_iterator;
616 const_reverse_body_iterator body_rbegin() const {
617 return const_reverse_body_iterator(body_end());
620 const_reverse_body_iterator body_rend() const {
621 return const_reverse_body_iterator(body_begin());
624 SourceLocation getLocStart() const LLVM_READONLY { return LBraceLoc; }
625 SourceLocation getLocEnd() const LLVM_READONLY { return RBraceLoc; }
627 SourceLocation getLBracLoc() const { return LBraceLoc; }
628 SourceLocation getRBracLoc() const { return RBraceLoc; }
630 static bool classof(const Stmt *T) {
631 return T->getStmtClass() == CompoundStmtClass;
635 child_range children() {
636 return child_range(Body, Body + CompoundStmtBits.NumStmts);
639 const_child_range children() const {
640 return child_range(Body, Body + CompoundStmtBits.NumStmts);
644 // SwitchCase is the base class for CaseStmt and DefaultStmt,
645 class SwitchCase : public Stmt {
647 // A pointer to the following CaseStmt or DefaultStmt class,
648 // used by SwitchStmt.
649 SwitchCase *NextSwitchCase;
650 SourceLocation KeywordLoc;
651 SourceLocation ColonLoc;
653 SwitchCase(StmtClass SC, SourceLocation KWLoc, SourceLocation ColonLoc)
654 : Stmt(SC), NextSwitchCase(nullptr), KeywordLoc(KWLoc), ColonLoc(ColonLoc) {
657 SwitchCase(StmtClass SC, EmptyShell)
658 : Stmt(SC), NextSwitchCase(nullptr) {}
661 const SwitchCase *getNextSwitchCase() const { return NextSwitchCase; }
663 SwitchCase *getNextSwitchCase() { return NextSwitchCase; }
665 void setNextSwitchCase(SwitchCase *SC) { NextSwitchCase = SC; }
667 SourceLocation getKeywordLoc() const { return KeywordLoc; }
668 void setKeywordLoc(SourceLocation L) { KeywordLoc = L; }
669 SourceLocation getColonLoc() const { return ColonLoc; }
670 void setColonLoc(SourceLocation L) { ColonLoc = L; }
673 const Stmt *getSubStmt() const {
674 return const_cast<SwitchCase*>(this)->getSubStmt();
677 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
678 SourceLocation getLocEnd() const LLVM_READONLY;
680 static bool classof(const Stmt *T) {
681 return T->getStmtClass() == CaseStmtClass ||
682 T->getStmtClass() == DefaultStmtClass;
686 class CaseStmt : public SwitchCase {
687 enum { LHS, RHS, SUBSTMT, END_EXPR };
688 Stmt* SubExprs[END_EXPR]; // The expression for the RHS is Non-null for
689 // GNU "case 1 ... 4" extension
690 SourceLocation EllipsisLoc;
692 CaseStmt(Expr *lhs, Expr *rhs, SourceLocation caseLoc,
693 SourceLocation ellipsisLoc, SourceLocation colonLoc)
694 : SwitchCase(CaseStmtClass, caseLoc, colonLoc) {
695 SubExprs[SUBSTMT] = nullptr;
696 SubExprs[LHS] = reinterpret_cast<Stmt*>(lhs);
697 SubExprs[RHS] = reinterpret_cast<Stmt*>(rhs);
698 EllipsisLoc = ellipsisLoc;
701 /// \brief Build an empty switch case statement.
702 explicit CaseStmt(EmptyShell Empty) : SwitchCase(CaseStmtClass, Empty) { }
704 SourceLocation getCaseLoc() const { return KeywordLoc; }
705 void setCaseLoc(SourceLocation L) { KeywordLoc = L; }
706 SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
707 void setEllipsisLoc(SourceLocation L) { EllipsisLoc = L; }
708 SourceLocation getColonLoc() const { return ColonLoc; }
709 void setColonLoc(SourceLocation L) { ColonLoc = L; }
711 Expr *getLHS() { return reinterpret_cast<Expr*>(SubExprs[LHS]); }
712 Expr *getRHS() { return reinterpret_cast<Expr*>(SubExprs[RHS]); }
713 Stmt *getSubStmt() { return SubExprs[SUBSTMT]; }
715 const Expr *getLHS() const {
716 return reinterpret_cast<const Expr*>(SubExprs[LHS]);
718 const Expr *getRHS() const {
719 return reinterpret_cast<const Expr*>(SubExprs[RHS]);
721 const Stmt *getSubStmt() const { return SubExprs[SUBSTMT]; }
723 void setSubStmt(Stmt *S) { SubExprs[SUBSTMT] = S; }
724 void setLHS(Expr *Val) { SubExprs[LHS] = reinterpret_cast<Stmt*>(Val); }
725 void setRHS(Expr *Val) { SubExprs[RHS] = reinterpret_cast<Stmt*>(Val); }
727 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
728 SourceLocation getLocEnd() const LLVM_READONLY {
729 // Handle deeply nested case statements with iteration instead of recursion.
730 const CaseStmt *CS = this;
731 while (const CaseStmt *CS2 = dyn_cast<CaseStmt>(CS->getSubStmt()))
734 return CS->getSubStmt()->getLocEnd();
737 static bool classof(const Stmt *T) {
738 return T->getStmtClass() == CaseStmtClass;
742 child_range children() {
743 return child_range(&SubExprs[0], &SubExprs[END_EXPR]);
747 class DefaultStmt : public SwitchCase {
750 DefaultStmt(SourceLocation DL, SourceLocation CL, Stmt *substmt) :
751 SwitchCase(DefaultStmtClass, DL, CL), SubStmt(substmt) {}
753 /// \brief Build an empty default statement.
754 explicit DefaultStmt(EmptyShell Empty)
755 : SwitchCase(DefaultStmtClass, Empty) { }
757 Stmt *getSubStmt() { return SubStmt; }
758 const Stmt *getSubStmt() const { return SubStmt; }
759 void setSubStmt(Stmt *S) { SubStmt = S; }
761 SourceLocation getDefaultLoc() const { return KeywordLoc; }
762 void setDefaultLoc(SourceLocation L) { KeywordLoc = L; }
763 SourceLocation getColonLoc() const { return ColonLoc; }
764 void setColonLoc(SourceLocation L) { ColonLoc = L; }
766 SourceLocation getLocStart() const LLVM_READONLY { return KeywordLoc; }
767 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
769 static bool classof(const Stmt *T) {
770 return T->getStmtClass() == DefaultStmtClass;
774 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
777 inline SourceLocation SwitchCase::getLocEnd() const {
778 if (const CaseStmt *CS = dyn_cast<CaseStmt>(this))
779 return CS->getLocEnd();
780 return cast<DefaultStmt>(this)->getLocEnd();
783 /// LabelStmt - Represents a label, which has a substatement. For example:
786 class LabelStmt : public Stmt {
789 SourceLocation IdentLoc;
791 LabelStmt(SourceLocation IL, LabelDecl *D, Stmt *substmt)
792 : Stmt(LabelStmtClass), TheDecl(D), SubStmt(substmt), IdentLoc(IL) {
795 // \brief Build an empty label statement.
796 explicit LabelStmt(EmptyShell Empty) : Stmt(LabelStmtClass, Empty) { }
798 SourceLocation getIdentLoc() const { return IdentLoc; }
799 LabelDecl *getDecl() const { return TheDecl; }
800 void setDecl(LabelDecl *D) { TheDecl = D; }
801 const char *getName() const;
802 Stmt *getSubStmt() { return SubStmt; }
803 const Stmt *getSubStmt() const { return SubStmt; }
804 void setIdentLoc(SourceLocation L) { IdentLoc = L; }
805 void setSubStmt(Stmt *SS) { SubStmt = SS; }
807 SourceLocation getLocStart() const LLVM_READONLY { return IdentLoc; }
808 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
810 child_range children() { return child_range(&SubStmt, &SubStmt+1); }
812 static bool classof(const Stmt *T) {
813 return T->getStmtClass() == LabelStmtClass;
818 /// \brief Represents an attribute applied to a statement.
820 /// Represents an attribute applied to a statement. For example:
821 /// [[omp::for(...)]] for (...) { ... }
823 class AttributedStmt : public Stmt {
825 SourceLocation AttrLoc;
828 friend class ASTStmtReader;
830 AttributedStmt(SourceLocation Loc, ArrayRef<const Attr*> Attrs, Stmt *SubStmt)
831 : Stmt(AttributedStmtClass), SubStmt(SubStmt), AttrLoc(Loc),
832 NumAttrs(Attrs.size()) {
833 memcpy(getAttrArrayPtr(), Attrs.data(), Attrs.size() * sizeof(Attr *));
836 explicit AttributedStmt(EmptyShell Empty, unsigned NumAttrs)
837 : Stmt(AttributedStmtClass, Empty), NumAttrs(NumAttrs) {
838 memset(getAttrArrayPtr(), 0, NumAttrs * sizeof(Attr *));
841 Attr *const *getAttrArrayPtr() const {
842 return reinterpret_cast<Attr *const *>(this + 1);
844 Attr **getAttrArrayPtr() { return reinterpret_cast<Attr **>(this + 1); }
847 static AttributedStmt *Create(const ASTContext &C, SourceLocation Loc,
848 ArrayRef<const Attr*> Attrs, Stmt *SubStmt);
849 // \brief Build an empty attributed statement.
850 static AttributedStmt *CreateEmpty(const ASTContext &C, unsigned NumAttrs);
852 SourceLocation getAttrLoc() const { return AttrLoc; }
853 ArrayRef<const Attr*> getAttrs() const {
854 return llvm::makeArrayRef(getAttrArrayPtr(), NumAttrs);
856 Stmt *getSubStmt() { return SubStmt; }
857 const Stmt *getSubStmt() const { return SubStmt; }
859 SourceLocation getLocStart() const LLVM_READONLY { return AttrLoc; }
860 SourceLocation getLocEnd() const LLVM_READONLY { return SubStmt->getLocEnd();}
862 child_range children() { return child_range(&SubStmt, &SubStmt + 1); }
864 static bool classof(const Stmt *T) {
865 return T->getStmtClass() == AttributedStmtClass;
870 /// IfStmt - This represents an if/then/else.
872 class IfStmt : public Stmt {
873 enum { VAR, COND, THEN, ELSE, END_EXPR };
874 Stmt* SubExprs[END_EXPR];
876 SourceLocation IfLoc;
877 SourceLocation ElseLoc;
880 IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond,
881 Stmt *then, SourceLocation EL = SourceLocation(),
882 Stmt *elsev = nullptr);
884 /// \brief Build an empty if/then/else statement
885 explicit IfStmt(EmptyShell Empty) : Stmt(IfStmtClass, Empty) { }
887 /// \brief Retrieve the variable declared in this "if" statement, if any.
889 /// In the following example, "x" is the condition variable.
891 /// if (int x = foo()) {
892 /// printf("x is %d", x);
895 VarDecl *getConditionVariable() const;
896 void setConditionVariable(const ASTContext &C, VarDecl *V);
898 /// If this IfStmt has a condition variable, return the faux DeclStmt
899 /// associated with the creation of that condition variable.
900 const DeclStmt *getConditionVariableDeclStmt() const {
901 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
904 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
905 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
906 const Stmt *getThen() const { return SubExprs[THEN]; }
907 void setThen(Stmt *S) { SubExprs[THEN] = S; }
908 const Stmt *getElse() const { return SubExprs[ELSE]; }
909 void setElse(Stmt *S) { SubExprs[ELSE] = S; }
911 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
912 Stmt *getThen() { return SubExprs[THEN]; }
913 Stmt *getElse() { return SubExprs[ELSE]; }
915 SourceLocation getIfLoc() const { return IfLoc; }
916 void setIfLoc(SourceLocation L) { IfLoc = L; }
917 SourceLocation getElseLoc() const { return ElseLoc; }
918 void setElseLoc(SourceLocation L) { ElseLoc = L; }
920 SourceLocation getLocStart() const LLVM_READONLY { return IfLoc; }
921 SourceLocation getLocEnd() const LLVM_READONLY {
923 return SubExprs[ELSE]->getLocEnd();
925 return SubExprs[THEN]->getLocEnd();
928 // Iterators over subexpressions. The iterators will include iterating
929 // over the initialization expression referenced by the condition variable.
930 child_range children() {
931 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
934 static bool classof(const Stmt *T) {
935 return T->getStmtClass() == IfStmtClass;
939 /// SwitchStmt - This represents a 'switch' stmt.
941 class SwitchStmt : public Stmt {
942 enum { VAR, COND, BODY, END_EXPR };
943 Stmt* SubExprs[END_EXPR];
944 // This points to a linked list of case and default statements.
945 SwitchCase *FirstCase;
946 SourceLocation SwitchLoc;
948 /// If the SwitchStmt is a switch on an enum value, this records whether
949 /// all the enum values were covered by CaseStmts. This value is meant to
950 /// be a hint for possible clients.
951 unsigned AllEnumCasesCovered : 1;
954 SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond);
956 /// \brief Build a empty switch statement.
957 explicit SwitchStmt(EmptyShell Empty) : Stmt(SwitchStmtClass, Empty) { }
959 /// \brief Retrieve the variable declared in this "switch" statement, if any.
961 /// In the following example, "x" is the condition variable.
963 /// switch (int x = foo()) {
968 VarDecl *getConditionVariable() const;
969 void setConditionVariable(const ASTContext &C, VarDecl *V);
971 /// If this SwitchStmt has a condition variable, return the faux DeclStmt
972 /// associated with the creation of that condition variable.
973 const DeclStmt *getConditionVariableDeclStmt() const {
974 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
977 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
978 const Stmt *getBody() const { return SubExprs[BODY]; }
979 const SwitchCase *getSwitchCaseList() const { return FirstCase; }
981 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]);}
982 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt *>(E); }
983 Stmt *getBody() { return SubExprs[BODY]; }
984 void setBody(Stmt *S) { SubExprs[BODY] = S; }
985 SwitchCase *getSwitchCaseList() { return FirstCase; }
987 /// \brief Set the case list for this switch statement.
988 void setSwitchCaseList(SwitchCase *SC) { FirstCase = SC; }
990 SourceLocation getSwitchLoc() const { return SwitchLoc; }
991 void setSwitchLoc(SourceLocation L) { SwitchLoc = L; }
993 void setBody(Stmt *S, SourceLocation SL) {
997 void addSwitchCase(SwitchCase *SC) {
998 assert(!SC->getNextSwitchCase()
999 && "case/default already added to a switch");
1000 SC->setNextSwitchCase(FirstCase);
1004 /// Set a flag in the SwitchStmt indicating that if the 'switch (X)' is a
1005 /// switch over an enum value then all cases have been explicitly covered.
1006 void setAllEnumCasesCovered() {
1007 AllEnumCasesCovered = 1;
1010 /// Returns true if the SwitchStmt is a switch of an enum value and all cases
1011 /// have been explicitly covered.
1012 bool isAllEnumCasesCovered() const {
1013 return (bool) AllEnumCasesCovered;
1016 SourceLocation getLocStart() const LLVM_READONLY { return SwitchLoc; }
1017 SourceLocation getLocEnd() const LLVM_READONLY {
1018 return SubExprs[BODY] ? SubExprs[BODY]->getLocEnd() : SubExprs[COND]->getLocEnd();
1022 child_range children() {
1023 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1026 static bool classof(const Stmt *T) {
1027 return T->getStmtClass() == SwitchStmtClass;
1032 /// WhileStmt - This represents a 'while' stmt.
1034 class WhileStmt : public Stmt {
1035 enum { VAR, COND, BODY, END_EXPR };
1036 Stmt* SubExprs[END_EXPR];
1037 SourceLocation WhileLoc;
1039 WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body,
1042 /// \brief Build an empty while statement.
1043 explicit WhileStmt(EmptyShell Empty) : Stmt(WhileStmtClass, Empty) { }
1045 /// \brief Retrieve the variable declared in this "while" statement, if any.
1047 /// In the following example, "x" is the condition variable.
1049 /// while (int x = random()) {
1053 VarDecl *getConditionVariable() const;
1054 void setConditionVariable(const ASTContext &C, VarDecl *V);
1056 /// If this WhileStmt has a condition variable, return the faux DeclStmt
1057 /// associated with the creation of that condition variable.
1058 const DeclStmt *getConditionVariableDeclStmt() const {
1059 return reinterpret_cast<DeclStmt*>(SubExprs[VAR]);
1062 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1063 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1064 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1065 Stmt *getBody() { return SubExprs[BODY]; }
1066 const Stmt *getBody() const { return SubExprs[BODY]; }
1067 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1069 SourceLocation getWhileLoc() const { return WhileLoc; }
1070 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1072 SourceLocation getLocStart() const LLVM_READONLY { return WhileLoc; }
1073 SourceLocation getLocEnd() const LLVM_READONLY {
1074 return SubExprs[BODY]->getLocEnd();
1077 static bool classof(const Stmt *T) {
1078 return T->getStmtClass() == WhileStmtClass;
1082 child_range children() {
1083 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1087 /// DoStmt - This represents a 'do/while' stmt.
1089 class DoStmt : public Stmt {
1090 enum { BODY, COND, END_EXPR };
1091 Stmt* SubExprs[END_EXPR];
1092 SourceLocation DoLoc;
1093 SourceLocation WhileLoc;
1094 SourceLocation RParenLoc; // Location of final ')' in do stmt condition.
1097 DoStmt(Stmt *body, Expr *cond, SourceLocation DL, SourceLocation WL,
1099 : Stmt(DoStmtClass), DoLoc(DL), WhileLoc(WL), RParenLoc(RP) {
1100 SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
1101 SubExprs[BODY] = body;
1104 /// \brief Build an empty do-while statement.
1105 explicit DoStmt(EmptyShell Empty) : Stmt(DoStmtClass, Empty) { }
1107 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1108 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1109 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1110 Stmt *getBody() { return SubExprs[BODY]; }
1111 const Stmt *getBody() const { return SubExprs[BODY]; }
1112 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1114 SourceLocation getDoLoc() const { return DoLoc; }
1115 void setDoLoc(SourceLocation L) { DoLoc = L; }
1116 SourceLocation getWhileLoc() const { return WhileLoc; }
1117 void setWhileLoc(SourceLocation L) { WhileLoc = L; }
1119 SourceLocation getRParenLoc() const { return RParenLoc; }
1120 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1122 SourceLocation getLocStart() const LLVM_READONLY { return DoLoc; }
1123 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1125 static bool classof(const Stmt *T) {
1126 return T->getStmtClass() == DoStmtClass;
1130 child_range children() {
1131 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1136 /// ForStmt - This represents a 'for (init;cond;inc)' stmt. Note that any of
1137 /// the init/cond/inc parts of the ForStmt will be null if they were not
1138 /// specified in the source.
1140 class ForStmt : public Stmt {
1141 enum { INIT, CONDVAR, COND, INC, BODY, END_EXPR };
1142 Stmt* SubExprs[END_EXPR]; // SubExprs[INIT] is an expression or declstmt.
1143 SourceLocation ForLoc;
1144 SourceLocation LParenLoc, RParenLoc;
1147 ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar,
1148 Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP,
1151 /// \brief Build an empty for statement.
1152 explicit ForStmt(EmptyShell Empty) : Stmt(ForStmtClass, Empty) { }
1154 Stmt *getInit() { return SubExprs[INIT]; }
1156 /// \brief Retrieve the variable declared in this "for" statement, if any.
1158 /// In the following example, "y" is the condition variable.
1160 /// for (int x = random(); int y = mangle(x); ++x) {
1164 VarDecl *getConditionVariable() const;
1165 void setConditionVariable(const ASTContext &C, VarDecl *V);
1167 /// If this ForStmt has a condition variable, return the faux DeclStmt
1168 /// associated with the creation of that condition variable.
1169 const DeclStmt *getConditionVariableDeclStmt() const {
1170 return reinterpret_cast<DeclStmt*>(SubExprs[CONDVAR]);
1173 Expr *getCond() { return reinterpret_cast<Expr*>(SubExprs[COND]); }
1174 Expr *getInc() { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1175 Stmt *getBody() { return SubExprs[BODY]; }
1177 const Stmt *getInit() const { return SubExprs[INIT]; }
1178 const Expr *getCond() const { return reinterpret_cast<Expr*>(SubExprs[COND]);}
1179 const Expr *getInc() const { return reinterpret_cast<Expr*>(SubExprs[INC]); }
1180 const Stmt *getBody() const { return SubExprs[BODY]; }
1182 void setInit(Stmt *S) { SubExprs[INIT] = S; }
1183 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
1184 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
1185 void setBody(Stmt *S) { SubExprs[BODY] = S; }
1187 SourceLocation getForLoc() const { return ForLoc; }
1188 void setForLoc(SourceLocation L) { ForLoc = L; }
1189 SourceLocation getLParenLoc() const { return LParenLoc; }
1190 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
1191 SourceLocation getRParenLoc() const { return RParenLoc; }
1192 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1194 SourceLocation getLocStart() const LLVM_READONLY { return ForLoc; }
1195 SourceLocation getLocEnd() const LLVM_READONLY {
1196 return SubExprs[BODY]->getLocEnd();
1199 static bool classof(const Stmt *T) {
1200 return T->getStmtClass() == ForStmtClass;
1204 child_range children() {
1205 return child_range(&SubExprs[0], &SubExprs[0]+END_EXPR);
1209 /// GotoStmt - This represents a direct goto.
1211 class GotoStmt : public Stmt {
1213 SourceLocation GotoLoc;
1214 SourceLocation LabelLoc;
1216 GotoStmt(LabelDecl *label, SourceLocation GL, SourceLocation LL)
1217 : Stmt(GotoStmtClass), Label(label), GotoLoc(GL), LabelLoc(LL) {}
1219 /// \brief Build an empty goto statement.
1220 explicit GotoStmt(EmptyShell Empty) : Stmt(GotoStmtClass, Empty) { }
1222 LabelDecl *getLabel() const { return Label; }
1223 void setLabel(LabelDecl *D) { Label = D; }
1225 SourceLocation getGotoLoc() const { return GotoLoc; }
1226 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1227 SourceLocation getLabelLoc() const { return LabelLoc; }
1228 void setLabelLoc(SourceLocation L) { LabelLoc = L; }
1230 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1231 SourceLocation getLocEnd() const LLVM_READONLY { return LabelLoc; }
1233 static bool classof(const Stmt *T) {
1234 return T->getStmtClass() == GotoStmtClass;
1238 child_range children() { return child_range(); }
1241 /// IndirectGotoStmt - This represents an indirect goto.
1243 class IndirectGotoStmt : public Stmt {
1244 SourceLocation GotoLoc;
1245 SourceLocation StarLoc;
1248 IndirectGotoStmt(SourceLocation gotoLoc, SourceLocation starLoc,
1250 : Stmt(IndirectGotoStmtClass), GotoLoc(gotoLoc), StarLoc(starLoc),
1251 Target((Stmt*)target) {}
1253 /// \brief Build an empty indirect goto statement.
1254 explicit IndirectGotoStmt(EmptyShell Empty)
1255 : Stmt(IndirectGotoStmtClass, Empty) { }
1257 void setGotoLoc(SourceLocation L) { GotoLoc = L; }
1258 SourceLocation getGotoLoc() const { return GotoLoc; }
1259 void setStarLoc(SourceLocation L) { StarLoc = L; }
1260 SourceLocation getStarLoc() const { return StarLoc; }
1262 Expr *getTarget() { return reinterpret_cast<Expr*>(Target); }
1263 const Expr *getTarget() const {return reinterpret_cast<const Expr*>(Target);}
1264 void setTarget(Expr *E) { Target = reinterpret_cast<Stmt*>(E); }
1266 /// getConstantTarget - Returns the fixed target of this indirect
1267 /// goto, if one exists.
1268 LabelDecl *getConstantTarget();
1269 const LabelDecl *getConstantTarget() const {
1270 return const_cast<IndirectGotoStmt*>(this)->getConstantTarget();
1273 SourceLocation getLocStart() const LLVM_READONLY { return GotoLoc; }
1274 SourceLocation getLocEnd() const LLVM_READONLY { return Target->getLocEnd(); }
1276 static bool classof(const Stmt *T) {
1277 return T->getStmtClass() == IndirectGotoStmtClass;
1281 child_range children() { return child_range(&Target, &Target+1); }
1285 /// ContinueStmt - This represents a continue.
1287 class ContinueStmt : public Stmt {
1288 SourceLocation ContinueLoc;
1290 ContinueStmt(SourceLocation CL) : Stmt(ContinueStmtClass), ContinueLoc(CL) {}
1292 /// \brief Build an empty continue statement.
1293 explicit ContinueStmt(EmptyShell Empty) : Stmt(ContinueStmtClass, Empty) { }
1295 SourceLocation getContinueLoc() const { return ContinueLoc; }
1296 void setContinueLoc(SourceLocation L) { ContinueLoc = L; }
1298 SourceLocation getLocStart() const LLVM_READONLY { return ContinueLoc; }
1299 SourceLocation getLocEnd() const LLVM_READONLY { return ContinueLoc; }
1301 static bool classof(const Stmt *T) {
1302 return T->getStmtClass() == ContinueStmtClass;
1306 child_range children() { return child_range(); }
1309 /// BreakStmt - This represents a break.
1311 class BreakStmt : public Stmt {
1312 SourceLocation BreakLoc;
1314 BreakStmt(SourceLocation BL) : Stmt(BreakStmtClass), BreakLoc(BL) {}
1316 /// \brief Build an empty break statement.
1317 explicit BreakStmt(EmptyShell Empty) : Stmt(BreakStmtClass, Empty) { }
1319 SourceLocation getBreakLoc() const { return BreakLoc; }
1320 void setBreakLoc(SourceLocation L) { BreakLoc = L; }
1322 SourceLocation getLocStart() const LLVM_READONLY { return BreakLoc; }
1323 SourceLocation getLocEnd() const LLVM_READONLY { return BreakLoc; }
1325 static bool classof(const Stmt *T) {
1326 return T->getStmtClass() == BreakStmtClass;
1330 child_range children() { return child_range(); }
1334 /// ReturnStmt - This represents a return, optionally of an expression:
1338 /// Note that GCC allows return with no argument in a function declared to
1339 /// return a value, and it allows returning a value in functions declared to
1340 /// return void. We explicitly model this in the AST, which means you can't
1341 /// depend on the return type of the function and the presence of an argument.
1343 class ReturnStmt : public Stmt {
1345 SourceLocation RetLoc;
1346 const VarDecl *NRVOCandidate;
1349 ReturnStmt(SourceLocation RL)
1350 : Stmt(ReturnStmtClass), RetExpr(nullptr), RetLoc(RL),
1351 NRVOCandidate(nullptr) {}
1353 ReturnStmt(SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
1354 : Stmt(ReturnStmtClass), RetExpr((Stmt*) E), RetLoc(RL),
1355 NRVOCandidate(NRVOCandidate) {}
1357 /// \brief Build an empty return expression.
1358 explicit ReturnStmt(EmptyShell Empty) : Stmt(ReturnStmtClass, Empty) { }
1360 const Expr *getRetValue() const;
1361 Expr *getRetValue();
1362 void setRetValue(Expr *E) { RetExpr = reinterpret_cast<Stmt*>(E); }
1364 SourceLocation getReturnLoc() const { return RetLoc; }
1365 void setReturnLoc(SourceLocation L) { RetLoc = L; }
1367 /// \brief Retrieve the variable that might be used for the named return
1368 /// value optimization.
1370 /// The optimization itself can only be performed if the variable is
1371 /// also marked as an NRVO object.
1372 const VarDecl *getNRVOCandidate() const { return NRVOCandidate; }
1373 void setNRVOCandidate(const VarDecl *Var) { NRVOCandidate = Var; }
1375 SourceLocation getLocStart() const LLVM_READONLY { return RetLoc; }
1376 SourceLocation getLocEnd() const LLVM_READONLY {
1377 return RetExpr ? RetExpr->getLocEnd() : RetLoc;
1380 static bool classof(const Stmt *T) {
1381 return T->getStmtClass() == ReturnStmtClass;
1385 child_range children() {
1386 if (RetExpr) return child_range(&RetExpr, &RetExpr+1);
1387 return child_range();
1391 /// AsmStmt is the base class for GCCAsmStmt and MSAsmStmt.
1393 class AsmStmt : public Stmt {
1395 SourceLocation AsmLoc;
1396 /// \brief True if the assembly statement does not have any input or output
1400 /// \brief If true, treat this inline assembly as having side effects.
1401 /// This assembly statement should not be optimized, deleted or moved.
1404 unsigned NumOutputs;
1406 unsigned NumClobbers;
1410 AsmStmt(StmtClass SC, SourceLocation asmloc, bool issimple, bool isvolatile,
1411 unsigned numoutputs, unsigned numinputs, unsigned numclobbers) :
1412 Stmt (SC), AsmLoc(asmloc), IsSimple(issimple), IsVolatile(isvolatile),
1413 NumOutputs(numoutputs), NumInputs(numinputs), NumClobbers(numclobbers) { }
1415 friend class ASTStmtReader;
1418 /// \brief Build an empty inline-assembly statement.
1419 explicit AsmStmt(StmtClass SC, EmptyShell Empty) :
1420 Stmt(SC, Empty), Exprs(nullptr) { }
1422 SourceLocation getAsmLoc() const { return AsmLoc; }
1423 void setAsmLoc(SourceLocation L) { AsmLoc = L; }
1425 bool isSimple() const { return IsSimple; }
1426 void setSimple(bool V) { IsSimple = V; }
1428 bool isVolatile() const { return IsVolatile; }
1429 void setVolatile(bool V) { IsVolatile = V; }
1431 SourceLocation getLocStart() const LLVM_READONLY { return SourceLocation(); }
1432 SourceLocation getLocEnd() const LLVM_READONLY { return SourceLocation(); }
1434 //===--- Asm String Analysis ---===//
1436 /// Assemble final IR asm string.
1437 std::string generateAsmString(const ASTContext &C) const;
1439 //===--- Output operands ---===//
1441 unsigned getNumOutputs() const { return NumOutputs; }
1443 /// getOutputConstraint - Return the constraint string for the specified
1444 /// output operand. All output constraints are known to be non-empty (either
1446 StringRef getOutputConstraint(unsigned i) const;
1448 /// isOutputPlusConstraint - Return true if the specified output constraint
1449 /// is a "+" constraint (which is both an input and an output) or false if it
1450 /// is an "=" constraint (just an output).
1451 bool isOutputPlusConstraint(unsigned i) const {
1452 return getOutputConstraint(i)[0] == '+';
1455 const Expr *getOutputExpr(unsigned i) const;
1457 /// getNumPlusOperands - Return the number of output operands that have a "+"
1459 unsigned getNumPlusOperands() const;
1461 //===--- Input operands ---===//
1463 unsigned getNumInputs() const { return NumInputs; }
1465 /// getInputConstraint - Return the specified input constraint. Unlike output
1466 /// constraints, these can be empty.
1467 StringRef getInputConstraint(unsigned i) const;
1469 const Expr *getInputExpr(unsigned i) const;
1471 //===--- Other ---===//
1473 unsigned getNumClobbers() const { return NumClobbers; }
1474 StringRef getClobber(unsigned i) const;
1476 static bool classof(const Stmt *T) {
1477 return T->getStmtClass() == GCCAsmStmtClass ||
1478 T->getStmtClass() == MSAsmStmtClass;
1481 // Input expr iterators.
1483 typedef ExprIterator inputs_iterator;
1484 typedef ConstExprIterator const_inputs_iterator;
1485 typedef llvm::iterator_range<inputs_iterator> inputs_range;
1486 typedef llvm::iterator_range<const_inputs_iterator> inputs_const_range;
1488 inputs_iterator begin_inputs() {
1489 return &Exprs[0] + NumOutputs;
1492 inputs_iterator end_inputs() {
1493 return &Exprs[0] + NumOutputs + NumInputs;
1496 inputs_range inputs() { return inputs_range(begin_inputs(), end_inputs()); }
1498 const_inputs_iterator begin_inputs() const {
1499 return &Exprs[0] + NumOutputs;
1502 const_inputs_iterator end_inputs() const {
1503 return &Exprs[0] + NumOutputs + NumInputs;
1506 inputs_const_range inputs() const {
1507 return inputs_const_range(begin_inputs(), end_inputs());
1510 // Output expr iterators.
1512 typedef ExprIterator outputs_iterator;
1513 typedef ConstExprIterator const_outputs_iterator;
1514 typedef llvm::iterator_range<outputs_iterator> outputs_range;
1515 typedef llvm::iterator_range<const_outputs_iterator> outputs_const_range;
1517 outputs_iterator begin_outputs() {
1520 outputs_iterator end_outputs() {
1521 return &Exprs[0] + NumOutputs;
1523 outputs_range outputs() {
1524 return outputs_range(begin_outputs(), end_outputs());
1527 const_outputs_iterator begin_outputs() const {
1530 const_outputs_iterator end_outputs() const {
1531 return &Exprs[0] + NumOutputs;
1533 outputs_const_range outputs() const {
1534 return outputs_const_range(begin_outputs(), end_outputs());
1537 child_range children() {
1538 return child_range(&Exprs[0], &Exprs[0] + NumOutputs + NumInputs);
1542 /// This represents a GCC inline-assembly statement extension.
1544 class GCCAsmStmt : public AsmStmt {
1545 SourceLocation RParenLoc;
1546 StringLiteral *AsmStr;
1548 // FIXME: If we wanted to, we could allocate all of these in one big array.
1549 StringLiteral **Constraints;
1550 StringLiteral **Clobbers;
1551 IdentifierInfo **Names;
1553 friend class ASTStmtReader;
1556 GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, bool issimple,
1557 bool isvolatile, unsigned numoutputs, unsigned numinputs,
1558 IdentifierInfo **names, StringLiteral **constraints, Expr **exprs,
1559 StringLiteral *asmstr, unsigned numclobbers,
1560 StringLiteral **clobbers, SourceLocation rparenloc);
1562 /// \brief Build an empty inline-assembly statement.
1563 explicit GCCAsmStmt(EmptyShell Empty) : AsmStmt(GCCAsmStmtClass, Empty),
1564 Constraints(nullptr), Clobbers(nullptr), Names(nullptr) { }
1566 SourceLocation getRParenLoc() const { return RParenLoc; }
1567 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
1569 //===--- Asm String Analysis ---===//
1571 const StringLiteral *getAsmString() const { return AsmStr; }
1572 StringLiteral *getAsmString() { return AsmStr; }
1573 void setAsmString(StringLiteral *E) { AsmStr = E; }
1575 /// AsmStringPiece - this is part of a decomposed asm string specification
1576 /// (for use with the AnalyzeAsmString function below). An asm string is
1577 /// considered to be a concatenation of these parts.
1578 class AsmStringPiece {
1581 String, // String in .ll asm string form, "$" -> "$$" and "%%" -> "%".
1582 Operand // Operand reference, with optional modifier %c4.
1589 // Source range for operand references.
1590 CharSourceRange Range;
1592 AsmStringPiece(const std::string &S) : MyKind(String), Str(S) {}
1593 AsmStringPiece(unsigned OpNo, const std::string &S, SourceLocation Begin,
1595 : MyKind(Operand), Str(S), OperandNo(OpNo),
1596 Range(CharSourceRange::getCharRange(Begin, End)) {
1599 bool isString() const { return MyKind == String; }
1600 bool isOperand() const { return MyKind == Operand; }
1602 const std::string &getString() const {
1606 unsigned getOperandNo() const {
1607 assert(isOperand());
1611 CharSourceRange getRange() const {
1612 assert(isOperand() && "Range is currently used only for Operands.");
1616 /// getModifier - Get the modifier for this operand, if present. This
1617 /// returns '\0' if there was no modifier.
1618 char getModifier() const;
1621 /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing
1622 /// it into pieces. If the asm string is erroneous, emit errors and return
1623 /// true, otherwise return false. This handles canonicalization and
1624 /// translation of strings from GCC syntax to LLVM IR syntax, and handles
1625 //// flattening of named references like %[foo] to Operand AsmStringPiece's.
1626 unsigned AnalyzeAsmString(SmallVectorImpl<AsmStringPiece> &Pieces,
1627 const ASTContext &C, unsigned &DiagOffs) const;
1629 /// Assemble final IR asm string.
1630 std::string generateAsmString(const ASTContext &C) const;
1632 //===--- Output operands ---===//
1634 IdentifierInfo *getOutputIdentifier(unsigned i) const {
1638 StringRef getOutputName(unsigned i) const {
1639 if (IdentifierInfo *II = getOutputIdentifier(i))
1640 return II->getName();
1645 StringRef getOutputConstraint(unsigned i) const;
1647 const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
1648 return Constraints[i];
1650 StringLiteral *getOutputConstraintLiteral(unsigned i) {
1651 return Constraints[i];
1654 Expr *getOutputExpr(unsigned i);
1656 const Expr *getOutputExpr(unsigned i) const {
1657 return const_cast<GCCAsmStmt*>(this)->getOutputExpr(i);
1660 //===--- Input operands ---===//
1662 IdentifierInfo *getInputIdentifier(unsigned i) const {
1663 return Names[i + NumOutputs];
1666 StringRef getInputName(unsigned i) const {
1667 if (IdentifierInfo *II = getInputIdentifier(i))
1668 return II->getName();
1673 StringRef getInputConstraint(unsigned i) const;
1675 const StringLiteral *getInputConstraintLiteral(unsigned i) const {
1676 return Constraints[i + NumOutputs];
1678 StringLiteral *getInputConstraintLiteral(unsigned i) {
1679 return Constraints[i + NumOutputs];
1682 Expr *getInputExpr(unsigned i);
1683 void setInputExpr(unsigned i, Expr *E);
1685 const Expr *getInputExpr(unsigned i) const {
1686 return const_cast<GCCAsmStmt*>(this)->getInputExpr(i);
1690 void setOutputsAndInputsAndClobbers(const ASTContext &C,
1691 IdentifierInfo **Names,
1692 StringLiteral **Constraints,
1694 unsigned NumOutputs,
1696 StringLiteral **Clobbers,
1697 unsigned NumClobbers);
1700 //===--- Other ---===//
1702 /// getNamedOperand - Given a symbolic operand reference like %[foo],
1703 /// translate this into a numeric value needed to reference the same operand.
1704 /// This returns -1 if the operand name is invalid.
1705 int getNamedOperand(StringRef SymbolicName) const;
1707 StringRef getClobber(unsigned i) const;
1708 StringLiteral *getClobberStringLiteral(unsigned i) { return Clobbers[i]; }
1709 const StringLiteral *getClobberStringLiteral(unsigned i) const {
1713 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1714 SourceLocation getLocEnd() const LLVM_READONLY { return RParenLoc; }
1716 static bool classof(const Stmt *T) {
1717 return T->getStmtClass() == GCCAsmStmtClass;
1721 /// This represents a Microsoft inline-assembly statement extension.
1723 class MSAsmStmt : public AsmStmt {
1724 SourceLocation LBraceLoc, EndLoc;
1727 unsigned NumAsmToks;
1730 StringRef *Constraints;
1731 StringRef *Clobbers;
1733 friend class ASTStmtReader;
1736 MSAsmStmt(const ASTContext &C, SourceLocation asmloc,
1737 SourceLocation lbraceloc, bool issimple, bool isvolatile,
1738 ArrayRef<Token> asmtoks, unsigned numoutputs, unsigned numinputs,
1739 ArrayRef<StringRef> constraints,
1740 ArrayRef<Expr*> exprs, StringRef asmstr,
1741 ArrayRef<StringRef> clobbers, SourceLocation endloc);
1743 /// \brief Build an empty MS-style inline-assembly statement.
1744 explicit MSAsmStmt(EmptyShell Empty) : AsmStmt(MSAsmStmtClass, Empty),
1745 NumAsmToks(0), AsmToks(nullptr), Constraints(nullptr), Clobbers(nullptr) { }
1747 SourceLocation getLBraceLoc() const { return LBraceLoc; }
1748 void setLBraceLoc(SourceLocation L) { LBraceLoc = L; }
1749 SourceLocation getEndLoc() const { return EndLoc; }
1750 void setEndLoc(SourceLocation L) { EndLoc = L; }
1752 bool hasBraces() const { return LBraceLoc.isValid(); }
1754 unsigned getNumAsmToks() { return NumAsmToks; }
1755 Token *getAsmToks() { return AsmToks; }
1757 //===--- Asm String Analysis ---===//
1758 StringRef getAsmString() const { return AsmStr; }
1760 /// Assemble final IR asm string.
1761 std::string generateAsmString(const ASTContext &C) const;
1763 //===--- Output operands ---===//
1765 StringRef getOutputConstraint(unsigned i) const {
1766 assert(i < NumOutputs);
1767 return Constraints[i];
1770 Expr *getOutputExpr(unsigned i);
1772 const Expr *getOutputExpr(unsigned i) const {
1773 return const_cast<MSAsmStmt*>(this)->getOutputExpr(i);
1776 //===--- Input operands ---===//
1778 StringRef getInputConstraint(unsigned i) const {
1779 assert(i < NumInputs);
1780 return Constraints[i + NumOutputs];
1783 Expr *getInputExpr(unsigned i);
1784 void setInputExpr(unsigned i, Expr *E);
1786 const Expr *getInputExpr(unsigned i) const {
1787 return const_cast<MSAsmStmt*>(this)->getInputExpr(i);
1790 //===--- Other ---===//
1792 ArrayRef<StringRef> getAllConstraints() const {
1793 return llvm::makeArrayRef(Constraints, NumInputs + NumOutputs);
1795 ArrayRef<StringRef> getClobbers() const {
1796 return llvm::makeArrayRef(Clobbers, NumClobbers);
1798 ArrayRef<Expr*> getAllExprs() const {
1799 return llvm::makeArrayRef(reinterpret_cast<Expr**>(Exprs),
1800 NumInputs + NumOutputs);
1803 StringRef getClobber(unsigned i) const { return getClobbers()[i]; }
1806 void initialize(const ASTContext &C, StringRef AsmString,
1807 ArrayRef<Token> AsmToks, ArrayRef<StringRef> Constraints,
1808 ArrayRef<Expr*> Exprs, ArrayRef<StringRef> Clobbers);
1811 SourceLocation getLocStart() const LLVM_READONLY { return AsmLoc; }
1812 SourceLocation getLocEnd() const LLVM_READONLY { return EndLoc; }
1814 static bool classof(const Stmt *T) {
1815 return T->getStmtClass() == MSAsmStmtClass;
1818 child_range children() {
1819 return child_range(&Exprs[0], &Exprs[NumInputs + NumOutputs]);
1823 class SEHExceptStmt : public Stmt {
1827 enum { FILTER_EXPR, BLOCK };
1829 SEHExceptStmt(SourceLocation Loc,
1833 friend class ASTReader;
1834 friend class ASTStmtReader;
1835 explicit SEHExceptStmt(EmptyShell E) : Stmt(SEHExceptStmtClass, E) { }
1838 static SEHExceptStmt* Create(const ASTContext &C,
1839 SourceLocation ExceptLoc,
1843 SourceLocation getLocStart() const LLVM_READONLY { return getExceptLoc(); }
1844 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1846 SourceLocation getExceptLoc() const { return Loc; }
1847 SourceLocation getEndLoc() const { return getBlock()->getLocEnd(); }
1849 Expr *getFilterExpr() const {
1850 return reinterpret_cast<Expr*>(Children[FILTER_EXPR]);
1853 CompoundStmt *getBlock() const {
1854 return cast<CompoundStmt>(Children[BLOCK]);
1857 child_range children() {
1858 return child_range(Children,Children+2);
1861 static bool classof(const Stmt *T) {
1862 return T->getStmtClass() == SEHExceptStmtClass;
1867 class SEHFinallyStmt : public Stmt {
1871 SEHFinallyStmt(SourceLocation Loc,
1874 friend class ASTReader;
1875 friend class ASTStmtReader;
1876 explicit SEHFinallyStmt(EmptyShell E) : Stmt(SEHFinallyStmtClass, E) { }
1879 static SEHFinallyStmt* Create(const ASTContext &C,
1880 SourceLocation FinallyLoc,
1883 SourceLocation getLocStart() const LLVM_READONLY { return getFinallyLoc(); }
1884 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1886 SourceLocation getFinallyLoc() const { return Loc; }
1887 SourceLocation getEndLoc() const { return Block->getLocEnd(); }
1889 CompoundStmt *getBlock() const { return cast<CompoundStmt>(Block); }
1891 child_range children() {
1892 return child_range(&Block,&Block+1);
1895 static bool classof(const Stmt *T) {
1896 return T->getStmtClass() == SEHFinallyStmtClass;
1901 class SEHTryStmt : public Stmt {
1903 SourceLocation TryLoc;
1906 enum { TRY = 0, HANDLER = 1 };
1908 SEHTryStmt(bool isCXXTry, // true if 'try' otherwise '__try'
1909 SourceLocation TryLoc,
1913 friend class ASTReader;
1914 friend class ASTStmtReader;
1915 explicit SEHTryStmt(EmptyShell E) : Stmt(SEHTryStmtClass, E) { }
1918 static SEHTryStmt* Create(const ASTContext &C, bool isCXXTry,
1919 SourceLocation TryLoc, Stmt *TryBlock,
1922 SourceLocation getLocStart() const LLVM_READONLY { return getTryLoc(); }
1923 SourceLocation getLocEnd() const LLVM_READONLY { return getEndLoc(); }
1925 SourceLocation getTryLoc() const { return TryLoc; }
1926 SourceLocation getEndLoc() const { return Children[HANDLER]->getLocEnd(); }
1928 bool getIsCXXTry() const { return IsCXXTry; }
1930 CompoundStmt* getTryBlock() const {
1931 return cast<CompoundStmt>(Children[TRY]);
1934 Stmt *getHandler() const { return Children[HANDLER]; }
1936 /// Returns 0 if not defined
1937 SEHExceptStmt *getExceptHandler() const;
1938 SEHFinallyStmt *getFinallyHandler() const;
1940 child_range children() {
1941 return child_range(Children,Children+2);
1944 static bool classof(const Stmt *T) {
1945 return T->getStmtClass() == SEHTryStmtClass;
1949 /// Represents a __leave statement.
1951 class SEHLeaveStmt : public Stmt {
1952 SourceLocation LeaveLoc;
1954 explicit SEHLeaveStmt(SourceLocation LL)
1955 : Stmt(SEHLeaveStmtClass), LeaveLoc(LL) {}
1957 /// \brief Build an empty __leave statement.
1958 explicit SEHLeaveStmt(EmptyShell Empty) : Stmt(SEHLeaveStmtClass, Empty) { }
1960 SourceLocation getLeaveLoc() const { return LeaveLoc; }
1961 void setLeaveLoc(SourceLocation L) { LeaveLoc = L; }
1963 SourceLocation getLocStart() const LLVM_READONLY { return LeaveLoc; }
1964 SourceLocation getLocEnd() const LLVM_READONLY { return LeaveLoc; }
1966 static bool classof(const Stmt *T) {
1967 return T->getStmtClass() == SEHLeaveStmtClass;
1971 child_range children() { return child_range(); }
1974 /// \brief This captures a statement into a function. For example, the following
1975 /// pragma annotated compound statement can be represented as a CapturedStmt,
1976 /// and this compound statement is the body of an anonymous outlined function.
1978 /// #pragma omp parallel
1983 class CapturedStmt : public Stmt {
1985 /// \brief The different capture forms: by 'this', by reference, capture for
1986 /// variable-length array type etc.
1987 enum VariableCaptureKind {
1993 /// \brief Describes the capture of either a variable, or 'this', or
1994 /// variable-length array type.
1996 llvm::PointerIntPair<VarDecl *, 2, VariableCaptureKind> VarAndKind;
2000 /// \brief Create a new capture.
2002 /// \param Loc The source location associated with this capture.
2004 /// \param Kind The kind of capture (this, ByRef, ...).
2006 /// \param Var The variable being captured, or null if capturing this.
2008 Capture(SourceLocation Loc, VariableCaptureKind Kind,
2009 VarDecl *Var = nullptr)
2010 : VarAndKind(Var, Kind), Loc(Loc) {
2013 assert(!Var && "'this' capture cannot have a variable!");
2016 assert(Var && "capturing by reference must have a variable!");
2020 "Variable-length array type capture cannot have a variable!");
2025 /// \brief Determine the kind of capture.
2026 VariableCaptureKind getCaptureKind() const { return VarAndKind.getInt(); }
2028 /// \brief Retrieve the source location at which the variable or 'this' was
2030 SourceLocation getLocation() const { return Loc; }
2032 /// \brief Determine whether this capture handles the C++ 'this' pointer.
2033 bool capturesThis() const { return getCaptureKind() == VCK_This; }
2035 /// \brief Determine whether this capture handles a variable.
2036 bool capturesVariable() const { return getCaptureKind() == VCK_ByRef; }
2038 /// \brief Determine whether this capture handles a variable-length array
2040 bool capturesVariableArrayType() const {
2041 return getCaptureKind() == VCK_VLAType;
2044 /// \brief Retrieve the declaration of the variable being captured.
2046 /// This operation is only valid if this capture captures a variable.
2047 VarDecl *getCapturedVar() const {
2048 assert(capturesVariable() &&
2049 "No variable available for 'this' or VAT capture");
2050 return VarAndKind.getPointer();
2052 friend class ASTStmtReader;
2056 /// \brief The number of variable captured, including 'this'.
2057 unsigned NumCaptures;
2059 /// \brief The pointer part is the implicit the outlined function and the
2060 /// int part is the captured region kind, 'CR_Default' etc.
2061 llvm::PointerIntPair<CapturedDecl *, 1, CapturedRegionKind> CapDeclAndKind;
2063 /// \brief The record for captured variables, a RecordDecl or CXXRecordDecl.
2064 RecordDecl *TheRecordDecl;
2066 /// \brief Construct a captured statement.
2067 CapturedStmt(Stmt *S, CapturedRegionKind Kind, ArrayRef<Capture> Captures,
2068 ArrayRef<Expr *> CaptureInits, CapturedDecl *CD, RecordDecl *RD);
2070 /// \brief Construct an empty captured statement.
2071 CapturedStmt(EmptyShell Empty, unsigned NumCaptures);
2073 Stmt **getStoredStmts() const {
2074 return reinterpret_cast<Stmt **>(const_cast<CapturedStmt *>(this) + 1);
2077 Capture *getStoredCaptures() const;
2079 void setCapturedStmt(Stmt *S) { getStoredStmts()[NumCaptures] = S; }
2082 static CapturedStmt *Create(const ASTContext &Context, Stmt *S,
2083 CapturedRegionKind Kind,
2084 ArrayRef<Capture> Captures,
2085 ArrayRef<Expr *> CaptureInits,
2086 CapturedDecl *CD, RecordDecl *RD);
2088 static CapturedStmt *CreateDeserialized(const ASTContext &Context,
2089 unsigned NumCaptures);
2091 /// \brief Retrieve the statement being captured.
2092 Stmt *getCapturedStmt() { return getStoredStmts()[NumCaptures]; }
2093 const Stmt *getCapturedStmt() const {
2094 return const_cast<CapturedStmt *>(this)->getCapturedStmt();
2097 /// \brief Retrieve the outlined function declaration.
2098 CapturedDecl *getCapturedDecl() { return CapDeclAndKind.getPointer(); }
2099 const CapturedDecl *getCapturedDecl() const {
2100 return const_cast<CapturedStmt *>(this)->getCapturedDecl();
2103 /// \brief Set the outlined function declaration.
2104 void setCapturedDecl(CapturedDecl *D) {
2105 assert(D && "null CapturedDecl");
2106 CapDeclAndKind.setPointer(D);
2109 /// \brief Retrieve the captured region kind.
2110 CapturedRegionKind getCapturedRegionKind() const {
2111 return CapDeclAndKind.getInt();
2114 /// \brief Set the captured region kind.
2115 void setCapturedRegionKind(CapturedRegionKind Kind) {
2116 CapDeclAndKind.setInt(Kind);
2119 /// \brief Retrieve the record declaration for captured variables.
2120 const RecordDecl *getCapturedRecordDecl() const { return TheRecordDecl; }
2122 /// \brief Set the record declaration for captured variables.
2123 void setCapturedRecordDecl(RecordDecl *D) {
2124 assert(D && "null RecordDecl");
2128 /// \brief True if this variable has been captured.
2129 bool capturesVariable(const VarDecl *Var) const;
2131 /// \brief An iterator that walks over the captures.
2132 typedef Capture *capture_iterator;
2133 typedef const Capture *const_capture_iterator;
2134 typedef llvm::iterator_range<capture_iterator> capture_range;
2135 typedef llvm::iterator_range<const_capture_iterator> capture_const_range;
2137 capture_range captures() {
2138 return capture_range(capture_begin(), capture_end());
2140 capture_const_range captures() const {
2141 return capture_const_range(capture_begin(), capture_end());
2144 /// \brief Retrieve an iterator pointing to the first capture.
2145 capture_iterator capture_begin() { return getStoredCaptures(); }
2146 const_capture_iterator capture_begin() const { return getStoredCaptures(); }
2148 /// \brief Retrieve an iterator pointing past the end of the sequence of
2150 capture_iterator capture_end() const {
2151 return getStoredCaptures() + NumCaptures;
2154 /// \brief Retrieve the number of captures, including 'this'.
2155 unsigned capture_size() const { return NumCaptures; }
2157 /// \brief Iterator that walks over the capture initialization arguments.
2158 typedef Expr **capture_init_iterator;
2159 typedef llvm::iterator_range<capture_init_iterator> capture_init_range;
2161 capture_init_range capture_inits() const {
2162 return capture_init_range(capture_init_begin(), capture_init_end());
2165 /// \brief Retrieve the first initialization argument.
2166 capture_init_iterator capture_init_begin() const {
2167 return reinterpret_cast<Expr **>(getStoredStmts());
2170 /// \brief Retrieve the iterator pointing one past the last initialization
2172 capture_init_iterator capture_init_end() const {
2173 return capture_init_begin() + NumCaptures;
2176 SourceLocation getLocStart() const LLVM_READONLY {
2177 return getCapturedStmt()->getLocStart();
2179 SourceLocation getLocEnd() const LLVM_READONLY {
2180 return getCapturedStmt()->getLocEnd();
2182 SourceRange getSourceRange() const LLVM_READONLY {
2183 return getCapturedStmt()->getSourceRange();
2186 static bool classof(const Stmt *T) {
2187 return T->getStmtClass() == CapturedStmtClass;
2190 child_range children();
2192 friend class ASTStmtReader;
2195 } // end namespace clang