[FIR] hold one-to-one mapping for data flow variable and Fir
This commit is contained in:
@@ -5,8 +5,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.resolve.dfa
|
package org.jetbrains.kotlin.fir.resolve.dfa
|
||||||
|
|
||||||
import com.google.common.collect.LinkedHashMultimap
|
|
||||||
import com.google.common.collect.Multimap
|
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
|
import org.jetbrains.kotlin.fir.declarations.FirTypedDeclaration
|
||||||
@@ -31,7 +29,7 @@ data class DataFlowVariable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DataFlowVariableStorage(private val session: FirSession) {
|
class DataFlowVariableStorage(private val session: FirSession) {
|
||||||
private val dfi2FirMap: Multimap<DataFlowVariable, FirElement> = LinkedHashMultimap.create()
|
private val dfi2FirMap: MutableMap<DataFlowVariable, FirElement> = mutableMapOf()
|
||||||
private val fir2DfiMap: MutableMap<FirElement, DataFlowVariable> = mutableMapOf()
|
private val fir2DfiMap: MutableMap<FirElement, DataFlowVariable> = mutableMapOf()
|
||||||
private var counter: Int = 1
|
private var counter: Int = 1
|
||||||
|
|
||||||
@@ -57,12 +55,13 @@ class DataFlowVariableStorage(private val session: FirSession) {
|
|||||||
removeVariable(variable)
|
removeVariable(variable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun removeVariable(variable: DataFlowVariable) {
|
fun removeVariable(variable: DataFlowVariable): FirElement? {
|
||||||
val firExpressions = dfi2FirMap.removeAll(variable)
|
return dfi2FirMap.remove(variable)?.also {
|
||||||
firExpressions.forEach(fir2DfiMap::remove)
|
fir2DfiMap.remove(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun get(variable: DataFlowVariable): Collection<FirElement> {
|
operator fun get(variable: DataFlowVariable): FirElement? {
|
||||||
return dfi2FirMap[variable]
|
return dfi2FirMap[variable]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,12 +80,12 @@ class DataFlowVariableStorage(private val session: FirSession) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun storeVariable(variable: DataFlowVariable, fir: FirElement) {
|
private fun storeVariable(variable: DataFlowVariable, fir: FirElement) {
|
||||||
dfi2FirMap.put(variable, fir)
|
dfi2FirMap[variable] = fir
|
||||||
fir2DfiMap.put(fir, variable)
|
fir2DfiMap[fir] = variable
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("only for debug")
|
@Deprecated("only for debug")
|
||||||
fun getByName(name: String): DataFlowVariable? = dfi2FirMap.keySet().firstOrNull { it.name == name }
|
fun getByName(name: String): DataFlowVariable? = dfi2FirMap.keys.firstOrNull { it.name == name }
|
||||||
|
|
||||||
private val FirElement.type: FirTypeRef
|
private val FirElement.type: FirTypeRef
|
||||||
get() = when (this) {
|
get() = when (this) {
|
||||||
|
|||||||
Reference in New Issue
Block a user