@@ -66,16 +66,6 @@ open class KotlinUsesExtractor(
6666 ?.let { pluginContext.referenceClass(it.asSingleFqName()) }
6767 ?.owner
6868
69- private fun withSourceFile (clsFile : IrFile ): KotlinFileExtractor {
70- if (this is KotlinSourceFileExtractor && this .file == clsFile) {
71- return this
72- }
73-
74- val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, false )
75- val newLogger = FileLogger (logger.logCounter, newTrapWriter)
76- return KotlinSourceFileExtractor (newLogger, newTrapWriter, clsFile, externalClassExtractor, primitiveTypeMapping, pluginContext)
77- }
78-
7969 /* *
8070 * Gets a KotlinFileExtractor based on this one, except it attributes locations to the file that declares the given class.
8171 */
@@ -86,9 +76,15 @@ open class KotlinUsesExtractor(
8676 val newTrapWriter = tw.makeFileTrapWriter(getIrClassBinaryPath(cls))
8777 val newLogger = FileLogger (logger.logCounter, newTrapWriter)
8878 return KotlinFileExtractor (newLogger, newTrapWriter, dependencyCollector, externalClassExtractor, primitiveTypeMapping, pluginContext)
89- } else {
90- return withSourceFile(clsFile)
9179 }
80+
81+ if (this is KotlinSourceFileExtractor && this .file == clsFile) {
82+ return this
83+ }
84+
85+ val newTrapWriter = tw.makeSourceFileTrapWriter(clsFile, false )
86+ val newLogger = FileLogger (logger.logCounter, newTrapWriter)
87+ return KotlinSourceFileExtractor (newLogger, newTrapWriter, clsFile, externalClassExtractor, primitiveTypeMapping, pluginContext)
9288 }
9389
9490 fun useClassInstance (c : IrClass , typeArgs : List <IrTypeArgument >): UseClassInstanceResult {
@@ -158,6 +154,21 @@ open class KotlinUsesExtractor(
158154 classLabelResult.shortName)
159155 }
160156
157+ private val anonymousTypeMapping: MutableMap <IrClass , TypeResults > = mutableMapOf ()
158+
159+ fun useAnonymousClass (c : IrClass ): TypeResults {
160+ var res = anonymousTypeMapping[c]
161+ if (res == null ) {
162+ val javaResult = TypeResult (tw.getFreshIdLabel<DbClass >(), " " , " " )
163+ val kotlinResult = TypeResult (tw.getFreshIdLabel<DbKt_notnull_type >(), " " , " " )
164+ tw.writeKt_notnull_types(kotlinResult.id, javaResult.id)
165+ res = TypeResults (javaResult, kotlinResult)
166+ anonymousTypeMapping[c] = res
167+ }
168+
169+ return res
170+ }
171+
161172 fun useSimpleTypeClass (c : IrClass , args : List <IrTypeArgument >, hasQuestionMark : Boolean ): TypeResults {
162173 if (c.isAnonymousObject) {
163174 if (args.isNotEmpty()) {
@@ -167,7 +178,7 @@ open class KotlinUsesExtractor(
167178 logger.warn(Severity .ErrorHigh , " Unexpected nullable anonymous class" )
168179 }
169180
170- return withSourceFile(c.fileOrNull !! ). useAnonymousClass(c)
181+ return useAnonymousClass(c)
171182 }
172183
173184 val classInstanceResult = useClassInstance(c, args)
@@ -453,9 +464,33 @@ class X {
453464 this .origin != IrDeclarationOrigin .LOCAL_FUNCTION_FOR_LAMBDA
454465 }
455466
467+ private val generatedLocalFunctionTypeMapping: MutableMap <IrFunction , LocalFunctionLabels > = mutableMapOf ()
468+
469+ data class LocalFunctionLabels (val type : TypeResults , val constructor : Label <DbConstructor >, val function : Label <DbMethod >)
470+
471+ fun getLocalFunctionLabels (f : IrFunction ): LocalFunctionLabels {
472+ if (! f.isLocalFunction()){
473+ logger.warn(Severity .ErrorSevere , " Extracting a non-local function as a local one" )
474+ }
475+
476+ var res = generatedLocalFunctionTypeMapping[f]
477+ if (res == null ) {
478+ val javaResult = TypeResult (tw.getFreshIdLabel<DbClass >(), " " , " " )
479+ val kotlinResult = TypeResult (tw.getFreshIdLabel<DbKt_notnull_type >(), " " , " " )
480+ tw.writeKt_notnull_types(kotlinResult.id, javaResult.id)
481+ res = LocalFunctionLabels (
482+ TypeResults (javaResult, kotlinResult),
483+ tw.getFreshIdLabel(),
484+ tw.getFreshIdLabel())
485+ generatedLocalFunctionTypeMapping[f] = res
486+ }
487+
488+ return res
489+ }
490+
456491 fun <T : DbCallable > useFunction (f : IrFunction ): Label <out T > {
457492 if (f.isLocalFunction()) {
458- val ids = withSourceFile(f.fileOrNull !! ). getLocalFunctionLabels(f)
493+ val ids = getLocalFunctionLabels(f)
459494 @Suppress(" UNCHECKED_CAST" )
460495 return ids.function as Label <out T >
461496 }
@@ -559,7 +594,7 @@ class X {
559594 fun useClassSource (c : IrClass ): Label <out DbClassorinterface > {
560595 if (c.isAnonymousObject) {
561596 @Suppress(" UNCHECKED_CAST" )
562- return withSourceFile(c.fileOrNull !! ). useAnonymousClass(c).javaResult.id as Label <DbClass >
597+ return useAnonymousClass(c).javaResult.id as Label <DbClass >
563598 }
564599
565600 // For source classes, the label doesn't include and type arguments
0 commit comments