Skip to content

Commit 37412c2

Browse files
committed
AST: Add ParamDecl::toFunctionParam()
1 parent 4e3dafd commit 37412c2

File tree

5 files changed

+23
-32
lines changed

5 files changed

+23
-32
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5323,6 +5323,8 @@ class ParamDecl : public VarDecl {
53235323

53245324
SourceRange getSourceRange() const;
53255325

5326+
AnyFunctionType::Param toFunctionParam(Type type = Type()) const;
5327+
53265328
// Implement isa/cast/dyncast/etc.
53275329
static bool classof(const Decl *D) {
53285330
return D->getKind() == DeclKind::Param;

include/swift/AST/ParameterList.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ class alignas(ParamDecl *) ParameterList final :
127127
/// based on the interface types of the parameters in this list.
128128
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params) const;
129129

130-
/// Return a list of function parameters for this parameter list,
131-
/// based on types provided by a callback.
132-
void getParams(SmallVectorImpl<AnyFunctionType::Param> &params,
133-
llvm::function_ref<Type(ParamDecl *)> getType) const;
134-
135-
136130
/// Return the full source range of this parameter.
137131
SourceRange getSourceRange() const;
138132
SourceLoc getStartLoc() const { return getSourceRange().Start; }

lib/AST/Decl.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5673,6 +5673,21 @@ Type ParamDecl::getVarargBaseTy(Type VarArgT) {
56735673
return T;
56745674
}
56755675

5676+
AnyFunctionType::Param ParamDecl::toFunctionParam(Type type) const {
5677+
if (!type)
5678+
type = getInterfaceType();
5679+
5680+
if (isVariadic())
5681+
type = ParamDecl::getVarargBaseTy(type);
5682+
5683+
auto label = getArgumentName();
5684+
auto flags = ParameterTypeFlags::fromParameterType(type,
5685+
isVariadic(),
5686+
isAutoClosure(),
5687+
getValueOwnership());
5688+
return AnyFunctionType::Param(type, label, flags);
5689+
}
5690+
56765691
void ParamDecl::setDefaultValue(Expr *E) {
56775692
if (!DefaultValueAndFlags.getPointer()) {
56785693
if (!E) return;

lib/AST/Parameter.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,8 @@ ParameterList *ParameterList::clone(const ASTContext &C,
8989

9090
void ParameterList::getParams(
9191
SmallVectorImpl<AnyFunctionType::Param> &params) const {
92-
getParams(params,
93-
[](ParamDecl *decl) { return decl->getInterfaceType(); });
94-
}
95-
96-
void ParameterList::getParams(
97-
SmallVectorImpl<AnyFunctionType::Param> &params,
98-
llvm::function_ref<Type(ParamDecl *)> getType) const {
99-
if (size() == 0)
100-
return;
101-
102-
for (auto P : *this) {
103-
auto type = getType(P);
104-
105-
if (P->isVariadic())
106-
type = ParamDecl::getVarargBaseTy(type);
107-
108-
auto label = P->getArgumentName();
109-
auto flags = ParameterTypeFlags::fromParameterType(type,
110-
P->isVariadic(),
111-
P->isAutoClosure(),
112-
P->getValueOwnership());
113-
params.emplace_back(type, label, flags);
114-
}
92+
for (auto P : *this)
93+
params.push_back(P->toFunctionParam());
11594
}
11695

11796

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,8 @@ namespace {
20362036
SmallVectorImpl<AnyFunctionType::Param> &params) {
20372037
auto *paramList = closureExpr->getParameters();
20382038
unsigned i = 0;
2039-
paramList->getParams(params, [&](ParamDecl *param) {
2039+
2040+
for (auto *param : *paramList) {
20402041
auto *locator = CS.getConstraintLocator(
20412042
closureExpr, LocatorPathElt::getTupleElement(i++));
20422043
Type paramType, internalType;
@@ -2058,8 +2059,8 @@ namespace {
20582059
locator);
20592060
}
20602061
CS.setType(param, internalType);
2061-
return paramType;
2062-
});
2062+
params.push_back(param->toFunctionParam(paramType));
2063+
}
20632064
}
20642065

20652066
/// Produces a type for the given pattern, filling in any missing

0 commit comments

Comments
 (0)