Skip to content

Commit 988067e

Browse files
authored
Merge pull request #13902 from xedin/dedup-param-list-getters
[AST] NFC: Add ParameterList::getType accessor which supports callback for param types
2 parents bdbcb80 + 5c33809 commit 988067e

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

include/swift/AST/ParameterList.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class alignas(ParamDecl *) ParameterList final :
142142
ParameterList *clone(const ASTContext &C,
143143
OptionSet<CloneFlags> options = None) const;
144144

145+
/// Return a TupleType or ParenType for this parameter list,
146+
/// based on types provided by a callback.
147+
Type getType(const ASTContext &C,
148+
llvm::function_ref<Type(ParamDecl *)> getType) const;
149+
145150
/// Return a TupleType or ParenType for this parameter list, written in terms
146151
/// of contextual archetypes.
147152
Type getType(const ASTContext &C) const;

lib/AST/Parameter.cpp

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -116,43 +116,40 @@ ParameterList *ParameterList::clone(const ASTContext &C,
116116
return create(C, params);
117117
}
118118

119-
/// Return a TupleType or ParenType for this parameter list, written in terms
120-
/// of contextual archetypes.
121-
Type ParameterList::getType(const ASTContext &C) const {
119+
/// Return a TupleType or ParenType for this parameter list,
120+
/// based on types provided by a callback.
121+
Type ParameterList::getType(
122+
const ASTContext &C, llvm::function_ref<Type(ParamDecl *)> getType) const {
122123
if (size() == 0)
123124
return TupleType::getEmpty(C);
124-
125+
125126
SmallVector<TupleTypeElt, 8> argumentInfo;
126-
127+
127128
for (auto P : *this) {
128-
auto type = P->getType();
129-
130-
argumentInfo.emplace_back(
131-
type->getInOutObjectType(), P->getArgumentName(),
132-
ParameterTypeFlags::fromParameterType(type, P->isVariadic(), P->isShared()).withInOut(P->isInOut()));
129+
auto type = getType(P);
130+
argumentInfo.emplace_back(type->getInOutObjectType(), P->getArgumentName(),
131+
ParameterTypeFlags::fromParameterType(
132+
type, P->isVariadic(), P->isShared())
133+
.withInOut(P->isInOut()));
133134
}
134135

135136
return TupleType::get(argumentInfo, C);
136137
}
137138

139+
/// Return a TupleType or ParenType for this parameter list, written in terms
140+
/// of contextual archetypes.
141+
Type ParameterList::getType(const ASTContext &C) const {
142+
return getType(C, [](ParamDecl *P) { return P->getType(); });
143+
}
144+
138145
/// Return a TupleType or ParenType for this parameter list, written in terms
139146
/// of interface types.
140147
Type ParameterList::getInterfaceType(const ASTContext &C) const {
141-
if (size() == 0)
142-
return TupleType::getEmpty(C);
143-
144-
SmallVector<TupleTypeElt, 8> argumentInfo;
145-
146-
for (auto P : *this) {
148+
return getType(C, [](ParamDecl *P) {
147149
auto type = P->getInterfaceType();
148150
assert(!type->hasArchetype());
149-
150-
argumentInfo.emplace_back(
151-
type->getInOutObjectType(), P->getArgumentName(),
152-
ParameterTypeFlags::fromParameterType(type, P->isVariadic(), P->isShared()).withInOut(P->isInOut()));
153-
}
154-
155-
return TupleType::get(argumentInfo, C);
151+
return type;
152+
});
156153
}
157154

158155

0 commit comments

Comments
 (0)