@@ -2486,18 +2486,21 @@ open class KotlinFileExtractor(
2486
2486
}
2487
2487
}
2488
2488
2489
- private fun writeUpdateInPlaceExpr (origin : IrStatementOrigin , tw : TrapWriter , id : Label <DbAssignexpr >, type : TypeResults , exprParent : ExprParent ): Boolean {
2489
+ private fun writeUpdateInPlaceExpr (origin : IrStatementOrigin ): (( tw: TrapWriter , id: Label <out DbAssignexpr >, type: Label < out DbType > , exprParent: Label < out DbExprparent >, index: Int ) -> Unit ) ? {
2490
2490
when (origin) {
2491
- IrStatementOrigin .PLUSEQ -> tw .writeExprs_assignaddexpr(id.cast<DbAssignaddexpr >(), type.javaResult.id , exprParent.parent, exprParent.idx)
2492
- IrStatementOrigin .MINUSEQ -> tw .writeExprs_assignsubexpr(id.cast<DbAssignsubexpr >(), type.javaResult.id , exprParent.parent, exprParent.idx)
2493
- IrStatementOrigin .MULTEQ -> tw .writeExprs_assignmulexpr(id.cast<DbAssignmulexpr >(), type.javaResult.id , exprParent.parent, exprParent.idx)
2494
- IrStatementOrigin .DIVEQ -> tw .writeExprs_assigndivexpr(id.cast<DbAssigndivexpr >(), type.javaResult.id , exprParent.parent, exprParent.idx)
2495
- IrStatementOrigin .PERCEQ -> tw .writeExprs_assignremexpr(id.cast<DbAssignremexpr >(), type.javaResult.id , exprParent.parent, exprParent.idx)
2496
- else -> return false
2491
+ IrStatementOrigin .PLUSEQ -> return { tw : TrapWriter , id : Label < out DbAssignexpr >, type : Label < out DbType >, exprParent : Label < out DbExprparent >, index : Int -> tw .writeExprs_assignaddexpr(id.cast<DbAssignaddexpr >(), type, exprParent, index) }
2492
+ IrStatementOrigin .MINUSEQ -> return { tw : TrapWriter , id : Label < out DbAssignexpr >, type : Label < out DbType >, exprParent : Label < out DbExprparent >, index : Int -> tw .writeExprs_assignsubexpr(id.cast<DbAssignsubexpr >(), type, exprParent, index) }
2493
+ IrStatementOrigin .MULTEQ -> return { tw : TrapWriter , id : Label < out DbAssignexpr >, type : Label < out DbType >, exprParent : Label < out DbExprparent >, index : Int -> tw .writeExprs_assignmulexpr(id.cast<DbAssignmulexpr >(), type, exprParent, index) }
2494
+ IrStatementOrigin .DIVEQ -> return { tw : TrapWriter , id : Label < out DbAssignexpr >, type : Label < out DbType >, exprParent : Label < out DbExprparent >, index : Int -> tw .writeExprs_assigndivexpr(id.cast<DbAssigndivexpr >(), type, exprParent, index) }
2495
+ IrStatementOrigin .PERCEQ -> return { tw : TrapWriter , id : Label < out DbAssignexpr >, type : Label < out DbType >, exprParent : Label < out DbExprparent >, index : Int -> tw .writeExprs_assignremexpr(id.cast<DbAssignremexpr >(), type, exprParent, index) }
2496
+ else -> return null
2497
2497
}
2498
- return true
2499
2498
}
2500
2499
2500
+ /* *
2501
+ * This tried to extract a block as an array update.
2502
+ * It returns true if it succeeds, and false otherwise.
2503
+ */
2501
2504
private fun tryExtractArrayUpdate (e : IrContainerExpression , callable : Label <out DbCallable >, parent : StmtExprParent ): Boolean {
2502
2505
/*
2503
2506
* We're expecting the pattern
@@ -2528,6 +2531,12 @@ open class KotlinFileExtractor(
2528
2531
},
2529
2532
arraySetCall.getValueArgument(1 )!!
2530
2533
)?.let { updateRhs ->
2534
+ val writeUpdateInPlaceExprFun = writeUpdateInPlaceExpr(e.origin!! )
2535
+ if (writeUpdateInPlaceExprFun == null ) {
2536
+ logger.errorElement(" Unexpected origin" , e)
2537
+ return false
2538
+ }
2539
+
2531
2540
// Create an assignment skeleton _ op= _
2532
2541
val exprParent = parent.expr(e, callable)
2533
2542
val assignId = tw.getFreshIdLabel<DbAssignexpr >()
@@ -2538,10 +2547,7 @@ open class KotlinFileExtractor(
2538
2547
tw.writeCallableEnclosingExpr(assignId, callable)
2539
2548
tw.writeStatementEnclosingExpr(assignId, exprParent.enclosingStmt)
2540
2549
2541
- if (! writeUpdateInPlaceExpr(e.origin!! , tw, assignId, type, exprParent)) {
2542
- logger.errorElement(" Unexpected origin" , e)
2543
- return false
2544
- }
2550
+ writeUpdateInPlaceExprFun(tw, assignId, type.javaResult.id, exprParent.parent, exprParent.idx)
2545
2551
2546
2552
// Extract e1[e2]
2547
2553
val lhsId = tw.getFreshIdLabel<DbArrayaccess >()
@@ -2897,9 +2903,13 @@ open class KotlinFileExtractor(
2897
2903
if (origin == null ) {
2898
2904
logger.errorElement(" No origin for set-value" , e)
2899
2905
return
2900
- } else if (! writeUpdateInPlaceExpr(origin, tw, id, type, exprParent)) {
2901
- logger.errorElement(" Unexpected origin for set-value" , e)
2902
- return
2906
+ } else {
2907
+ val writeUpdateInPlaceExprFun = writeUpdateInPlaceExpr(origin)
2908
+ if (writeUpdateInPlaceExprFun == null ) {
2909
+ logger.errorElement(" Unexpected origin for set-value" , e)
2910
+ return
2911
+ }
2912
+ writeUpdateInPlaceExprFun(tw, id, type.javaResult.id, exprParent.parent, exprParent.idx)
2903
2913
}
2904
2914
} else {
2905
2915
tw.writeExprs_assignexpr(id, type.javaResult.id, exprParent.parent, exprParent.idx)
0 commit comments