FIR: make possible to use differently typed IDs in ScopeSession
This commit is contained in:
@@ -356,5 +356,5 @@ fun FqName.topLevelName() =
|
||||
asString().substringBefore(".")
|
||||
|
||||
|
||||
private val JAVA_ENHANCEMENT = scopeSessionKey<JavaClassEnhancementScope>()
|
||||
private val JAVA_USE_SITE = scopeSessionKey<JavaClassUseSiteMemberScope>()
|
||||
private val JAVA_ENHANCEMENT = scopeSessionKey<FirRegularClassSymbol, JavaClassEnhancementScope>()
|
||||
private val JAVA_USE_SITE = scopeSessionKey<FirRegularClassSymbol, JavaClassUseSiteMemberScope>()
|
||||
|
||||
@@ -38,25 +38,25 @@ fun lookupSuperTypes(
|
||||
}
|
||||
|
||||
class ScopeSession {
|
||||
private val scopes = hashMapOf<FirClassifierSymbol<*>, HashMap<ScopeSessionKey<*>, FirScope>>()
|
||||
fun <T : FirScope> getOrBuild(symbol: FirClassifierSymbol<*>, key: ScopeSessionKey<T>, build: () -> T): T {
|
||||
return scopes.getOrPut(symbol) {
|
||||
private val scopes = hashMapOf<Any, HashMap<ScopeSessionKey<*, *>, FirScope>>()
|
||||
fun <ID : Any, FS : FirScope> getOrBuild(id: ID, key: ScopeSessionKey<ID, FS>, build: () -> FS): FS {
|
||||
return scopes.getOrPut(id) {
|
||||
hashMapOf()
|
||||
}.getOrPut(key) {
|
||||
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> {
|
||||
return object : ScopeSessionKey<T>() {}
|
||||
inline fun <reified ID : Any, reified FS : FirScope> scopeSessionKey(): ScopeSessionKey<ID, FS> {
|
||||
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? {
|
||||
return when (this) {
|
||||
|
||||
+1
-1
@@ -76,7 +76,7 @@ class FirIntegerLiteralTypeScope(private val session: FirSession) : FirScope() {
|
||||
private val ALL_OPERATORS = FirIntegerOperator.Kind.values().map { it.operatorName to it }.toMap()
|
||||
|
||||
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 ->
|
||||
|
||||
Reference in New Issue
Block a user