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]. */
|
/** 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 progressionType: ProgressionType,
|
||||||
val first: IrExpression,
|
val first: IrExpression,
|
||||||
val last: IrExpression,
|
val last: IrExpression,
|
||||||
@@ -76,14 +85,7 @@ internal sealed class HeaderInfo(
|
|||||||
val isReversed: Boolean,
|
val isReversed: Boolean,
|
||||||
val direction: ProgressionDirection,
|
val direction: ProgressionDirection,
|
||||||
val additionalNotEmptyCondition: IrExpression?
|
val additionalNotEmptyCondition: IrExpression?
|
||||||
) {
|
) : 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?
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Information about a for-loop over a progression. */
|
/** Information about a for-loop over a progression. */
|
||||||
internal class ProgressionHeaderInfo(
|
internal class ProgressionHeaderInfo(
|
||||||
@@ -96,7 +98,7 @@ internal class ProgressionHeaderInfo(
|
|||||||
direction: ProgressionDirection,
|
direction: ProgressionDirection,
|
||||||
additionalNotEmptyCondition: IrExpression? = null,
|
additionalNotEmptyCondition: IrExpression? = null,
|
||||||
val additionalVariables: List<IrVariable> = listOf()
|
val additionalVariables: List<IrVariable> = listOf()
|
||||||
) : HeaderInfo(
|
) : NumericHeaderInfo(
|
||||||
progressionType, first, last, step,
|
progressionType, first, last, step,
|
||||||
canCacheLast = true,
|
canCacheLast = true,
|
||||||
isReversed = isReversed,
|
isReversed = isReversed,
|
||||||
@@ -175,7 +177,7 @@ internal class IndexedGetHeaderInfo(
|
|||||||
canCacheLast: Boolean = true,
|
canCacheLast: Boolean = true,
|
||||||
val objectVariable: IrVariable,
|
val objectVariable: IrVariable,
|
||||||
val expressionHandler: IndexedGetIterationHandler
|
val expressionHandler: IndexedGetIterationHandler
|
||||||
) : HeaderInfo(
|
) : NumericHeaderInfo(
|
||||||
ProgressionType.INT_PROGRESSION,
|
ProgressionType.INT_PROGRESSION,
|
||||||
first,
|
first,
|
||||||
last,
|
last,
|
||||||
|
|||||||
+2
-2
@@ -53,7 +53,7 @@ internal interface ForLoopHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal abstract class NumericForLoopHeader(
|
internal abstract class NumericForLoopHeader(
|
||||||
headerInfo: HeaderInfo,
|
headerInfo: NumericHeaderInfo,
|
||||||
builder: DeclarationIrBuilder,
|
builder: DeclarationIrBuilder,
|
||||||
protected val isLastInclusive: Boolean
|
protected val isLastInclusive: Boolean
|
||||||
) : ForLoopHeader {
|
) : 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
|
// 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.
|
// 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.
|
// 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) =
|
private fun DeclarationIrBuilder.ensureNotNullable(expression: IrExpression) =
|
||||||
if (expression.type is IrSimpleType && expression.type.isNullable()) {
|
if (expression.type is IrSimpleType && expression.type.isNullable()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user