Extract arrayOf-like calls

This commit is contained in:
Tamas Vajk
2021-11-24 14:20:52 +01:00
committed by Ian Lynagh
parent 8b81ee7e59
commit 8de5e39309
4 changed files with 212 additions and 24 deletions

View File

@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.IrTypeArgument
import org.jetbrains.kotlin.ir.types.classFqName
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.*
open class KotlinFileExtractor(
@@ -532,7 +529,10 @@ open class KotlinFileExtractor(
}
}
fun isBuiltinCall(c: IrCall, fName: String): Boolean {
private fun isBuiltinCallInternal(c: IrCall, fName: String) = isBuiltinCall(c, fName, "kotlin.internal.ir")
private fun isBuiltinCallKotlin(c: IrCall, fName: String) = isBuiltinCall(c, fName, "kotlin")
private fun isBuiltinCall(c: IrCall, fName: String, pName: String): Boolean {
val verbose = false
fun verboseln(s: String) { if(verbose) println(s) }
verboseln("Attempting builtin match for $fName")
@@ -549,7 +549,7 @@ open class KotlinFileExtractor(
verboseln("No match as didn't find target package")
return false
}
if (targetPkg.fqName.asString() != "kotlin.internal.ir") {
if (targetPkg.fqName.asString() != pName) {
verboseln("No match as package name is ${targetPkg.fqName.asString()}")
return false
}
@@ -719,19 +719,19 @@ open class KotlinFileExtractor(
}
// != gets desugared into not and ==. Here we resugar it.
// TODO: This is wrong. Kotlin `a == b` is `a?.equals(b) ?: (b === null)`
c.origin == IrStatementOrigin.EXCLEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCall(dr, "EQEQ") -> {
c.origin == IrStatementOrigin.EXCLEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCallInternal(dr, "EQEQ") -> {
val id = tw.getFreshIdLabel<DbNeexpr>()
val type = useType(c.type)
tw.writeExprs_neexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, dr, callable, enclosingStmt)
}
c.origin == IrStatementOrigin.EXCLEQEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCall(dr, "EQEQEQ") -> {
c.origin == IrStatementOrigin.EXCLEQEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCallInternal(dr, "EQEQEQ") -> {
val id = tw.getFreshIdLabel<DbNeexpr>()
val type = useType(c.type)
tw.writeExprs_neexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, dr, callable, enclosingStmt)
}
c.origin == IrStatementOrigin.EXCLEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCall(dr, "ieee754equals") -> {
c.origin == IrStatementOrigin.EXCLEQ && isFunction("kotlin", "Boolean", "not") && c.valueArgumentsCount == 0 && dr != null && dr is IrCall && isBuiltinCallInternal(dr, "ieee754equals") -> {
val id = tw.getFreshIdLabel<DbNeexpr>()
val type = useType(c.type)
// TODO: Is this consistent with Java?
@@ -741,7 +741,7 @@ open class KotlinFileExtractor(
// We need to handle all the builtin operators defines in BuiltInOperatorNames in
// compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/IrBuiltIns.kt
// as they can't be extracted as external dependencies.
isBuiltinCall(c, "less") -> {
isBuiltinCallInternal(c, "less") -> {
if(c.origin != IrStatementOrigin.LT) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for LT: ${c.origin}", c)
}
@@ -750,7 +750,7 @@ open class KotlinFileExtractor(
tw.writeExprs_ltexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "lessOrEqual") -> {
isBuiltinCallInternal(c, "lessOrEqual") -> {
if(c.origin != IrStatementOrigin.LTEQ) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for LTEQ: ${c.origin}", c)
}
@@ -759,7 +759,7 @@ open class KotlinFileExtractor(
tw.writeExprs_leexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "greater") -> {
isBuiltinCallInternal(c, "greater") -> {
if(c.origin != IrStatementOrigin.GT) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for GT: ${c.origin}", c)
}
@@ -768,7 +768,7 @@ open class KotlinFileExtractor(
tw.writeExprs_gtexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "greaterOrEqual") -> {
isBuiltinCallInternal(c, "greaterOrEqual") -> {
if(c.origin != IrStatementOrigin.GTEQ) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for GTEQ: ${c.origin}", c)
}
@@ -777,7 +777,7 @@ open class KotlinFileExtractor(
tw.writeExprs_geexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "EQEQ") -> {
isBuiltinCallInternal(c, "EQEQ") -> {
if(c.origin != IrStatementOrigin.EQEQ) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for EQEQ: ${c.origin}", c)
}
@@ -787,7 +787,7 @@ open class KotlinFileExtractor(
tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "EQEQEQ") -> {
isBuiltinCallInternal(c, "EQEQEQ") -> {
if(c.origin != IrStatementOrigin.EQEQEQ) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for EQEQEQ: ${c.origin}", c)
}
@@ -796,7 +796,7 @@ open class KotlinFileExtractor(
tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "ieee754equals") -> {
isBuiltinCallInternal(c, "ieee754equals") -> {
if(c.origin != IrStatementOrigin.EQEQ) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for ieee754equals: ${c.origin}", c)
}
@@ -806,7 +806,7 @@ open class KotlinFileExtractor(
tw.writeExprs_eqexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
binOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "CHECK_NOT_NULL") -> {
isBuiltinCallInternal(c, "CHECK_NOT_NULL") -> {
if(c.origin != IrStatementOrigin.EXCLEXCL) {
logger.warnElement(Severity.ErrorSevere, "Unexpected origin for CHECK_NOT_NULL: ${c.origin}", c)
}
@@ -816,30 +816,108 @@ open class KotlinFileExtractor(
tw.writeExprs_notnullexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
unaryOp(id, c, callable, enclosingStmt)
}
isBuiltinCall(c, "THROW_CCE") -> {
isBuiltinCallInternal(c, "THROW_CCE") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCall(c, "THROW_ISE") -> {
isBuiltinCallInternal(c, "THROW_ISE") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCall(c, "noWhenBranchMatchedException") -> {
isBuiltinCallInternal(c, "noWhenBranchMatchedException") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCall(c, "illegalArgumentException") -> {
isBuiltinCallInternal(c, "illegalArgumentException") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCall(c, "ANDAND") -> {
isBuiltinCallInternal(c, "ANDAND") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCall(c, "OROR") -> {
isBuiltinCallInternal(c, "OROR") -> {
// TODO
logger.warnElement(Severity.ErrorSevere, "Unhandled builtin", c)
}
isBuiltinCallKotlin(c, "arrayOfNulls") -> {
val id = tw.getFreshIdLabel<DbArraycreationexpr>()
val type = useType(c.type)
tw.writeExprs_arraycreationexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
val locId = tw.getLocation(c)
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
if (c.typeArgumentsCount == 1) {
extractTypeArguments(c, id, callable, -1)
} else {
logger.warnElement(Severity.ErrorSevere, "Expected to find exactly one type argument in an arrayOfNulls call", c)
}
if (c.valueArgumentsCount == 1) {
val dim = c.getValueArgument(0)
if (dim != null) {
extractExpressionExpr(dim, callable, id, 0)
} else {
logger.warnElement(Severity.ErrorSevere, "Expected to find non-null argument in an arrayOfNulls call", c)
}
} else {
logger.warnElement(Severity.ErrorSevere, "Expected to find only one argument in an arrayOfNulls call", c)
}
}
isBuiltinCallKotlin(c, "arrayOf")
|| isBuiltinCallKotlin(c, "doubleArrayOf")
|| isBuiltinCallKotlin(c, "floatArrayOf")
|| isBuiltinCallKotlin(c, "longArrayOf")
|| isBuiltinCallKotlin(c, "intArrayOf")
|| isBuiltinCallKotlin(c, "charArrayOf")
|| isBuiltinCallKotlin(c, "shortArrayOf")
|| isBuiltinCallKotlin(c, "byteArrayOf")
|| isBuiltinCallKotlin(c, "booleanArrayOf") -> {
val id = tw.getFreshIdLabel<DbArraycreationexpr>()
val type = useType(c.type)
tw.writeExprs_arraycreationexpr(id, type.javaResult.id, type.kotlinResult.id, parent, idx)
val locId = tw.getLocation(c)
tw.writeHasLocation(id, locId)
tw.writeCallableEnclosingExpr(id, callable)
if (isBuiltinCallKotlin(c, "arrayOf")) {
if (c.typeArgumentsCount == 1) {
extractTypeArguments(c, id, callable, -1)
} else {
logger.warnElement( Severity.ErrorSevere, "Expected to find one type argument in arrayOf call", c )
}
} else {
val argId = tw.getFreshIdLabel<DbUnannotatedtypeaccess>()
val elementType = c.type.getArrayElementType(pluginContext.irBuiltIns)
val elementTypeResult = useType(elementType)
tw.writeExprs_unannotatedtypeaccess(argId, elementTypeResult.javaResult.id, elementTypeResult.kotlinResult.id, id, -1)
tw.writeCallableEnclosingExpr(argId, callable)
}
if (c.valueArgumentsCount == 1) {
val vararg = c.getValueArgument(0)
if (vararg is IrVararg) {
val initId = tw.getFreshIdLabel<DbArrayinit>()
tw.writeExprs_arrayinit(initId, type.javaResult.id, type.kotlinResult.id, id, -2)
tw.writeHasLocation(initId, locId)
tw.writeCallableEnclosingExpr(initId, callable)
vararg.elements.forEachIndexed { i, arg -> extractVarargElement(arg, callable, initId, i) }
val dim = vararg.elements.size
val dimId = tw.getFreshIdLabel<DbIntegerliteral>()
val dimType = useType(pluginContext.irBuiltIns.intType)
tw.writeExprs_integerliteral(dimId, dimType.javaResult.id, dimType.kotlinResult.id, id, 0)
tw.writeHasLocation(dimId, locId)
tw.writeCallableEnclosingExpr(dimId, callable)
tw.writeNamestrings(dim.toString(), dim.toString(), dimId)
} else {
logger.warnElement(Severity.ErrorSevere, "Expected to find vararg argument in ${c.symbol.owner.name.asString()} call", c)
}
} else {
logger.warnElement(Severity.ErrorSevere, "Expected to find only one (vararg) argument in ${c.symbol.owner.name.asString()} call", c)
}
}
else -> {
val id = tw.getFreshIdLabel<DbMethodaccess>()
val type = useType(c.type)

View File

@@ -1,3 +1,105 @@
arrayCreationTypes
| arrayCreations.kt:5:14:5:33 | new Integer[] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer |
| arrayCreations.kt:6:14:6:32 | new Integer[] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer |
| arrayCreations.kt:7:14:7:46 | new double[] | file://:0:0:0:0 | double[] | file://:0:0:0:0 | double |
| arrayCreations.kt:8:14:8:49 | new float[] | file://:0:0:0:0 | float[] | file://:0:0:0:0 | float |
| arrayCreations.kt:9:14:9:36 | new long[] | file://:0:0:0:0 | long[] | file://:0:0:0:0 | long |
| arrayCreations.kt:10:14:10:35 | new int[] | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int |
| arrayCreations.kt:11:14:11:34 | new char[] | file://:0:0:0:0 | char[] | file://:0:0:0:0 | char |
| arrayCreations.kt:12:14:12:37 | new short[] | file://:0:0:0:0 | short[] | file://:0:0:0:0 | short |
| arrayCreations.kt:13:14:13:36 | new byte[] | file://:0:0:0:0 | byte[] | file://:0:0:0:0 | byte |
| arrayCreations.kt:14:14:14:52 | new boolean[] | file://:0:0:0:0 | boolean[] | file://:0:0:0:0 | boolean |
| arrayCreations.kt:16:14:16:68 | new int[][] | file://:0:0:0:0 | int[][] | file://:0:0:0:0 | int[] |
| arrayCreations.kt:16:22:16:43 | new int[] | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int |
| arrayCreations.kt:16:46:16:67 | new int[] | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int |
| arrayCreations.kt:17:14:17:65 | new Object[] | file://:0:0:0:0 | Object[] | file://:0:0:0:0 | Object |
| arrayCreations.kt:17:22:17:43 | new int[] | file://:0:0:0:0 | int[] | file://:0:0:0:0 | int |
| arrayCreations.kt:17:46:17:64 | new Integer[] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer |
| arrayCreations.kt:18:14:18:62 | new Integer[][] | file://:0:0:0:0 | Integer[][] | file://:0:0:0:0 | Integer[] |
| arrayCreations.kt:18:22:18:40 | new Integer[] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer |
| arrayCreations.kt:18:43:18:61 | new Integer[] | file://:0:0:0:0 | Integer[] | file://:0:0:0:0 | Integer |
arrayCreationDimensions
| arrayCreations.kt:5:14:5:33 | new Integer[] | arrayCreations.kt:5:32:5:32 | 1 | 0 |
| arrayCreations.kt:6:14:6:32 | new Integer[] | arrayCreations.kt:6:14:6:32 | 4 | 0 |
| arrayCreations.kt:7:14:7:46 | new double[] | arrayCreations.kt:7:14:7:46 | 4 | 0 |
| arrayCreations.kt:8:14:8:49 | new float[] | arrayCreations.kt:8:14:8:49 | 4 | 0 |
| arrayCreations.kt:9:14:9:36 | new long[] | arrayCreations.kt:9:14:9:36 | 4 | 0 |
| arrayCreations.kt:10:14:10:35 | new int[] | arrayCreations.kt:10:14:10:35 | 4 | 0 |
| arrayCreations.kt:11:14:11:34 | new char[] | arrayCreations.kt:11:14:11:34 | 2 | 0 |
| arrayCreations.kt:12:14:12:37 | new short[] | arrayCreations.kt:12:14:12:37 | 4 | 0 |
| arrayCreations.kt:13:14:13:36 | new byte[] | arrayCreations.kt:13:14:13:36 | 4 | 0 |
| arrayCreations.kt:14:14:14:52 | new boolean[] | arrayCreations.kt:14:14:14:52 | 4 | 0 |
| arrayCreations.kt:16:14:16:68 | new int[][] | arrayCreations.kt:16:14:16:68 | 2 | 0 |
| arrayCreations.kt:16:22:16:43 | new int[] | arrayCreations.kt:16:22:16:43 | 4 | 0 |
| arrayCreations.kt:16:46:16:67 | new int[] | arrayCreations.kt:16:46:16:67 | 4 | 0 |
| arrayCreations.kt:17:14:17:65 | new Object[] | arrayCreations.kt:17:14:17:65 | 2 | 0 |
| arrayCreations.kt:17:22:17:43 | new int[] | arrayCreations.kt:17:22:17:43 | 4 | 0 |
| arrayCreations.kt:17:46:17:64 | new Integer[] | arrayCreations.kt:17:46:17:64 | 4 | 0 |
| arrayCreations.kt:18:14:18:62 | new Integer[][] | arrayCreations.kt:18:14:18:62 | 2 | 0 |
| arrayCreations.kt:18:22:18:40 | new Integer[] | arrayCreations.kt:18:22:18:40 | 4 | 0 |
| arrayCreations.kt:18:43:18:61 | new Integer[] | arrayCreations.kt:18:43:18:61 | 4 | 0 |
arrayCreationInit
| arrayCreations.kt:6:14:6:32 | new Integer[] | arrayCreations.kt:6:14:6:32 | {...} | arrayCreations.kt:6:22:6:22 | 1 | 0 |
| arrayCreations.kt:6:14:6:32 | new Integer[] | arrayCreations.kt:6:14:6:32 | {...} | arrayCreations.kt:6:25:6:25 | 2 | 1 |
| arrayCreations.kt:6:14:6:32 | new Integer[] | arrayCreations.kt:6:14:6:32 | {...} | arrayCreations.kt:6:28:6:28 | 3 | 2 |
| arrayCreations.kt:6:14:6:32 | new Integer[] | arrayCreations.kt:6:14:6:32 | {...} | arrayCreations.kt:6:31:6:31 | 4 | 3 |
| arrayCreations.kt:7:14:7:46 | new double[] | arrayCreations.kt:7:14:7:46 | {...} | arrayCreations.kt:7:28:7:30 | 1.0 | 0 |
| arrayCreations.kt:7:14:7:46 | new double[] | arrayCreations.kt:7:14:7:46 | {...} | arrayCreations.kt:7:33:7:35 | 2.0 | 1 |
| arrayCreations.kt:7:14:7:46 | new double[] | arrayCreations.kt:7:14:7:46 | {...} | arrayCreations.kt:7:38:7:40 | 3.0 | 2 |
| arrayCreations.kt:7:14:7:46 | new double[] | arrayCreations.kt:7:14:7:46 | {...} | arrayCreations.kt:7:43:7:45 | 4.0 | 3 |
| arrayCreations.kt:8:14:8:49 | new float[] | arrayCreations.kt:8:14:8:49 | {...} | arrayCreations.kt:8:27:8:30 | 1.0 | 0 |
| arrayCreations.kt:8:14:8:49 | new float[] | arrayCreations.kt:8:14:8:49 | {...} | arrayCreations.kt:8:33:8:36 | 2.0 | 1 |
| arrayCreations.kt:8:14:8:49 | new float[] | arrayCreations.kt:8:14:8:49 | {...} | arrayCreations.kt:8:39:8:42 | 3.0 | 2 |
| arrayCreations.kt:8:14:8:49 | new float[] | arrayCreations.kt:8:14:8:49 | {...} | arrayCreations.kt:8:45:8:48 | 4.0 | 3 |
| arrayCreations.kt:9:14:9:36 | new long[] | arrayCreations.kt:9:14:9:36 | {...} | arrayCreations.kt:9:26:9:26 | 1 | 0 |
| arrayCreations.kt:9:14:9:36 | new long[] | arrayCreations.kt:9:14:9:36 | {...} | arrayCreations.kt:9:29:9:29 | 2 | 1 |
| arrayCreations.kt:9:14:9:36 | new long[] | arrayCreations.kt:9:14:9:36 | {...} | arrayCreations.kt:9:32:9:32 | 3 | 2 |
| arrayCreations.kt:9:14:9:36 | new long[] | arrayCreations.kt:9:14:9:36 | {...} | arrayCreations.kt:9:35:9:35 | 4 | 3 |
| arrayCreations.kt:10:14:10:35 | new int[] | arrayCreations.kt:10:14:10:35 | {...} | arrayCreations.kt:10:25:10:25 | 1 | 0 |
| arrayCreations.kt:10:14:10:35 | new int[] | arrayCreations.kt:10:14:10:35 | {...} | arrayCreations.kt:10:28:10:28 | 2 | 1 |
| arrayCreations.kt:10:14:10:35 | new int[] | arrayCreations.kt:10:14:10:35 | {...} | arrayCreations.kt:10:31:10:31 | 3 | 2 |
| arrayCreations.kt:10:14:10:35 | new int[] | arrayCreations.kt:10:14:10:35 | {...} | arrayCreations.kt:10:34:10:34 | 4 | 3 |
| arrayCreations.kt:11:14:11:34 | new char[] | arrayCreations.kt:11:14:11:34 | {...} | arrayCreations.kt:11:26:11:28 | a | 0 |
| arrayCreations.kt:11:14:11:34 | new char[] | arrayCreations.kt:11:14:11:34 | {...} | arrayCreations.kt:11:31:11:33 | b | 1 |
| arrayCreations.kt:12:14:12:37 | new short[] | arrayCreations.kt:12:14:12:37 | {...} | arrayCreations.kt:12:27:12:27 | 1 | 0 |
| arrayCreations.kt:12:14:12:37 | new short[] | arrayCreations.kt:12:14:12:37 | {...} | arrayCreations.kt:12:30:12:30 | 2 | 1 |
| arrayCreations.kt:12:14:12:37 | new short[] | arrayCreations.kt:12:14:12:37 | {...} | arrayCreations.kt:12:33:12:33 | 3 | 2 |
| arrayCreations.kt:12:14:12:37 | new short[] | arrayCreations.kt:12:14:12:37 | {...} | arrayCreations.kt:12:36:12:36 | 4 | 3 |
| arrayCreations.kt:13:14:13:36 | new byte[] | arrayCreations.kt:13:14:13:36 | {...} | arrayCreations.kt:13:26:13:26 | 1 | 0 |
| arrayCreations.kt:13:14:13:36 | new byte[] | arrayCreations.kt:13:14:13:36 | {...} | arrayCreations.kt:13:29:13:29 | 2 | 1 |
| arrayCreations.kt:13:14:13:36 | new byte[] | arrayCreations.kt:13:14:13:36 | {...} | arrayCreations.kt:13:32:13:32 | 3 | 2 |
| arrayCreations.kt:13:14:13:36 | new byte[] | arrayCreations.kt:13:14:13:36 | {...} | arrayCreations.kt:13:35:13:35 | 4 | 3 |
| arrayCreations.kt:14:14:14:52 | new boolean[] | arrayCreations.kt:14:14:14:52 | {...} | arrayCreations.kt:14:29:14:32 | true | 0 |
| arrayCreations.kt:14:14:14:52 | new boolean[] | arrayCreations.kt:14:14:14:52 | {...} | arrayCreations.kt:14:35:14:39 | false | 1 |
| arrayCreations.kt:14:14:14:52 | new boolean[] | arrayCreations.kt:14:14:14:52 | {...} | arrayCreations.kt:14:42:14:45 | true | 2 |
| arrayCreations.kt:14:14:14:52 | new boolean[] | arrayCreations.kt:14:14:14:52 | {...} | arrayCreations.kt:14:48:14:51 | true | 3 |
| arrayCreations.kt:16:14:16:68 | new int[][] | arrayCreations.kt:16:14:16:68 | {...} | arrayCreations.kt:16:22:16:43 | new int[] | 0 |
| arrayCreations.kt:16:14:16:68 | new int[][] | arrayCreations.kt:16:14:16:68 | {...} | arrayCreations.kt:16:46:16:67 | new int[] | 1 |
| arrayCreations.kt:16:22:16:43 | new int[] | arrayCreations.kt:16:22:16:43 | {...} | arrayCreations.kt:16:33:16:33 | 1 | 0 |
| arrayCreations.kt:16:22:16:43 | new int[] | arrayCreations.kt:16:22:16:43 | {...} | arrayCreations.kt:16:36:16:36 | 2 | 1 |
| arrayCreations.kt:16:22:16:43 | new int[] | arrayCreations.kt:16:22:16:43 | {...} | arrayCreations.kt:16:39:16:39 | 3 | 2 |
| arrayCreations.kt:16:22:16:43 | new int[] | arrayCreations.kt:16:22:16:43 | {...} | arrayCreations.kt:16:42:16:42 | 4 | 3 |
| arrayCreations.kt:16:46:16:67 | new int[] | arrayCreations.kt:16:46:16:67 | {...} | arrayCreations.kt:16:57:16:57 | 1 | 0 |
| arrayCreations.kt:16:46:16:67 | new int[] | arrayCreations.kt:16:46:16:67 | {...} | arrayCreations.kt:16:60:16:60 | 2 | 1 |
| arrayCreations.kt:16:46:16:67 | new int[] | arrayCreations.kt:16:46:16:67 | {...} | arrayCreations.kt:16:63:16:63 | 3 | 2 |
| arrayCreations.kt:16:46:16:67 | new int[] | arrayCreations.kt:16:46:16:67 | {...} | arrayCreations.kt:16:66:16:66 | 4 | 3 |
| arrayCreations.kt:17:14:17:65 | new Object[] | arrayCreations.kt:17:14:17:65 | {...} | arrayCreations.kt:17:22:17:43 | new int[] | 0 |
| arrayCreations.kt:17:14:17:65 | new Object[] | arrayCreations.kt:17:14:17:65 | {...} | arrayCreations.kt:17:46:17:64 | new Integer[] | 1 |
| arrayCreations.kt:17:22:17:43 | new int[] | arrayCreations.kt:17:22:17:43 | {...} | arrayCreations.kt:17:33:17:33 | 1 | 0 |
| arrayCreations.kt:17:22:17:43 | new int[] | arrayCreations.kt:17:22:17:43 | {...} | arrayCreations.kt:17:36:17:36 | 2 | 1 |
| arrayCreations.kt:17:22:17:43 | new int[] | arrayCreations.kt:17:22:17:43 | {...} | arrayCreations.kt:17:39:17:39 | 3 | 2 |
| arrayCreations.kt:17:22:17:43 | new int[] | arrayCreations.kt:17:22:17:43 | {...} | arrayCreations.kt:17:42:17:42 | 4 | 3 |
| arrayCreations.kt:17:46:17:64 | new Integer[] | arrayCreations.kt:17:46:17:64 | {...} | arrayCreations.kt:17:54:17:54 | 1 | 0 |
| arrayCreations.kt:17:46:17:64 | new Integer[] | arrayCreations.kt:17:46:17:64 | {...} | arrayCreations.kt:17:57:17:57 | 2 | 1 |
| arrayCreations.kt:17:46:17:64 | new Integer[] | arrayCreations.kt:17:46:17:64 | {...} | arrayCreations.kt:17:60:17:60 | 3 | 2 |
| arrayCreations.kt:17:46:17:64 | new Integer[] | arrayCreations.kt:17:46:17:64 | {...} | arrayCreations.kt:17:63:17:63 | 4 | 3 |
| arrayCreations.kt:18:14:18:62 | new Integer[][] | arrayCreations.kt:18:14:18:62 | {...} | arrayCreations.kt:18:22:18:40 | new Integer[] | 0 |
| arrayCreations.kt:18:14:18:62 | new Integer[][] | arrayCreations.kt:18:14:18:62 | {...} | arrayCreations.kt:18:43:18:61 | new Integer[] | 1 |
| arrayCreations.kt:18:22:18:40 | new Integer[] | arrayCreations.kt:18:22:18:40 | {...} | arrayCreations.kt:18:30:18:30 | 1 | 0 |
| arrayCreations.kt:18:22:18:40 | new Integer[] | arrayCreations.kt:18:22:18:40 | {...} | arrayCreations.kt:18:33:18:33 | 2 | 1 |
| arrayCreations.kt:18:22:18:40 | new Integer[] | arrayCreations.kt:18:22:18:40 | {...} | arrayCreations.kt:18:36:18:36 | 3 | 2 |
| arrayCreations.kt:18:22:18:40 | new Integer[] | arrayCreations.kt:18:22:18:40 | {...} | arrayCreations.kt:18:39:18:39 | 4 | 3 |
| arrayCreations.kt:18:43:18:61 | new Integer[] | arrayCreations.kt:18:43:18:61 | {...} | arrayCreations.kt:18:51:18:51 | 1 | 0 |
| arrayCreations.kt:18:43:18:61 | new Integer[] | arrayCreations.kt:18:43:18:61 | {...} | arrayCreations.kt:18:54:18:54 | 2 | 1 |
| arrayCreations.kt:18:43:18:61 | new Integer[] | arrayCreations.kt:18:43:18:61 | {...} | arrayCreations.kt:18:57:18:57 | 3 | 2 |
| arrayCreations.kt:18:43:18:61 | new Integer[] | arrayCreations.kt:18:43:18:61 | {...} | arrayCreations.kt:18:60:18:60 | 4 | 3 |

View File

@@ -13,6 +13,12 @@ class TestArrayCreation {
val a8 = byteArrayOf(1, 2, 3, 4)
val a9 = booleanArrayOf(true, false, true, true)
// TODO: These don't match the corresponding Java hierarchy
val n0 = arrayOf(intArrayOf(1, 2, 3, 4), intArrayOf(1, 2, 3, 4)) // int[][]
val n1 = arrayOf(intArrayOf(1, 2, 3, 4), arrayOf(1, 2, 3, 4)) // Object[]
val n2 = arrayOf(arrayOf(1, 2, 3, 4), arrayOf(1, 2, 3, 4)) // Integer[][]
// TODO: these are constructor calls:
val a10 = Array<Int>(1) { 1 }
val a11 = Array(5) { 1 }
val a12 = IntArray(5)

View File

@@ -1,6 +1,8 @@
import java
query predicate arrayCreationTypes(ArrayCreationExpr ace, Type t) { t = ace.getType() }
query predicate arrayCreationTypes(ArrayCreationExpr ace, Type t, TypeAccess elementType) {
t = ace.getType() and elementType.getParent() = ace
}
query predicate arrayCreationDimensions(ArrayCreationExpr ace, Expr dimension, int dimensionIdx) {
ace.getDimension(dimensionIdx) = dimension