FIR: use EQUALS & TO_STRING from OperatorNameConventions

This commit is contained in:
Mikhail Glukhikh
2021-02-26 10:34:18 +03:00
committed by TeamCityServer
parent e6cfd5d06f
commit b138b166e3
2 changed files with 13 additions and 15 deletions
@@ -7,9 +7,7 @@ package org.jetbrains.kotlin.fir.backend.generators
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.FirMetadataSource
import org.jetbrains.kotlin.fir.backend.declareThisReceiverParameter
@@ -45,6 +43,8 @@ import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS
import org.jetbrains.kotlin.util.OperatorNameConventions.TO_STRING
/**
* A generator that generates synthetic members of data class as well as part of inline class.
@@ -170,9 +170,9 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
returnTypeRef.toIrType(components.typeConverter) == components.irBuiltIns.stringType
private val FirSimpleFunction.matchesDataClassSyntheticMemberSignatures: Boolean
get() = (this.name == EQUALS_NAME && matchesEqualsSignature) ||
get() = (this.name == EQUALS && matchesEqualsSignature) ||
(this.name == HASHCODE_NAME && matchesHashCodeSignature) ||
(this.name == TOSTRING_NAME && matchesToStringSignature)
(this.name == TO_STRING && matchesToStringSignature)
fun generate(klass: FirClass<*>): List<FirDeclaration> {
val propertyParametersCount = irClass.primaryConstructor?.explicitParameters?.size ?: 0
@@ -194,7 +194,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
val contributedFunctionsInSupertypes =
@OptIn(ExperimentalStdlibApi::class)
buildMap<Name, FirSimpleFunction> {
for (name in listOf(EQUALS_NAME, HASHCODE_NAME, TOSTRING_NAME)) {
for (name in listOf(EQUALS, HASHCODE_NAME, TO_STRING)) {
klass.unsubstitutedScope(
components.session,
components.scopeSession,
@@ -213,12 +213,12 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
return declaration.modality != Modality.FINAL
}
if (!contributedFunctionsInThisType.contains(EQUALS_NAME) &&
isOverridableDeclaration(EQUALS_NAME)
if (!contributedFunctionsInThisType.contains(EQUALS) &&
isOverridableDeclaration(EQUALS)
) {
result.add(contributedFunctionsInSupertypes.getValue(EQUALS_NAME))
result.add(contributedFunctionsInSupertypes.getValue(EQUALS))
val equalsFunction = createSyntheticIrFunction(
EQUALS_NAME,
EQUALS,
components.irBuiltIns.booleanType,
otherParameterNeeded = true
)
@@ -238,12 +238,12 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
irClass.declarations.add(hashCodeFunction)
}
if (!contributedFunctionsInThisType.contains(TOSTRING_NAME) &&
isOverridableDeclaration(TOSTRING_NAME)
if (!contributedFunctionsInThisType.contains(TO_STRING) &&
isOverridableDeclaration(TO_STRING)
) {
result.add(contributedFunctionsInSupertypes.getValue(TOSTRING_NAME))
result.add(contributedFunctionsInSupertypes.getValue(TO_STRING))
val toStringFunction = createSyntheticIrFunction(
TOSTRING_NAME,
TO_STRING,
components.irBuiltIns.stringType,
)
irDataClassMembersGenerator.generateToStringMethod(toStringFunction, properties)
@@ -13,6 +13,4 @@ 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")