Extract varargs constructors

This commit is contained in:
Chris Smowton
2022-03-16 17:52:42 +00:00
committed by Ian Lynagh
parent e24d78ae14
commit 35d213afc0
4 changed files with 126 additions and 73 deletions

View File

@@ -1146,14 +1146,21 @@ open class KotlinFileExtractor(
idxOffset = 0
}
extractCallValueArguments(id, valueArguments, enclosingStmt, enclosingCallable, idxOffset)
}
private fun extractCallValueArguments(callId: Label<out DbExprparent>, call: IrFunctionAccessExpression, enclosingStmt: Label<out DbStmt>, enclosingCallable: Label<out DbCallable>, idxOffset: Int) =
extractCallValueArguments(callId, (0 until call.valueArgumentsCount).map { call.getValueArgument(it) }, enclosingStmt, enclosingCallable, idxOffset)
private fun extractCallValueArguments(callId: Label<out DbExprparent>, valueArguments: List<IrExpression?>, enclosingStmt: Label<out DbStmt>, enclosingCallable: Label<out DbCallable>, idxOffset: Int) {
var i = 0
valueArguments.forEach { arg ->
if(arg != null) {
if (arg is IrVararg) {
arg.elements.forEachIndexed { varargNo, vararg -> extractVarargElement(vararg, enclosingCallable, id, i + idxOffset + varargNo, enclosingStmt) }
arg.elements.forEachIndexed { varargNo, vararg -> extractVarargElement(vararg, enclosingCallable, callId, i + idxOffset + varargNo, enclosingStmt) }
i += arg.elements.size
} else {
extractExpressionExpr(arg, enclosingCallable, id, (i++) + idxOffset, enclosingStmt)
extractExpressionExpr(arg, enclosingCallable, callId, (i++) + idxOffset, enclosingStmt)
}
}
}
@@ -1807,12 +1814,8 @@ open class KotlinFileExtractor(
tw.writeIsAnonymClass(type.javaResult.id as Label<DbClass>, id)
}
for (i in 0 until e.valueArgumentsCount) {
val arg = e.getValueArgument(i)
if (arg != null) {
extractExpressionExpr(arg, callable, id, i, enclosingStmt)
}
}
extractCallValueArguments(id, e, enclosingStmt, callable, 0)
val dr = e.dispatchReceiver
if (dr != null) {
extractExpressionExpr(dr, callable, id, -2, enclosingStmt)
@@ -2020,12 +2023,7 @@ open class KotlinFileExtractor(
tw.writeHasLocation(id, locId)
@Suppress("UNCHECKED_CAST")
tw.writeCallableBinding(id as Label<DbCaller>, methodId)
for (i in 0 until e.valueArgumentsCount) {
val arg = e.getValueArgument(i)
if (arg != null) {
extractExpressionExpr(arg, callable, id, i, id)
}
}
extractCallValueArguments(id, e, id, callable, 0)
val dr = e.dispatchReceiver
if (dr != null) {
extractExpressionExpr(dr, callable, id, -1, id)

View File

@@ -1,54 +1,80 @@
varargsParams
| test.kt:6:24:6:37 | xs | file://:0:0:0:0 | int[] |
| test.kt:10:50:10:63 | xs | file://:0:0:0:0 | int[] |
| test.kt:14:37:14:50 | xs | file://:0:0:0:0 | int[] |
| test.kt:8:15:8:28 | xs | file://:0:0:0:0 | int[] |
| test.kt:12:26:12:39 | xs | file://:0:0:0:0 | int[] |
| test.kt:20:24:20:37 | xs | file://:0:0:0:0 | int[] |
| test.kt:24:50:24:63 | xs | file://:0:0:0:0 | int[] |
| test.kt:28:37:28:50 | xs | file://:0:0:0:0 | int[] |
explicitVarargsArguments
| test.kt:24:25:24:29 | array | test.kt:24:5:24:30 | funWithOnlyVarArgs(...) |
| test.kt:25:41:25:45 | array | test.kt:25:5:25:46 | funWithArgsAndVarArgs(...) |
| test.kt:26:34:26:38 | array | test.kt:26:5:26:49 | funWithMiddleVarArgs(...) |
| test.kt:12:50:12:51 | xs | test.kt:12:44:12:52 | this(...) |
| test.kt:38:25:38:29 | array | test.kt:38:5:38:30 | funWithOnlyVarArgs(...) |
| test.kt:39:41:39:45 | array | test.kt:39:5:39:46 | funWithArgsAndVarArgs(...) |
| test.kt:40:34:40:38 | array | test.kt:40:5:40:49 | funWithMiddleVarArgs(...) |
| test.kt:44:27:44:31 | array | test.kt:44:5:44:32 | new HasVarargConstructor(...) |
| test.kt:45:34:45:38 | array | test.kt:45:5:45:39 | new HasVarargConstructor(...) |
implicitVarargsArguments
| intList.kt:3:21:3:22 | 10 | intList.kt:3:14:3:31 | listOf(...) | 0 |
| intList.kt:3:25:3:26 | 11 | intList.kt:3:14:3:31 | listOf(...) | 1 |
| intList.kt:3:29:3:30 | 12 | intList.kt:3:14:3:31 | listOf(...) | 2 |
| test.kt:19:21:19:22 | 10 | test.kt:19:14:19:31 | listOf(...) | 0 |
| test.kt:19:25:19:26 | 11 | test.kt:19:14:19:31 | listOf(...) | 1 |
| test.kt:19:29:19:30 | 12 | test.kt:19:14:19:31 | listOf(...) | 2 |
| test.kt:21:24:21:25 | 20 | test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 0 |
| test.kt:21:28:21:29 | 21 | test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 1 |
| test.kt:21:32:21:33 | 22 | test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 2 |
| test.kt:22:40:22:41 | 30 | test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 0 |
| test.kt:22:44:22:45 | 31 | test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 1 |
| test.kt:22:48:22:49 | 32 | test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 2 |
| test.kt:23:33:23:34 | 41 | test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 0 |
| test.kt:23:37:23:38 | 42 | test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 1 |
| test.kt:23:41:23:42 | 43 | test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 2 |
| test.kt:16:69:16:69 | x | test.kt:16:48:16:70 | super(...) | 0 |
| test.kt:33:21:33:22 | 10 | test.kt:33:14:33:31 | listOf(...) | 0 |
| test.kt:33:25:33:26 | 11 | test.kt:33:14:33:31 | listOf(...) | 1 |
| test.kt:33:29:33:30 | 12 | test.kt:33:14:33:31 | listOf(...) | 2 |
| test.kt:35:24:35:25 | 20 | test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 0 |
| test.kt:35:28:35:29 | 21 | test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 1 |
| test.kt:35:32:35:33 | 22 | test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 2 |
| test.kt:36:40:36:41 | 30 | test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 0 |
| test.kt:36:44:36:45 | 31 | test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 1 |
| test.kt:36:48:36:49 | 32 | test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 2 |
| test.kt:37:33:37:34 | 41 | test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 0 |
| test.kt:37:37:37:38 | 42 | test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 1 |
| test.kt:37:41:37:42 | 43 | test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 2 |
| test.kt:41:26:41:27 | 51 | test.kt:41:5:41:36 | new HasVarargConstructor(...) | 0 |
| test.kt:41:30:41:31 | 52 | test.kt:41:5:41:36 | new HasVarargConstructor(...) | 1 |
| test.kt:41:34:41:35 | 53 | test.kt:41:5:41:36 | new HasVarargConstructor(...) | 2 |
| test.kt:42:33:42:34 | 61 | test.kt:42:5:42:43 | new HasVarargConstructor(...) | 0 |
| test.kt:42:37:42:38 | 62 | test.kt:42:5:42:43 | new HasVarargConstructor(...) | 1 |
| test.kt:42:41:42:42 | 63 | test.kt:42:5:42:43 | new HasVarargConstructor(...) | 2 |
#select
| intList.kt:3:14:3:31 | listOf(...) | 0 | intList.kt:3:21:3:22 | 10 |
| intList.kt:3:14:3:31 | listOf(...) | 1 | intList.kt:3:25:3:26 | 11 |
| intList.kt:3:14:3:31 | listOf(...) | 2 | intList.kt:3:29:3:30 | 12 |
| test.kt:7:5:7:19 | sink(...) | 0 | test.kt:7:10:7:18 | ...[...] |
| test.kt:11:5:11:19 | sink(...) | 0 | test.kt:11:10:11:18 | ...[...] |
| test.kt:15:5:15:19 | sink(...) | 0 | test.kt:15:10:15:18 | ...[...] |
| test.kt:19:14:19:31 | listOf(...) | 0 | test.kt:19:21:19:22 | 10 |
| test.kt:19:14:19:31 | listOf(...) | 1 | test.kt:19:25:19:26 | 11 |
| test.kt:19:14:19:31 | listOf(...) | 2 | test.kt:19:29:19:30 | 12 |
| test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 0 | test.kt:21:24:21:25 | 20 |
| test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 1 | test.kt:21:28:21:29 | 21 |
| test.kt:21:5:21:34 | funWithOnlyVarArgs(...) | 2 | test.kt:21:32:21:33 | 22 |
| test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 0 | test.kt:22:28:22:30 | foo |
| test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 1 | test.kt:22:34:22:37 | true |
| test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 2 | test.kt:22:40:22:41 | 30 |
| test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 3 | test.kt:22:44:22:45 | 31 |
| test.kt:22:5:22:50 | funWithArgsAndVarArgs(...) | 4 | test.kt:22:48:22:49 | 32 |
| test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 0 | test.kt:23:27:23:29 | foo |
| test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 1 | test.kt:23:33:23:34 | 41 |
| test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 2 | test.kt:23:37:23:38 | 42 |
| test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 3 | test.kt:23:41:23:42 | 43 |
| test.kt:23:5:23:53 | funWithMiddleVarArgs(...) | 4 | test.kt:23:49:23:52 | true |
| test.kt:24:5:24:30 | funWithOnlyVarArgs(...) | 0 | test.kt:24:25:24:29 | array |
| test.kt:25:5:25:46 | funWithArgsAndVarArgs(...) | 0 | test.kt:25:28:25:30 | foo |
| test.kt:25:5:25:46 | funWithArgsAndVarArgs(...) | 1 | test.kt:25:34:25:37 | true |
| test.kt:25:5:25:46 | funWithArgsAndVarArgs(...) | 2 | test.kt:25:41:25:45 | array |
| test.kt:26:5:26:49 | funWithMiddleVarArgs(...) | 0 | test.kt:26:27:26:29 | foo |
| test.kt:26:5:26:49 | funWithMiddleVarArgs(...) | 1 | test.kt:26:34:26:38 | array |
| test.kt:26:5:26:49 | funWithMiddleVarArgs(...) | 2 | test.kt:26:45:26:48 | true |
| test.kt:9:5:9:19 | sink(...) | 0 | test.kt:9:10:9:18 | ...[...] |
| test.kt:12:44:12:52 | this(...) | 0 | test.kt:12:50:12:51 | xs |
| test.kt:16:48:16:70 | super(...) | 0 | test.kt:16:69:16:69 | x |
| test.kt:21:5:21:19 | sink(...) | 0 | test.kt:21:10:21:18 | ...[...] |
| test.kt:25:5:25:19 | sink(...) | 0 | test.kt:25:10:25:18 | ...[...] |
| test.kt:29:5:29:19 | sink(...) | 0 | test.kt:29:10:29:18 | ...[...] |
| test.kt:33:14:33:31 | listOf(...) | 0 | test.kt:33:21:33:22 | 10 |
| test.kt:33:14:33:31 | listOf(...) | 1 | test.kt:33:25:33:26 | 11 |
| test.kt:33:14:33:31 | listOf(...) | 2 | test.kt:33:29:33:30 | 12 |
| test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 0 | test.kt:35:24:35:25 | 20 |
| test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 1 | test.kt:35:28:35:29 | 21 |
| test.kt:35:5:35:34 | funWithOnlyVarArgs(...) | 2 | test.kt:35:32:35:33 | 22 |
| test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 0 | test.kt:36:28:36:30 | foo |
| test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 1 | test.kt:36:34:36:37 | true |
| test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 2 | test.kt:36:40:36:41 | 30 |
| test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 3 | test.kt:36:44:36:45 | 31 |
| test.kt:36:5:36:50 | funWithArgsAndVarArgs(...) | 4 | test.kt:36:48:36:49 | 32 |
| test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 0 | test.kt:37:27:37:29 | foo |
| test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 1 | test.kt:37:33:37:34 | 41 |
| test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 2 | test.kt:37:37:37:38 | 42 |
| test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 3 | test.kt:37:41:37:42 | 43 |
| test.kt:37:5:37:53 | funWithMiddleVarArgs(...) | 4 | test.kt:37:49:37:52 | true |
| test.kt:38:5:38:30 | funWithOnlyVarArgs(...) | 0 | test.kt:38:25:38:29 | array |
| test.kt:39:5:39:46 | funWithArgsAndVarArgs(...) | 0 | test.kt:39:28:39:30 | foo |
| test.kt:39:5:39:46 | funWithArgsAndVarArgs(...) | 1 | test.kt:39:34:39:37 | true |
| test.kt:39:5:39:46 | funWithArgsAndVarArgs(...) | 2 | test.kt:39:41:39:45 | array |
| test.kt:40:5:40:49 | funWithMiddleVarArgs(...) | 0 | test.kt:40:27:40:29 | foo |
| test.kt:40:5:40:49 | funWithMiddleVarArgs(...) | 1 | test.kt:40:34:40:38 | array |
| test.kt:40:5:40:49 | funWithMiddleVarArgs(...) | 2 | test.kt:40:45:40:48 | true |
| test.kt:41:5:41:36 | new HasVarargConstructor(...) | 0 | test.kt:41:26:41:27 | 51 |
| test.kt:41:5:41:36 | new HasVarargConstructor(...) | 1 | test.kt:41:30:41:31 | 52 |
| test.kt:41:5:41:36 | new HasVarargConstructor(...) | 2 | test.kt:41:34:41:35 | 53 |
| test.kt:42:5:42:43 | new HasVarargConstructor(...) | 0 | test.kt:42:27:42:29 | foo |
| test.kt:42:5:42:43 | new HasVarargConstructor(...) | 1 | test.kt:42:33:42:34 | 61 |
| test.kt:42:5:42:43 | new HasVarargConstructor(...) | 2 | test.kt:42:37:42:38 | 62 |
| test.kt:42:5:42:43 | new HasVarargConstructor(...) | 3 | test.kt:42:41:42:42 | 63 |
| test.kt:43:5:43:38 | new SuperclassHasVarargConstructor(...) | 0 | test.kt:43:36:43:37 | 91 |
| test.kt:44:5:44:32 | new HasVarargConstructor(...) | 0 | test.kt:44:27:44:31 | array |
| test.kt:45:5:45:39 | new HasVarargConstructor(...) | 0 | test.kt:45:27:45:29 | foo |
| test.kt:45:5:45:39 | new HasVarargConstructor(...) | 1 | test.kt:45:34:45:38 | array |

View File

@@ -1,15 +1,25 @@
| test.kt:20:28:20:30 | 100 | test.kt:7:10:7:18 | ...[...] |
| test.kt:20:28:20:30 | 100 | test.kt:11:10:11:18 | ...[...] |
| test.kt:20:28:20:30 | 100 | test.kt:15:10:15:18 | ...[...] |
| test.kt:20:33:20:35 | 101 | test.kt:7:10:7:18 | ...[...] |
| test.kt:20:33:20:35 | 101 | test.kt:11:10:11:18 | ...[...] |
| test.kt:20:33:20:35 | 101 | test.kt:15:10:15:18 | ...[...] |
| test.kt:20:38:20:40 | 102 | test.kt:7:10:7:18 | ...[...] |
| test.kt:20:38:20:40 | 102 | test.kt:11:10:11:18 | ...[...] |
| test.kt:20:38:20:40 | 102 | test.kt:15:10:15:18 | ...[...] |
| test.kt:21:24:21:25 | 20 | test.kt:7:10:7:18 | ...[...] |
| test.kt:21:28:21:29 | 21 | test.kt:7:10:7:18 | ...[...] |
| test.kt:21:32:21:33 | 22 | test.kt:7:10:7:18 | ...[...] |
| test.kt:22:40:22:41 | 30 | test.kt:11:10:11:18 | ...[...] |
| test.kt:22:44:22:45 | 31 | test.kt:11:10:11:18 | ...[...] |
| test.kt:22:48:22:49 | 32 | test.kt:11:10:11:18 | ...[...] |
| test.kt:34:28:34:30 | 100 | test.kt:9:10:9:18 | ...[...] |
| test.kt:34:28:34:30 | 100 | test.kt:21:10:21:18 | ...[...] |
| test.kt:34:28:34:30 | 100 | test.kt:25:10:25:18 | ...[...] |
| test.kt:34:28:34:30 | 100 | test.kt:29:10:29:18 | ...[...] |
| test.kt:34:33:34:35 | 101 | test.kt:9:10:9:18 | ...[...] |
| test.kt:34:33:34:35 | 101 | test.kt:21:10:21:18 | ...[...] |
| test.kt:34:33:34:35 | 101 | test.kt:25:10:25:18 | ...[...] |
| test.kt:34:33:34:35 | 101 | test.kt:29:10:29:18 | ...[...] |
| test.kt:34:38:34:40 | 102 | test.kt:9:10:9:18 | ...[...] |
| test.kt:34:38:34:40 | 102 | test.kt:21:10:21:18 | ...[...] |
| test.kt:34:38:34:40 | 102 | test.kt:25:10:25:18 | ...[...] |
| test.kt:34:38:34:40 | 102 | test.kt:29:10:29:18 | ...[...] |
| test.kt:35:24:35:25 | 20 | test.kt:21:10:21:18 | ...[...] |
| test.kt:35:28:35:29 | 21 | test.kt:21:10:21:18 | ...[...] |
| test.kt:35:32:35:33 | 22 | test.kt:21:10:21:18 | ...[...] |
| test.kt:36:40:36:41 | 30 | test.kt:25:10:25:18 | ...[...] |
| test.kt:36:44:36:45 | 31 | test.kt:25:10:25:18 | ...[...] |
| test.kt:36:48:36:49 | 32 | test.kt:25:10:25:18 | ...[...] |
| test.kt:41:26:41:27 | 51 | test.kt:9:10:9:18 | ...[...] |
| test.kt:41:30:41:31 | 52 | test.kt:9:10:9:18 | ...[...] |
| test.kt:41:34:41:35 | 53 | test.kt:9:10:9:18 | ...[...] |
| test.kt:42:33:42:34 | 61 | test.kt:9:10:9:18 | ...[...] |
| test.kt:42:37:42:38 | 62 | test.kt:9:10:9:18 | ...[...] |
| test.kt:42:41:42:42 | 63 | test.kt:9:10:9:18 | ...[...] |
| test.kt:43:36:43:37 | 91 | test.kt:9:10:9:18 | ...[...] |

View File

@@ -3,6 +3,20 @@ fun sink(sunk: Int) {
}
open class HasVarargConstructor {
constructor(vararg xs: Int) {
sink(xs[xs[0]])
}
constructor(x: String, vararg xs: Int) : this(*xs) { }
}
class SuperclassHasVarargConstructor(x: Int) : HasVarargConstructor(x) {
}
fun funWithOnlyVarArgs(vararg xs: Int) {
sink(xs[xs[0]])
}
@@ -24,4 +38,9 @@ fun myFun() {
funWithOnlyVarArgs(*array)
funWithArgsAndVarArgs("foo", true, *array)
funWithMiddleVarArgs("foo", *array, y = true)
HasVarargConstructor(51, 52, 53)
HasVarargConstructor("foo", 61, 62, 63)
SuperclassHasVarargConstructor(91)
HasVarargConstructor(*array)
HasVarargConstructor("foo", *array)
}