diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.kt index 46327bec12c..1eec7561701 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/DataClassMethodGenerator.kt @@ -16,17 +16,11 @@ package org.jetbrains.kotlin.backend.common -import org.jetbrains.kotlin.backend.common.CodegenUtil.getMemberToGenerate -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor -import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.BindingContextUtils /** * A platform-independent logic for generating data class synthetic methods. diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AnnotationGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AnnotationGenerator.kt index 8e2dc800a04..4568fc36e2a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AnnotationGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AnnotationGenerator.kt @@ -15,6 +15,14 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.util.isPropertyField import org.jetbrains.kotlin.ir.util.isSetter +/** + * A generator that converts annotations in [FirAnnotationContainer] to annotations in [IrMutableAnnotationContainer]. + * + * In general, annotations are bound to the target in the beginning, i.e., clearly targeted at source level. But, there are some cases that + * need special handling: [AnnotationUseSiteTarget]. In particular, [FirProperty] contains all annotations associated with that property, + * whose targets may vary. After all the necessary pieces of IR elements, e.g., backing field, are ready, this generator splits those + * annotations to the specified targets. + */ internal class AnnotationGenerator(private val visitor: Fir2IrVisitor) { fun generate(irContainer: IrMutableAnnotationContainer, firContainer: FirAnnotationContainer) { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt index 01f8cd29295..7ad78c47c5e 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DataClassMembersGenerator.kt @@ -42,6 +42,14 @@ import org.jetbrains.kotlin.ir.util.defaultType import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name +/** + * A generator that generates synthetic members of data class as well as part of inline class. + * + * This one uses [DataClassMembersGenerator] to generate function bodies, shared with the counterpart in psi. But, there are two main + * differences. Unlike the counterpart in psi, which uses descriptor-based logic to determine which members to synthesize, this one uses + * fir own logic that traverses class hierarchies in fir elements. Also, this one creates and passes IR elements, instead of providing how + * to declare them, to [DataClassMembersGenerator]. + */ class DataClassMembersGenerator(val components: Fir2IrComponents) { fun generateInlineClassMembers(klass: FirClass<*>, irClass: IrClass): List = diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt index b9b3a436ddc..46b687cbaf5 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt @@ -30,6 +30,12 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils +/** + * A generator that generates synthetic members of data class as well as part of inline class. + * + * This one uses [DataClassMethodGenerator] to determine which members are needed to generate; uses [DataClassMembersGenerator] to generate + * function bodies; and provides ways to declare functions or parameters based on descriptors and binding context. + */ class DataClassMembersGenerator( declarationGenerator: DeclarationGenerator ) : DeclarationGeneratorExtension(declarationGenerator) { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DataClassMembersGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DataClassMembersGenerator.kt index 03a8fdd423a..b1094c41842 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DataClassMembersGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DataClassMembersGenerator.kt @@ -27,6 +27,12 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.isNullable import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound +/** + * A platform-, frontend-independent logic for generating synthetic members of data class: equals, hashCode, toString, componentN, and copy. + * Different front-ends may need to define how to declare functions, parameters, etc., or simply provide predefined ones. + * + * Generating synthetic members of inline class can use this as well, in particular, members from Any: equals, hashCode, and toString. + */ abstract class DataClassMembersGenerator( val context: IrGeneratorContext, val symbolTable: SymbolTable,