Extract HeaderInfo base class and add NumericHeaderInfo class, in
preparation for handling withIndex().
This commit is contained in:
committed by
max-kammerer
parent
2ab539c5eb
commit
735535dd5a
+13
-11
@@ -67,7 +67,16 @@ internal enum class ProgressionDirection {
|
||||
}
|
||||
|
||||
/** Information about a loop that is required by [HeaderProcessor] to build a [ForLoopHeader]. */
|
||||
internal sealed class HeaderInfo(
|
||||
internal sealed class HeaderInfo {
|
||||
/**
|
||||
* Returns a copy of this [HeaderInfo] with the values reversed.
|
||||
* I.e., first and last are swapped, step is negated.
|
||||
* Returns null if the iterable cannot be iterated in reverse.
|
||||
*/
|
||||
abstract fun asReversed(): HeaderInfo?
|
||||
}
|
||||
|
||||
internal sealed class NumericHeaderInfo(
|
||||
val progressionType: ProgressionType,
|
||||
val first: IrExpression,
|
||||
val last: IrExpression,
|
||||
@@ -76,14 +85,7 @@ internal sealed class HeaderInfo(
|
||||
val isReversed: Boolean,
|
||||
val direction: ProgressionDirection,
|
||||
val additionalNotEmptyCondition: IrExpression?
|
||||
) {
|
||||
/**
|
||||
* Returns a copy of this [HeaderInfo] with the values reversed.
|
||||
* I.e., first and last are swapped, step is negated.
|
||||
* Returns null if the iterable cannot be iterated in reverse.
|
||||
*/
|
||||
abstract fun asReversed(): HeaderInfo?
|
||||
}
|
||||
) : HeaderInfo()
|
||||
|
||||
/** Information about a for-loop over a progression. */
|
||||
internal class ProgressionHeaderInfo(
|
||||
@@ -96,7 +98,7 @@ internal class ProgressionHeaderInfo(
|
||||
direction: ProgressionDirection,
|
||||
additionalNotEmptyCondition: IrExpression? = null,
|
||||
val additionalVariables: List<IrVariable> = listOf()
|
||||
) : HeaderInfo(
|
||||
) : NumericHeaderInfo(
|
||||
progressionType, first, last, step,
|
||||
canCacheLast = true,
|
||||
isReversed = isReversed,
|
||||
@@ -175,7 +177,7 @@ internal class IndexedGetHeaderInfo(
|
||||
canCacheLast: Boolean = true,
|
||||
val objectVariable: IrVariable,
|
||||
val expressionHandler: IndexedGetIterationHandler
|
||||
) : HeaderInfo(
|
||||
) : NumericHeaderInfo(
|
||||
ProgressionType.INT_PROGRESSION,
|
||||
first,
|
||||
last,
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ internal interface ForLoopHeader {
|
||||
}
|
||||
|
||||
internal abstract class NumericForLoopHeader(
|
||||
headerInfo: HeaderInfo,
|
||||
headerInfo: NumericHeaderInfo,
|
||||
builder: DeclarationIrBuilder,
|
||||
protected val isLastInclusive: Boolean
|
||||
) : ForLoopHeader {
|
||||
@@ -123,7 +123,7 @@ internal abstract class NumericForLoopHeader(
|
||||
// This cannot be declared and initialized directly in the constructor. At the time of the base class (ForLoopHeader) constructor
|
||||
// execution, the `headerInfo` property overridden in the derived class (e.g., NumericForLoopHeader) is not yet initialized.
|
||||
// Therefore, we must use the `headerInfo` constructor parameter in the "init" block above instead of using the property.
|
||||
protected open val headerInfo: HeaderInfo = headerInfo
|
||||
protected open val headerInfo: NumericHeaderInfo = headerInfo
|
||||
|
||||
private fun DeclarationIrBuilder.ensureNotNullable(expression: IrExpression) =
|
||||
if (expression.type is IrSimpleType && expression.type.isNullable()) {
|
||||
|
||||
Reference in New Issue
Block a user