FIR: make possible to use differently typed IDs in ScopeSession

This commit is contained in:
Mikhail Glukhikh
2019-12-19 12:52:21 +03:00
parent 4d1b032c1f
commit cb93b25fca
3 changed files with 12 additions and 12 deletions
@@ -356,5 +356,5 @@ fun FqName.topLevelName() =
asString().substringBefore(".") asString().substringBefore(".")
private val JAVA_ENHANCEMENT = scopeSessionKey<JavaClassEnhancementScope>() private val JAVA_ENHANCEMENT = scopeSessionKey<FirRegularClassSymbol, JavaClassEnhancementScope>()
private val JAVA_USE_SITE = scopeSessionKey<JavaClassUseSiteMemberScope>() private val JAVA_USE_SITE = scopeSessionKey<FirRegularClassSymbol, JavaClassUseSiteMemberScope>()
@@ -38,25 +38,25 @@ fun lookupSuperTypes(
} }
class ScopeSession { class ScopeSession {
private val scopes = hashMapOf<FirClassifierSymbol<*>, HashMap<ScopeSessionKey<*>, FirScope>>() private val scopes = hashMapOf<Any, HashMap<ScopeSessionKey<*, *>, FirScope>>()
fun <T : FirScope> getOrBuild(symbol: FirClassifierSymbol<*>, key: ScopeSessionKey<T>, build: () -> T): T { fun <ID : Any, FS : FirScope> getOrBuild(id: ID, key: ScopeSessionKey<ID, FS>, build: () -> FS): FS {
return scopes.getOrPut(symbol) { return scopes.getOrPut(id) {
hashMapOf() hashMapOf()
}.getOrPut(key) { }.getOrPut(key) {
build() build()
} as T } as FS
} }
} }
abstract class ScopeSessionKey<T : FirScope>() abstract class ScopeSessionKey<ID : Any, FS : FirScope>
inline fun <reified T : FirScope> scopeSessionKey(): ScopeSessionKey<T> { inline fun <reified ID : Any, reified FS : FirScope> scopeSessionKey(): ScopeSessionKey<ID, FS> {
return object : ScopeSessionKey<T>() {} return object : ScopeSessionKey<ID, FS>() {}
} }
val USE_SITE = scopeSessionKey<FirScope>() val USE_SITE = scopeSessionKey<FirClassSymbol<*>, FirScope>()
data class SubstitutionScopeKey(val type: ConeClassLikeType) : ScopeSessionKey<FirClassSubstitutionScope>() {} data class SubstitutionScopeKey(val type: ConeClassLikeType) : ScopeSessionKey<FirClassLikeSymbol<*>, FirClassSubstitutionScope>() {}
fun FirClassSymbol<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: ScopeSession): FirScope? { fun FirClassSymbol<*>.buildUseSiteMemberScope(useSiteSession: FirSession, builder: ScopeSession): FirScope? {
return when (this) { return when (this) {
@@ -76,7 +76,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession) : FirScope() {
private val ALL_OPERATORS = FirIntegerOperator.Kind.values().map { it.operatorName to it }.toMap() private val ALL_OPERATORS = FirIntegerOperator.Kind.values().map { it.operatorName to it }.toMap()
val ILT_SYMBOL: FirClassifierSymbol<*> = FirIntegerLiteralTypeClassifierSymbol val ILT_SYMBOL: FirClassifierSymbol<*> = FirIntegerLiteralTypeClassifierSymbol
val SCOPE_SESSION_KEY = scopeSessionKey<FirIntegerLiteralTypeScope>() val SCOPE_SESSION_KEY = scopeSessionKey<FirClassifierSymbol<*>, FirIntegerLiteralTypeScope>()
} }
private val BINARY_OPERATOR_SYMBOLS = BINARY_OPERATOR_NAMES.map { name -> private val BINARY_OPERATOR_SYMBOLS = BINARY_OPERATOR_NAMES.map { name ->