@@ -389,9 +389,7 @@ open class KotlinFileExtractor(
389
389
addModifiers(obinitId, " private" )
390
390
391
391
// add body:
392
- val blockId = tw.getFreshIdLabel<DbBlock >()
393
- tw.writeStmts_block(blockId, obinitId, 0 , obinitId)
394
- tw.writeHasLocation(blockId, locId)
392
+ val blockId = extractBlockBody(obinitId, locId)
395
393
396
394
extractDeclInitializers(c.declarations, false ) { Pair (blockId, obinitId) }
397
395
}
@@ -707,10 +705,7 @@ open class KotlinFileExtractor(
707
705
tw.writeHasLocation(clinitId, locId)
708
706
709
707
// add and return body block:
710
- Pair (tw.getFreshIdLabel<DbBlock >().also ({
711
- tw.writeStmts_block(it, clinitId, 0 , clinitId)
712
- tw.writeHasLocation(it, locId)
713
- }), clinitId)
708
+ Pair (extractBlockBody(clinitId, locId), clinitId)
714
709
}
715
710
}
716
711
}
@@ -775,32 +770,18 @@ open class KotlinFileExtractor(
775
770
val expr = initializer.expression
776
771
777
772
val declLocId = tw.getLocation(f)
778
- val stmtId = tw.getFreshIdLabel<DbExprstmt >()
779
- tw.writeStmts_exprstmt(stmtId, blockAndFunctionId.first, idx++ , blockAndFunctionId.second)
780
- tw.writeHasLocation(stmtId, declLocId)
781
- val assignmentId = tw.getFreshIdLabel<DbAssignexpr >()
782
- val type = useType(if (isAnnotationClassField) kClassToJavaClass(expr.type) else expr.type)
783
- tw.writeExprs_assignexpr(assignmentId, type.javaResult.id, stmtId, 0 )
784
- tw.writeExprsKotlinType(assignmentId, type.kotlinResult.id)
785
- tw.writeHasLocation(assignmentId, declLocId)
786
- tw.writeCallableEnclosingExpr(assignmentId, blockAndFunctionId.second)
787
- tw.writeStatementEnclosingExpr(assignmentId, stmtId)
788
- tw.writeKtInitializerAssignment(assignmentId)
789
-
790
- val lhsId = tw.getFreshIdLabel<DbVaraccess >()
791
- tw.writeExprs_varaccess(lhsId, lhsType.javaResult.id, assignmentId, 0 )
792
- tw.writeExprsKotlinType(lhsId, lhsType.kotlinResult.id)
793
- tw.writeHasLocation(lhsId, declLocId)
794
- tw.writeCallableEnclosingExpr(lhsId, blockAndFunctionId.second)
795
- tw.writeStatementEnclosingExpr(lhsId, stmtId)
796
-
797
- tw.writeVariableBinding(lhsId, vId)
798
-
799
- if (static) {
800
- extractStaticTypeAccessQualifier(f, lhsId, declLocId, blockAndFunctionId.second, stmtId)
773
+ extractExpressionStmt(declLocId, blockAndFunctionId.first, idx++ , blockAndFunctionId.second).also { stmtId ->
774
+ val type = if (isAnnotationClassField) kClassToJavaClass(expr.type) else expr.type
775
+ extractAssignExpr(type, declLocId, stmtId, 0 , blockAndFunctionId.second, stmtId).also { assignmentId ->
776
+ tw.writeKtInitializerAssignment(assignmentId)
777
+ extractVariableAccess(vId, lhsType, declLocId, assignmentId, 0 , blockAndFunctionId.second, stmtId).also { lhsId ->
778
+ if (static) {
779
+ extractStaticTypeAccessQualifier(f, lhsId, declLocId, blockAndFunctionId.second, stmtId)
780
+ }
781
+ }
782
+ extractExpressionExpr(expr, blockAndFunctionId.second, assignmentId, 1 , stmtId)
783
+ }
801
784
}
802
-
803
- extractExpressionExpr(expr, blockAndFunctionId.second, assignmentId, 1 , stmtId)
804
785
}
805
786
806
787
for (decl in declarations) {
@@ -993,10 +974,7 @@ open class KotlinFileExtractor(
993
974
994
975
// Create a synthetic function body that calls the real function supplying default arguments where required:
995
976
if (f is IrConstructor ) {
996
- val blockId = tw.getFreshIdLabel<DbBlock >()
997
- tw.writeStmts_block(blockId, overloadId, 0 , overloadId)
998
- tw.writeHasLocation(blockId, realFunctionLocId)
999
-
977
+ val blockId = extractBlockBody(overloadId, realFunctionLocId)
1000
978
val constructorCallId = tw.getFreshIdLabel<DbConstructorinvocationstmt >()
1001
979
tw.writeStmts_constructorinvocationstmt(constructorCallId, blockId, 0 , overloadId)
1002
980
tw.writeHasLocation(constructorCallId, realFunctionLocId)
@@ -1356,11 +1334,8 @@ open class KotlinFileExtractor(
1356
1334
}
1357
1335
}
1358
1336
1359
- fun extractExpressionBody (callable : Label <out DbCallable >, locId : Label <out DbLocation >): Label <out DbStmt > {
1360
- val blockId = tw.getFreshIdLabel<DbBlock >()
1361
- tw.writeStmts_block(blockId, callable, 0 , callable)
1362
- tw.writeHasLocation(blockId, locId)
1363
-
1337
+ fun extractExpressionBody (callable : Label <out DbCallable >, locId : Label <DbLocation >): Label <out DbStmt > {
1338
+ val blockId = extractBlockBody(callable, locId)
1364
1339
return tw.getFreshIdLabel<DbReturnstmt >().also { returnId ->
1365
1340
tw.writeStmts_returnstmt(returnId, blockId, 0 , callable)
1366
1341
tw.writeHasLocation(returnId, locId)
@@ -2664,15 +2639,7 @@ open class KotlinFileExtractor(
2664
2639
tw.writeStatementEnclosingExpr(initId, enclosingStmt)
2665
2640
it.elements.forEachIndexed { i, arg -> extractVarargElement(arg, callable, initId, i, enclosingStmt) }
2666
2641
2667
- val dim = it.elements.size
2668
- val dimId = tw.getFreshIdLabel<DbIntegerliteral >()
2669
- val dimType = useType(pluginContext.irBuiltIns.intType)
2670
- tw.writeExprs_integerliteral(dimId, dimType.javaResult.id, id, 0 )
2671
- tw.writeExprsKotlinType(dimId, dimType.kotlinResult.id)
2672
- tw.writeHasLocation(dimId, locId)
2673
- tw.writeCallableEnclosingExpr(dimId, callable)
2674
- tw.writeStatementEnclosingExpr(dimId, enclosingStmt)
2675
- tw.writeNamestrings(dim.toString(), dim.toString(), dimId)
2642
+ extractConstantInteger(it.elements.size, locId, id, 0 , callable, enclosingStmt)
2676
2643
}
2677
2644
}
2678
2645
}
@@ -2744,27 +2711,21 @@ open class KotlinFileExtractor(
2744
2711
2745
2712
if (array != null && arrayIdx != null && assignedValue != null ) {
2746
2713
2747
- val assignId = tw.getFreshIdLabel<DbAssignexpr >()
2748
- val type = useType(c.type)
2749
2714
val locId = tw.getLocation(c)
2750
- tw.writeExprs_assignexpr(assignId, type.javaResult.id, parent, idx)
2751
- tw.writeExprsKotlinType(assignId, type.kotlinResult.id)
2752
- tw.writeHasLocation(assignId, locId)
2753
- tw.writeCallableEnclosingExpr(assignId, callable)
2754
- tw.writeStatementEnclosingExpr(assignId, enclosingStmt)
2755
-
2756
- val arrayAccessId = tw.getFreshIdLabel<DbArrayaccess >()
2757
- val arrayType = useType(array.type)
2758
- tw.writeExprs_arrayaccess(arrayAccessId, arrayType.javaResult.id, assignId, 0 )
2759
- tw.writeExprsKotlinType(arrayAccessId, arrayType.kotlinResult.id)
2760
- tw.writeHasLocation(arrayAccessId, locId)
2761
- tw.writeCallableEnclosingExpr(arrayAccessId, callable)
2762
- tw.writeStatementEnclosingExpr(arrayAccessId, enclosingStmt)
2763
-
2764
- extractExpressionExpr(array, callable, arrayAccessId, 0 , enclosingStmt)
2765
- extractExpressionExpr(arrayIdx, callable, arrayAccessId, 1 , enclosingStmt)
2766
-
2767
- extractExpressionExpr(assignedValue, callable, assignId, 1 , enclosingStmt)
2715
+ extractAssignExpr(c.type, locId, parent, idx, callable, enclosingStmt).also { assignId ->
2716
+ tw.getFreshIdLabel<DbArrayaccess >().also { arrayAccessId ->
2717
+ val arrayType = useType(array.type)
2718
+ tw.writeExprs_arrayaccess(arrayAccessId, arrayType.javaResult.id, assignId, 0 )
2719
+ tw.writeExprsKotlinType(arrayAccessId, arrayType.kotlinResult.id)
2720
+ tw.writeHasLocation(arrayAccessId, locId)
2721
+ tw.writeCallableEnclosingExpr(arrayAccessId, callable)
2722
+ tw.writeStatementEnclosingExpr(arrayAccessId, enclosingStmt)
2723
+
2724
+ extractExpressionExpr(array, callable, arrayAccessId, 0 , enclosingStmt)
2725
+ extractExpressionExpr(arrayIdx, callable, arrayAccessId, 1 , enclosingStmt)
2726
+ }
2727
+ extractExpressionExpr(assignedValue, callable, assignId, 1 , enclosingStmt)
2728
+ }
2768
2729
2769
2730
} else {
2770
2731
logger.errorElement(" Unexpected Array.set function signature" , c)
@@ -3002,16 +2963,12 @@ open class KotlinFileExtractor(
3002
2963
}
3003
2964
3004
2965
inner class StmtParent (val parent : Label <out DbStmtparent >, val idx : Int ): StmtExprParent() {
3005
- override fun stmt (e : IrExpression , callable : Label <out DbCallable >): StmtParent {
3006
- return this
3007
- }
3008
- override fun expr (e : IrExpression , callable : Label <out DbCallable >): ExprParent {
3009
- val id = tw.getFreshIdLabel<DbExprstmt >()
3010
- val locId = tw.getLocation(e)
3011
- tw.writeStmts_exprstmt(id, parent, idx, callable)
3012
- tw.writeHasLocation(id, locId)
3013
- return ExprParent (id, 0 , id)
3014
- }
2966
+ override fun stmt (e : IrExpression , callable : Label <out DbCallable >) = this
2967
+
2968
+ override fun expr (e : IrExpression , callable : Label <out DbCallable >) =
2969
+ extractExpressionStmt(tw.getLocation(e), parent, idx, callable).let { id ->
2970
+ ExprParent (id, 0 , id)
2971
+ }
3015
2972
}
3016
2973
inner class ExprParent (val parent : Label <out DbExprparent >, val idx : Int , val enclosingStmt : Label <out DbStmt >): StmtExprParent() {
3017
2974
override fun stmt (e : IrExpression , callable : Label <out DbCallable >): StmtParent {
@@ -3798,16 +3755,18 @@ open class KotlinFileExtractor(
3798
3755
extractTypeAccessRecursive(irType, locId, it, 0 )
3799
3756
}
3800
3757
3801
- private fun extractThisAccess (irType : IrType , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int , enclosingStmt : Label <out DbStmt >, locId : Label <out DbLocation >) =
3758
+ private fun extractThisAccess (type : TypeResults , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int , enclosingStmt : Label <out DbStmt >, locId : Label <out DbLocation >) =
3802
3759
tw.getFreshIdLabel<DbThisaccess >().also {
3803
- val type = useType(irType)
3804
3760
tw.writeExprs_thisaccess(it, type.javaResult.id, parent, idx)
3805
3761
tw.writeExprsKotlinType(it, type.kotlinResult.id)
3806
3762
tw.writeHasLocation(it, locId)
3807
3763
tw.writeCallableEnclosingExpr(it, callable)
3808
3764
tw.writeStatementEnclosingExpr(it, enclosingStmt)
3809
3765
}
3810
3766
3767
+ private fun extractThisAccess (irType : IrType , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int , enclosingStmt : Label <out DbStmt >, locId : Label <out DbLocation >) =
3768
+ extractThisAccess(useType(irType), callable, parent, idx, enclosingStmt, locId)
3769
+
3811
3770
private fun extractThisAccess (e : IrGetValue , thisParamParent : IrDeclarationParent , exprParent : ExprParent , callable : Label <out DbCallable >) {
3812
3771
val containingDeclaration = declarationStack.peek().first
3813
3772
val locId = tw.getLocation(e)
@@ -3866,9 +3825,8 @@ open class KotlinFileExtractor(
3866
3825
}
3867
3826
}
3868
3827
3869
- private fun extractVariableAccess (variable : Label <out DbVariable >? , irType : IrType , locId : Label <out DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3828
+ private fun extractVariableAccess (variable : Label <out DbVariable >? , type : TypeResults , locId : Label <out DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3870
3829
tw.getFreshIdLabel<DbVaraccess >().also {
3871
- val type = useType(irType)
3872
3830
tw.writeExprs_varaccess(it, type.javaResult.id, parent, idx)
3873
3831
tw.writeExprsKotlinType(it, type.kotlinResult.id)
3874
3832
tw.writeHasLocation(it, locId)
@@ -3880,6 +3838,9 @@ open class KotlinFileExtractor(
3880
3838
}
3881
3839
}
3882
3840
3841
+ private fun extractVariableAccess (variable : Label <out DbVariable >? , irType : IrType , locId : Label <out DbLocation >, parent : Label <out DbExprparent >, idx : Int , callable : Label <out DbCallable >, enclosingStmt : Label <out DbStmt >) =
3842
+ extractVariableAccess(variable, useType(irType), locId, parent, idx, callable, enclosingStmt)
3843
+
3883
3844
private fun extractLoop (
3884
3845
loop : IrLoop ,
3885
3846
stmtExprParent : StmtExprParent ,
@@ -3953,33 +3914,16 @@ open class KotlinFileExtractor(
3953
3914
stmtIdx : Int
3954
3915
) {
3955
3916
val paramId = tw.getFreshIdLabel<DbParam >()
3956
- val paramTypeRes = extractValueParameter(paramId, paramType, paramName, locId, ids.constructor , paramIdx, paramId, syntheticParameterNames = false , isVararg = false , isNoinline = false , isCrossinline = false )
3957
-
3958
- val assignmentStmtId = tw.getFreshIdLabel<DbExprstmt >()
3959
- tw.writeStmts_exprstmt(assignmentStmtId, ids.constructorBlock, stmtIdx, ids.constructor )
3960
- tw.writeHasLocation(assignmentStmtId, locId)
3961
-
3962
- val assignmentId = tw.getFreshIdLabel<DbAssignexpr >()
3963
- tw.writeExprs_assignexpr(assignmentId, paramTypeRes.javaResult.id, assignmentStmtId, 0 )
3964
- tw.writeExprsKotlinType(assignmentId, paramTypeRes.kotlinResult.id)
3965
- writeExpressionMetadataToTrapFile(assignmentId, ids.constructor , assignmentStmtId)
3966
-
3967
- val lhsId = tw.getFreshIdLabel<DbVaraccess >()
3968
- tw.writeExprs_varaccess(lhsId, paramTypeRes.javaResult.id, assignmentId, 0 )
3969
- tw.writeExprsKotlinType(lhsId, paramTypeRes.kotlinResult.id)
3970
- tw.writeVariableBinding(lhsId, fieldId)
3971
- writeExpressionMetadataToTrapFile(lhsId, ids.constructor , assignmentStmtId)
3972
-
3973
- val thisId = tw.getFreshIdLabel<DbThisaccess >()
3974
- tw.writeExprs_thisaccess(thisId, ids.type.javaResult.id, lhsId, - 1 )
3975
- tw.writeExprsKotlinType(thisId, ids.type.kotlinResult.id)
3976
- writeExpressionMetadataToTrapFile(thisId, ids.constructor , assignmentStmtId)
3977
-
3978
- val rhsId = tw.getFreshIdLabel<DbVaraccess >()
3979
- tw.writeExprs_varaccess(rhsId, paramTypeRes.javaResult.id, assignmentId, 1 )
3980
- tw.writeExprsKotlinType(rhsId, paramTypeRes.kotlinResult.id)
3981
- tw.writeVariableBinding(rhsId, paramId)
3982
- writeExpressionMetadataToTrapFile(rhsId, ids.constructor , assignmentStmtId)
3917
+ extractValueParameter(paramId, paramType, paramName, locId, ids.constructor , paramIdx, paramId, syntheticParameterNames = false , isVararg = false , isNoinline = false , isCrossinline = false )
3918
+
3919
+ extractExpressionStmt(locId, ids.constructorBlock, stmtIdx, ids.constructor ).also { assignmentStmtId ->
3920
+ extractAssignExpr(paramType, locId, assignmentStmtId, 0 , ids.constructor , assignmentStmtId).also { assignmentId ->
3921
+ extractVariableAccess(fieldId, paramType, locId, assignmentId, 0 , ids.constructor , assignmentStmtId).also { lhsId ->
3922
+ extractThisAccess(ids.type, ids.constructor , lhsId, - 1 , assignmentStmtId, locId)
3923
+ }
3924
+ extractVariableAccess(paramId, paramType, locId, assignmentId, 1 , ids.constructor , assignmentStmtId)
3925
+ }
3926
+ }
3983
3927
}
3984
3928
}
3985
3929
@@ -4037,35 +3981,22 @@ open class KotlinFileExtractor(
4037
3981
}
4038
3982
4039
3983
protected fun writeThisAccess (parent : Label <out DbExprparent >, callable : Label <out DbCallable >, stmt : Label <out DbStmt >) {
4040
- val thisId = tw.getFreshIdLabel<DbThisaccess >()
4041
- tw.writeExprs_thisaccess(thisId, ids.type.javaResult.id, parent, - 1 )
4042
- tw.writeExprsKotlinType(thisId, ids.type.kotlinResult.id)
4043
- writeExpressionMetadataToTrapFile(thisId, callable, stmt)
3984
+ extractThisAccess(ids.type, callable, parent, - 1 , stmt, locId)
4044
3985
}
4045
3986
4046
3987
fun extractFieldWriteOfReflectionTarget (
4047
3988
labels : FunctionLabels , // labels of the containing function
4048
3989
target : IrFieldSymbol , // the target field being accessed)
4049
3990
) {
4050
- // ...;
4051
- val exprStmtId = tw.getFreshIdLabel<DbExprstmt >()
4052
- tw.writeStmts_exprstmt(exprStmtId, labels.blockId, 0 , labels.methodId)
4053
- tw.writeHasLocation(exprStmtId, locId)
4054
-
4055
3991
val fieldType = useType(target.owner.type)
4056
3992
4057
- // ... = ...
4058
- val assignExprId = tw.getFreshIdLabel<DbAssignexpr >()
4059
- tw.writeExprs_assignexpr(assignExprId, fieldType.javaResult.id, exprStmtId, 0 )
4060
- tw.writeExprsKotlinType(assignExprId, fieldType.kotlinResult.id)
4061
- writeExpressionMetadataToTrapFile(assignExprId, labels.methodId, exprStmtId)
4062
-
4063
- // LHS
4064
- extractFieldAccess(fieldType, assignExprId, exprStmtId, labels, target)
4065
-
4066
- // RHS
4067
- val p = labels.parameters.first()
4068
- writeVariableAccessInFunctionBody(p.second, 1 , p.first, assignExprId, labels.methodId, exprStmtId)
3993
+ extractExpressionStmt(locId, labels.blockId, 0 , labels.methodId).also { exprStmtId ->
3994
+ extractAssignExpr(target.owner.type, locId, exprStmtId, 0 , labels.methodId, exprStmtId).also { assignExprId ->
3995
+ extractFieldAccess(fieldType, assignExprId, exprStmtId, labels, target)
3996
+ val p = labels.parameters.first()
3997
+ writeVariableAccessInFunctionBody(p.second, 1 , p.first, assignExprId, labels.methodId, exprStmtId)
3998
+ }
3999
+ }
4069
4000
}
4070
4001
4071
4002
fun extractFieldReturnOfReflectionTarget (
@@ -4641,12 +4572,7 @@ open class KotlinFileExtractor(
4641
4572
addModifiers(methodId, " public" )
4642
4573
addModifiers(methodId, " override" )
4643
4574
4644
- // Block
4645
- val blockId = tw.getFreshIdLabel<DbBlock >()
4646
- tw.writeStmts_block(blockId, methodId, 0 , methodId)
4647
- tw.writeHasLocation(blockId, locId)
4648
-
4649
- return FunctionLabels (methodId, blockId, parameters)
4575
+ return FunctionLabels (methodId, extractBlockBody(methodId, locId), parameters)
4650
4576
}
4651
4577
4652
4578
/*
@@ -4688,10 +4614,7 @@ open class KotlinFileExtractor(
4688
4614
tw.writeCallableBinding(callId, calledMethodId)
4689
4615
4690
4616
// this access
4691
- val thisId = tw.getFreshIdLabel<DbThisaccess >()
4692
- tw.writeExprs_thisaccess(thisId, ids.type.javaResult.id, callId, - 1 )
4693
- tw.writeExprsKotlinType(thisId, ids.type.kotlinResult.id)
4694
- extractCommonExpr(thisId)
4617
+ extractThisAccess(ids.type, funLabels.methodId, callId, - 1 , retId, locId)
4695
4618
4696
4619
addArgumentsToInvocationInInvokeNBody(parameters.map { it.type }, funLabels, retId, callId, locId, ::extractCommonExpr)
4697
4620
}
@@ -4953,13 +4876,7 @@ open class KotlinFileExtractor(
4953
4876
tw.writeExprsKotlinType(initId, at.kotlinResult.id)
4954
4877
extractCommonExpr(initId)
4955
4878
4956
- val dim = arraySize.toString()
4957
- val dimId = tw.getFreshIdLabel<DbIntegerliteral >()
4958
- val dimType = useType(pluginContext.irBuiltIns.intType)
4959
- tw.writeExprs_integerliteral(dimId, dimType.javaResult.id, arrayCreationId, 0 )
4960
- tw.writeExprsKotlinType(dimId, dimType.kotlinResult.id)
4961
- extractCommonExpr(dimId)
4962
- tw.writeNamestrings(dim, dim, dimId)
4879
+ extractConstantInteger(arraySize, locId, arrayCreationId, 0 , enclosingCallable, enclosingStmt)
4963
4880
4964
4881
return initId
4965
4882
}
@@ -5158,9 +5075,7 @@ open class KotlinFileExtractor(
5158
5075
}
5159
5076
5160
5077
// body
5161
- val blockId = tw.getFreshIdLabel<DbBlock >()
5162
- tw.writeStmts_block(blockId, ids.function, 0 , ids.function)
5163
- tw.writeHasLocation(blockId, locId)
5078
+ val blockId = extractBlockBody(ids.function, locId)
5164
5079
5165
5080
// return stmt
5166
5081
val returnId = tw.getFreshIdLabel<DbReturnstmt >()
0 commit comments