@@ -5499,6 +5499,165 @@ class BuiltinBitCastExpr final
54995499 }
55005500};
55015501
5502+ // / Represents an expansion-init-list of an enumerating expansion statement.
5503+ // /
5504+ // / \see CXXEnumeratingExpansionStmtPattern
5505+ class CXXExpansionInitListExpr final
5506+ : public Expr,
5507+ llvm::TrailingObjects<CXXExpansionInitListExpr, Expr *> {
5508+ friend class ASTStmtReader ;
5509+ friend TrailingObjects;
5510+
5511+ const unsigned NumExprs;
5512+ SourceLocation LBraceLoc;
5513+ SourceLocation RBraceLoc;
5514+
5515+ CXXExpansionInitListExpr (EmptyShell ES, unsigned NumExprs);
5516+ CXXExpansionInitListExpr (ArrayRef<Expr *> Exprs, SourceLocation LBraceLoc,
5517+ SourceLocation RBraceLoc);
5518+
5519+ public:
5520+ static CXXExpansionInitListExpr *Create (const ASTContext &C,
5521+ ArrayRef<Expr *> Exprs,
5522+ SourceLocation LBraceLoc,
5523+ SourceLocation RBraceLoc);
5524+
5525+ static CXXExpansionInitListExpr *
5526+ CreateEmpty (const ASTContext &C, EmptyShell Empty, unsigned NumExprs);
5527+
5528+ ArrayRef<Expr *> getExprs () const { return getTrailingObjects (NumExprs); }
5529+ MutableArrayRef<Expr *> getExprs () { return getTrailingObjects (NumExprs); }
5530+ unsigned getNumExprs () const { return NumExprs; }
5531+
5532+ bool containsPackExpansion () const ;
5533+
5534+ SourceLocation getBeginLoc () const { return getLBraceLoc (); }
5535+ SourceLocation getEndLoc () const { return getRBraceLoc (); }
5536+
5537+ SourceLocation getLBraceLoc () const { return LBraceLoc; }
5538+ SourceLocation getRBraceLoc () const { return RBraceLoc; }
5539+
5540+ child_range children () {
5541+ const_child_range CCR =
5542+ const_cast <const CXXExpansionInitListExpr *>(this )->children ();
5543+ return child_range (cast_away_const (CCR.begin ()),
5544+ cast_away_const (CCR.end ()));
5545+ }
5546+
5547+ const_child_range children () const {
5548+ Stmt **Stmts = getTrailingStmts ();
5549+ return const_child_range (Stmts, Stmts + NumExprs);
5550+ }
5551+
5552+ static bool classof (const Stmt *T) {
5553+ return T->getStmtClass () == CXXExpansionInitListExprClass;
5554+ }
5555+
5556+ private:
5557+ Stmt **getTrailingStmts () const {
5558+ return reinterpret_cast <Stmt **>(const_cast <Expr **>(getTrailingObjects ()));
5559+ }
5560+ };
5561+
5562+ // / Helper that selects an expression from an expansion init list depending
5563+ // / on the current expansion index.
5564+ // /
5565+ // / \see CXXEnumeratingExpansionStmtPattern
5566+ class CXXExpansionInitListSelectExpr : public Expr {
5567+ friend class ASTStmtReader ;
5568+
5569+ enum SubExpr { RANGE, INDEX, COUNT };
5570+ Expr *SubExprs[COUNT];
5571+
5572+ public:
5573+ CXXExpansionInitListSelectExpr (EmptyShell Empty);
5574+ CXXExpansionInitListSelectExpr (const ASTContext &C,
5575+ CXXExpansionInitListExpr *Range, Expr *Idx);
5576+
5577+ CXXExpansionInitListExpr *getRangeExpr () {
5578+ return cast<CXXExpansionInitListExpr>(SubExprs[RANGE]);
5579+ }
5580+
5581+ const CXXExpansionInitListExpr *getRangeExpr () const {
5582+ return cast<CXXExpansionInitListExpr>(SubExprs[RANGE]);
5583+ }
5584+
5585+ void setRangeExpr (CXXExpansionInitListExpr *E) { SubExprs[RANGE] = E; }
5586+
5587+ Expr *getIndexExpr () { return SubExprs[INDEX]; }
5588+ const Expr *getIndexExpr () const { return SubExprs[INDEX]; }
5589+ void setIndexExpr (Expr *E) { SubExprs[INDEX] = E; }
5590+
5591+ SourceLocation getBeginLoc () const { return getRangeExpr ()->getBeginLoc (); }
5592+ SourceLocation getEndLoc () const { return getRangeExpr ()->getEndLoc (); }
5593+
5594+ child_range children () {
5595+ return child_range (reinterpret_cast <Stmt **>(SubExprs),
5596+ reinterpret_cast <Stmt **>(SubExprs + COUNT));
5597+ }
5598+
5599+ const_child_range children () const {
5600+ return const_child_range (
5601+ reinterpret_cast <Stmt **>(const_cast <Expr **>(SubExprs)),
5602+ reinterpret_cast <Stmt **>(const_cast <Expr **>(SubExprs + COUNT)));
5603+ }
5604+
5605+ static bool classof (const Stmt *T) {
5606+ return T->getStmtClass () == CXXExpansionInitListSelectExprClass;
5607+ }
5608+ };
5609+
5610+ // / This class serves the same purpose as CXXExpansionInitListSelectExpr, but
5611+ // / for destructuring expansion statements; that is, instead of selecting among
5612+ // / a list of expressions, it selects from a list of 'BindingDecl's.
5613+ // /
5614+ // / \see CXXEnumeratingExpansionStmtPattern
5615+ // / \see CXXDestructuringExpansionStmtPattern
5616+ class CXXDestructuringExpansionSelectExpr : public Expr {
5617+ friend class ASTStmtReader ;
5618+
5619+ DecompositionDecl *Decomposition;
5620+ Expr *Index;
5621+
5622+ public:
5623+ CXXDestructuringExpansionSelectExpr (EmptyShell Empty);
5624+ CXXDestructuringExpansionSelectExpr (const ASTContext &C,
5625+ DecompositionDecl *Decomposition,
5626+ Expr *Index);
5627+
5628+ DecompositionDecl *getDecompositionDecl () {
5629+ return cast<DecompositionDecl>(Decomposition);
5630+ }
5631+
5632+ const DecompositionDecl *getDecompositionDecl () const {
5633+ return cast<DecompositionDecl>(Decomposition);
5634+ }
5635+
5636+ void setDecompositionDecl (DecompositionDecl *E) { Decomposition = E; }
5637+
5638+ Expr *getIndexExpr () { return Index; }
5639+ const Expr *getIndexExpr () const { return Index; }
5640+ void setIndexExpr (Expr *E) { Index = E; }
5641+
5642+ SourceLocation getBeginLoc () const { return Decomposition->getBeginLoc (); }
5643+ SourceLocation getEndLoc () const { return Decomposition->getEndLoc (); }
5644+
5645+ child_range children () {
5646+ return child_range (reinterpret_cast <Stmt **>(&Index),
5647+ reinterpret_cast <Stmt **>(&Index + 1 ));
5648+ }
5649+
5650+ const_child_range children () const {
5651+ return const_child_range (
5652+ reinterpret_cast <Stmt **>(const_cast <Expr **>(&Index)),
5653+ reinterpret_cast <Stmt **>(const_cast <Expr **>(&Index + 1 )));
5654+ }
5655+
5656+ static bool classof (const Stmt *T) {
5657+ return T->getStmtClass () == CXXDestructuringExpansionSelectExprClass;
5658+ }
5659+ };
5660+
55025661} // namespace clang
55035662
55045663#endif // LLVM_CLANG_AST_EXPRCXX_H
0 commit comments