[FIR] Add containingDeclarationSymbol to FirTypeParameter
This commit is contained in:
committed by
TeamCityServer
parent
0c25d280ee
commit
345152d198
+24
-9
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.buildExpressionStub
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
@@ -62,7 +63,8 @@ class FirDeserializationContext(
|
||||
containerSource: DeserializedContainerSource? = this.containerSource,
|
||||
outerClassSymbol: FirRegularClassSymbol? = this.outerClassSymbol,
|
||||
annotationDeserializer: AbstractAnnotationDeserializer = this.annotationDeserializer,
|
||||
capturesTypeParameters: Boolean = true
|
||||
capturesTypeParameters: Boolean = true,
|
||||
containingDeclarationSymbol: FirBasedSymbol<*>? = this.outerClassSymbol
|
||||
): FirDeserializationContext = FirDeserializationContext(
|
||||
nameResolver,
|
||||
typeTable,
|
||||
@@ -70,7 +72,15 @@ class FirDeserializationContext(
|
||||
moduleData,
|
||||
packageFqName,
|
||||
relativeClassName,
|
||||
FirTypeDeserializer(moduleData, nameResolver, typeTable, annotationDeserializer, typeParameterProtos, typeDeserializer),
|
||||
FirTypeDeserializer(
|
||||
moduleData,
|
||||
nameResolver,
|
||||
typeTable,
|
||||
annotationDeserializer,
|
||||
typeParameterProtos,
|
||||
typeDeserializer,
|
||||
containingDeclarationSymbol
|
||||
),
|
||||
annotationDeserializer,
|
||||
constDeserializer,
|
||||
containerSource,
|
||||
@@ -101,7 +111,8 @@ class FirDeserializationContext(
|
||||
relativeClassName = null,
|
||||
typeParameterProtos = emptyList(),
|
||||
containerSource,
|
||||
outerClassSymbol = null
|
||||
outerClassSymbol = null,
|
||||
containingDeclarationSymbol = null
|
||||
)
|
||||
|
||||
fun createForClass(
|
||||
@@ -124,6 +135,7 @@ class FirDeserializationContext(
|
||||
classId.relativeClassName,
|
||||
classProto.typeParameterList,
|
||||
containerSource,
|
||||
outerClassSymbol,
|
||||
outerClassSymbol
|
||||
)
|
||||
|
||||
@@ -139,6 +151,7 @@ class FirDeserializationContext(
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
containerSource: DeserializedContainerSource?,
|
||||
outerClassSymbol: FirRegularClassSymbol?,
|
||||
containingDeclarationSymbol: FirBasedSymbol<*>?
|
||||
): FirDeserializationContext {
|
||||
return FirDeserializationContext(
|
||||
nameResolver, typeTable,
|
||||
@@ -152,7 +165,8 @@ class FirDeserializationContext(
|
||||
typeTable,
|
||||
annotationDeserializer,
|
||||
typeParameterProtos,
|
||||
null
|
||||
null,
|
||||
containingDeclarationSymbol
|
||||
),
|
||||
annotationDeserializer,
|
||||
constDeserializer,
|
||||
@@ -176,8 +190,9 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
fun loadTypeAlias(proto: ProtoBuf.TypeAlias): FirTypeAlias {
|
||||
val flags = proto.flags
|
||||
val name = c.nameResolver.getName(proto.name)
|
||||
val local = c.childContext(proto.typeParameterList)
|
||||
val classId = ClassId(c.packageFqName, name)
|
||||
val symbol = FirTypeAliasSymbol(classId)
|
||||
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
|
||||
return buildTypeAlias {
|
||||
moduleData = c.moduleData
|
||||
origin = FirDeclarationOrigin.Library
|
||||
@@ -193,7 +208,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
}
|
||||
|
||||
annotations += c.annotationDeserializer.loadTypeAliasAnnotations(proto, local.nameResolver)
|
||||
symbol = FirTypeAliasSymbol(classId)
|
||||
this.symbol = symbol
|
||||
expandedTypeRef = proto.underlyingType(c.typeTable).toTypeRef(local)
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.fir }
|
||||
@@ -212,7 +227,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
val callableName = c.nameResolver.getName(proto.name)
|
||||
val callableId = CallableId(c.packageFqName, c.relativeClassName, callableName)
|
||||
val symbol = FirPropertySymbol(callableId)
|
||||
val local = c.childContext(proto.typeParameterList)
|
||||
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
|
||||
|
||||
// Per documentation on Property.getter_flags in metadata.proto, if an accessor flags field is absent, its value should be computed
|
||||
// by taking hasAnnotations/visibility/modality from property flags, and using false for the rest
|
||||
@@ -381,7 +396,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
val callableName = c.nameResolver.getName(proto.name)
|
||||
val callableId = CallableId(c.packageFqName, c.relativeClassName, callableName)
|
||||
val symbol = FirNamedFunctionSymbol(callableId)
|
||||
val local = c.childContext(proto.typeParameterList)
|
||||
val local = c.childContext(proto.typeParameterList, containingDeclarationSymbol = symbol)
|
||||
|
||||
val simpleFunction = buildSimpleFunction {
|
||||
moduleData = c.moduleData
|
||||
@@ -443,7 +458,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
val relativeClassName = c.relativeClassName!!
|
||||
val callableId = CallableId(c.packageFqName, relativeClassName, relativeClassName.shortName())
|
||||
val symbol = FirConstructorSymbol(callableId)
|
||||
val local = c.childContext(emptyList())
|
||||
val local = c.childContext(emptyList(), containingDeclarationSymbol = symbol)
|
||||
val isPrimary = !Flags.IS_SECONDARY.get(flags)
|
||||
|
||||
val typeParameters = classBuilder.typeParameters
|
||||
|
||||
+4
-1
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
@@ -43,7 +44,8 @@ class FirTypeDeserializer(
|
||||
val typeTable: TypeTable,
|
||||
val annotationDeserializer: AbstractAnnotationDeserializer,
|
||||
typeParameterProtos: List<ProtoBuf.TypeParameter>,
|
||||
val parent: FirTypeDeserializer?
|
||||
val parent: FirTypeDeserializer?,
|
||||
val containingSymbol: FirBasedSymbol<*>?
|
||||
) {
|
||||
private val typeParameterDescriptors: Map<Int, FirTypeParameterSymbol> = if (typeParameterProtos.isNotEmpty()) {
|
||||
LinkedHashMap<Int, FirTypeParameterSymbol>()
|
||||
@@ -73,6 +75,7 @@ class FirTypeDeserializer(
|
||||
origin = FirDeclarationOrigin.Library
|
||||
this.name = name
|
||||
this.symbol = symbol
|
||||
this.containingDeclarationSymbol = containingSymbol
|
||||
variance = proto.variance.convertVariance()
|
||||
isReified = proto.reified
|
||||
}
|
||||
|
||||
+2
@@ -229,6 +229,7 @@ private class SyntheticFunctionalInterfaceCache(private val moduleData: FirModul
|
||||
origin = FirDeclarationOrigin.BuiltIns
|
||||
name = Name.identifier("P$it")
|
||||
symbol = FirTypeParameterSymbol()
|
||||
containingDeclarationSymbol = this@symbol
|
||||
variance = Variance.IN_VARIANCE
|
||||
isReified = false
|
||||
bounds += moduleData.session.builtinTypes.nullableAnyType
|
||||
@@ -242,6 +243,7 @@ private class SyntheticFunctionalInterfaceCache(private val moduleData: FirModul
|
||||
origin = FirDeclarationOrigin.BuiltIns
|
||||
name = Name.identifier("R")
|
||||
symbol = FirTypeParameterSymbol()
|
||||
containingDeclarationSymbol = this@symbol
|
||||
variance = Variance.OUT_VARIANCE
|
||||
isReified = false
|
||||
bounds += moduleData.session.builtinTypes.nullableAnyType
|
||||
|
||||
+44
-18
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.fir.references.builder.buildExplicitThisReference
|
||||
import org.jetbrains.kotlin.fir.references.builder.buildSimpleNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.impl.FirReferencePlaceholderForResolvedAnnotations
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.*
|
||||
@@ -374,8 +375,8 @@ class DeclarationsConverter(
|
||||
val typeConstraints = mutableListOf<TypeConstraint>()
|
||||
var classBody: LighterASTNode? = null
|
||||
var superTypeList: LighterASTNode? = null
|
||||
|
||||
var typeParameterList: LighterASTNode? = null
|
||||
|
||||
classNode.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
MODIFIER_LIST -> modifiers = convertModifierList(it, isInClass = true)
|
||||
@@ -390,7 +391,6 @@ class DeclarationsConverter(
|
||||
CLASS_BODY -> classBody = it
|
||||
}
|
||||
}
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints) }
|
||||
|
||||
if (classKind == ClassKind.CLASS) {
|
||||
classKind = when {
|
||||
@@ -418,6 +418,10 @@ class DeclarationsConverter(
|
||||
isExternal = modifiers.hasExternal()
|
||||
}
|
||||
|
||||
val classSymbol = FirRegularClassSymbol(context.currentClassId)
|
||||
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints, classSymbol) }
|
||||
|
||||
withCapturedTypeParameters(status.isInner, firTypeParameters) {
|
||||
buildRegularClass {
|
||||
source = classNode.toFirSourceElement()
|
||||
@@ -427,7 +431,7 @@ class DeclarationsConverter(
|
||||
this.status = status
|
||||
this.classKind = classKind
|
||||
scopeProvider = baseScopeProvider
|
||||
symbol = FirRegularClassSymbol(context.currentClassId)
|
||||
symbol = classSymbol
|
||||
annotations += modifiers.annotations
|
||||
typeParameters += firTypeParameters
|
||||
|
||||
@@ -565,7 +569,8 @@ class DeclarationsConverter(
|
||||
scopeProvider = baseScopeProvider
|
||||
symbol = FirAnonymousObjectSymbol()
|
||||
context.applyToActualCapturedTypeParameters(false) {
|
||||
typeParameters += buildOuterClassTypeParameterRef { this.symbol = it } }
|
||||
typeParameters += buildOuterClassTypeParameterRef { this.symbol = it }
|
||||
}
|
||||
val delegatedSelfType = objectLiteral.toDelegatedSelfType(this)
|
||||
registerSelfType(delegatedSelfType)
|
||||
|
||||
@@ -958,18 +963,26 @@ class DeclarationsConverter(
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
lateinit var firType: FirTypeRef
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
|
||||
typeAlias.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
MODIFIER_LIST -> modifiers = convertModifierList(it)
|
||||
IDENTIFIER -> identifier = it.asText
|
||||
TYPE_PARAMETER_LIST -> firTypeParameters += convertTypeParameters(it, emptyList())
|
||||
TYPE_REFERENCE -> firType = convertType(it)
|
||||
}
|
||||
}
|
||||
|
||||
val typeAliasName = identifier.nameAsSafeName()
|
||||
return withChildClassName(typeAliasName) {
|
||||
val classSymbol = FirTypeAliasSymbol(context.currentClassId)
|
||||
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
typeAlias.forEachChildren {
|
||||
if (it.tokenType == TYPE_PARAMETER_LIST) {
|
||||
firTypeParameters += convertTypeParameters(it, emptyList(), classSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
return@withChildClassName buildTypeAlias {
|
||||
source = typeAlias.toFirSourceElement()
|
||||
moduleData = baseModuleData
|
||||
@@ -979,7 +992,7 @@ class DeclarationsConverter(
|
||||
isExpect = modifiers.hasExpect()
|
||||
isActual = modifiers.hasActual()
|
||||
}
|
||||
symbol = FirTypeAliasSymbol(context.currentClassId)
|
||||
symbol = classSymbol
|
||||
expandedTypeRef = firType
|
||||
annotations += modifiers.annotations
|
||||
typeParameters += firTypeParameters
|
||||
@@ -1020,8 +1033,6 @@ class DeclarationsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints) }
|
||||
|
||||
val propertyName = identifier.nameAsSafeName()
|
||||
|
||||
val parentNode = property.getParent()
|
||||
@@ -1042,9 +1053,12 @@ class DeclarationsConverter(
|
||||
(it.getExpressionInParentheses() ?: it).toFirSourceElement()
|
||||
}
|
||||
|
||||
symbol = if (isLocal) FirPropertySymbol(propertyName) else FirPropertySymbol(callableIdForName(propertyName))
|
||||
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints, symbol) }
|
||||
|
||||
if (isLocal) {
|
||||
this.isLocal = true
|
||||
symbol = FirPropertySymbol(propertyName)
|
||||
val delegateBuilder = delegateExpression?.let {
|
||||
FirWrappedDelegateExpressionBuilder().apply {
|
||||
source = delegateSource
|
||||
@@ -1071,7 +1085,6 @@ class DeclarationsConverter(
|
||||
} else {
|
||||
this.isLocal = false
|
||||
receiverTypeRef = receiverType
|
||||
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
||||
dispatchReceiverType = currentDispatchReceiverType()
|
||||
withCapturedTypeParameters(true, firTypeParameters) {
|
||||
typeParameters += firTypeParameters
|
||||
@@ -1353,7 +1366,6 @@ class DeclarationsConverter(
|
||||
fun convertFunctionDeclaration(functionDeclaration: LighterASTNode, classWrapper: ClassWrapper? = null): FirStatement {
|
||||
var modifiers = Modifier()
|
||||
var identifier: String? = null
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
var valueParametersList: LighterASTNode? = null
|
||||
var isReturnType = false
|
||||
var receiverType: FirTypeRef? = null
|
||||
@@ -1379,7 +1391,6 @@ class DeclarationsConverter(
|
||||
else -> if (it.isExpression()) expression = it
|
||||
}
|
||||
}
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints) }
|
||||
|
||||
if (returnType == null) {
|
||||
returnType =
|
||||
@@ -1391,19 +1402,22 @@ class DeclarationsConverter(
|
||||
val isLocal = !(parentNode?.tokenType == KT_FILE || parentNode?.tokenType == CLASS_BODY)
|
||||
val target: FirFunctionTarget
|
||||
val functionSource = functionDeclaration.toFirSourceElement()
|
||||
val functionSymbol: FirFunctionSymbol<*>
|
||||
val functionBuilder = if (identifier == null && isLocal) {
|
||||
val labelName = functionDeclaration.getLabelName() ?: context.calleeNamesForLambda.lastOrNull()?.identifier
|
||||
target = FirFunctionTarget(labelName = labelName, isLambda = false)
|
||||
functionSymbol = FirAnonymousFunctionSymbol()
|
||||
FirAnonymousFunctionBuilder().apply {
|
||||
source = functionSource
|
||||
receiverTypeRef = receiverType
|
||||
symbol = FirAnonymousFunctionSymbol()
|
||||
symbol = functionSymbol
|
||||
isLambda = false
|
||||
}
|
||||
} else {
|
||||
val functionName = identifier.nameAsSafeName()
|
||||
val labelName = runIf(!functionName.isSpecial) { functionName.identifier }
|
||||
target = FirFunctionTarget(labelName, isLambda = false)
|
||||
functionSymbol = FirNamedFunctionSymbol(callableIdForName(functionName))
|
||||
FirSimpleFunctionBuilder().apply {
|
||||
source = functionSource
|
||||
receiverTypeRef = receiverType
|
||||
@@ -1423,11 +1437,14 @@ class DeclarationsConverter(
|
||||
isSuspend = modifiers.hasSuspend()
|
||||
}
|
||||
|
||||
symbol = FirNamedFunctionSymbol(callableIdForName(functionName))
|
||||
symbol = functionSymbol
|
||||
dispatchReceiverType = currentDispatchReceiverType()
|
||||
}
|
||||
}
|
||||
|
||||
val firTypeParameters = mutableListOf<FirTypeParameter>()
|
||||
typeParameterList?.let { firTypeParameters += convertTypeParameters(it, typeConstraints, functionSymbol) }
|
||||
|
||||
val function = functionBuilder.apply {
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
@@ -1627,10 +1644,14 @@ class DeclarationsConverter(
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeParameterList
|
||||
*/
|
||||
private fun convertTypeParameters(typeParameterList: LighterASTNode, typeConstraints: List<TypeConstraint>): List<FirTypeParameter> {
|
||||
private fun convertTypeParameters(
|
||||
typeParameterList: LighterASTNode,
|
||||
typeConstraints: List<TypeConstraint>,
|
||||
containingDeclarationSymbol: FirBasedSymbol<*>
|
||||
): List<FirTypeParameter> {
|
||||
return typeParameterList.forEachChildrenReturnList { node, container ->
|
||||
when (node.tokenType) {
|
||||
TYPE_PARAMETER -> container += convertTypeParameter(node, typeConstraints)
|
||||
TYPE_PARAMETER -> container += convertTypeParameter(node, typeConstraints, containingDeclarationSymbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1672,7 +1693,11 @@ class DeclarationsConverter(
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinParsing.parseTypeParameter
|
||||
*/
|
||||
private fun convertTypeParameter(typeParameter: LighterASTNode, typeConstraints: List<TypeConstraint>): FirTypeParameter {
|
||||
private fun convertTypeParameter(
|
||||
typeParameter: LighterASTNode,
|
||||
typeConstraints: List<TypeConstraint>,
|
||||
containingSymbol: FirBasedSymbol<*>
|
||||
): FirTypeParameter {
|
||||
var typeParameterModifiers = TypeParameterModifier()
|
||||
var identifier: String? = null
|
||||
var firType: FirTypeRef? = null
|
||||
@@ -1690,6 +1715,7 @@ class DeclarationsConverter(
|
||||
origin = FirDeclarationOrigin.Source
|
||||
name = identifier.nameAsSafeName()
|
||||
symbol = FirTypeParameterSymbol()
|
||||
containingDeclarationSymbol = containingSymbol
|
||||
variance = typeParameterModifiers.getVariance()
|
||||
isReified = typeParameterModifiers.hasReified()
|
||||
annotations += typeParameterModifiers.annotations
|
||||
|
||||
+46
-34
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.fir.expressions.builder.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.references.builder.*
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScopeProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.*
|
||||
@@ -532,18 +533,55 @@ open class RawFirBuilder(
|
||||
extractAnnotationsTo(container.annotations)
|
||||
}
|
||||
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(container: FirTypeParameterRefsOwnerBuilder) {
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(
|
||||
container: FirTypeParameterRefsOwnerBuilder,
|
||||
declarationSymbol: FirBasedSymbol<*>
|
||||
) {
|
||||
for (typeParameter in typeParameters) {
|
||||
container.typeParameters += typeParameter.convert<FirTypeParameter>()
|
||||
container.typeParameters += extractTypeParameter(typeParameter, declarationSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(container: FirTypeParametersOwnerBuilder) {
|
||||
private fun KtTypeParameterListOwner.extractTypeParametersTo(
|
||||
container: FirTypeParametersOwnerBuilder,
|
||||
declarationSymbol: FirBasedSymbol<*>
|
||||
) {
|
||||
for (typeParameter in typeParameters) {
|
||||
container.typeParameters += typeParameter.convert<FirTypeParameter>()
|
||||
container.typeParameters += extractTypeParameter(typeParameter, declarationSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
private fun extractTypeParameter(parameter: KtTypeParameter, declarationSymbol: FirBasedSymbol<*>): FirTypeParameter {
|
||||
val parameterName = parameter.nameAsSafeName
|
||||
return buildTypeParameter {
|
||||
source = parameter.toFirSourceElement()
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
name = parameterName
|
||||
symbol = FirTypeParameterSymbol()
|
||||
containingDeclarationSymbol = declarationSymbol
|
||||
variance = parameter.variance
|
||||
isReified = parameter.hasModifier(REIFIED_KEYWORD)
|
||||
parameter.extractAnnotationsTo(this)
|
||||
val extendsBound = parameter.extendsBound
|
||||
if (extendsBound != null) {
|
||||
bounds += extendsBound.convert<FirTypeRef>()
|
||||
}
|
||||
val owner = parameter.getStrictParentOfType<KtTypeParameterListOwner>() ?: return@buildTypeParameter
|
||||
for (typeConstraint in owner.typeConstraints) {
|
||||
val subjectName = typeConstraint.subjectTypeParameterName?.getReferencedNameAsName()
|
||||
if (subjectName == parameterName) {
|
||||
bounds += typeConstraint.boundTypeReference.toFirOrErrorType()
|
||||
}
|
||||
}
|
||||
addDefaultBoundIfNecessary()
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit?): FirElement {
|
||||
throw AssertionError("KtTypeParameter should be process via extractTypeParameter")
|
||||
}
|
||||
|
||||
private fun <T> KtTypeParameterListOwner.fillDanglingConstraintsTo(to: T) where T : FirDeclaration, T : FirTypeParameterRefsOwner {
|
||||
val typeParamNames = typeParameters.mapNotNull { it.nameAsName }.toSet()
|
||||
val result = typeConstraints.mapNotNull { constraint ->
|
||||
@@ -890,7 +928,7 @@ open class RawFirBuilder(
|
||||
symbol = FirRegularClassSymbol(context.currentClassId)
|
||||
|
||||
classOrObject.extractAnnotationsTo(this)
|
||||
classOrObject.extractTypeParametersTo(this)
|
||||
classOrObject.extractTypeParametersTo(this, symbol)
|
||||
|
||||
context.applyToActualCapturedTypeParameters(true) {
|
||||
typeParameters += buildOuterClassTypeParameterRef { symbol = it }
|
||||
@@ -1032,7 +1070,7 @@ open class RawFirBuilder(
|
||||
symbol = FirTypeAliasSymbol(context.currentClassId)
|
||||
expandedTypeRef = typeAlias.getTypeReference().toFirOrErrorType()
|
||||
typeAlias.extractAnnotationsTo(this)
|
||||
typeAlias.extractTypeParametersTo(this)
|
||||
typeAlias.extractTypeParametersTo(this, symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1090,7 +1128,7 @@ open class RawFirBuilder(
|
||||
context.firFunctionTargets += target
|
||||
function.extractAnnotationsTo(this)
|
||||
if (this is FirSimpleFunctionBuilder) {
|
||||
function.extractTypeParametersTo(this)
|
||||
function.extractTypeParametersTo(this, symbol)
|
||||
}
|
||||
for (valueParameter in function.valueParameters) {
|
||||
valueParameters += valueParameter.convert<FirValueParameter>()
|
||||
@@ -1373,7 +1411,7 @@ open class RawFirBuilder(
|
||||
receiverTypeRef = receiverTypeReference.convertSafe()
|
||||
symbol = FirPropertySymbol(callableIdForName(propertyName))
|
||||
dispatchReceiverType = currentDispatchReceiverType()
|
||||
extractTypeParametersTo(this)
|
||||
extractTypeParametersTo(this, symbol)
|
||||
withCapturedTypeParameters(true, this.typeParameters) {
|
||||
val delegateBuilder = if (hasDelegate()) {
|
||||
FirWrappedDelegateExpressionBuilder().apply {
|
||||
@@ -1557,32 +1595,6 @@ open class RawFirBuilder(
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(parameter: KtTypeParameter, data: Unit): FirElement {
|
||||
val parameterName = parameter.nameAsSafeName
|
||||
return buildTypeParameter {
|
||||
source = parameter.toFirSourceElement()
|
||||
moduleData = baseModuleData
|
||||
origin = FirDeclarationOrigin.Source
|
||||
name = parameterName
|
||||
symbol = FirTypeParameterSymbol()
|
||||
variance = parameter.variance
|
||||
isReified = parameter.hasModifier(REIFIED_KEYWORD)
|
||||
parameter.extractAnnotationsTo(this)
|
||||
val extendsBound = parameter.extendsBound
|
||||
if (extendsBound != null) {
|
||||
bounds += extendsBound.convert<FirTypeRef>()
|
||||
}
|
||||
val owner = parameter.getStrictParentOfType<KtTypeParameterListOwner>() ?: return@buildTypeParameter
|
||||
for (typeConstraint in owner.typeConstraints) {
|
||||
val subjectName = typeConstraint.subjectTypeParameterName?.getReferencedNameAsName()
|
||||
if (subjectName == parameterName) {
|
||||
bounds += typeConstraint.boundTypeReference.toFirOrErrorType()
|
||||
}
|
||||
}
|
||||
addDefaultBoundIfNecessary()
|
||||
}
|
||||
}
|
||||
|
||||
// TODO introduce placeholder projection type
|
||||
private fun KtTypeProjection.isPlaceholderProjection() =
|
||||
projectionKind == KtProjectionKind.NONE && (typeReference?.typeElement as? KtUserType)?.referencedName == "_"
|
||||
|
||||
+5
-4
@@ -218,7 +218,7 @@ class FirSyntheticCallGenerator(
|
||||
containingDeclarations = components.containingDeclarations
|
||||
)
|
||||
|
||||
private fun generateSyntheticSelectTypeParameter(): Pair<FirTypeParameter, FirResolvedTypeRef> {
|
||||
private fun generateSyntheticSelectTypeParameter(functionSymbol: FirSyntheticFunctionSymbol): Pair<FirTypeParameter, FirResolvedTypeRef> {
|
||||
val typeParameterSymbol = FirTypeParameterSymbol()
|
||||
val typeParameter =
|
||||
buildTypeParameter {
|
||||
@@ -227,6 +227,7 @@ class FirSyntheticCallGenerator(
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
name = Name.identifier("K")
|
||||
symbol = typeParameterSymbol
|
||||
containingDeclarationSymbol = functionSymbol
|
||||
variance = Variance.INVARIANT
|
||||
isReified = false
|
||||
addDefaultBoundIfNecessary()
|
||||
@@ -242,7 +243,7 @@ class FirSyntheticCallGenerator(
|
||||
// fun <K> select(vararg values: K): K
|
||||
val functionSymbol = FirSyntheticFunctionSymbol(callableId)
|
||||
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter()
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter(functionSymbol)
|
||||
|
||||
val argumentType = buildResolvedTypeRef { type = returnType.type.createArrayType() }
|
||||
val typeArgument = buildTypeProjectionWithVariance {
|
||||
@@ -264,7 +265,7 @@ class FirSyntheticCallGenerator(
|
||||
// fun <X> test(a: X) = a!!
|
||||
// `X` is not a subtype of `Any` and hence cannot satisfy `K` if it had an upper bound of `Any`.
|
||||
val functionSymbol = FirSyntheticFunctionSymbol(SyntheticCallableId.CHECK_NOT_NULL)
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter()
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter(functionSymbol)
|
||||
|
||||
val argumentType = buildResolvedTypeRef {
|
||||
type = returnType.type.withNullability(ConeNullability.NULLABLE, session.typeContext)
|
||||
@@ -292,7 +293,7 @@ class FirSyntheticCallGenerator(
|
||||
// fun <X> test(a: X, b: X) = a ?: b
|
||||
// `X` is not a subtype of `Any` and hence cannot satisfy `K` if it had an upper bound of `Any`.
|
||||
val functionSymbol = FirSyntheticFunctionSymbol(SyntheticCallableId.ELVIS_NOT_NULL)
|
||||
val (typeParameter, rightArgumentType) = generateSyntheticSelectTypeParameter()
|
||||
val (typeParameter, rightArgumentType) = generateSyntheticSelectTypeParameter(functionSymbol)
|
||||
|
||||
val leftArgumentType = buildResolvedTypeRef {
|
||||
type = rightArgumentType.coneTypeUnsafe<ConeKotlinType>().withNullability(ConeNullability.NULLABLE, session.typeContext)
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -28,6 +29,7 @@ abstract class FirTypeParameter : FirTypeParameterRef, FirAnnotatedDeclaration()
|
||||
abstract override val attributes: FirDeclarationAttributes
|
||||
abstract val name: Name
|
||||
abstract override val symbol: FirTypeParameterSymbol
|
||||
abstract val containingDeclarationSymbol: FirBasedSymbol<*>?
|
||||
abstract val variance: Variance
|
||||
abstract val isReified: Boolean
|
||||
abstract val bounds: List<FirTypeRef>
|
||||
|
||||
+3
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirTypeParameterImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.visitors.*
|
||||
@@ -36,6 +37,7 @@ class FirTypeParameterBuilder : FirAnnotationContainerBuilder {
|
||||
var attributes: FirDeclarationAttributes = FirDeclarationAttributes()
|
||||
lateinit var name: Name
|
||||
lateinit var symbol: FirTypeParameterSymbol
|
||||
var containingDeclarationSymbol: FirBasedSymbol<*>? = null
|
||||
lateinit var variance: Variance
|
||||
var isReified: Boolean by kotlin.properties.Delegates.notNull<Boolean>()
|
||||
val bounds: MutableList<FirTypeRef> = mutableListOf()
|
||||
@@ -50,6 +52,7 @@ class FirTypeParameterBuilder : FirAnnotationContainerBuilder {
|
||||
attributes,
|
||||
name,
|
||||
symbol,
|
||||
containingDeclarationSymbol,
|
||||
variance,
|
||||
isReified,
|
||||
bounds,
|
||||
|
||||
+2
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -31,6 +32,7 @@ internal class FirTypeParameterImpl(
|
||||
override val attributes: FirDeclarationAttributes,
|
||||
override val name: Name,
|
||||
override val symbol: FirTypeParameterSymbol,
|
||||
override val containingDeclarationSymbol: FirBasedSymbol<*>?,
|
||||
override val variance: Variance,
|
||||
override val isReified: Boolean,
|
||||
override val bounds: MutableList<FirTypeRef>,
|
||||
|
||||
+1
@@ -289,6 +289,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
||||
typeParameter.configure {
|
||||
+name
|
||||
+symbol("FirTypeParameterSymbol")
|
||||
+field("containingDeclarationSymbol", firBasedSymbolType, "*", nullable = true)
|
||||
+field(varianceType)
|
||||
+booleanField("isReified")
|
||||
+fieldList("bounds", typeRef, withReplace = true)
|
||||
|
||||
+15
-15
@@ -102,23 +102,23 @@ fun SmartPrinter.printImplementation(implementation: Implementation) {
|
||||
}
|
||||
|
||||
|
||||
element.allFields.filter { it.type.contains("Symbol") && it !is FieldList }
|
||||
.takeIf {
|
||||
it.isNotEmpty() && !isInterface && !isAbstract &&
|
||||
!element.type.contains("Reference")
|
||||
&& !element.type.contains("ResolvedQualifier")
|
||||
&& !element.type.endsWith("Ref")
|
||||
}
|
||||
?.let { symbolFields ->
|
||||
println("init {")
|
||||
for (symbolField in symbolFields) {
|
||||
withIndent {
|
||||
println("${symbolField.name}${symbolField.call()}bind(this)")
|
||||
}
|
||||
element.allFields.filter {
|
||||
it.name != "containingDeclarationSymbol" && it.type.contains("Symbol") && it !is FieldList
|
||||
}.takeIf {
|
||||
it.isNotEmpty() && !isInterface && !isAbstract &&
|
||||
!element.type.contains("Reference")
|
||||
&& !element.type.contains("ResolvedQualifier")
|
||||
&& !element.type.endsWith("Ref")
|
||||
}?.let { symbolFields ->
|
||||
println("init {")
|
||||
for (symbolField in symbolFields) {
|
||||
withIndent {
|
||||
println("${symbolField.name}${symbolField.call()}bind(this)")
|
||||
}
|
||||
println("}")
|
||||
println()
|
||||
}
|
||||
println("}")
|
||||
println()
|
||||
}
|
||||
|
||||
fun Field.acceptString(): String = "${name}${call()}accept(visitor, data)"
|
||||
if (!isInterface && !isAbstract) {
|
||||
|
||||
Reference in New Issue
Block a user