@@ -4331,6 +4331,105 @@ class SizeOfPackExpr final
4331
4331
}
4332
4332
};
4333
4333
4334
+ class PackIndexingExpr final
4335
+ : public Expr,
4336
+ private llvm::TrailingObjects<PackIndexingExpr, Expr *> {
4337
+ friend class ASTStmtReader ;
4338
+ friend class ASTStmtWriter ;
4339
+ friend TrailingObjects;
4340
+
4341
+ SourceLocation EllipsisLoc;
4342
+
4343
+ // The location of the closing bracket
4344
+ SourceLocation RSquareLoc;
4345
+
4346
+ // The pack being indexed, followed by the index
4347
+ Stmt *SubExprs[2 ];
4348
+
4349
+ size_t TransformedExpressions;
4350
+
4351
+ PackIndexingExpr (QualType Type, SourceLocation EllipsisLoc,
4352
+ SourceLocation RSquareLoc, Expr *PackIdExpr, Expr *IndexExpr,
4353
+ ArrayRef<Expr *> SubstitutedExprs = {})
4354
+ : Expr(PackIndexingExprClass, Type, VK_LValue, OK_Ordinary),
4355
+ EllipsisLoc (EllipsisLoc), RSquareLoc(RSquareLoc),
4356
+ SubExprs{PackIdExpr, IndexExpr},
4357
+ TransformedExpressions (SubstitutedExprs.size()) {
4358
+
4359
+ auto *Exprs = getTrailingObjects<Expr *>();
4360
+ std::uninitialized_copy (SubstitutedExprs.begin (), SubstitutedExprs.end (),
4361
+ Exprs);
4362
+
4363
+ setDependence (computeDependence (this ));
4364
+ if (!isInstantiationDependent ())
4365
+ setValueKind (getSelectedExpr ()->getValueKind ());
4366
+ }
4367
+
4368
+ // / Create an empty expression.
4369
+ PackIndexingExpr (EmptyShell Empty) : Expr(PackIndexingExprClass, Empty) {}
4370
+
4371
+ unsigned numTrailingObjects (OverloadToken<Expr *>) const {
4372
+ return TransformedExpressions;
4373
+ }
4374
+
4375
+ public:
4376
+ static PackIndexingExpr *Create (ASTContext &Context,
4377
+ SourceLocation EllipsisLoc,
4378
+ SourceLocation RSquareLoc, Expr *PackIdExpr,
4379
+ Expr *IndexExpr, std::optional<int64_t > Index,
4380
+ ArrayRef<Expr *> SubstitutedExprs = {});
4381
+ static PackIndexingExpr *CreateDeserialized (ASTContext &Context,
4382
+ unsigned NumTransformedExprs);
4383
+
4384
+ // / Determine the location of the 'sizeof' keyword.
4385
+ SourceLocation getEllipsisLoc () const { return EllipsisLoc; }
4386
+
4387
+ // / Determine the location of the parameter pack.
4388
+ SourceLocation getPackLoc () const { return SubExprs[0 ]->getBeginLoc (); }
4389
+
4390
+ // / Determine the location of the right parenthesis.
4391
+ SourceLocation getRSquareLoc () const { return RSquareLoc; }
4392
+
4393
+ SourceLocation getBeginLoc () const LLVM_READONLY { return getPackLoc (); }
4394
+ SourceLocation getEndLoc () const LLVM_READONLY { return RSquareLoc; }
4395
+
4396
+ Expr *getPackIdExpression () const { return cast<Expr>(SubExprs[0 ]); }
4397
+
4398
+ NamedDecl *getPackDecl () const ;
4399
+
4400
+ Expr *getIndexExpr () const { return cast<Expr>(SubExprs[1 ]); }
4401
+
4402
+ std::optional<unsigned > getSelectedIndex () const {
4403
+ if (isInstantiationDependent ())
4404
+ return std::nullopt ;
4405
+ ConstantExpr *CE = cast<ConstantExpr>(getIndexExpr ());
4406
+ auto Index = CE->getResultAsAPSInt ();
4407
+ assert (Index.isNonNegative () && " Invalid index" );
4408
+ return static_cast <unsigned >(Index.getExtValue ());
4409
+ }
4410
+
4411
+ Expr *getSelectedExpr () const {
4412
+ std::optional<unsigned > Index = getSelectedIndex ();
4413
+ assert (Index && " extracting the indexed expression of a dependant pack" );
4414
+ return getTrailingObjects<Expr *>()[*Index];
4415
+ }
4416
+
4417
+ ArrayRef<Expr *> getExpressions () const {
4418
+ return {getTrailingObjects<Expr *>(), TransformedExpressions};
4419
+ }
4420
+
4421
+ static bool classof (const Stmt *T) {
4422
+ return T->getStmtClass () == PackIndexingExprClass;
4423
+ }
4424
+
4425
+ // Iterators
4426
+ child_range children () { return child_range (SubExprs, SubExprs + 2 ); }
4427
+
4428
+ const_child_range children () const {
4429
+ return const_child_range (SubExprs, SubExprs + 2 );
4430
+ }
4431
+ };
4432
+
4334
4433
// / Represents a reference to a non-type template parameter
4335
4434
// / that has been substituted with a template argument.
4336
4435
class SubstNonTypeTemplateParmExpr : public Expr {
0 commit comments