FIR: move data class synthetic members' names
This commit is contained in:
committed by
TeamCityServer
parent
856838f82c
commit
e6cfd5d06f
+21
-24
@@ -6,6 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.fir.backend.generators
|
package org.jetbrains.kotlin.fir.backend.generators
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.fir.COPY_NAME
|
||||||
|
import org.jetbrains.kotlin.fir.EQUALS_NAME
|
||||||
|
import org.jetbrains.kotlin.fir.HASHCODE_NAME
|
||||||
|
import org.jetbrains.kotlin.fir.TOSTRING_NAME
|
||||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||||
import org.jetbrains.kotlin.fir.backend.FirMetadataSource
|
import org.jetbrains.kotlin.fir.backend.FirMetadataSource
|
||||||
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
|
||||||
@@ -41,8 +45,6 @@ import org.jetbrains.kotlin.ir.types.classifierOrNull
|
|||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
|
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A generator that generates synthetic members of data class as well as part of inline class.
|
* A generator that generates synthetic members of data class as well as part of inline class.
|
||||||
@@ -168,9 +170,9 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
returnTypeRef.toIrType(components.typeConverter) == components.irBuiltIns.stringType
|
returnTypeRef.toIrType(components.typeConverter) == components.irBuiltIns.stringType
|
||||||
|
|
||||||
private val FirSimpleFunction.matchesDataClassSyntheticMemberSignatures: Boolean
|
private val FirSimpleFunction.matchesDataClassSyntheticMemberSignatures: Boolean
|
||||||
get() = (this.name == equalsName && matchesEqualsSignature) ||
|
get() = (this.name == EQUALS_NAME && matchesEqualsSignature) ||
|
||||||
(this.name == hashCodeName && matchesHashCodeSignature) ||
|
(this.name == HASHCODE_NAME && matchesHashCodeSignature) ||
|
||||||
(this.name == toStringName && matchesToStringSignature)
|
(this.name == TOSTRING_NAME && matchesToStringSignature)
|
||||||
|
|
||||||
fun generate(klass: FirClass<*>): List<FirDeclaration> {
|
fun generate(klass: FirClass<*>): List<FirDeclaration> {
|
||||||
val propertyParametersCount = irClass.primaryConstructor?.explicitParameters?.size ?: 0
|
val propertyParametersCount = irClass.primaryConstructor?.explicitParameters?.size ?: 0
|
||||||
@@ -192,7 +194,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
val contributedFunctionsInSupertypes =
|
val contributedFunctionsInSupertypes =
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
buildMap<Name, FirSimpleFunction> {
|
buildMap<Name, FirSimpleFunction> {
|
||||||
for (name in listOf(equalsName, hashCodeName, toStringName)) {
|
for (name in listOf(EQUALS_NAME, HASHCODE_NAME, TOSTRING_NAME)) {
|
||||||
klass.unsubstitutedScope(
|
klass.unsubstitutedScope(
|
||||||
components.session,
|
components.session,
|
||||||
components.scopeSession,
|
components.scopeSession,
|
||||||
@@ -211,12 +213,12 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
return declaration.modality != Modality.FINAL
|
return declaration.modality != Modality.FINAL
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contributedFunctionsInThisType.contains(equalsName) &&
|
if (!contributedFunctionsInThisType.contains(EQUALS_NAME) &&
|
||||||
isOverridableDeclaration(equalsName)
|
isOverridableDeclaration(EQUALS_NAME)
|
||||||
) {
|
) {
|
||||||
result.add(contributedFunctionsInSupertypes.getValue(equalsName))
|
result.add(contributedFunctionsInSupertypes.getValue(EQUALS_NAME))
|
||||||
val equalsFunction = createSyntheticIrFunction(
|
val equalsFunction = createSyntheticIrFunction(
|
||||||
equalsName,
|
EQUALS_NAME,
|
||||||
components.irBuiltIns.booleanType,
|
components.irBuiltIns.booleanType,
|
||||||
otherParameterNeeded = true
|
otherParameterNeeded = true
|
||||||
)
|
)
|
||||||
@@ -224,24 +226,24 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
irClass.declarations.add(equalsFunction)
|
irClass.declarations.add(equalsFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contributedFunctionsInThisType.contains(hashCodeName) &&
|
if (!contributedFunctionsInThisType.contains(HASHCODE_NAME) &&
|
||||||
isOverridableDeclaration(hashCodeName)
|
isOverridableDeclaration(HASHCODE_NAME)
|
||||||
) {
|
) {
|
||||||
result.add(contributedFunctionsInSupertypes.getValue(hashCodeName))
|
result.add(contributedFunctionsInSupertypes.getValue(HASHCODE_NAME))
|
||||||
val hashCodeFunction = createSyntheticIrFunction(
|
val hashCodeFunction = createSyntheticIrFunction(
|
||||||
hashCodeName,
|
HASHCODE_NAME,
|
||||||
components.irBuiltIns.intType,
|
components.irBuiltIns.intType,
|
||||||
)
|
)
|
||||||
irDataClassMembersGenerator.generateHashCodeMethod(hashCodeFunction, properties)
|
irDataClassMembersGenerator.generateHashCodeMethod(hashCodeFunction, properties)
|
||||||
irClass.declarations.add(hashCodeFunction)
|
irClass.declarations.add(hashCodeFunction)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!contributedFunctionsInThisType.contains(toStringName) &&
|
if (!contributedFunctionsInThisType.contains(TOSTRING_NAME) &&
|
||||||
isOverridableDeclaration(toStringName)
|
isOverridableDeclaration(TOSTRING_NAME)
|
||||||
) {
|
) {
|
||||||
result.add(contributedFunctionsInSupertypes.getValue(toStringName))
|
result.add(contributedFunctionsInSupertypes.getValue(TOSTRING_NAME))
|
||||||
val toStringFunction = createSyntheticIrFunction(
|
val toStringFunction = createSyntheticIrFunction(
|
||||||
toStringName,
|
TOSTRING_NAME,
|
||||||
components.irBuiltIns.stringType,
|
components.irBuiltIns.stringType,
|
||||||
)
|
)
|
||||||
irDataClassMembersGenerator.generateToStringMethod(toStringFunction, properties)
|
irDataClassMembersGenerator.generateToStringMethod(toStringFunction, properties)
|
||||||
@@ -335,13 +337,8 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val copyName = Name.identifier("copy")
|
|
||||||
private val equalsName = Name.identifier("equals")
|
|
||||||
private val hashCodeName = Name.identifier("hashCode")
|
|
||||||
private val toStringName = Name.identifier("toString")
|
|
||||||
|
|
||||||
fun isCopy(irFunction: IrFunction): Boolean =
|
fun isCopy(irFunction: IrFunction): Boolean =
|
||||||
irFunction.name == copyName
|
irFunction.name == COPY_NAME
|
||||||
|
|
||||||
fun isComponentN(irFunction: IrFunction): Boolean {
|
fun isComponentN(irFunction: IrFunction): Boolean {
|
||||||
if (irFunction.name.isSpecial) {
|
if (irFunction.name.isSpecial) {
|
||||||
|
|||||||
@@ -10,3 +10,9 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
val NAME_FOR_BACKING_FIELD = Name.identifier("field")
|
val NAME_FOR_BACKING_FIELD = Name.identifier("field")
|
||||||
val NAME_FOR_DEFAULT_VALUE_PARAMETER = Name.identifier("value")
|
val NAME_FOR_DEFAULT_VALUE_PARAMETER = Name.identifier("value")
|
||||||
val CONSTRUCTOR_NAME = Name.special("<init>")
|
val CONSTRUCTOR_NAME = Name.special("<init>")
|
||||||
|
|
||||||
|
// Data class synthetic members
|
||||||
|
val COPY_NAME = Name.identifier("copy")
|
||||||
|
val EQUALS_NAME = Name.identifier("equals")
|
||||||
|
val HASHCODE_NAME = Name.identifier("hashCode")
|
||||||
|
val TOSTRING_NAME = Name.identifier("toString")
|
||||||
|
|||||||
Reference in New Issue
Block a user