mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[GenericEnvironment] Add a method to retrieve the bindings from pack element
archetypes to their originating pack archetypes.
This commit is contained in:
@@ -125,6 +125,33 @@ UUID GenericEnvironment::getOpenedElementUUID() const {
|
||||
return getTrailingObjects<OpenedElementEnvironmentData>()->uuid;
|
||||
}
|
||||
|
||||
void GenericEnvironment::getPackElementBindings(
|
||||
SmallVectorImpl<PackElementBinding> &bindings) const {
|
||||
auto packElements = getGenericSignature().getInnermostGenericParams();
|
||||
auto packElementDepth = packElements.front()->getDepth();
|
||||
auto elementIt = packElements.begin();
|
||||
|
||||
// Each parameter pack in the outer generic parameters has
|
||||
// a corresponding pack element parameter at the innermost
|
||||
// depth.
|
||||
for (auto *genericParam : getGenericParams()) {
|
||||
if (genericParam->getDepth() == packElementDepth)
|
||||
break;
|
||||
|
||||
if (!genericParam->isParameterPack())
|
||||
continue;
|
||||
|
||||
assert(elementIt != packElements.end());
|
||||
auto *elementArchetype =
|
||||
mapTypeIntoContext(*elementIt++)->getAs<ElementArchetypeType>();
|
||||
auto *packArchetype =
|
||||
mapTypeIntoContext(genericParam)->getAs<PackArchetypeType>();
|
||||
|
||||
assert(elementArchetype && packArchetype);
|
||||
bindings.emplace_back(elementArchetype, packArchetype);
|
||||
}
|
||||
}
|
||||
|
||||
GenericEnvironment::GenericEnvironment(GenericSignature signature)
|
||||
: SignatureAndKind(signature, Kind::Primary)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user