-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Clang][P1061] Consolidate ResolvedUnpexandedPackExpr into FunctionParmPackExpr #125394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a323e05
96b0096
f6a77d4
588dbe9
3b8bece
802e5cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4633,8 +4633,8 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { | |
} | ||
}; | ||
|
||
/// Represents a reference to a function parameter pack or init-capture pack | ||
/// that has been substituted but not yet expanded. | ||
/// Represents a reference to a function parameter pack, init-capture pack, | ||
/// or binding pack that has been substituted but not yet expanded. | ||
/// | ||
/// When a pack expansion contains multiple parameter packs at different levels, | ||
/// this node is used to represent a function parameter pack at an outer level | ||
|
@@ -4649,49 +4649,48 @@ class SubstNonTypeTemplateParmPackExpr : public Expr { | |
/// \endcode | ||
class FunctionParmPackExpr final | ||
: public Expr, | ||
private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> { | ||
private llvm::TrailingObjects<FunctionParmPackExpr, ValueDecl *> { | ||
Comment on lines
4650
to
+4652
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also update the attached comments to reflect it now supports structure binding pack? |
||
friend class ASTReader; | ||
friend class ASTStmtReader; | ||
friend TrailingObjects; | ||
|
||
/// The function parameter pack which was referenced. | ||
VarDecl *ParamPack; | ||
ValueDecl *ParamPack; | ||
|
||
/// The location of the function parameter pack reference. | ||
SourceLocation NameLoc; | ||
|
||
/// The number of expansions of this pack. | ||
unsigned NumParameters; | ||
|
||
FunctionParmPackExpr(QualType T, VarDecl *ParamPack, | ||
SourceLocation NameLoc, unsigned NumParams, | ||
VarDecl *const *Params); | ||
FunctionParmPackExpr(QualType T, ValueDecl *ParamPack, SourceLocation NameLoc, | ||
unsigned NumParams, ValueDecl *const *Params); | ||
|
||
public: | ||
static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, | ||
VarDecl *ParamPack, | ||
ValueDecl *ParamPack, | ||
SourceLocation NameLoc, | ||
ArrayRef<VarDecl *> Params); | ||
ArrayRef<ValueDecl *> Params); | ||
static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, | ||
unsigned NumParams); | ||
|
||
/// Get the parameter pack which this expression refers to. | ||
VarDecl *getParameterPack() const { return ParamPack; } | ||
ValueDecl *getParameterPack() const { return ParamPack; } | ||
|
||
/// Get the location of the parameter pack. | ||
SourceLocation getParameterPackLocation() const { return NameLoc; } | ||
|
||
/// Iterators over the parameters which the parameter pack expanded | ||
/// into. | ||
using iterator = VarDecl * const *; | ||
iterator begin() const { return getTrailingObjects<VarDecl *>(); } | ||
using iterator = ValueDecl *const *; | ||
iterator begin() const { return getTrailingObjects<ValueDecl *>(); } | ||
iterator end() const { return begin() + NumParameters; } | ||
|
||
/// Get the number of parameters in this parameter pack. | ||
unsigned getNumExpansions() const { return NumParameters; } | ||
|
||
/// Get an expansion of the parameter pack by index. | ||
VarDecl *getExpansion(unsigned I) const { return begin()[I]; } | ||
ValueDecl *getExpansion(unsigned I) const { return begin()[I]; } | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; } | ||
SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; } | ||
|
@@ -5319,59 +5318,6 @@ class BuiltinBitCastExpr final | |
} | ||
}; | ||
|
||
// Represents an unexpanded pack where the list of expressions are | ||
// known. These are used when structured bindings introduce a pack. | ||
class ResolvedUnexpandedPackExpr final | ||
: public Expr, | ||
private llvm::TrailingObjects<ResolvedUnexpandedPackExpr, Expr *> { | ||
friend class ASTStmtReader; | ||
friend class ASTStmtWriter; | ||
friend TrailingObjects; | ||
|
||
SourceLocation BeginLoc; | ||
unsigned NumExprs; | ||
|
||
ResolvedUnexpandedPackExpr(SourceLocation BL, QualType QT, unsigned NumExprs); | ||
|
||
public: | ||
static ResolvedUnexpandedPackExpr *CreateDeserialized(ASTContext &C, | ||
unsigned NumExprs); | ||
static ResolvedUnexpandedPackExpr * | ||
Create(ASTContext &C, SourceLocation BeginLoc, QualType T, unsigned NumExprs); | ||
static ResolvedUnexpandedPackExpr *Create(ASTContext &C, | ||
SourceLocation BeginLoc, QualType T, | ||
llvm::ArrayRef<Expr *> Exprs); | ||
|
||
unsigned getNumExprs() const { return NumExprs; } | ||
|
||
llvm::MutableArrayRef<Expr *> getExprs() { | ||
return {getTrailingObjects<Expr *>(), NumExprs}; | ||
} | ||
|
||
llvm::ArrayRef<Expr *> getExprs() const { | ||
return {getTrailingObjects<Expr *>(), NumExprs}; | ||
} | ||
|
||
Expr *getExpansion(unsigned Idx) { return getExprs()[Idx]; } | ||
Expr *getExpansion(unsigned Idx) const { return getExprs()[Idx]; } | ||
|
||
// Iterators | ||
child_range children() { | ||
return child_range((Stmt **)getTrailingObjects<Expr *>(), | ||
(Stmt **)getTrailingObjects<Expr *>() + getNumExprs()); | ||
} | ||
|
||
SourceLocation getBeginLoc() const LLVM_READONLY { return BeginLoc; } | ||
SourceLocation getEndLoc() const LLVM_READONLY { return BeginLoc; } | ||
|
||
// Returns the resolved pack of a decl or nullptr | ||
static ResolvedUnexpandedPackExpr *getFromDecl(Decl *); | ||
|
||
static bool classof(const Stmt *T) { | ||
return T->getStmtClass() == ResolvedUnexpandedPackExprClass; | ||
} | ||
}; | ||
|
||
} // namespace clang | ||
|
||
#endif // LLVM_CLANG_AST_EXPRCXX_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3492,10 +3492,13 @@ VarDecl *BindingDecl::getHoldingVar() const { | |
return VD; | ||
} | ||
|
||
llvm::ArrayRef<Expr *> BindingDecl::getBindingPackExprs() const { | ||
llvm::ArrayRef<BindingDecl *> BindingDecl::getBindingPackDecls() const { | ||
assert(Binding && "expecting a pack expr"); | ||
auto *RP = cast<ResolvedUnexpandedPackExpr>(Binding); | ||
return RP->getExprs(); | ||
auto *FP = cast<FunctionParmPackExpr>(Binding); | ||
ValueDecl *const *First = FP->getNumExpansions() > 0 ? FP->begin() : nullptr; | ||
assert((!First || isa<BindingDecl>(*First)) && "expecting a BindingDecl"); | ||
return llvm::ArrayRef<BindingDecl *>( | ||
reinterpret_cast<BindingDecl *const *>(First), FP->getNumExpansions()); | ||
Comment on lines
+3500
to
+3501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we use llvm::cast here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
} | ||
|
||
void DecompositionDecl::anchor() {} | ||
|
Uh oh!
There was an error while loading. Please reload this page.