[FIR] Replace PersistentList with MutableList in Context, simplify DeclarationConverter
This commit is contained in:
+29
-25
@@ -397,21 +397,21 @@ class DeclarationsConverter(
|
|||||||
val isLocal = isClassLocal(classNode) { getParent() }
|
val isLocal = isClassLocal(classNode) { getParent() }
|
||||||
|
|
||||||
return withChildClassName(className, isLocal) {
|
return withChildClassName(className, isLocal) {
|
||||||
withCapturedTypeParameters {
|
val status = FirDeclarationStatusImpl(
|
||||||
val status = FirDeclarationStatusImpl(
|
if (isLocal) Visibilities.Local else modifiers.getVisibility(),
|
||||||
if (isLocal) Visibilities.Local else modifiers.getVisibility(),
|
modifiers.getModality(isClassOrObject = true)
|
||||||
modifiers.getModality(isClassOrObject = true)
|
).apply {
|
||||||
).apply {
|
isExpect = modifiers.hasExpect()
|
||||||
isExpect = modifiers.hasExpect()
|
isActual = modifiers.hasActual()
|
||||||
isActual = modifiers.hasActual()
|
isInner = modifiers.isInner()
|
||||||
isInner = modifiers.isInner()
|
isCompanion = modifiers.isCompanion() && classKind == ClassKind.OBJECT
|
||||||
isCompanion = modifiers.isCompanion() && classKind == ClassKind.OBJECT
|
isData = modifiers.isDataClass()
|
||||||
isData = modifiers.isDataClass()
|
isInline = modifiers.isInlineClass()
|
||||||
isInline = modifiers.isInlineClass()
|
isFun = modifiers.isFunctionalInterface()
|
||||||
isFun = modifiers.isFunctionalInterface()
|
isExternal = modifiers.hasExternal()
|
||||||
isExternal = modifiers.hasExternal()
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
withCapturedTypeParameters(status.isInner, firTypeParameters) {
|
||||||
buildRegularClass {
|
buildRegularClass {
|
||||||
source = classNode.toFirSourceElement()
|
source = classNode.toFirSourceElement()
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
@@ -424,9 +424,9 @@ class DeclarationsConverter(
|
|||||||
annotations += modifiers.annotations
|
annotations += modifiers.annotations
|
||||||
typeParameters += firTypeParameters
|
typeParameters += firTypeParameters
|
||||||
|
|
||||||
if (!status.isInner) clearCapturedTypeParameters()
|
context.applyToActualCapturedTypeParameters(true) {
|
||||||
typeParameters += context.capturedTypeParameters.map { buildOuterClassTypeParameterRef { symbol = it } }
|
typeParameters += buildOuterClassTypeParameterRef { symbol = it }
|
||||||
addCapturedTypeParameters(firTypeParameters)
|
}
|
||||||
|
|
||||||
val selfType = classNode.toDelegatedSelfType(this)
|
val selfType = classNode.toDelegatedSelfType(this)
|
||||||
registerSelfType(selfType)
|
registerSelfType(selfType)
|
||||||
@@ -554,7 +554,9 @@ class DeclarationsConverter(
|
|||||||
classKind = ClassKind.OBJECT
|
classKind = ClassKind.OBJECT
|
||||||
scopeProvider = baseScopeProvider
|
scopeProvider = baseScopeProvider
|
||||||
symbol = FirAnonymousObjectSymbol()
|
symbol = FirAnonymousObjectSymbol()
|
||||||
typeParameters += context.capturedTypeParameters.map { buildOuterClassTypeParameterRef { this.symbol = it } }
|
context.applyToActualCapturedTypeParameters(false) {
|
||||||
|
typeParameters += buildOuterClassTypeParameterRef { this.symbol = it }
|
||||||
|
}
|
||||||
val delegatedSelfType = objectLiteral.toDelegatedSelfType(this)
|
val delegatedSelfType = objectLiteral.toDelegatedSelfType(this)
|
||||||
registerSelfType(delegatedSelfType)
|
registerSelfType(delegatedSelfType)
|
||||||
|
|
||||||
@@ -1059,9 +1061,8 @@ class DeclarationsConverter(
|
|||||||
receiverTypeRef = receiverType
|
receiverTypeRef = receiverType
|
||||||
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
||||||
dispatchReceiverType = currentDispatchReceiverType()
|
dispatchReceiverType = currentDispatchReceiverType()
|
||||||
withCapturedTypeParameters {
|
withCapturedTypeParameters(true, firTypeParameters) {
|
||||||
typeParameters += firTypeParameters
|
typeParameters += firTypeParameters
|
||||||
addCapturedTypeParameters(firTypeParameters)
|
|
||||||
|
|
||||||
val delegateBuilder = delegateExpression?.let {
|
val delegateBuilder = delegateExpression?.let {
|
||||||
FirWrappedDelegateExpressionBuilder().apply {
|
FirWrappedDelegateExpressionBuilder().apply {
|
||||||
@@ -1419,11 +1420,14 @@ class DeclarationsConverter(
|
|||||||
context.firFunctionTargets += target
|
context.firFunctionTargets += target
|
||||||
annotations += modifiers.annotations
|
annotations += modifiers.annotations
|
||||||
|
|
||||||
withCapturedTypeParameters {
|
val actualTypeParameters = if (this is FirSimpleFunctionBuilder) {
|
||||||
if (this is FirSimpleFunctionBuilder) {
|
typeParameters += firTypeParameters
|
||||||
typeParameters += firTypeParameters
|
typeParameters
|
||||||
addCapturedTypeParameters(typeParameters)
|
} else {
|
||||||
}
|
listOf()
|
||||||
|
}
|
||||||
|
|
||||||
|
withCapturedTypeParameters(true, actualTypeParameters) {
|
||||||
valueParametersList?.let { list -> valueParameters += convertValueParameters(list).map { it.firValueParameter } }
|
valueParametersList?.let { list -> valueParameters += convertValueParameters(list).map { it.firValueParameter } }
|
||||||
|
|
||||||
val hasContractEffectList = outerContractDescription != null
|
val hasContractEffectList = outerContractDescription != null
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.fir.types.impl.FirTypeArgumentListImpl
|
|||||||
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
import org.jetbrains.kotlin.fir.types.impl.FirTypePlaceholderProjection
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens.*
|
import org.jetbrains.kotlin.lexer.KtTokens.*
|
||||||
import org.jetbrains.kotlin.name.CallableId
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
|
import org.jetbrains.kotlin.name.LocalCallableIdConstructor
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -839,9 +840,8 @@ open class RawFirBuilder(
|
|||||||
isFun = classOrObject.hasModifier(FUN_KEYWORD)
|
isFun = classOrObject.hasModifier(FUN_KEYWORD)
|
||||||
isExternal = classOrObject.hasModifier(EXTERNAL_KEYWORD)
|
isExternal = classOrObject.hasModifier(EXTERNAL_KEYWORD)
|
||||||
}
|
}
|
||||||
withCapturedTypeParameters {
|
|
||||||
if (!status.isInner) context.capturedTypeParameters = context.capturedTypeParameters.clear()
|
|
||||||
|
|
||||||
|
withCapturedTypeParameters(status.isInner, listOf()) {
|
||||||
buildRegularClass {
|
buildRegularClass {
|
||||||
source = classOrObject.toFirSourceElement()
|
source = classOrObject.toFirSourceElement()
|
||||||
moduleData = baseModuleData
|
moduleData = baseModuleData
|
||||||
@@ -854,9 +854,14 @@ open class RawFirBuilder(
|
|||||||
|
|
||||||
classOrObject.extractAnnotationsTo(this)
|
classOrObject.extractAnnotationsTo(this)
|
||||||
classOrObject.extractTypeParametersTo(this)
|
classOrObject.extractTypeParametersTo(this)
|
||||||
typeParameters += context.capturedTypeParameters.map { buildOuterClassTypeParameterRef { symbol = it } }
|
|
||||||
|
|
||||||
addCapturedTypeParameters(typeParameters.take(classOrObject.typeParameters.size))
|
context.applyToActualCapturedTypeParameters(true) {
|
||||||
|
typeParameters += buildOuterClassTypeParameterRef { symbol = it }
|
||||||
|
}
|
||||||
|
context.pushFirTypeParameters(
|
||||||
|
status.isInner,
|
||||||
|
typeParameters.subList(0, classOrObject.typeParameters.size)
|
||||||
|
)
|
||||||
|
|
||||||
val delegatedSelfType = classOrObject.toDelegatedSelfType(this)
|
val delegatedSelfType = classOrObject.toDelegatedSelfType(this)
|
||||||
registerSelfType(delegatedSelfType)
|
registerSelfType(delegatedSelfType)
|
||||||
@@ -925,6 +930,8 @@ open class RawFirBuilder(
|
|||||||
classOrObject.hasExpectModifier()
|
classOrObject.hasExpectModifier()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.popFirTypeParameters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.also {
|
}.also {
|
||||||
@@ -943,7 +950,9 @@ open class RawFirBuilder(
|
|||||||
classKind = ClassKind.OBJECT
|
classKind = ClassKind.OBJECT
|
||||||
scopeProvider = baseScopeProvider
|
scopeProvider = baseScopeProvider
|
||||||
symbol = FirAnonymousObjectSymbol()
|
symbol = FirAnonymousObjectSymbol()
|
||||||
typeParameters += context.capturedTypeParameters.map { buildOuterClassTypeParameterRef { symbol = it } }
|
context.applyToActualCapturedTypeParameters(false) {
|
||||||
|
typeParameters += buildOuterClassTypeParameterRef { symbol = it }
|
||||||
|
}
|
||||||
val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this)
|
val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this)
|
||||||
registerSelfType(delegatedSelfType)
|
registerSelfType(delegatedSelfType)
|
||||||
objectDeclaration.extractAnnotationsTo(this)
|
objectDeclaration.extractAnnotationsTo(this)
|
||||||
@@ -1046,8 +1055,11 @@ open class RawFirBuilder(
|
|||||||
for (valueParameter in function.valueParameters) {
|
for (valueParameter in function.valueParameters) {
|
||||||
valueParameters += valueParameter.convert<FirValueParameter>()
|
valueParameters += valueParameter.convert<FirValueParameter>()
|
||||||
}
|
}
|
||||||
withCapturedTypeParameters {
|
val actualTypeParameters = if (this is FirSimpleFunctionBuilder)
|
||||||
if (this is FirSimpleFunctionBuilder) addCapturedTypeParameters(this.typeParameters)
|
this.typeParameters
|
||||||
|
else
|
||||||
|
listOf()
|
||||||
|
withCapturedTypeParameters(true, actualTypeParameters) {
|
||||||
val outerContractDescription = function.obtainContractDescription()
|
val outerContractDescription = function.obtainContractDescription()
|
||||||
val bodyWithContractDescription = function.buildFirBody()
|
val bodyWithContractDescription = function.buildFirBody()
|
||||||
this.body = bodyWithContractDescription.first
|
this.body = bodyWithContractDescription.first
|
||||||
@@ -1310,8 +1322,7 @@ open class RawFirBuilder(
|
|||||||
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
||||||
dispatchReceiverType = currentDispatchReceiverType()
|
dispatchReceiverType = currentDispatchReceiverType()
|
||||||
extractTypeParametersTo(this)
|
extractTypeParametersTo(this)
|
||||||
withCapturedTypeParameters {
|
withCapturedTypeParameters(true, this.typeParameters) {
|
||||||
addCapturedTypeParameters(this.typeParameters)
|
|
||||||
val delegateBuilder = if (hasDelegate()) {
|
val delegateBuilder = if (hasDelegate()) {
|
||||||
FirWrappedDelegateExpressionBuilder().apply {
|
FirWrappedDelegateExpressionBuilder().apply {
|
||||||
source =
|
source =
|
||||||
|
|||||||
+3
-12
@@ -90,24 +90,15 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
|||||||
context.dispatchReceiverTypesStack.add(selfType.type as ConeClassLikeType)
|
context.dispatchReceiverTypesStack.add(selfType.type as ConeClassLikeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withCapturedTypeParameters(block: () -> T): T {
|
inline fun <T> withCapturedTypeParameters(status: Boolean, currentFirTypeParameters: List<FirTypeParameterRef>, block: () -> T): T {
|
||||||
val previous = context.capturedTypeParameters
|
context.pushFirTypeParameters(status, currentFirTypeParameters)
|
||||||
return try {
|
return try {
|
||||||
block()
|
block()
|
||||||
} finally {
|
} finally {
|
||||||
context.capturedTypeParameters = previous
|
context.popFirTypeParameters()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addCapturedTypeParameters(typeParameters: List<FirTypeParameterRef>) {
|
|
||||||
context.capturedTypeParameters =
|
|
||||||
context.capturedTypeParameters.addAll(0, typeParameters.map { typeParameter -> typeParameter.symbol })
|
|
||||||
}
|
|
||||||
|
|
||||||
fun clearCapturedTypeParameters() {
|
|
||||||
context.capturedTypeParameters = context.capturedTypeParameters.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun callableIdForName(name: Name, local: Boolean = false) =
|
fun callableIdForName(name: Name, local: Boolean = false) =
|
||||||
when {
|
when {
|
||||||
local -> {
|
local -> {
|
||||||
|
|||||||
+29
-3
@@ -5,15 +5,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.builder
|
package org.jetbrains.kotlin.fir.builder
|
||||||
|
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
|
||||||
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
import org.jetbrains.kotlin.fir.FirFunctionTarget
|
||||||
import org.jetbrains.kotlin.fir.FirLabel
|
import org.jetbrains.kotlin.fir.FirLabel
|
||||||
import org.jetbrains.kotlin.fir.FirLoopTarget
|
import org.jetbrains.kotlin.fir.FirLoopTarget
|
||||||
import org.jetbrains.kotlin.fir.FirSourceElementKind
|
import org.jetbrains.kotlin.fir.FirSourceElementKind
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameterRef
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -28,9 +27,36 @@ class Context<T> {
|
|||||||
val calleeNamesForLambda = mutableListOf<Name>()
|
val calleeNamesForLambda = mutableListOf<Name>()
|
||||||
val firLabels = mutableListOf<FirLabel>()
|
val firLabels = mutableListOf<FirLabel>()
|
||||||
val firLoopTargets = mutableListOf<FirLoopTarget>()
|
val firLoopTargets = mutableListOf<FirLoopTarget>()
|
||||||
var capturedTypeParameters = persistentListOf<FirTypeParameterSymbol>()
|
val capturedTypeParameters = mutableListOf<StatusFirTypeParameterSymbolList>()
|
||||||
val arraySetArgument = mutableMapOf<T, FirExpression>()
|
val arraySetArgument = mutableMapOf<T, FirExpression>()
|
||||||
|
|
||||||
var forcedElementSourceKind: FirSourceElementKind? = null
|
var forcedElementSourceKind: FirSourceElementKind? = null
|
||||||
val dispatchReceiverTypesStack = mutableListOf<ConeClassLikeType>()
|
val dispatchReceiverTypesStack = mutableListOf<ConeClassLikeType>()
|
||||||
|
|
||||||
|
fun pushFirTypeParameters(notNested: Boolean, parameters: List<FirTypeParameterRef>) {
|
||||||
|
capturedTypeParameters.add(StatusFirTypeParameterSymbolList(notNested, parameters.map { it.symbol }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun popFirTypeParameters() {
|
||||||
|
val list = capturedTypeParameters
|
||||||
|
list.removeAt(list.lastIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun applyToActualCapturedTypeParameters(ignoreLastLevel: Boolean, action: (FirTypeParameterSymbol) -> Unit) {
|
||||||
|
for (index in capturedTypeParameters.lastIndex downTo 0) {
|
||||||
|
val element = capturedTypeParameters[index]
|
||||||
|
|
||||||
|
if (index < capturedTypeParameters.lastIndex || !ignoreLastLevel) {
|
||||||
|
for (capturedTypeParameter in element.list) {
|
||||||
|
action(capturedTypeParameter)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!element.notNested) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class StatusFirTypeParameterSymbolList(val notNested: Boolean, val list: List<FirTypeParameterSymbol> = listOf())
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -89,9 +89,7 @@ internal class RawFirNonLocalDeclarationBuilder private constructor(
|
|||||||
check(classOrObject is KtClassOrObject)
|
check(classOrObject is KtClassOrObject)
|
||||||
|
|
||||||
withChildClassName(classOrObject.nameAsSafeName, false) {
|
withChildClassName(classOrObject.nameAsSafeName, false) {
|
||||||
withCapturedTypeParameters {
|
withCapturedTypeParameters(parent.isInner, parent.typeParameters.subList(0, classOrObject.typeParameters.size)) {
|
||||||
if (!parent.isInner) context.capturedTypeParameters = context.capturedTypeParameters.clear()
|
|
||||||
addCapturedTypeParameters(parent.typeParameters.take(classOrObject.typeParameters.size))
|
|
||||||
registerSelfType(classOrObject.toDelegatedSelfType(parent))
|
registerSelfType(classOrObject.toDelegatedSelfType(parent))
|
||||||
return moveNext(iterator, parent)
|
return moveNext(iterator, parent)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user