mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Kotlin: Move anonymousTypeMapping and locallyVisibleFunctionLabelMapping
They're now in LabelManager, so they are shared between extractors.
This commit is contained in:
@@ -329,16 +329,14 @@ open class KotlinUsesExtractor(
|
||||
classLabelResult.shortName)
|
||||
}
|
||||
|
||||
private val anonymousTypeMapping: MutableMap<IrClass, TypeResults> = mutableMapOf()
|
||||
|
||||
fun useAnonymousClass(c: IrClass): TypeResults {
|
||||
var res = anonymousTypeMapping[c]
|
||||
var res = tw.lm.anonymousTypeMapping[c]
|
||||
if (res == null) {
|
||||
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")
|
||||
val kotlinResult = TypeResult(tw.getFreshIdLabel<DbKt_notnull_type>(), "", "")
|
||||
tw.writeKt_notnull_types(kotlinResult.id, javaResult.id)
|
||||
res = TypeResults(javaResult, kotlinResult)
|
||||
anonymousTypeMapping[c] = res
|
||||
tw.lm.anonymousTypeMapping[c] = res
|
||||
}
|
||||
|
||||
return res
|
||||
@@ -749,8 +747,6 @@ open class KotlinUsesExtractor(
|
||||
return this.visibility == DescriptorVisibilities.LOCAL
|
||||
}
|
||||
|
||||
private val locallyVisibleFunctionLabelMapping: MutableMap<IrFunction, LocallyVisibleFunctionLabels> = mutableMapOf()
|
||||
|
||||
/**
|
||||
* Class to hold labels for generated classes around local functions, lambdas, function references, and property references.
|
||||
*/
|
||||
@@ -775,7 +771,7 @@ open class KotlinUsesExtractor(
|
||||
logger.error("Extracting a non-local function as a local one")
|
||||
}
|
||||
|
||||
var res = locallyVisibleFunctionLabelMapping[f]
|
||||
var res = tw.lm.locallyVisibleFunctionLabelMapping[f]
|
||||
if (res == null) {
|
||||
val javaResult = TypeResult(tw.getFreshIdLabel<DbClass>(), "", "")
|
||||
val kotlinResult = TypeResult(tw.getFreshIdLabel<DbKt_notnull_type>(), "", "")
|
||||
@@ -786,7 +782,7 @@ open class KotlinUsesExtractor(
|
||||
tw.getFreshIdLabel(),
|
||||
tw.getFreshIdLabel()
|
||||
)
|
||||
locallyVisibleFunctionLabelMapping[f] = res
|
||||
tw.lm.locallyVisibleFunctionLabelMapping[f] = res
|
||||
}
|
||||
|
||||
return res
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.github.codeql
|
||||
|
||||
import com.github.codeql.KotlinUsesExtractor.LocallyVisibleFunctionLabels
|
||||
import com.github.codeql.KotlinUsesExtractor.TypeResults
|
||||
import com.github.codeql.utils.versions.FileEntry
|
||||
import java.io.BufferedWriter
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.path
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
|
||||
@@ -32,6 +36,10 @@ class TrapLabelManager {
|
||||
* key, if any.
|
||||
*/
|
||||
val labelMapping: MutableMap<String, Label<*>> = mutableMapOf<String, Label<*>>()
|
||||
|
||||
val anonymousTypeMapping: MutableMap<IrClass, TypeResults> = mutableMapOf()
|
||||
|
||||
val locallyVisibleFunctionLabelMapping: MutableMap<IrFunction, LocallyVisibleFunctionLabels> = mutableMapOf()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,7 +48,8 @@ class TrapLabelManager {
|
||||
* instances will have different additional state, but they must all
|
||||
* share the same `TrapLabelManager` and `BufferedWriter`.
|
||||
*/
|
||||
open class TrapWriter (protected val loggerBase: LoggerBase, protected val lm: TrapLabelManager, private val bw: BufferedWriter) {
|
||||
// TODO lm was `protected` before anonymousTypeMapping and locallyVisibleFunctionLabelMapping moved into it. Should we re-protect it and provide accessors?
|
||||
open class TrapWriter (protected val loggerBase: LoggerBase, val lm: TrapLabelManager, private val bw: BufferedWriter) {
|
||||
/**
|
||||
* Returns the label that is defined to be the given key, if such
|
||||
* a label exists, and `null` otherwise. Most users will want to use
|
||||
|
||||
Reference in New Issue
Block a user