@@ -634,6 +634,8 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
634634 }
635635 }
636636
637+ private val loopIdMap: MutableMap <IrLoop , Label <out DbKtloopstmt >> = mutableMapOf ()
638+
637639 fun extractExpression (e : IrExpression , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int ) {
638640 when (e) {
639641 is IrCall -> extractCall(e, callable, parent, idx)
@@ -725,15 +727,13 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
725727 }
726728 is IrBreak -> {
727729 val id = tw.getFreshIdLabel<DbBreakstmt >()
728- val locId = tw.getLocation(e)
729730 tw.writeStmts_breakstmt(id, parent, idx, callable)
730- tw.writeHasLocation(id, locId )
731+ extractBreakContinue(e, id )
731732 }
732733 is IrContinue -> {
733734 val id = tw.getFreshIdLabel<DbContinuestmt >()
734- val locId = tw.getLocation(e)
735735 tw.writeStmts_continuestmt(id, parent, idx, callable)
736- tw.writeHasLocation(id, locId )
736+ extractBreakContinue(e, id )
737737 }
738738 is IrReturn -> {
739739 val id = tw.getFreshIdLabel<DbReturnstmt >()
@@ -753,6 +753,7 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
753753 }
754754 is IrWhileLoop -> {
755755 val id = tw.getFreshIdLabel<DbWhilestmt >()
756+ loopIdMap[e] = id
756757 val locId = tw.getLocation(e)
757758 tw.writeStmts_whilestmt(id, parent, idx, callable)
758759 tw.writeHasLocation(id, locId)
@@ -761,9 +762,11 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
761762 if (body != null ) {
762763 extractExpression(body, callable, id, 1 )
763764 }
765+ loopIdMap.remove(e)
764766 }
765767 is IrDoWhileLoop -> {
766768 val id = tw.getFreshIdLabel<DbDostmt >()
769+ loopIdMap[e] = id
767770 val locId = tw.getLocation(e)
768771 tw.writeStmts_dostmt(id, parent, idx, callable)
769772 tw.writeHasLocation(id, locId)
@@ -772,6 +775,7 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
772775 if (body != null ) {
773776 extractExpression(body, callable, id, 1 )
774777 }
778+ loopIdMap.remove(e)
775779 }
776780 is IrWhen -> {
777781 val id = tw.getFreshIdLabel<DbWhenexpr >()
@@ -807,5 +811,27 @@ class KotlinFileExtractor(val logger: FileLogger, val tw: FileTrapWriter, val fi
807811 }
808812 }
809813 }
814+
815+ private fun extractBreakContinue (
816+ e : IrBreakContinue ,
817+ id : Label <out DbBreakcontinuestmt >
818+ ) {
819+ val locId = tw.getLocation(e)
820+ @Suppress(" UNCHECKED_CAST" )
821+ tw.writeHasLocation(id as Label <out DbLocatable >, locId)
822+ val label = e.label
823+ if (label != null ) {
824+ @Suppress(" UNCHECKED_CAST" )
825+ tw.writeNamestrings(label, " " , id as Label <out DbNamedexprorstmt >)
826+ }
827+
828+ val loopId = loopIdMap[e.loop]
829+ if (loopId == null ) {
830+ logger.warnElement(Severity .ErrorSevere , " Missing break/continue target" , e)
831+ return
832+ }
833+
834+ tw.writeKtBreakContinueTarget(id, loopId)
835+ }
810836}
811837
0 commit comments