Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90f7cc1

Browse files
committed
Kotlin: Move anonymousTypeMapping and locallyVisibleFunctionLabelMapping
They're now in LabelManager, so they are shared between extractors.
1 parent aad9e56 commit 90f7cc1

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,16 +329,14 @@ open class KotlinUsesExtractor(
329329
classLabelResult.shortName)
330330
}
331331

332-
private val anonymousTypeMapping: MutableMap<IrClass, TypeResults> = mutableMapOf()
333-
334332
fun useAnonymousClass(c: IrClass): TypeResults {
335-
var res = anonymousTypeMapping[c]
333+
var res = tw.lm.anonymousTypeMapping[c]
336334
if (res == null) {
337335
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")
338336
val kotlinResult = TypeResult(tw.getFreshIdLabel<DbKt_notnull_type>(), "", "")
339337
tw.writeKt_notnull_types(kotlinResult.id, javaResult.id)
340338
res = TypeResults(javaResult, kotlinResult)
341-
anonymousTypeMapping[c] = res
339+
tw.lm.anonymousTypeMapping[c] = res
342340
}
343341

344342
return res
@@ -749,8 +747,6 @@ open class KotlinUsesExtractor(
749747
return this.visibility == DescriptorVisibilities.LOCAL
750748
}
751749

752-
private val locallyVisibleFunctionLabelMapping: MutableMap<IrFunction, LocallyVisibleFunctionLabels> = mutableMapOf()
753-
754750
/**
755751
* Class to hold labels for generated classes around local functions, lambdas, function references, and property references.
756752
*/
@@ -775,7 +771,7 @@ open class KotlinUsesExtractor(
775771
logger.error("Extracting a non-local function as a local one")
776772
}
777773

778-
var res = locallyVisibleFunctionLabelMapping[f]
774+
var res = tw.lm.locallyVisibleFunctionLabelMapping[f]
779775
if (res == null) {
780776
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")
781777
val kotlinResult = TypeResult(tw.getFreshIdLabel<DbKt_notnull_type>(), "", "")
@@ -786,7 +782,7 @@ open class KotlinUsesExtractor(
786782
tw.getFreshIdLabel(),
787783
tw.getFreshIdLabel()
788784
)
789-
locallyVisibleFunctionLabelMapping[f] = res
785+
tw.lm.locallyVisibleFunctionLabelMapping[f] = res
790786
}
791787

792788
return res

java/kotlin-extractor/src/main/kotlin/TrapWriter.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package com.github.codeql
22

3+
import com.github.codeql.KotlinUsesExtractor.LocallyVisibleFunctionLabels
4+
import com.github.codeql.KotlinUsesExtractor.TypeResults
35
import com.github.codeql.utils.versions.FileEntry
46
import java.io.BufferedWriter
57
import java.io.File
68
import org.jetbrains.kotlin.ir.IrElement
79
import org.jetbrains.kotlin.ir.declarations.path
10+
import org.jetbrains.kotlin.ir.declarations.IrClass
811
import org.jetbrains.kotlin.ir.declarations.IrFile
12+
import org.jetbrains.kotlin.ir.declarations.IrFunction
913
import org.jetbrains.kotlin.ir.declarations.IrVariable
1014
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
1115
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
@@ -32,6 +36,10 @@ class TrapLabelManager {
3236
* key, if any.
3337
*/
3438
val labelMapping: MutableMap<String, Label<*>> = mutableMapOf<String, Label<*>>()
39+
40+
val anonymousTypeMapping: MutableMap<IrClass, TypeResults> = mutableMapOf()
41+
42+
val locallyVisibleFunctionLabelMapping: MutableMap<IrFunction, LocallyVisibleFunctionLabels> = mutableMapOf()
3543
}
3644

3745
/**
@@ -40,7 +48,8 @@ class TrapLabelManager {
4048
* instances will have different additional state, but they must all
4149
* share the same `TrapLabelManager` and `BufferedWriter`.
4250
*/
43-
open class TrapWriter (protected val loggerBase: LoggerBase, protected val lm: TrapLabelManager, private val bw: BufferedWriter) {
51+
// TODO lm was `protected` before anonymousTypeMapping and locallyVisibleFunctionLabelMapping moved into it. Should we re-protect it and provide accessors?
52+
open class TrapWriter (protected val loggerBase: LoggerBase, val lm: TrapLabelManager, private val bw: BufferedWriter) {
4453
/**
4554
* Returns the label that is defined to be the given key, if such
4655
* a label exists, and `null` otherwise. Most users will want to use

0 commit comments

Comments
 (0)