@@ -2197,8 +2197,6 @@ open class KotlinFileExtractor(
2197
2197
}
2198
2198
}
2199
2199
2200
- private val loopIdMap: MutableMap <IrLoop , Label <out DbKtloopstmt >> = mutableMapOf ()
2201
-
2202
2200
// todo: calculating the enclosing ref type could be done through this, instead of walking up the declaration parent chain
2203
2201
private val declarationStack: Stack <IrDeclaration > = Stack ()
2204
2202
@@ -2446,32 +2444,10 @@ open class KotlinFileExtractor(
2446
2444
}
2447
2445
}
2448
2446
is IrWhileLoop -> {
2449
- val stmtParent = parent.stmt(e, callable)
2450
- val id = tw.getFreshIdLabel<DbWhilestmt >()
2451
- loopIdMap[e] = id
2452
- val locId = tw.getLocation(e)
2453
- tw.writeStmts_whilestmt(id, stmtParent.parent, stmtParent.idx, callable)
2454
- tw.writeHasLocation(id, locId)
2455
- extractExpressionExpr(e.condition, callable, id, 0 , id)
2456
- val body = e.body
2457
- if (body != null ) {
2458
- extractExpressionStmt(body, callable, id, 1 )
2459
- }
2460
- loopIdMap.remove(e)
2447
+ extractLoop(e, parent, callable)
2461
2448
}
2462
2449
is IrDoWhileLoop -> {
2463
- val stmtParent = parent.stmt(e, callable)
2464
- val id = tw.getFreshIdLabel<DbDostmt >()
2465
- loopIdMap[e] = id
2466
- val locId = tw.getLocation(e)
2467
- tw.writeStmts_dostmt(id, stmtParent.parent, stmtParent.idx, callable)
2468
- tw.writeHasLocation(id, locId)
2469
- extractExpressionExpr(e.condition, callable, id, 0 , id)
2470
- val body = e.body
2471
- if (body != null ) {
2472
- extractExpressionStmt(body, callable, id, 1 )
2473
- }
2474
- loopIdMap.remove(e)
2450
+ extractLoop(e, parent, callable)
2475
2451
}
2476
2452
is IrInstanceInitializerCall -> {
2477
2453
val irConstructor = declarationStack.peek() as ? IrConstructor
@@ -2988,6 +2964,49 @@ open class KotlinFileExtractor(
2988
2964
}
2989
2965
}
2990
2966
2967
+ private fun extractLoop (
2968
+ loop : IrLoop ,
2969
+ stmtExprParent : StmtExprParent ,
2970
+ callable : Label <out DbCallable >
2971
+ ) {
2972
+ val stmtParent = stmtExprParent.stmt(loop, callable)
2973
+ val locId = tw.getLocation(loop)
2974
+
2975
+ val idx: Int
2976
+ val parent: Label <out DbStmtparent >
2977
+
2978
+ val label = loop.label
2979
+ if (label != null ) {
2980
+ val labeledStmt = tw.getFreshIdLabel<DbLabeledstmt >()
2981
+ tw.writeStmts_labeledstmt(labeledStmt, stmtParent.parent, stmtParent.idx, callable)
2982
+ tw.writeHasLocation(labeledStmt, locId)
2983
+
2984
+ tw.writeNamestrings(label, " " , labeledStmt)
2985
+ idx = 0
2986
+ parent = labeledStmt
2987
+ } else {
2988
+ idx = stmtParent.idx
2989
+ parent = stmtParent.parent
2990
+ }
2991
+
2992
+ val id = if (loop is IrWhileLoop ) {
2993
+ val id = tw.getFreshIdLabel<DbWhilestmt >()
2994
+ tw.writeStmts_whilestmt(id, parent, idx, callable)
2995
+ id
2996
+ } else {
2997
+ val id = tw.getFreshIdLabel<DbDostmt >()
2998
+ tw.writeStmts_dostmt(id, parent, idx, callable)
2999
+ id
3000
+ }
3001
+
3002
+ tw.writeHasLocation(id, locId)
3003
+ extractExpressionExpr(loop.condition, callable, id, 0 , id)
3004
+ val body = loop.body
3005
+ if (body != null ) {
3006
+ extractExpressionStmt(body, callable, id, 1 )
3007
+ }
3008
+ }
3009
+
2991
3010
private fun IrValueParameter.isExtensionReceiver (): Boolean {
2992
3011
val parentFun = parent as ? IrFunction ? : return false
2993
3012
return parentFun.extensionReceiverParameter == this
@@ -4261,7 +4280,7 @@ open class KotlinFileExtractor(
4261
4280
4262
4281
private fun extractBreakContinue (
4263
4282
e : IrBreakContinue ,
4264
- id : Label <out DbBreakcontinuestmt >
4283
+ id : Label <out DbNamedexprorstmt >
4265
4284
) {
4266
4285
with (" break/continue" , e) {
4267
4286
val locId = tw.getLocation(e)
@@ -4270,14 +4289,6 @@ open class KotlinFileExtractor(
4270
4289
if (label != null ) {
4271
4290
tw.writeNamestrings(label, " " , id)
4272
4291
}
4273
-
4274
- val loopId = loopIdMap[e.loop]
4275
- if (loopId == null ) {
4276
- logger.errorElement(" Missing break/continue target" , e)
4277
- return
4278
- }
4279
-
4280
- tw.writeKtBreakContinueTargets(id, loopId)
4281
4292
}
4282
4293
}
4283
4294
0 commit comments