@@ -1151,10 +1151,10 @@ open class KotlinFileExtractor(
11511151
11521152 fun extractCall (c : IrCall , callable : Label <out DbCallable >, parent : Label <out DbExprparent >, idx : Int , enclosingStmt : Label <out DbStmt >) {
11531153 with (" call" , c) {
1154- fun isFunction (pkgName : String , className : String , fName : String , hasQuestionMark : Boolean? = false): Boolean {
1154+ fun isFunction (pkgName : String , classNameLogged : String , classNamePredicate : ( String ) -> Boolean , fName : String , hasQuestionMark : Boolean? = false): Boolean {
11551155 val verbose = false
11561156 fun verboseln (s : String ) { if (verbose) println (s) }
1157- verboseln(" Attempting match for $pkgName $className $fName " )
1157+ verboseln(" Attempting match for $pkgName $classNameLogged $fName " )
11581158 val target = c.symbol.owner
11591159 if (target.name.asString() != fName) {
11601160 verboseln(" No match as function name is ${target.name.asString()} not $fName " )
@@ -1179,8 +1179,8 @@ open class KotlinFileExtractor(
11791179 verboseln(" No match as didn't find target class" )
11801180 return false
11811181 }
1182- if (targetClass.name.asString() != className ) {
1183- verboseln(" No match as class name is ${targetClass.name.asString()} not $className " )
1182+ if (! classNamePredicate( targetClass.name.asString()) ) {
1183+ verboseln(" No match as class name is ${targetClass.name.asString()} not $classNameLogged " )
11841184 return false
11851185 }
11861186 val targetPkg = targetClass.parent
@@ -1195,7 +1195,10 @@ open class KotlinFileExtractor(
11951195 verboseln(" Match" )
11961196 return true
11971197 }
1198-
1198+
1199+ fun isFunction (pkgName : String , className : String , fName : String , hasQuestionMark : Boolean? = false) =
1200+ isFunction(pkgName, className, { it == className }, fName, hasQuestionMark)
1201+
11991202 fun isNumericFunction (fName : String ): Boolean {
12001203 return isFunction(" kotlin" , " Int" , fName) ||
12011204 isFunction(" kotlin" , " Byte" , fName) ||
@@ -1205,6 +1208,20 @@ open class KotlinFileExtractor(
12051208 isFunction(" kotlin" , " Double" , fName)
12061209 }
12071210
1211+ fun isArrayType (typeName : String ) =
1212+ when (typeName) {
1213+ " Array" -> true
1214+ " IntArray" -> true
1215+ " ByteArray" -> true
1216+ " ShortArray" -> true
1217+ " LongArray" -> true
1218+ " FloatArray" -> true
1219+ " DoubleArray" -> true
1220+ " CharArray" -> true
1221+ " BooleanArray" -> true
1222+ else -> false
1223+ }
1224+
12081225 fun extractMethodAccess (syntacticCallTarget : IrFunction , extractMethodTypeArguments : Boolean = true, extractClassTypeArguments : Boolean = false) {
12091226 val typeArgs =
12101227 if (extractMethodTypeArguments)
@@ -1561,6 +1578,46 @@ open class KotlinFileExtractor(
15611578 }
15621579 }
15631580 }
1581+ isFunction(" kotlin" , " (some array type)" , { isArrayType(it) }, " get" ) && c.origin == IrStatementOrigin .GET_ARRAY_ELEMENT -> {
1582+ val id = tw.getFreshIdLabel<DbArrayaccess >()
1583+ val type = useType(c.type)
1584+ tw.writeExprs_arrayaccess(id, type.javaResult.id, parent, idx)
1585+ tw.writeExprsKotlinType(id, type.kotlinResult.id)
1586+ binopDisp(id)
1587+ }
1588+ isFunction(" kotlin" , " (some array type)" , { isArrayType(it) }, " set" ) && c.origin == IrStatementOrigin .EQ -> {
1589+ val array = c.dispatchReceiver
1590+ val arrayIdx = c.getValueArgument(0 )
1591+ val assignedValue = c.getValueArgument(1 )
1592+
1593+ if (array != null && arrayIdx != null && assignedValue != null ) {
1594+
1595+ val assignId = tw.getFreshIdLabel<DbAssignexpr >()
1596+ val type = useType(c.type)
1597+ val locId = tw.getLocation(c)
1598+ tw.writeExprs_assignexpr(assignId, type.javaResult.id, parent, idx)
1599+ tw.writeExprsKotlinType(assignId, type.kotlinResult.id)
1600+ tw.writeHasLocation(assignId, locId)
1601+ tw.writeCallableEnclosingExpr(assignId, callable)
1602+ tw.writeStatementEnclosingExpr(assignId, enclosingStmt)
1603+
1604+ val arrayAccessId = tw.getFreshIdLabel<DbArrayaccess >()
1605+ val arrayType = useType(array.type)
1606+ tw.writeExprs_arrayaccess(arrayAccessId, arrayType.javaResult.id, assignId, 0 )
1607+ tw.writeExprsKotlinType(arrayAccessId, arrayType.kotlinResult.id)
1608+ tw.writeHasLocation(arrayAccessId, locId)
1609+ tw.writeCallableEnclosingExpr(arrayAccessId, callable)
1610+ tw.writeStatementEnclosingExpr(arrayAccessId, enclosingStmt)
1611+
1612+ extractExpressionExpr(array, callable, arrayAccessId, 0 , enclosingStmt)
1613+ extractExpressionExpr(arrayIdx, callable, arrayAccessId, 1 , enclosingStmt)
1614+
1615+ extractExpressionExpr(assignedValue, callable, assignId, 1 , enclosingStmt)
1616+
1617+ } else {
1618+ logger.errorElement(" Unexpected Array.set function signature" , c)
1619+ }
1620+ }
15641621 isBuiltinCall(c, " <unsafe-coerce>" , " kotlin.jvm.internal" ) -> {
15651622
15661623 if (c.valueArgumentsCount != 1 ) {
0 commit comments