Revert dataflow changes, extract actual iterator function

This commit is contained in:
Tamas Vajk
2022-04-28 10:46:46 +02:00
committed by Chris Smowton
parent 538e05995a
commit fbae0f5053
3 changed files with 26 additions and 9 deletions

View File

@@ -1347,6 +1347,23 @@ open class KotlinFileExtractor(
return result
}
private fun findTopLevelFunctionOrWarn(functionFilter: String, type: String, warnAgainstElement: IrElement): IrFunction? {
val fn = pluginContext.referenceFunctions(FqName(functionFilter))
.firstOrNull { it.owner.parentClassOrNull?.fqNameWhenAvailable?.asString() == type }
?.owner
if (fn != null) {
if (fn.parentClassOrNull != null) {
extractExternalClassLater(fn.parentAsClass)
}
} else {
logger.errorElement("Couldn't find JVM intrinsic function $functionFilter in $type", warnAgainstElement)
}
return fn
}
val javaLangString by lazy {
val result = pluginContext.referenceClass(FqName("java.lang.String"))?.owner
result?.let { extractExternalClassLater(it) }
@@ -1860,6 +1877,11 @@ open class KotlinFileExtractor(
}
}
}
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "iterator") && c.origin == IrStatementOrigin.FOR_LOOP_ITERATOR -> {
findTopLevelFunctionOrWarn("kotlin.jvm.internal.iterator", "kotlin.jvm.internal.ArrayIteratorKt", c)?.let { iteratorFn ->
extractRawMethodAccess(iteratorFn, c, callable, parent, idx, enclosingStmt, listOf(c.dispatchReceiver), null, null, listOf((c.dispatchReceiver!!.type as IrSimpleType).arguments.first().typeOrNull!!))
}
}
isFunction(target, "kotlin", "(some array type)", { isArrayType(it) }, "get") && c.origin == IrStatementOrigin.GET_ARRAY_ELEMENT -> {
val id = tw.getFreshIdLabel<DbArrayaccess>()
val type = useType(c.type)