Fir2IrVisitor: simplify creating for-loop blocks due to changed FIR side
This commit is contained in:
@@ -86,7 +86,7 @@ class Fir2IrVisitor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun FirDeclaration.toIrDeclaration(): IrDeclaration? =
|
private fun FirDeclaration.toIrDeclaration(): IrDeclaration =
|
||||||
accept(this@Fir2IrVisitor, null) as IrDeclaration
|
accept(this@Fir2IrVisitor, null) as IrDeclaration
|
||||||
|
|
||||||
// ==================================================================================
|
// ==================================================================================
|
||||||
@@ -449,7 +449,9 @@ class Fir2IrVisitor(
|
|||||||
|
|
||||||
internal fun convertToIrExpression(expression: FirExpression, annotationMode: Boolean = false): IrExpression {
|
internal fun convertToIrExpression(expression: FirExpression, annotationMode: Boolean = false): IrExpression {
|
||||||
return when (expression) {
|
return when (expression) {
|
||||||
is FirBlock -> expression.convertToIrExpressionOrBlock()
|
is FirBlock -> expression.convertToIrExpressionOrBlock(
|
||||||
|
if (expression.source?.kind == FirFakeSourceElementKind.DesugaredForLoop) IrStatementOrigin.FOR_LOOP else null
|
||||||
|
)
|
||||||
is FirUnitExpression -> expression.convertWithOffsets { startOffset, endOffset ->
|
is FirUnitExpression -> expression.convertWithOffsets { startOffset, endOffset ->
|
||||||
IrGetObjectValueImpl(
|
IrGetObjectValueImpl(
|
||||||
startOffset, endOffset, irBuiltIns.unitType,
|
startOffset, endOffset, irBuiltIns.unitType,
|
||||||
@@ -502,26 +504,7 @@ class Fir2IrVisitor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun FirBlock.mapToIrStatements(): List<IrStatement?> {
|
private fun FirBlock.mapToIrStatements(): List<IrStatement?> {
|
||||||
val irRawStatements = statements.map { it.toIrStatement() }
|
return statements.map { it.toIrStatement() }
|
||||||
val result = mutableListOf<IrStatement?>()
|
|
||||||
var missNext = false
|
|
||||||
for ((index, irRawStatement) in irRawStatements.withIndex()) {
|
|
||||||
if (missNext) {
|
|
||||||
missNext = false
|
|
||||||
continue
|
|
||||||
} else if (irRawStatement is IrVariable && irRawStatement.origin == IrDeclarationOrigin.FOR_LOOP_ITERATOR) {
|
|
||||||
missNext = true
|
|
||||||
val irNextStatement = irRawStatements[index + 1]!!
|
|
||||||
result += IrBlockImpl(
|
|
||||||
irRawStatement.startOffset, irNextStatement.endOffset,
|
|
||||||
(irNextStatement as IrExpression).type, IrStatementOrigin.FOR_LOOP,
|
|
||||||
listOf(irRawStatement, irNextStatement)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
result += irRawStatement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun convertToIrBlockBody(block: FirBlock): IrBlockBody {
|
internal fun convertToIrBlockBody(block: FirBlock): IrBlockBody {
|
||||||
@@ -551,7 +534,9 @@ class Fir2IrVisitor(
|
|||||||
private fun FirBlock.convertToIrExpressionOrBlock(origin: IrStatementOrigin? = null): IrExpression {
|
private fun FirBlock.convertToIrExpressionOrBlock(origin: IrStatementOrigin? = null): IrExpression {
|
||||||
if (statements.size == 1) {
|
if (statements.size == 1) {
|
||||||
val firStatement = statements.single()
|
val firStatement = statements.single()
|
||||||
if (firStatement is FirExpression) {
|
if (firStatement is FirExpression &&
|
||||||
|
(firStatement !is FirBlock || firStatement.source?.kind != FirFakeSourceElementKind.DesugaredForLoop)
|
||||||
|
) {
|
||||||
return convertToIrExpression(firStatement)
|
return convertToIrExpression(firStatement)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user