Add comments for generators about data/inline class (in psi2ir and fir2ir) and annotations (fir2ir).
This commit is contained in:
committed by
Mikhail Glukhikh
parent
e844c59e7e
commit
bcf277d885
-6
@@ -16,17 +16,11 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.backend.common
|
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.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtParameter
|
import org.jetbrains.kotlin.psi.KtParameter
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.BindingContextUtils
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A platform-independent logic for generating data class synthetic methods.
|
* A platform-independent logic for generating data class synthetic methods.
|
||||||
|
|||||||
+8
@@ -15,6 +15,14 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
|||||||
import org.jetbrains.kotlin.ir.util.isPropertyField
|
import org.jetbrains.kotlin.ir.util.isPropertyField
|
||||||
import org.jetbrains.kotlin.ir.util.isSetter
|
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) {
|
internal class AnnotationGenerator(private val visitor: Fir2IrVisitor) {
|
||||||
|
|
||||||
fun generate(irContainer: IrMutableAnnotationContainer, firContainer: FirAnnotationContainer) {
|
fun generate(irContainer: IrMutableAnnotationContainer, firContainer: FirAnnotationContainer) {
|
||||||
|
|||||||
+8
@@ -42,6 +42,14 @@ import org.jetbrains.kotlin.ir.util.defaultType
|
|||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.Name
|
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) {
|
class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
||||||
|
|
||||||
fun generateInlineClassMembers(klass: FirClass<*>, irClass: IrClass): List<Name> =
|
fun generateInlineClassMembers(klass: FirClass<*>, irClass: IrClass): List<Name> =
|
||||||
|
|||||||
+6
@@ -30,6 +30,12 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
|||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
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(
|
class DataClassMembersGenerator(
|
||||||
declarationGenerator: DeclarationGenerator
|
declarationGenerator: DeclarationGenerator
|
||||||
) : DeclarationGeneratorExtension(declarationGenerator) {
|
) : DeclarationGeneratorExtension(declarationGenerator) {
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
|||||||
import org.jetbrains.kotlin.types.isNullable
|
import org.jetbrains.kotlin.types.isNullable
|
||||||
import org.jetbrains.kotlin.types.typeUtil.representativeUpperBound
|
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(
|
abstract class DataClassMembersGenerator(
|
||||||
val context: IrGeneratorContext,
|
val context: IrGeneratorContext,
|
||||||
val symbolTable: SymbolTable,
|
val symbolTable: SymbolTable,
|
||||||
|
|||||||
Reference in New Issue
Block a user