Skip to content

Commit cb66dab

Browse files
committed
AST: Add getNextDepth() and getMaxDepth() methods to GenericSignature
1 parent 865b155 commit cb66dab

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

include/swift/AST/GenericSignature.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ class GenericSignature {
197197
/// array of the generic parameters for the innermost generic type.
198198
ArrayRef<GenericTypeParamType *> getInnermostGenericParams() const;
199199

200+
/// Returns the depth that a generic parameter at the next level of
201+
/// nesting would have. This is zero for the empty signature,
202+
/// and one plus the depth of the final generic parameter otherwise.
203+
unsigned getNextDepth() const;
204+
200205
/// Retrieve the requirements.
201206
ArrayRef<Requirement> getRequirements() const;
202207

@@ -307,6 +312,9 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
307312
return Mem;
308313
}
309314

315+
/// Returns the depth of the last generic parameter.
316+
unsigned getMaxDepth() const;
317+
310318
/// Transform the requirements into a form where implicit Copyable and
311319
/// Escapable conformances are omitted, and their absence is explicitly
312320
/// noted.

lib/AST/GenericSignature.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ GenericSignatureImpl::getInnermostGenericParams() const {
9595
return params.slice(sliceCount);
9696
}
9797

98+
unsigned GenericSignatureImpl::getMaxDepth() const {
99+
return getGenericParams().back()->getDepth();
100+
}
101+
102+
unsigned GenericSignature::getNextDepth() const {
103+
if (!getPointer())
104+
return 0;
105+
return getPointer()->getMaxDepth() + 1;
106+
}
107+
98108
void GenericSignatureImpl::forEachParam(
99109
llvm::function_ref<void(GenericTypeParamType *, bool)> callback) const {
100110
// Figure out which generic parameters are concrete or same-typed to another

0 commit comments

Comments
 (0)