[JS IR] Improve debug info for if and when statements

#KT-46276
This commit is contained in:
Sergej Jaskiewicz
2022-10-31 14:18:10 +01:00
committed by Space Team
parent ccbb2a08a0
commit 4ae03ea74a
9 changed files with 53 additions and 24 deletions
@@ -157,9 +157,29 @@ object JsIrBuilder {
fun buildBreak(type: IrType, loop: IrLoop) = IrBreakImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop)
fun buildContinue(type: IrType, loop: IrLoop) = IrContinueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, loop)
fun buildIfElse(type: IrType, cond: IrExpression, thenBranch: IrExpression, elseBranch: IrExpression? = null): IrWhen = buildIfElse(
UNDEFINED_OFFSET, UNDEFINED_OFFSET, type, cond, thenBranch, elseBranch, JsStatementOrigins.SYNTHESIZED_STATEMENT
)
fun buildIfElse(
type: IrType,
cond: IrExpression,
thenBranch: IrExpression,
elseBranch: IrExpression? = null,
thenBranchStartOffset: Int = cond.startOffset,
thenBranchEndOffset: Int = thenBranch.endOffset,
elseBranchStartOffset: Int = UNDEFINED_OFFSET,
elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET,
): IrWhen =
buildIfElse(
startOffset = UNDEFINED_OFFSET,
endOffset = UNDEFINED_OFFSET,
type = type,
cond = cond,
thenBranch = thenBranch,
elseBranch = elseBranch,
origin = JsStatementOrigins.SYNTHESIZED_STATEMENT,
thenBranchStartOffset = thenBranchStartOffset,
thenBranchEndOffset = thenBranchEndOffset,
elseBranchStartOffset = elseBranchStartOffset,
elseBranchEndOffset = elseBranchEndOffset
)
fun buildIfElse(
startOffset: Int,
@@ -168,13 +188,17 @@ object JsIrBuilder {
cond: IrExpression,
thenBranch: IrExpression,
elseBranch: IrExpression? = null,
origin: IrStatementOrigin? = null
origin: IrStatementOrigin? = null,
thenBranchStartOffset: Int = cond.startOffset,
thenBranchEndOffset: Int = thenBranch.endOffset,
elseBranchStartOffset: Int = UNDEFINED_OFFSET,
elseBranchEndOffset: Int = elseBranch?.endOffset ?: UNDEFINED_OFFSET,
): IrWhen {
val element = IrIfThenElseImpl(startOffset, endOffset, type, origin)
element.branches.add(IrBranchImpl(cond, thenBranch))
element.branches.add(IrBranchImpl(thenBranchStartOffset, thenBranchEndOffset, cond, thenBranch))
if (elseBranch != null) {
val irTrue = IrConstImpl.boolean(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type, true)
element.branches.add(IrElseBranchImpl(irTrue, elseBranch))
val irTrue = IrConstImpl.constTrue(UNDEFINED_OFFSET, UNDEFINED_OFFSET, cond.type)
element.branches.add(IrElseBranchImpl(elseBranchStartOffset, elseBranchEndOffset, irTrue, elseBranch))
}
return element
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.ir.isPure
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.backend.js.JsCommonBackendContext
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
@@ -424,13 +425,17 @@ class BlockDecomposerTransformer(
isElseBranch(orig) -> (res as? IrBlock)?.statements ?: listOf(res)
else -> listOf(
JsIrBuilder.buildIfElse(
orig.startOffset,
orig.endOffset,
unitType,
condValue,
res,
elseBlock,
expression.origin
startOffset = UNDEFINED_OFFSET,
endOffset = UNDEFINED_OFFSET,
type = unitType,
cond = condValue,
thenBranch = res,
elseBranch = elseBlock,
origin = expression.origin,
thenBranchStartOffset = orig.startOffset,
thenBranchEndOffset = orig.endOffset,
elseBranchStartOffset = UNDEFINED_OFFSET,
elseBranchEndOffset = UNDEFINED_OFFSET,
)
)
}
+1 -1
View File
@@ -26,6 +26,6 @@ inline fun getB(): Int {
// EXPECTATIONS JS_IR
// test.kt:14 box
// test.kt:5 box
// test.kt:4 box
// test.kt:11 getA
// test.kt:14 box
@@ -66,13 +66,13 @@ fun nop() {}
// test.kt:8 box
// test.kt:24 box
// test.kt:9 box
// test.kt:10 box
// test.kt:7 box
// test.kt:11 box
// test.kt:30 nop
// test.kt:24 box
// test.kt:16 box
// test.kt:27 box
// test.kt:15 box
// test.kt:14 box
// test.kt:19 box
// test.kt:30 nop
// test.kt:21 box