|
clang 23.0.0git
|
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement. More...
#include "clang/AST/StmtCXX.h"
Public Types | |
| enum class | ExpansionStmtKind : uint8_t { Enumerating , Iterating , Destructuring , Dependent } |
| Public Types inherited from clang::Stmt | |
| enum | StmtClass { NoStmtClass = 0 } |
| enum | Likelihood { LH_Unlikely = -1 , LH_None , LH_Likely } |
| The likelihood of a branch being taken. More... | |
| using | child_iterator = StmtIterator |
| Child Iterators: All subclasses must implement 'children' to permit easy iteration over the substatements/subexpressions of an AST node. | |
| using | const_child_iterator = ConstStmtIterator |
| using | child_range = llvm::iterator_range<child_iterator> |
| using | const_child_range = llvm::iterator_range<const_child_iterator> |
Public Member Functions | |
| SourceLocation | getLParenLoc () const |
| SourceLocation | getColonLoc () const |
| SourceLocation | getRParenLoc () const |
| SourceLocation | getBeginLoc () const |
| SourceLocation | getEndLoc () const |
| ExpansionStmtKind | getKind () const |
| bool | isDependent () const |
| bool | isEnumerating () const |
| bool | isIterating () const |
| bool | isDestructuring () const |
| unsigned | getNumSubStmts () const |
| CXXExpansionStmtDecl * | getDecl () |
| const CXXExpansionStmtDecl * | getDecl () const |
| Stmt * | getInit () |
| const Stmt * | getInit () const |
| void | setInit (Stmt *S) |
| VarDecl * | getExpansionVariable () |
| const VarDecl * | getExpansionVariable () const |
| DeclStmt * | getExpansionVarStmt () |
| const DeclStmt * | getExpansionVarStmt () const |
| void | setExpansionVarStmt (Stmt *S) |
| Stmt * | getBody () |
| const Stmt * | getBody () const |
| void | setBody (Stmt *S) |
| const DeclStmt * | getRangeVarStmt () const |
| DeclStmt * | getRangeVarStmt () |
| void | setRangeVarStmt (DeclStmt *S) |
| const VarDecl * | getRangeVar () const |
| VarDecl * | getRangeVar () |
| const DeclStmt * | getBeginVarStmt () const |
| DeclStmt * | getBeginVarStmt () |
| void | setBeginVarStmt (DeclStmt *S) |
| const VarDecl * | getBeginVar () const |
| VarDecl * | getBeginVar () |
| const DeclStmt * | getIterVarStmt () const |
| DeclStmt * | getIterVarStmt () |
| void | setIterVarStmt (DeclStmt *S) |
| const VarDecl * | getIterVar () const |
| VarDecl * | getIterVar () |
| Stmt * | getDecompositionDeclStmt () |
| const Stmt * | getDecompositionDeclStmt () const |
| void | setDecompositionDeclStmt (Stmt *S) |
| DecompositionDecl * | getDecompositionDecl () |
| const DecompositionDecl * | getDecompositionDecl () const |
| Expr * | getExpansionInitializer () |
| const Expr * | getExpansionInitializer () const |
| void | setExpansionInitializer (Expr *S) |
| child_range | children () |
| const_child_range | children () const |
| Public Member Functions inherited from clang::Stmt | |
| void * | operator new (size_t bytes, const ASTContext &C, unsigned alignment=8) |
| void * | operator new (size_t bytes, const ASTContext *C, unsigned alignment=8) |
| void * | operator new (size_t bytes, void *mem) noexcept |
| void | operator delete (void *, const ASTContext &, unsigned) noexcept |
| void | operator delete (void *, const ASTContext *, unsigned) noexcept |
| void | operator delete (void *, size_t) noexcept |
| void | operator delete (void *, void *) noexcept |
| Stmt ()=delete | |
| Stmt (const Stmt &)=delete | |
| Stmt (Stmt &&)=delete | |
| Stmt & | operator= (const Stmt &)=delete |
| Stmt & | operator= (Stmt &&)=delete |
| Stmt (StmtClass SC) | |
| StmtClass | getStmtClass () const |
| const char * | getStmtClassName () const |
| SourceRange | getSourceRange () const LLVM_READONLY |
| SourceLocation tokens are not useful in isolation - they are low level value objects created/interpreted by SourceManager. | |
| SourceLocation | getBeginLoc () const LLVM_READONLY |
| SourceLocation | getEndLoc () const LLVM_READONLY |
| void | dump () const |
Dumps the specified AST fragment and all subtrees to llvm::errs(). | |
| void | dump (raw_ostream &OS, const ASTContext &Context) const |
| int64_t | getID (const ASTContext &Context) const |
| void | dumpColor () const |
| dumpColor - same as dump(), but forces color highlighting. | |
| void | dumpPretty (const ASTContext &Context) const |
| dumpPretty/printPretty - These two methods do a "pretty print" of the AST back to its original source language syntax. | |
| void | printPretty (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const |
| void | printPrettyControlled (raw_ostream &OS, PrinterHelper *Helper, const PrintingPolicy &Policy, unsigned Indentation=0, StringRef NewlineSymbol="\n", const ASTContext *Context=nullptr) const |
| void | printJson (raw_ostream &Out, PrinterHelper *Helper, const PrintingPolicy &Policy, bool AddQuotes) const |
| Pretty-prints in JSON format. | |
| void | viewAST () const |
| viewAST - Visualize an AST rooted at this Stmt* using GraphViz. | |
| Stmt * | IgnoreContainers (bool IgnoreCaptured=false) |
| Skip no-op (attributed, compound) container stmts and skip captured stmt at the top, if IgnoreCaptured is true. | |
| const Stmt * | IgnoreContainers (bool IgnoreCaptured=false) const |
| const Stmt * | stripLabelLikeStatements () const |
| Strip off all label-like statements. | |
| Stmt * | stripLabelLikeStatements () |
| child_range | children () |
| const_child_range | children () const |
| child_iterator | child_begin () |
| child_iterator | child_end () |
| const_child_iterator | child_begin () const |
| const_child_iterator | child_end () const |
| void | Profile (llvm::FoldingSetNodeID &ID, const ASTContext &Context, bool Canonical, bool ProfileLambdaExpr=false) const |
| Produce a unique representation of the given statement. | |
| void | ProcessODRHash (llvm::FoldingSetNodeID &ID, ODRHash &Hash) const |
| Calculate a unique representation for a statement that is stable across compiler invocations. | |
Static Public Member Functions | |
| static CXXExpansionStmtPattern * | CreateEmpty (ASTContext &Context, EmptyShell Empty, ExpansionStmtKind Kind) |
| 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. | |
| 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. | |
| static CXXExpansionStmtPattern * | CreateEnumerating (ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc) |
| Create an enumerating expansion statement pattern. | |
| 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. | |
| static bool | classof (const Stmt *T) |
| Static Public Member Functions inherited from clang::Stmt | |
| static void | addStmtClass (const StmtClass s) |
| static void | EnableStatistics () |
| static void | PrintStats () |
| static Likelihood | getLikelihood (ArrayRef< const Attr * > Attrs) |
| static Likelihood | getLikelihood (const Stmt *S) |
| static const Attr * | getLikelihoodAttr (const Stmt *S) |
| static Likelihood | getLikelihood (const Stmt *Then, const Stmt *Else) |
| static std::tuple< bool, const Attr *, const Attr * > | determineLikelihoodConflict (const Stmt *Then, const Stmt *Else) |
Friends | |
| class | ASTStmtReader |
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
There are four kinds of expansion statements.
Example:
/// template for (auto x : { 1, 2, 3 }) {
/// // ...
/// }
/// Note that the expression-list may also contain pack expansions, e.g. '{ 1, xs... }', in which case the expansion size is dependent.
Here, the '{ 1, 2, 3 }' is parsed as an 'InitListExpr'. This node handles storing (and pack-expanding) the individual expressions.
Sema then wraps this with a 'CXXExpansionSelectExpr', which also contains a reference to an integral NTTP that is used as the expansion index; this index is either dependent (if the expansion-size is dependent), or set to a value of I in the I-th expansion during the expansion process.
The actual expansion is done by 'BuildCXXExpansionSelectExpr()': for example, during the 2nd expansion of '{ a, b, c }', I is equal to 1, and BuildCXXExpansionSelectExpr(), when called via TreeTransform, 'instantiates' the expression '{ a, b, c }' to just 'b'.
An 'iterating' expansion statement is one whose expansion-initializer is a a range, i.e. it has a corresponding 'begin()'/'end()' pair that is determined based on a number of conditions as stated in [stmt.expand] and [stmt.ranged].
Specifically, let E denote the expansion-initializer; the expansion statement is iterating if the type of E is not an array type, and either
2a. 'E.begin' and 'E.end' exist (irrespective of whether they're accessible, deleted, or even callable), or
2b. ADL for 'begin(E)' and 'end(E)' finds at least one viable function.
If neither A nor B apply to E (or if E is an array type), we treat this as a destructuring expansion statement instead (see case 3 below).
Notably, case 2a only checks whether the 'begin' and 'end' members exist and does not perform proper overload resolution; this is because if there is a begin/end function, but it for some reason is not usable (e.g. because it is non-const but E is const), then we'd rather error and tell the user that their begin/end function is wrong rather than falling back to destructuring.
Conversely, case 2b does perform overload resolution, simply because ADL may find quite a few begin/end overloads for unrelated types that happen to be in the same namespace. E.g. if the type of E is 'std::tuple', then there are quite a few begin/end pairs in the namespace 'std', but non of them can actually be used for a 'std::tuple', and we definitely want to destructure a tuple rather than error about it not being iterable.
In either case, once we've decided that the expansion statement is indeed iterating, we do make sure that the expression 'E.begin()'/'begin(E)' is well-formed, but any error at that point is a hard error and does not make us switch to destructuring instead.
The result of this expression is stored in a variable 'begin', which is then used to compute another variable 'iter' (which is just 'begin' + the expansion index) during expansion. During the N-th expansion, the expansion variable is then set to '*iter'. See [stmt.expand] for more information.
The expression used to compute the size of the expansion is not stored and is only created at the moment of expansion. See Sema::ComputeExpansionSize() for more information about this.
Example:
/// static constexpr std::string_view foo = "abcd";
/// template for (auto x : foo) {
/// // ...
/// }
/// Here, 'begin' is 'foo.begin()', and during e.g. the 0-th expansion, 'iter' is 'begin + 0', and thus '*iter' yields 'a', which results in 'x' being a variable of type 'char' with value 'a'.
A 'destructuring' expansion statement is any expansion statement that is not enumerating or iterating (i.e. destructuring is the last thing we try, and if it doesn't work, the program is ill-formed).
This essentially involves treating the expansion-initializer as the initializer of a structured-binding declaration, with the number of bindings and expansion size determined by the usual means (array size, std::tuple_size, etc.).
During the N-th expansion, the expansion variable is then initialized with the N-th binding of the structured-binding declaration. This is implemented by wrapping the initializer with a CXXExpansionSelectExpr, which selects a binding based on the current expansion index when called from TreeTransform.
Example:
/// std::tuple<int, long, unsigned> a {1, 2l, 3u};
/// template for (auto x : a) {
/// // ...
/// }
/// Here, we build 'auto [_U0, _U1, _U2] = a', and during e.g. the 0-th expansion, 'x' is initialized with '_U0'.
This will eventually become an iterating or destructuring expansion statement once the expansion-initializer is no longer dependent.
Dependent expansion statements can never be enumerating: even if the expansion size of an enumerating expansion statement is dependent (which is possible if the expression-list contains a pack), we still don't build an 'Enumerating' 'CXXExpansionStmtPattern' for it.
Example:
/// template <typename T>
/// void f() {
/// template for (auto x : T()) {
/// // ...
/// }
/// }
///
|
strong |
|
inline |
Definition at line 927 of file StmtCXX.h.
References getNumSubStmts().
|
inline |
Definition at line 932 of file StmtCXX.h.
References getNumSubStmts().
Definition at line 937 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
static |
Create a dependent expansion statement pattern.
Definition at line 155 of file StmtCXX.cpp.
References Dependent, clang::Init, setExpansionInitializer(), and clang::Stmt::Stmt().
Referenced by clang::Sema::BuildNonEnumeratingCXXExpansionStmtPattern(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
static |
Create a destructuring expansion statement pattern.
Definition at line 167 of file StmtCXX.cpp.
References Destructuring, clang::Init, setDecompositionDeclStmt(), and clang::Stmt::Stmt().
Referenced by clang::Sema::BuildNonEnumeratingCXXExpansionStmtPattern(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
static |
Definition at line 180 of file StmtCXX.cpp.
References clang::Empty.
|
static |
Create an enumerating expansion statement pattern.
Definition at line 185 of file StmtCXX.cpp.
References Enumerating, clang::Init, and clang::Stmt::Stmt().
Referenced by clang::Sema::BuildCXXEnumeratingExpansionStmtPattern(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
static |
Create an iterating expansion statement pattern.
Definition at line 194 of file StmtCXX.cpp.
References clang::Init, Iterating, setBeginVarStmt(), setIterVarStmt(), setRangeVarStmt(), and clang::Stmt::Stmt().
Referenced by clang::Sema::BuildNonEnumeratingCXXExpansionStmtPattern(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
| SourceLocation CXXExpansionStmtPattern::getBeginLoc | ( | ) | const |
Definition at line 208 of file StmtCXX.cpp.
|
inline |
Definition at line 860 of file StmtCXX.h.
References clang::cast(), getBeginVarStmt(), and isIterating().
|
inline |
Definition at line 855 of file StmtCXX.h.
References clang::cast(), getBeginVarStmt(), and isIterating().
|
inline |
Definition at line 845 of file StmtCXX.h.
References clang::cast(), and isIterating().
|
inline |
Definition at line 840 of file StmtCXX.h.
References clang::cast(), and isIterating().
Referenced by getBeginVar(), getBeginVar(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 810 of file StmtCXX.h.
References clang::Stmt::Stmt().
Referenced by getEndLoc().
|
inline |
Definition at line 811 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
inline |
Definition at line 767 of file StmtCXX.h.
Referenced by clang::Sema::ComputeExpansionSize(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 791 of file StmtCXX.h.
Referenced by clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
| DecompositionDecl * CXXExpansionStmtPattern::getDecompositionDecl | ( | ) |
Definition at line 212 of file StmtCXX.cpp.
References clang::cast(), getDecompositionDeclStmt(), and isDestructuring().
Referenced by clang::Sema::ComputeExpansionSize(), and getDecompositionDecl().
|
inline |
Definition at line 907 of file StmtCXX.h.
References getDecompositionDecl().
|
inline |
Definition at line 891 of file StmtCXX.h.
References isDestructuring(), and clang::Stmt::Stmt().
Referenced by getDecompositionDecl(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 896 of file StmtCXX.h.
References isDestructuring(), and clang::Stmt::Stmt().
|
inline |
Definition at line 770 of file StmtCXX.h.
References getBody(), and clang::Stmt::getEndLoc().
|
inline |
Definition at line 912 of file StmtCXX.h.
References clang::cast(), and isDependent().
Referenced by clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 917 of file StmtCXX.h.
References clang::cast(), and isDependent().
| VarDecl * CXXExpansionStmtPattern::getExpansionVariable | ( | ) |
Definition at line 218 of file StmtCXX.cpp.
References clang::cast(), and getExpansionVarStmt().
Referenced by clang::Sema::ComputeExpansionSize(), getExpansionVariable(), and HasDependentSize().
|
inline |
Definition at line 799 of file StmtCXX.h.
References getExpansionVariable().
|
inline |
Definition at line 803 of file StmtCXX.h.
References clang::cast().
Referenced by getExpansionVariable(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 804 of file StmtCXX.h.
References clang::cast().
|
inline |
Definition at line 794 of file StmtCXX.h.
References clang::Stmt::Stmt().
Referenced by clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 795 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
inline |
Definition at line 885 of file StmtCXX.h.
References clang::cast(), getIterVarStmt(), and isIterating().
|
inline |
Definition at line 880 of file StmtCXX.h.
References clang::cast(), getIterVarStmt(), and isIterating().
|
inline |
Definition at line 870 of file StmtCXX.h.
References clang::cast(), and isIterating().
|
inline |
Definition at line 865 of file StmtCXX.h.
References clang::cast(), and isIterating().
Referenced by getIterVar(), getIterVar(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 774 of file StmtCXX.h.
Referenced by HasDependentSize(), clang::ASTNodeImporter::VisitCXXExpansionStmtPattern(), and clang::TextNodeDumper::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 766 of file StmtCXX.h.
Referenced by clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 788 of file StmtCXX.h.
References getNumSubStmts().
Referenced by children(), children(), and getNumSubStmts().
|
inline |
Definition at line 835 of file StmtCXX.h.
References clang::cast(), getRangeVarStmt(), and isIterating().
|
inline |
Definition at line 830 of file StmtCXX.h.
References clang::cast(), getRangeVarStmt(), and isIterating().
|
inline |
Definition at line 820 of file StmtCXX.h.
References clang::cast(), and isIterating().
|
inline |
Definition at line 815 of file StmtCXX.h.
References clang::cast(), and isIterating().
Referenced by getRangeVar(), getRangeVar(), and clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 768 of file StmtCXX.h.
Referenced by clang::ASTNodeImporter::VisitCXXExpansionStmtPattern().
|
inline |
Definition at line 775 of file StmtCXX.h.
References Dependent.
Referenced by getExpansionInitializer(), getExpansionInitializer(), and setExpansionInitializer().
|
inline |
Definition at line 784 of file StmtCXX.h.
References Destructuring.
Referenced by clang::Sema::ComputeExpansionSize(), getDecompositionDecl(), getDecompositionDeclStmt(), getDecompositionDeclStmt(), and setDecompositionDeclStmt().
|
inline |
Definition at line 778 of file StmtCXX.h.
References Enumerating.
Referenced by clang::Sema::ComputeExpansionSize().
|
inline |
Definition at line 781 of file StmtCXX.h.
References Iterating.
Referenced by clang::Sema::ComputeExpansionSize(), getBeginVar(), getBeginVar(), getBeginVarStmt(), getBeginVarStmt(), getIterVar(), getIterVar(), getIterVarStmt(), getIterVarStmt(), getRangeVar(), getRangeVar(), getRangeVarStmt(), getRangeVarStmt(), setBeginVarStmt(), setIterVarStmt(), and setRangeVarStmt().
|
inline |
Definition at line 850 of file StmtCXX.h.
References isIterating().
Referenced by CreateIterating().
|
inline |
Definition at line 812 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
inline |
Definition at line 901 of file StmtCXX.h.
References isDestructuring(), and clang::Stmt::Stmt().
Referenced by CreateDestructuring().
|
inline |
Definition at line 922 of file StmtCXX.h.
References isDependent().
Referenced by CreateDependent().
|
inline |
Definition at line 808 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
inline |
Definition at line 796 of file StmtCXX.h.
References clang::Stmt::Stmt().
|
inline |
Definition at line 875 of file StmtCXX.h.
References isIterating().
Referenced by CreateIterating().
|
inline |
Definition at line 825 of file StmtCXX.h.
References isIterating().
Referenced by CreateIterating().
|
friend |