clang 24.0.0git
StmtCXX.h
Go to the documentation of this file.
1//===--- StmtCXX.h - Classes for representing C++ statements ----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the C++ statement AST node classes.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_AST_STMTCXX_H
14#define LLVM_CLANG_AST_STMTCXX_H
15
17#include "clang/AST/Expr.h"
19#include "clang/AST/Stmt.h"
20#include "llvm/Support/Compiler.h"
21
22namespace clang {
23
24class VarDecl;
26
27/// CXXCatchStmt - This represents a C++ catch block.
28///
29class CXXCatchStmt : public Stmt {
30 SourceLocation CatchLoc;
31 /// The exception-declaration of the type.
32 VarDecl *ExceptionDecl;
33 /// The handler block.
34 Stmt *HandlerBlock;
35
36public:
37 CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock)
38 : Stmt(CXXCatchStmtClass), CatchLoc(catchLoc), ExceptionDecl(exDecl),
39 HandlerBlock(handlerBlock) {}
40
42 : Stmt(CXXCatchStmtClass), ExceptionDecl(nullptr), HandlerBlock(nullptr) {}
43
44 SourceLocation getBeginLoc() const LLVM_READONLY { return CatchLoc; }
45 SourceLocation getEndLoc() const LLVM_READONLY {
46 return HandlerBlock->getEndLoc();
47 }
48
49 SourceLocation getCatchLoc() const { return CatchLoc; }
50 VarDecl *getExceptionDecl() const { return ExceptionDecl; }
51 QualType getCaughtType() const;
52 Stmt *getHandlerBlock() const { return HandlerBlock; }
53
54 static bool classof(const Stmt *T) {
55 return T->getStmtClass() == CXXCatchStmtClass;
56 }
57
58 child_range children() { return child_range(&HandlerBlock, &HandlerBlock+1); }
59
61 return const_child_range(&HandlerBlock, &HandlerBlock + 1);
62 }
63
64 friend class ASTStmtReader;
65};
66
67/// CXXTryStmt - A C++ try block, including all handlers.
68///
69class CXXTryStmt final : public Stmt,
70 private llvm::TrailingObjects<CXXTryStmt, Stmt *> {
71
72 friend TrailingObjects;
73 friend class ASTStmtReader;
74
75 SourceLocation TryLoc;
76 unsigned NumHandlers;
77 size_t numTrailingObjects(OverloadToken<Stmt *>) const { return NumHandlers; }
78
79 CXXTryStmt(SourceLocation tryLoc, CompoundStmt *tryBlock,
80 ArrayRef<Stmt *> handlers);
81 CXXTryStmt(EmptyShell Empty, unsigned numHandlers)
82 : Stmt(CXXTryStmtClass), NumHandlers(numHandlers) { }
83
84 Stmt *const *getStmts() const { return getTrailingObjects(); }
85 Stmt **getStmts() { return getTrailingObjects(); }
86
87public:
88 static CXXTryStmt *Create(const ASTContext &C, SourceLocation tryLoc,
89 CompoundStmt *tryBlock, ArrayRef<Stmt *> handlers);
90
91 static CXXTryStmt *Create(const ASTContext &C, EmptyShell Empty,
92 unsigned numHandlers);
93
94 SourceLocation getBeginLoc() const LLVM_READONLY { return getTryLoc(); }
95
96 SourceLocation getTryLoc() const { return TryLoc; }
98 return getStmts()[NumHandlers]->getEndLoc();
99 }
100
102 return cast<CompoundStmt>(getStmts()[0]);
103 }
104 const CompoundStmt *getTryBlock() const {
105 return cast<CompoundStmt>(getStmts()[0]);
106 }
107
108 unsigned getNumHandlers() const { return NumHandlers; }
110 return cast<CXXCatchStmt>(getStmts()[i + 1]);
111 }
112 const CXXCatchStmt *getHandler(unsigned i) const {
113 return cast<CXXCatchStmt>(getStmts()[i + 1]);
114 }
115
116 static bool classof(const Stmt *T) {
117 return T->getStmtClass() == CXXTryStmtClass;
118 }
119
121 return child_range(getStmts(), getStmts() + getNumHandlers() + 1);
122 }
123
125 return const_child_range(getStmts(), getStmts() + getNumHandlers() + 1);
126 }
127};
128
129/// CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for
130/// statement, represented as 'for (range-declarator : range-expression)'
131/// or 'for (init-statement range-declarator : range-expression)'.
132///
133/// This is stored in a partially-desugared form to allow full semantic
134/// analysis of the constituent components. The original syntactic components
135/// can be extracted using getLoopVariable and getRangeInit.
136class CXXForRangeStmt : public Stmt {
137 enum { INIT, RANGE, BEGINSTMT, ENDSTMT, COND, INC, LOOPVAR, BODY, END };
138 // SubExprs[RANGE] is an expression or declstmt.
139 // SubExprs[COND] and SubExprs[INC] are expressions.
140 Stmt *SubExprs[END];
141 SourceLocation ForLoc;
142 SourceLocation CoawaitLoc;
143 SourceLocation ColonLoc;
144 SourceLocation RParenLoc;
145
146 friend class ASTStmtReader;
147public:
148 CXXForRangeStmt(Stmt *InitStmt, DeclStmt *Range, DeclStmt *Begin,
149 DeclStmt *End, Expr *Cond, Expr *Inc, DeclStmt *LoopVar,
150 Stmt *Body, SourceLocation FL, SourceLocation CAL,
152 CXXForRangeStmt(EmptyShell Empty) : Stmt(CXXForRangeStmtClass, Empty) { }
153
154 Stmt *getInit() { return SubExprs[INIT]; }
157
158 const Stmt *getInit() const { return SubExprs[INIT]; }
159 const VarDecl *getLoopVariable() const;
160 const Expr *getRangeInit() const;
161
162
163 DeclStmt *getRangeStmt() { return cast<DeclStmt>(SubExprs[RANGE]); }
165 return cast_or_null<DeclStmt>(SubExprs[BEGINSTMT]);
166 }
167 DeclStmt *getEndStmt() { return cast_or_null<DeclStmt>(SubExprs[ENDSTMT]); }
168 Expr *getCond() { return cast_or_null<Expr>(SubExprs[COND]); }
169 Expr *getInc() { return cast_or_null<Expr>(SubExprs[INC]); }
170 DeclStmt *getLoopVarStmt() { return cast<DeclStmt>(SubExprs[LOOPVAR]); }
171 Stmt *getBody() { return SubExprs[BODY]; }
172
173 const DeclStmt *getRangeStmt() const {
174 return cast<DeclStmt>(SubExprs[RANGE]);
175 }
176 const DeclStmt *getBeginStmt() const {
177 return cast_or_null<DeclStmt>(SubExprs[BEGINSTMT]);
178 }
179 const DeclStmt *getEndStmt() const {
180 return cast_or_null<DeclStmt>(SubExprs[ENDSTMT]);
181 }
182 const Expr *getCond() const {
183 return cast_or_null<Expr>(SubExprs[COND]);
184 }
185 const Expr *getInc() const {
186 return cast_or_null<Expr>(SubExprs[INC]);
187 }
188 const DeclStmt *getLoopVarStmt() const {
189 return cast<DeclStmt>(SubExprs[LOOPVAR]);
190 }
191 const Stmt *getBody() const { return SubExprs[BODY]; }
192
193 void setInit(Stmt *S) { SubExprs[INIT] = S; }
194 void setRangeInit(Expr *E) { SubExprs[RANGE] = reinterpret_cast<Stmt*>(E); }
195 void setRangeStmt(Stmt *S) { SubExprs[RANGE] = S; }
196 void setBeginStmt(Stmt *S) { SubExprs[BEGINSTMT] = S; }
197 void setEndStmt(Stmt *S) { SubExprs[ENDSTMT] = S; }
198 void setCond(Expr *E) { SubExprs[COND] = reinterpret_cast<Stmt*>(E); }
199 void setInc(Expr *E) { SubExprs[INC] = reinterpret_cast<Stmt*>(E); }
200 void setLoopVarStmt(Stmt *S) { SubExprs[LOOPVAR] = S; }
201 void setBody(Stmt *S) { SubExprs[BODY] = S; }
202
203 SourceLocation getForLoc() const { return ForLoc; }
204 SourceLocation getCoawaitLoc() const { return CoawaitLoc; }
205 SourceLocation getColonLoc() const { return ColonLoc; }
206 SourceLocation getRParenLoc() const { return RParenLoc; }
207
208 SourceLocation getBeginLoc() const LLVM_READONLY { return ForLoc; }
209 SourceLocation getEndLoc() const LLVM_READONLY {
210 return SubExprs[BODY]->getEndLoc();
211 }
212
213 static bool classof(const Stmt *T) {
214 return T->getStmtClass() == CXXForRangeStmtClass;
215 }
216
217 // Iterators
219 return child_range(&SubExprs[0], &SubExprs[END]);
220 }
221
223 return const_child_range(&SubExprs[0], &SubExprs[END]);
224 }
225};
226
227/// Representation of a Microsoft __if_exists or __if_not_exists
228/// statement with a dependent name.
229///
230/// The __if_exists statement can be used to include a sequence of statements
231/// in the program only when a particular dependent name does not exist. For
232/// example:
233///
234/// \code
235/// template<typename T>
236/// void call_foo(T &t) {
237/// __if_exists (T::foo) {
238/// t.foo(); // okay: only called when T::foo exists.
239/// }
240/// }
241/// \endcode
242///
243/// Similarly, the __if_not_exists statement can be used to include the
244/// statements when a particular name does not exist.
245///
246/// Note that this statement only captures __if_exists and __if_not_exists
247/// statements whose name is dependent. All non-dependent cases are handled
248/// directly in the parser, so that they don't introduce a new scope. Clang
249/// introduces scopes in the dependent case to keep names inside the compound
250/// statement from leaking out into the surround statements, which would
251/// compromise the template instantiation model. This behavior differs from
252/// Visual C++ (which never introduces a scope), but is a fairly reasonable
253/// approximation of the VC++ behavior.
255 SourceLocation KeywordLoc;
256 bool IsIfExists;
257 NestedNameSpecifierLoc QualifierLoc;
258 DeclarationNameInfo NameInfo;
259 Stmt *SubStmt;
260
261 friend class ASTReader;
262 friend class ASTStmtReader;
263
264public:
265 MSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists,
266 NestedNameSpecifierLoc QualifierLoc,
267 DeclarationNameInfo NameInfo,
268 CompoundStmt *SubStmt)
269 : Stmt(MSDependentExistsStmtClass),
270 KeywordLoc(KeywordLoc), IsIfExists(IsIfExists),
271 QualifierLoc(QualifierLoc), NameInfo(NameInfo),
272 SubStmt(reinterpret_cast<Stmt *>(SubStmt)) { }
273
274 /// Retrieve the location of the __if_exists or __if_not_exists
275 /// keyword.
276 SourceLocation getKeywordLoc() const { return KeywordLoc; }
277
278 /// Determine whether this is an __if_exists statement.
279 bool isIfExists() const { return IsIfExists; }
280
281 /// Determine whether this is an __if_exists statement.
282 bool isIfNotExists() const { return !IsIfExists; }
283
284 /// Retrieve the nested-name-specifier that qualifies this name, if
285 /// any.
286 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
287
288 /// Retrieve the name of the entity we're testing for, along with
289 /// location information
290 DeclarationNameInfo getNameInfo() const { return NameInfo; }
291
292 /// Retrieve the compound statement that will be included in the
293 /// program only if the existence of the symbol matches the initial keyword.
295 return reinterpret_cast<CompoundStmt *>(SubStmt);
296 }
297
298 SourceLocation getBeginLoc() const LLVM_READONLY { return KeywordLoc; }
299 SourceLocation getEndLoc() const LLVM_READONLY {
300 return SubStmt->getEndLoc();
301 }
302
304 return child_range(&SubStmt, &SubStmt+1);
305 }
306
308 return const_child_range(&SubStmt, &SubStmt + 1);
309 }
310
311 static bool classof(const Stmt *T) {
312 return T->getStmtClass() == MSDependentExistsStmtClass;
313 }
314};
315
316/// Represents the body of a coroutine. This wraps the normal function
317/// body and holds the additional semantic context required to set up and tear
318/// down the coroutine frame.
319class CoroutineBodyStmt final
320 : public Stmt,
321 private llvm::TrailingObjects<CoroutineBodyStmt, Stmt *> {
322 enum SubStmt {
323 Body, ///< The body of the coroutine.
324 Promise, ///< The promise statement.
325 InitSuspend, ///< The initial suspend statement, run before the body.
326 FinalSuspend, ///< The final suspend statement, run after the body.
327 OnException, ///< Handler for exceptions thrown in the body.
328 OnFallthrough, ///< Handler for control flow falling off the body.
329 Allocate, ///< Coroutine frame memory allocation.
330 Deallocate, ///< Coroutine frame memory deallocation.
331 ResultDecl, ///< Declaration holding the result of get_return_object.
332 ReturnValue, ///< Return value for thunk function: p.get_return_object().
333 ReturnStmt, ///< Return statement for the thunk function.
334 ReturnStmtOnAllocFailure, ///< Return statement if allocation failed.
335 FirstParamMove ///< First offset for move construction of parameter copies.
336 };
337 unsigned NumParams;
338
339 friend class ASTStmtReader;
340 friend class ASTReader;
341 friend TrailingObjects;
342
343 Stmt **getStoredStmts() { return getTrailingObjects(); }
344
345 Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
346
347public:
348
349 struct CtorArgs {
350 Stmt *Body = nullptr;
351 Stmt *Promise = nullptr;
353 Expr *FinalSuspend = nullptr;
354 Stmt *OnException = nullptr;
355 Stmt *OnFallthrough = nullptr;
356 Expr *Allocate = nullptr;
357 Expr *Deallocate = nullptr;
358 Stmt *ResultDecl = nullptr;
359 Expr *ReturnValue = nullptr;
360 Stmt *ReturnStmt = nullptr;
363 };
364
365private:
366
367 CoroutineBodyStmt(CtorArgs const& Args);
368
369public:
370 static CoroutineBodyStmt *Create(const ASTContext &C, CtorArgs const &Args);
371 static CoroutineBodyStmt *Create(const ASTContext &C, EmptyShell,
372 unsigned NumParams);
373
376 }
377
378 /// Retrieve the body of the coroutine as written. This will be either
379 /// a CompoundStmt. If the coroutine is in function-try-block, we will
380 /// wrap the CXXTryStmt into a CompoundStmt to keep consistency.
382 return cast<CompoundStmt>(getStoredStmts()[SubStmt::Body]);
383 }
384
386 return getStoredStmts()[SubStmt::Promise];
387 }
389 return cast<VarDecl>(cast<DeclStmt>(getPromiseDeclStmt())->getSingleDecl());
390 }
391
393 return getStoredStmts()[SubStmt::InitSuspend];
394 }
396 return getStoredStmts()[SubStmt::FinalSuspend];
397 }
398
400 return getStoredStmts()[SubStmt::OnException];
401 }
403 return getStoredStmts()[SubStmt::OnFallthrough];
404 }
405
406 Expr *getAllocate() const {
407 return cast_or_null<Expr>(getStoredStmts()[SubStmt::Allocate]);
408 }
410 return cast_or_null<Expr>(getStoredStmts()[SubStmt::Deallocate]);
411 }
412 Stmt *getResultDecl() const { return getStoredStmts()[SubStmt::ResultDecl]; }
414 return cast<Expr>(getStoredStmts()[SubStmt::ReturnValue]);
415 }
417 auto *RS = dyn_cast_or_null<clang::ReturnStmt>(getReturnStmt());
418 return RS ? RS->getRetValue() : nullptr;
419 }
420 Stmt *getReturnStmt() const { return getStoredStmts()[SubStmt::ReturnStmt]; }
422 return getStoredStmts()[SubStmt::ReturnStmtOnAllocFailure];
423 }
425 return {getStoredStmts() + SubStmt::FirstParamMove, NumParams};
426 }
427
428 SourceLocation getBeginLoc() const LLVM_READONLY {
429 return getBody() ? getBody()->getBeginLoc()
431 }
432 SourceLocation getEndLoc() const LLVM_READONLY {
433 return getBody() ? getBody()->getEndLoc() : getPromiseDecl()->getEndLoc();
434 }
435
437 return child_range(getStoredStmts(),
438 getStoredStmts() + SubStmt::FirstParamMove + NumParams);
439 }
440
442 return const_child_range(getStoredStmts(), getStoredStmts() +
443 SubStmt::FirstParamMove +
444 NumParams);
445 }
446
448 return child_range(getStoredStmts() + SubStmt::Body + 1,
449 getStoredStmts() + SubStmt::FirstParamMove + NumParams);
450 }
451
453 return const_child_range(getStoredStmts() + SubStmt::Body + 1,
454 getStoredStmts() + SubStmt::FirstParamMove +
455 NumParams);
456 }
457
458 static bool classof(const Stmt *T) {
459 return T->getStmtClass() == CoroutineBodyStmtClass;
460 }
461};
462
463/// Represents a 'co_return' statement in the C++ Coroutines TS.
464///
465/// This statament models the initialization of the coroutine promise
466/// (encapsulating the eventual notional return value) from an expression
467/// (or braced-init-list), followed by termination of the coroutine.
468///
469/// This initialization is modeled by the evaluation of the operand
470/// followed by a call to one of:
471/// <promise>.return_value(<operand>)
472/// <promise>.return_void()
473/// which we name the "promise call".
474class CoreturnStmt : public Stmt {
475 SourceLocation CoreturnLoc;
476
477 enum SubStmt { Operand, PromiseCall, Count };
478 Stmt *SubStmts[SubStmt::Count];
479
480 bool IsImplicit : 1;
481
482 friend class ASTStmtReader;
483public:
484 CoreturnStmt(SourceLocation CoreturnLoc, Stmt *Operand, Stmt *PromiseCall,
485 bool IsImplicit = false)
486 : Stmt(CoreturnStmtClass), CoreturnLoc(CoreturnLoc),
487 IsImplicit(IsImplicit) {
488 SubStmts[SubStmt::Operand] = Operand;
489 SubStmts[SubStmt::PromiseCall] = PromiseCall;
490 }
491
493
494 SourceLocation getKeywordLoc() const { return CoreturnLoc; }
495
496 /// Retrieve the operand of the 'co_return' statement. Will be nullptr
497 /// if none was specified.
498 Expr *getOperand() const { return static_cast<Expr*>(SubStmts[Operand]); }
499
500 /// Retrieve the promise call that results from this 'co_return'
501 /// statement. Will be nullptr if either the coroutine has not yet been
502 /// finalized or the coroutine has no eventual return type.
504 return static_cast<Expr*>(SubStmts[PromiseCall]);
505 }
506
507 bool isImplicit() const { return IsImplicit; }
508 void setIsImplicit(bool value = true) { IsImplicit = value; }
509
510 SourceLocation getBeginLoc() const LLVM_READONLY { return CoreturnLoc; }
511 SourceLocation getEndLoc() const LLVM_READONLY {
512 return getOperand() ? getOperand()->getEndLoc() : getBeginLoc();
513 }
514
516 return child_range(SubStmts, SubStmts + SubStmt::Count);
517 }
518
520 return const_child_range(SubStmts, SubStmts + SubStmt::Count);
521 }
522
523 static bool classof(const Stmt *T) {
524 return T->getStmtClass() == CoreturnStmtClass;
525 }
526};
527
528/// CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
529///
530/// There are four kinds of expansion statements.
531///
532/// 1. Enumerating expansion statements.
533/// 2. Iterating expansion statements.
534/// 3. Destructuring expansion statements.
535/// 4. Dependent expansion statements.
536///
537/// 1. An 'enumerating' expansion statement is one whose expansion-initializer
538/// is a brace-enclosed expression-list; this list is syntactically similar to
539/// an initializer list, but it isn't actually an expression in and of itself
540/// (in that it is never evaluated or emitted) and instead is just treated as
541/// a group of expressions. The expansion initializer of this is always a
542/// syntactic-form 'InitListExpr'.
543///
544/// Example:
545/// \verbatim
546/// template for (auto x : { 1, 2, 3 }) {
547/// // ...
548/// }
549/// \endverbatim
550///
551/// Note that the expression-list may also contain pack expansions, e.g.
552/// '{ 1, xs... }', in which case the expansion size is dependent.
553///
554/// Here, the '{ 1, 2, 3 }' is parsed as an 'InitListExpr'. This node
555/// handles storing (and pack-expanding) the individual expressions.
556///
557/// Sema then wraps this with a 'CXXExpansionSelectExpr', which also
558/// contains a reference to an integral NTTP that is used as the expansion
559/// index; this index is either dependent (if the expansion-size is dependent),
560/// or set to a value of I in the I-th expansion during the expansion process.
561///
562/// The actual expansion is done by 'BuildCXXExpansionSelectExpr()': for
563/// example, during the 2nd expansion of '{ a, b, c }', I is equal to 1, and
564/// BuildCXXExpansionSelectExpr(), when called via TreeTransform,
565/// 'instantiates' the expression '{ a, b, c }' to just 'b'.
566///
567/// 2. Represents an unexpanded iterating expansion statement.
568///
569/// An 'iterating' expansion statement is one whose expansion-initializer is a
570/// a range, i.e. it has a corresponding 'begin()'/'end()' pair that is
571/// determined based on a number of conditions as stated in [stmt.expand] and
572/// [stmt.ranged].
573///
574/// Specifically, let E denote the expansion-initializer; the expansion
575/// statement is iterating if the type of E is not an array type, and either
576///
577/// 2a. 'E.begin' and 'E.end' *exist* (irrespective of whether they're
578/// accessible, deleted, or even callable), or
579///
580/// 2b. ADL for 'begin(E)' and 'end(E)' finds at least one viable function.
581///
582/// If neither A nor B apply to E (or if E is an array type), we treat this as
583/// a destructuring expansion statement instead (see case 3 below).
584///
585/// Notably, case 2a only checks whether the 'begin' and 'end' members exist and
586/// does *not* perform proper overload resolution; this is because if there is
587/// a begin/end function, but it for some reason is not usable (e.g. because it
588/// is non-const but E is const), then we'd rather error and tell the user that
589/// their begin/end function is wrong rather than falling back to destructuring.
590///
591/// Conversely, case 2b *does* perform overload resolution, simply because ADL
592/// may find quite a few begin/end overloads for unrelated types that happen to
593/// be in the same namespace. E.g. if the type of E is 'std::tuple', then there
594/// are quite a few begin/end pairs in the namespace 'std', but non of them can
595/// actually be used for a 'std::tuple', and we definitely want to destructure a
596/// tuple rather than error about it not being iterable.
597///
598/// In either case, once we've decided that the expansion statement is indeed
599/// iterating, we *do* make sure that the expression 'E.begin()'/'begin(E)' is
600/// well-formed, but any error at that point is a hard error and does not make
601/// us switch to destructuring instead.
602///
603/// The result of this expression is stored in a variable 'begin', which is then
604/// used to compute another variable 'iter' (which is just 'begin' + the
605/// expansion index) during expansion. During the N-th expansion, the expansion
606/// variable is then set to '*iter'. See [stmt.expand] for more information.
607///
608/// The expression used to compute the size of the expansion is not stored and
609/// is only created at the moment of expansion. See Sema::ComputeExpansionSize()
610/// for more information about this.
611///
612/// Example:
613/// \verbatim
614/// static constexpr std::string_view foo = "abcd";
615/// template for (auto x : foo) {
616/// // ...
617/// }
618/// \endverbatim
619///
620/// Here, 'begin' is 'foo.begin()', and during e.g. the 0-th expansion, 'iter'
621/// is 'begin + 0', and thus '*iter' yields 'a', which results in 'x' being
622/// a variable of type 'char' with value 'a'.
623///
624/// 3. Represents an unexpanded destructuring expansion statement.
625///
626/// A 'destructuring' expansion statement is any expansion statement that is
627/// not enumerating or iterating (i.e. destructuring is the last thing we try,
628/// and if it doesn't work, the program is ill-formed).
629///
630/// This essentially involves treating the expansion-initializer as the
631/// initializer of a structured-binding declaration, with the number of
632/// bindings and expansion size determined by the usual means (array size,
633/// std::tuple_size, etc.).
634///
635/// During the N-th expansion, the expansion variable is then initialized with
636/// the N-th binding of the structured-binding declaration. This is implemented
637/// by wrapping the initializer with a CXXExpansionSelectExpr, which selects a
638/// binding based on the current expansion index when called from TreeTransform.
639///
640/// Example:
641/// \verbatim
642/// std::tuple<int, long, unsigned> a {1, 2l, 3u};
643/// template for (auto x : a) {
644/// // ...
645/// }
646/// \endverbatim
647///
648/// Here, we build 'auto [_U0, _U1, _U2] = a', and during e.g. the 0-th
649/// expansion, 'x' is initialized with '_U0'.
650///
651/// 4. Represents an expansion statement whose expansion-initializer is
652/// type-dependent.
653///
654/// This will eventually become an iterating or destructuring expansion
655/// statement once the expansion-initializer is no longer dependent.
656///
657/// Dependent expansion statements can never be enumerating: even if the
658/// expansion size of an enumerating expansion statement is dependent (which
659/// is possible if the expression-list contains a pack), we still don't build
660/// an 'Enumerating' 'CXXExpansionStmtPattern' for it.
661///
662/// Example:
663/// \verbatim
664/// template <typename T>
665/// void f() {
666/// template for (auto x : T()) {
667/// // ...
668/// }
669/// }
670/// \endverbatim
671///
672/// \see CXXExpansionStmtDecl for more documentation on expansion statements.
673class CXXExpansionStmtPattern final
674 : public Stmt,
675 llvm::TrailingObjects<CXXExpansionStmtPattern, Stmt *> {
676 friend class ASTStmtReader;
677 friend TrailingObjects;
678
679public:
686
687private:
688 ExpansionStmtKind PatternKind;
689 SourceLocation LParenLoc;
690 SourceLocation ColonLoc;
691 SourceLocation RParenLoc;
692 CXXExpansionStmtDecl *ParentDecl;
693
694 /// Substatements of an unexpanded expansion statement.
695 ///
696 /// 'INIT', 'VAR', and 'BODY' are common to all kinds of expansion statements;
697 /// the former may be null if there is no init-statement.
698 ///
699 /// Depending on the kind of expansion statement, we may have to store
700 /// additional sub-statements, the first of which is denoted by
701 /// 'FIRST_CHILD_STATEMENT'.
702 ///
703 /// All of the sub-statements are allocated as 'TrailingObjects' so we can
704 /// return a single contiguous range from 'children()'.
705 enum SubStmt {
706 INIT,
707 VAR,
708 BODY,
709 FIRST_CHILD_STMT,
710
711 // Enumerating expansion statement (no additional sub-statements).
712 COUNT_Enumerating = FIRST_CHILD_STMT,
713
714 // Dependent expansion statement (1 additional sub-statement).
715 EXPANSION_INITIALIZER = FIRST_CHILD_STMT,
716 COUNT_Dependent,
717
718 // Destructuring expansion statement (1 additional sub-statement).
719 DECOMP_DECL = FIRST_CHILD_STMT,
720 COUNT_Destructuring,
721
722 // Iterating expansion statement (3 additional sub-statements).
723 RANGE = FIRST_CHILD_STMT,
724 BEGIN,
725 ITER,
726 COUNT_Iterating,
727 };
728
729 CXXExpansionStmtPattern(ExpansionStmtKind PatternKind, EmptyShell Empty);
730 CXXExpansionStmtPattern(ExpansionStmtKind PatternKind,
731 CXXExpansionStmtDecl *ESD, Stmt *Init,
732 DeclStmt *ExpansionVar, SourceLocation LParenLoc,
733 SourceLocation ColonLoc, SourceLocation RParenLoc);
734
735public:
736 static CXXExpansionStmtPattern *
737 CreateEmpty(ASTContext &Context, EmptyShell Empty, ExpansionStmtKind Kind);
738
739 /// Create a dependent expansion statement pattern.
740 static CXXExpansionStmtPattern *
741 CreateDependent(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init,
742 DeclStmt *ExpansionVar, Expr *ExpansionInitializer,
743 SourceLocation LParenLoc, SourceLocation ColonLoc,
744 SourceLocation RParenLoc);
745
746 /// Create a destructuring expansion statement pattern.
747 static CXXExpansionStmtPattern *
748 CreateDestructuring(ASTContext &Context, CXXExpansionStmtDecl *ESD,
749 Stmt *Init, DeclStmt *ExpansionVar,
750 Stmt *DecompositionDeclStmt, SourceLocation LParenLoc,
751 SourceLocation ColonLoc, SourceLocation RParenLoc);
752
753 /// Create an enumerating expansion statement pattern.
754 static CXXExpansionStmtPattern *
755 CreateEnumerating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init,
756 DeclStmt *ExpansionVar, SourceLocation LParenLoc,
757 SourceLocation ColonLoc, SourceLocation RParenLoc);
758
759 /// Create an iterating expansion statement pattern.
760 static CXXExpansionStmtPattern *
761 CreateIterating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init,
762 DeclStmt *ExpansionVar, DeclStmt *Range, DeclStmt *Begin,
763 DeclStmt *Iter, SourceLocation LParenLoc,
764 SourceLocation ColonLoc, SourceLocation RParenLoc);
765
766 SourceLocation getLParenLoc() const { return LParenLoc; }
767 SourceLocation getColonLoc() const { return ColonLoc; }
768 SourceLocation getRParenLoc() const { return RParenLoc; }
771 return getBody() ? getBody()->getEndLoc() : RParenLoc;
772 }
773
774 ExpansionStmtKind getKind() const { return PatternKind; }
775 bool isDependent() const {
776 return PatternKind == ExpansionStmtKind::Dependent;
777 }
778 bool isEnumerating() const {
779 return PatternKind == ExpansionStmtKind::Enumerating;
780 }
781 bool isIterating() const {
782 return PatternKind == ExpansionStmtKind::Iterating;
783 }
784 bool isDestructuring() const {
785 return PatternKind == ExpansionStmtKind::Destructuring;
786 }
787
788 unsigned getNumSubStmts() const { return getNumSubStmts(PatternKind); }
789
790 // Accessors for subcomponents common to all expansion statements.
791 CXXExpansionStmtDecl *getDecl() { return ParentDecl; }
792 const CXXExpansionStmtDecl *getDecl() const { return ParentDecl; }
793
794 Stmt *getInit() { return getSubStmt(INIT); }
795 const Stmt *getInit() const { return getSubStmt(INIT); }
796 void setInit(Stmt *S) { getSubStmt(INIT) = S; }
797
800 return const_cast<CXXExpansionStmtPattern *>(this)->getExpansionVariable();
801 }
802
803 DeclStmt *getExpansionVarStmt() { return cast<DeclStmt>(getSubStmt(VAR)); }
805 return cast<DeclStmt>(getSubStmt(VAR));
806 }
807
808 void setExpansionVarStmt(Stmt *S) { getSubStmt(VAR) = S; }
809
810 Stmt *getBody() { return getSubStmt(BODY); }
811 const Stmt *getBody() const { return getSubStmt(BODY); }
812 void setBody(Stmt *S) { getSubStmt(BODY) = S; }
813
814 // Accessors for iterating statements.
815 const DeclStmt *getRangeVarStmt() const {
816 assert(isIterating());
817 return cast<DeclStmt>(getSubStmt(RANGE));
818 }
819
821 assert(isIterating());
822 return cast<DeclStmt>(getSubStmt(RANGE));
823 }
824
826 assert(isIterating());
827 getSubStmt(RANGE) = S;
828 }
829
830 const VarDecl *getRangeVar() const {
831 assert(isIterating());
832 return cast<VarDecl>(getRangeVarStmt()->getSingleDecl());
833 }
834
836 assert(isIterating());
837 return cast<VarDecl>(getRangeVarStmt()->getSingleDecl());
838 }
839
840 const DeclStmt *getBeginVarStmt() const {
841 assert(isIterating());
842 return cast<DeclStmt>(getSubStmt(BEGIN));
843 }
844
846 assert(isIterating());
847 return cast<DeclStmt>(getSubStmt(BEGIN));
848 }
849
851 assert(isIterating());
852 getSubStmt(BEGIN) = S;
853 }
854
855 const VarDecl *getBeginVar() const {
856 assert(isIterating());
857 return cast<VarDecl>(getBeginVarStmt()->getSingleDecl());
858 }
859
861 assert(isIterating());
862 return cast<VarDecl>(getBeginVarStmt()->getSingleDecl());
863 }
864
865 const DeclStmt *getIterVarStmt() const {
866 assert(isIterating());
867 return cast<DeclStmt>(getSubStmt(ITER));
868 }
869
871 assert(isIterating());
872 return cast<DeclStmt>(getSubStmt(ITER));
873 }
874
876 assert(isIterating());
877 getSubStmt(ITER) = S;
878 }
879
880 const VarDecl *getIterVar() const {
881 assert(isIterating());
882 return cast<VarDecl>(getIterVarStmt()->getSingleDecl());
883 }
884
886 assert(isIterating());
887 return cast<VarDecl>(getIterVarStmt()->getSingleDecl());
888 }
889
890 // Accessors for destructuring statements.
892 assert(isDestructuring());
893 return getSubStmt(DECOMP_DECL);
894 }
895
897 assert(isDestructuring());
898 return getSubStmt(DECOMP_DECL);
899 }
900
902 assert(isDestructuring());
903 getSubStmt(DECOMP_DECL) = S;
904 }
905
908 return const_cast<CXXExpansionStmtPattern *>(this)->getDecompositionDecl();
909 }
910
911 // Accessors for dependent statements.
913 assert(isDependent());
914 return cast<Expr>(getSubStmt(EXPANSION_INITIALIZER));
915 }
916
918 assert(isDependent());
919 return cast<Expr>(getSubStmt(EXPANSION_INITIALIZER));
920 }
921
923 assert(isDependent());
924 getSubStmt(EXPANSION_INITIALIZER) = S;
925 }
926
928 return child_range(getTrailingObjects(),
929 getTrailingObjects() + getNumSubStmts());
930 }
931
933 return const_child_range(getTrailingObjects(),
934 getTrailingObjects() + getNumSubStmts());
935 }
936
937 static bool classof(const Stmt *T) {
938 return T->getStmtClass() == CXXExpansionStmtPatternClass;
939 }
940
941private:
942 template <typename... Args>
943 static CXXExpansionStmtPattern *AllocateAndConstruct(ASTContext &Context,
944 ExpansionStmtKind Kind,
945 Args &&...Arguments);
946
947 static unsigned getNumSubStmts(ExpansionStmtKind Kind);
948 Stmt *getSubStmt(unsigned Idx) const {
949 assert(Idx < getNumSubStmts());
950 return getTrailingObjects()[Idx];
951 }
952
953 Stmt *&getSubStmt(unsigned Idx) {
954 assert(Idx < getNumSubStmts());
955 return getTrailingObjects()[Idx];
956 }
957};
958
959/// Represents the code generated for an expanded expansion statement.
960///
961/// This holds 'preamble statements' and 'instantiations'; these encode the
962/// general underlying pattern that all expansion statements desugar to. Note
963/// that only the inner '{}' (i.e. those marked as 'Actual "CompoundStmt"'
964/// below) are actually present as 'CompoundStmt's in the AST; the outer braces
965/// that wrap everything do *not* correspond to an actual 'CompoundStmt' and are
966/// implicit in the sense that we simply push a scope when evaluating or
967/// emitting IR for a 'CXXExpansionStmtInstantiation'.
968///
969/// The 'instantiations' are precisely these inner compound statements.
970///
971/// \verbatim
972/// { // Not actually present in the AST.
973/// <preamble statements>
974/// { // Actual 'CompoundStmt'.
975/// <1st instantiation>
976/// }
977/// ...
978/// { // Actual 'CompoundStmt'.
979/// <n-th instantiation>
980/// }
981/// }
982/// \endverbatim
983///
984/// For example, the CXXExpansionStmtInstantiation that corresponds to the
985/// following expansion statement
986///
987/// \verbatim
988/// std::tuple<int, int, int> a{1, 2, 3};
989/// template for (auto x : a) {
990/// // ...
991/// }
992/// \endverbatim
993///
994/// would be
995///
996/// \verbatim
997/// {
998/// auto [__u0, __u1, __u2] = a;
999/// {
1000/// auto x = __u0;
1001/// // ...
1002/// }
1003/// {
1004/// auto x = __u1;
1005/// // ...
1006/// }
1007/// {
1008/// auto x = __u2;
1009/// // ...
1010/// }
1011/// }
1012/// \endverbatim
1013///
1014/// There are two reasons why this needs to exist and why we don't just store a
1015/// list of instantiations in some other node:
1016///
1017/// 1. We need custom codegen to handle break/continue in expansion statements
1018/// properly, so it can't just be a compound statement.
1019///
1020/// 2. The expansions are created after both the pattern and the
1021/// 'CXXExpansionStmtDecl', so we can't just store them as trailing data in
1022/// either of those nodes (because we don't know how many expansions there
1023/// will be when those notes are allocated).
1024///
1025/// \see CXXExpansionStmtDecl
1026class CXXExpansionStmtInstantiation final
1027 : public Stmt,
1028 llvm::TrailingObjects<CXXExpansionStmtInstantiation, Stmt *> {
1029 friend class ASTStmtReader;
1030 friend TrailingObjects;
1031
1032 CXXExpansionStmtDecl *Parent;
1033
1034 // Instantiations are stored first, then preamble statements.
1035 const unsigned NumInstantiations : 20;
1036 const unsigned NumPreambleStmts : 3;
1037 unsigned ShouldApplyLifetimeExtensionToPreamble : 1;
1038
1039 CXXExpansionStmtInstantiation(EmptyShell Empty, unsigned NumInstantiations,
1040 unsigned NumPreambleStmts);
1041 CXXExpansionStmtInstantiation(CXXExpansionStmtDecl *Parent,
1042 ArrayRef<Stmt *> Instantiations,
1043 ArrayRef<Stmt *> PreambleStmts,
1044 bool ShouldApplyLifetimeExtensionToPreamble);
1045
1046public:
1047 static CXXExpansionStmtInstantiation *
1049 ArrayRef<Stmt *> Instantiations, ArrayRef<Stmt *> PreambleStmts,
1050 bool ShouldApplyLifetimeExtensionToPreamble);
1051
1052 static CXXExpansionStmtInstantiation *CreateEmpty(ASTContext &C,
1054 unsigned NumInstantiations,
1055 unsigned NumPreambleStmts);
1056
1058 return getTrailingObjects(getNumSubStmts());
1059 }
1060
1062 return getTrailingObjects(getNumSubStmts());
1063 }
1064
1065 unsigned getNumSubStmts() const {
1066 return NumInstantiations + NumPreambleStmts;
1067 }
1068
1070 return getTrailingObjects(NumInstantiations);
1071 }
1072
1074 return getAllSubStmts().drop_front(NumInstantiations);
1075 }
1076
1078 return ShouldApplyLifetimeExtensionToPreamble;
1079 }
1080
1082 ShouldApplyLifetimeExtensionToPreamble = Apply;
1083 }
1084
1086 SourceLocation getEndLoc() const;
1087
1088 CXXExpansionStmtDecl *getParent() { return Parent; }
1089 const CXXExpansionStmtDecl *getParent() const { return Parent; }
1090
1092 Stmt **S = getTrailingObjects();
1093 return child_range(S, S + getNumSubStmts());
1094 }
1095
1097 Stmt *const *S = getTrailingObjects();
1098 return const_child_range(S, S + getNumSubStmts());
1099 }
1100
1101 static bool classof(const Stmt *T) {
1102 return T->getStmtClass() == CXXExpansionStmtInstantiationClass;
1103 }
1104};
1105
1106} // end namespace clang
1107
1108#endif
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:29
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:45
CXXCatchStmt(SourceLocation catchLoc, VarDecl *exDecl, Stmt *handlerBlock)
Definition StmtCXX.h:37
SourceLocation getCatchLoc() const
Definition StmtCXX.h:49
Stmt * getHandlerBlock() const
Definition StmtCXX.h:52
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:44
CXXCatchStmt(EmptyShell Empty)
Definition StmtCXX.h:41
static bool classof(const Stmt *T)
Definition StmtCXX.h:54
child_range children()
Definition StmtCXX.h:58
const_child_range children() const
Definition StmtCXX.h:60
VarDecl * getExceptionDecl() const
Definition StmtCXX.h:50
QualType getCaughtType() const
Definition StmtCXX.cpp:20
friend class ASTStmtReader
Definition StmtCXX.h:64
Represents a C++26 expansion statement declaration.
ArrayRef< Stmt * > getInstantiations() const
Definition StmtCXX.h:1069
bool shouldApplyLifetimeExtensionToPreamble() const
Definition StmtCXX.h:1077
CXXExpansionStmtDecl * getParent()
Definition StmtCXX.h:1088
ArrayRef< Stmt * > getPreambleStmts() const
Definition StmtCXX.h:1073
const_child_range children() const
Definition StmtCXX.h:1096
ArrayRef< Stmt * > getAllSubStmts() const
Definition StmtCXX.h:1057
SourceLocation getBeginLoc() const
Definition StmtCXX.cpp:284
const CXXExpansionStmtDecl * getParent() const
Definition StmtCXX.h:1089
static bool classof(const Stmt *T)
Definition StmtCXX.h:1101
SourceLocation getEndLoc() const
Definition StmtCXX.cpp:288
MutableArrayRef< Stmt * > getAllSubStmts()
Definition StmtCXX.h:1061
static CXXExpansionStmtInstantiation * CreateEmpty(ASTContext &C, EmptyShell Empty, unsigned NumInstantiations, unsigned NumPreambleStmts)
Definition StmtCXX.cpp:274
void setShouldApplyLifetimeExtensionToPreamble(bool Apply)
Definition StmtCXX.h:1081
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
Definition StmtCXX.h:675
ExpansionStmtKind getKind() const
Definition StmtCXX.h:774
const CXXExpansionStmtDecl * getDecl() const
Definition StmtCXX.h:792
static CXXExpansionStmtPattern * CreateIterating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, DeclStmt *Range, DeclStmt *Begin, DeclStmt *Iter, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an iterating expansion statement pattern.
Definition StmtCXX.cpp:194
SourceLocation getEndLoc() const
Definition StmtCXX.h:770
SourceLocation getBeginLoc() const
Definition StmtCXX.cpp:208
const DeclStmt * getIterVarStmt() const
Definition StmtCXX.h:865
const Expr * getExpansionInitializer() const
Definition StmtCXX.h:917
DecompositionDecl * getDecompositionDecl()
Definition StmtCXX.cpp:212
DeclStmt * getExpansionVarStmt()
Definition StmtCXX.h:803
static CXXExpansionStmtPattern * CreateDependent(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, Expr *ExpansionInitializer, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create a dependent expansion statement pattern.
Definition StmtCXX.cpp:155
static CXXExpansionStmtPattern * CreateEmpty(ASTContext &Context, EmptyShell Empty, ExpansionStmtKind Kind)
Definition StmtCXX.cpp:180
SourceLocation getRParenLoc() const
Definition StmtCXX.h:768
const VarDecl * getRangeVar() const
Definition StmtCXX.h:830
static CXXExpansionStmtPattern * CreateDestructuring(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, Stmt *DecompositionDeclStmt, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create a destructuring expansion statement pattern.
Definition StmtCXX.cpp:167
const Stmt * getBody() const
Definition StmtCXX.h:811
const VarDecl * getIterVar() const
Definition StmtCXX.h:880
const VarDecl * getExpansionVariable() const
Definition StmtCXX.h:799
const_child_range children() const
Definition StmtCXX.h:932
const Stmt * getInit() const
Definition StmtCXX.h:795
void setRangeVarStmt(DeclStmt *S)
Definition StmtCXX.h:825
const Stmt * getDecompositionDeclStmt() const
Definition StmtCXX.h:896
void setBeginVarStmt(DeclStmt *S)
Definition StmtCXX.h:850
unsigned getNumSubStmts() const
Definition StmtCXX.h:788
void setIterVarStmt(DeclStmt *S)
Definition StmtCXX.h:875
const DeclStmt * getExpansionVarStmt() const
Definition StmtCXX.h:804
const DeclStmt * getBeginVarStmt() const
Definition StmtCXX.h:840
const DecompositionDecl * getDecompositionDecl() const
Definition StmtCXX.h:907
void setDecompositionDeclStmt(Stmt *S)
Definition StmtCXX.h:901
void setExpansionInitializer(Expr *S)
Definition StmtCXX.h:922
SourceLocation getColonLoc() const
Definition StmtCXX.h:767
void setExpansionVarStmt(Stmt *S)
Definition StmtCXX.h:808
const DeclStmt * getRangeVarStmt() const
Definition StmtCXX.h:815
CXXExpansionStmtDecl * getDecl()
Definition StmtCXX.h:791
const VarDecl * getBeginVar() const
Definition StmtCXX.h:855
static CXXExpansionStmtPattern * CreateEnumerating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an enumerating expansion statement pattern.
Definition StmtCXX.cpp:185
static bool classof(const Stmt *T)
Definition StmtCXX.h:937
SourceLocation getLParenLoc() const
Definition StmtCXX.h:766
void setLoopVarStmt(Stmt *S)
Definition StmtCXX.h:200
void setRangeStmt(Stmt *S)
Definition StmtCXX.h:195
DeclStmt * getBeginStmt()
Definition StmtCXX.h:164
CXXForRangeStmt(Stmt *InitStmt, DeclStmt *Range, DeclStmt *Begin, DeclStmt *End, Expr *Cond, Expr *Inc, DeclStmt *LoopVar, Stmt *Body, SourceLocation FL, SourceLocation CAL, SourceLocation CL, SourceLocation RPL)
Definition StmtCXX.cpp:49
DeclStmt * getLoopVarStmt()
Definition StmtCXX.h:170
DeclStmt * getEndStmt()
Definition StmtCXX.h:167
const DeclStmt * getRangeStmt() const
Definition StmtCXX.h:173
SourceLocation getForLoc() const
Definition StmtCXX.h:203
const DeclStmt * getEndStmt() const
Definition StmtCXX.h:179
void setEndStmt(Stmt *S)
Definition StmtCXX.h:197
DeclStmt * getRangeStmt()
Definition StmtCXX.h:163
const DeclStmt * getBeginStmt() const
Definition StmtCXX.h:176
void setInc(Expr *E)
Definition StmtCXX.h:199
const Expr * getCond() const
Definition StmtCXX.h:182
SourceLocation getRParenLoc() const
Definition StmtCXX.h:206
const Expr * getInc() const
Definition StmtCXX.h:185
SourceLocation getColonLoc() const
Definition StmtCXX.h:205
void setBeginStmt(Stmt *S)
Definition StmtCXX.h:196
const_child_range children() const
Definition StmtCXX.h:222
VarDecl * getLoopVariable()
Definition StmtCXX.cpp:78
void setInit(Stmt *S)
Definition StmtCXX.h:193
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:209
void setBody(Stmt *S)
Definition StmtCXX.h:201
CXXForRangeStmt(EmptyShell Empty)
Definition StmtCXX.h:152
const Stmt * getBody() const
Definition StmtCXX.h:191
void setCond(Expr *E)
Definition StmtCXX.h:198
SourceLocation getCoawaitLoc() const
Definition StmtCXX.h:204
static bool classof(const Stmt *T)
Definition StmtCXX.h:213
const DeclStmt * getLoopVarStmt() const
Definition StmtCXX.h:188
friend class ASTStmtReader
Definition StmtCXX.h:146
void setRangeInit(Expr *E)
Definition StmtCXX.h:194
child_range children()
Definition StmtCXX.h:218
const Stmt * getInit() const
Definition StmtCXX.h:158
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:208
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:70
SourceLocation getTryLoc() const
Definition StmtCXX.h:96
const CXXCatchStmt * getHandler(unsigned i) const
Definition StmtCXX.h:112
static bool classof(const Stmt *T)
Definition StmtCXX.h:116
const_child_range children() const
Definition StmtCXX.h:124
CXXCatchStmt * getHandler(unsigned i)
Definition StmtCXX.h:109
unsigned getNumHandlers() const
Definition StmtCXX.h:108
child_range children()
Definition StmtCXX.h:120
SourceLocation getEndLoc() const
Definition StmtCXX.h:97
friend class ASTStmtReader
Definition StmtCXX.h:73
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:94
const CompoundStmt * getTryBlock() const
Definition StmtCXX.h:104
CompoundStmt * getTryBlock()
Definition StmtCXX.h:101
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
SourceLocation getBeginLoc() const
Definition Stmt.h:1864
SourceLocation getEndLoc() const
Definition Stmt.h:1865
Expr * getOperand() const
Retrieve the operand of the 'co_return' statement.
Definition StmtCXX.h:498
void setIsImplicit(bool value=true)
Definition StmtCXX.h:508
Expr * getPromiseCall() const
Retrieve the promise call that results from this 'co_return' statement.
Definition StmtCXX.h:503
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:511
CoreturnStmt(EmptyShell)
Definition StmtCXX.h:492
child_range children()
Definition StmtCXX.h:515
bool isImplicit() const
Definition StmtCXX.h:507
SourceLocation getKeywordLoc() const
Definition StmtCXX.h:494
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:510
CoreturnStmt(SourceLocation CoreturnLoc, Stmt *Operand, Stmt *PromiseCall, bool IsImplicit=false)
Definition StmtCXX.h:484
static bool classof(const Stmt *T)
Definition StmtCXX.h:523
friend class ASTStmtReader
Definition StmtCXX.h:482
const_child_range children() const
Definition StmtCXX.h:519
CompoundStmt * getBody() const
Retrieve the body of the coroutine as written.
Definition StmtCXX.h:381
static bool classof(const Stmt *T)
Definition StmtCXX.h:458
Stmt * getReturnStmtOnAllocFailure() const
Definition StmtCXX.h:421
Expr * getReturnValueInit() const
Definition StmtCXX.h:413
Stmt * getReturnStmt() const
Definition StmtCXX.h:420
bool hasDependentPromiseType() const
Definition StmtCXX.h:374
Stmt * getResultDecl() const
Definition StmtCXX.h:412
child_range childrenExclBody()
Definition StmtCXX.h:447
Stmt * getInitSuspendStmt() const
Definition StmtCXX.h:392
Expr * getAllocate() const
Definition StmtCXX.h:406
Stmt * getPromiseDeclStmt() const
Definition StmtCXX.h:385
VarDecl * getPromiseDecl() const
Definition StmtCXX.h:388
Expr * getDeallocate() const
Definition StmtCXX.h:409
Stmt * getFallthroughHandler() const
Definition StmtCXX.h:402
Stmt * getExceptionHandler() const
Definition StmtCXX.h:399
friend class ASTReader
Definition StmtCXX.h:340
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:428
Expr * getReturnValue() const
Definition StmtCXX.h:416
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:432
friend class ASTStmtReader
Definition StmtCXX.h:339
child_range children()
Definition StmtCXX.h:436
Stmt * getFinalSuspendStmt() const
Definition StmtCXX.h:395
const_child_range children() const
Definition StmtCXX.h:441
ArrayRef< Stmt const * > getParamMoves() const
Definition StmtCXX.h:424
const_child_range childrenExclBody() const
Definition StmtCXX.h:452
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
SourceLocation getEndLoc() const LLVM_READONLY
Definition DeclBase.h:443
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Decl.h:831
A decomposition declaration.
Definition DeclCXX.h:4270
This represents one expression.
Definition Expr.h:112
bool isIfExists() const
Determine whether this is an __if_exists statement.
Definition StmtCXX.h:279
DeclarationNameInfo getNameInfo() const
Retrieve the name of the entity we're testing for, along with location information.
Definition StmtCXX.h:290
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies this name, if any.
Definition StmtCXX.h:286
CompoundStmt * getSubStmt() const
Retrieve the compound statement that will be included in the program only if the existence of the sym...
Definition StmtCXX.h:294
SourceLocation getEndLoc() const LLVM_READONLY
Definition StmtCXX.h:299
SourceLocation getKeywordLoc() const
Retrieve the location of the __if_exists or __if_not_exists keyword.
Definition StmtCXX.h:276
static bool classof(const Stmt *T)
Definition StmtCXX.h:311
bool isIfNotExists() const
Determine whether this is an __if_exists statement.
Definition StmtCXX.h:282
const_child_range children() const
Definition StmtCXX.h:307
MSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, CompoundStmt *SubStmt)
Definition StmtCXX.h:265
SourceLocation getBeginLoc() const LLVM_READONLY
Definition StmtCXX.h:298
A C++ nested-name-specifier augmented with source location information.
A (possibly-)qualified type.
Definition TypeBase.h:937
Encodes a location in the source.
Stmt - This represents one statement.
Definition Stmt.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
Stmt(StmtClass SC, EmptyShell)
Construct an empty statement.
Definition Stmt.h:1485
llvm::iterator_range< child_iterator > child_range
Definition Stmt.h:1592
Stmt()=delete
llvm::iterator_range< const_child_iterator > const_child_range
Definition Stmt.h:1593
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition TypeBase.h:2846
QualType getType() const
Definition Decl.h:723
Represents a variable declaration or definition.
Definition Decl.h:932
Definition SPIR.cpp:35
The JSON file list parser is used to communicate input to InstallAPI.
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
Expr * Cond
};
U cast(CodeGen::Address addr)
Definition Address.h:327
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
ArrayRef< Stmt * > ParamMoves
Definition StmtCXX.h:362
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
A placeholder type used to construct an empty shell of a type, that will be filled in later (e....
Definition Stmt.h:1443