[K/N] Consolidate forward declarations handling

This is refactoring in preparation for KT-59764.
Names and layout of forward declarations related classes
was copy-pasted many times over compiler code.

Implementing KT-59764 would require copy-pasting it two more times.
So instead of doing this it was put in single place.

No behaviour changes intended in this commit.
This commit is contained in:
Pavel Kunyavskiy
2023-07-03 14:49:03 +02:00
committed by Space Team
parent 0179b45840
commit ef9413108b
16 changed files with 130 additions and 113 deletions
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.name
import org.jetbrains.kotlin.descriptors.ClassKind
/**
* Enum class representing different kinds of synthetic forward declarations.
*
* @property packageFqName The fully qualified name of the package where the forward declarations of this kind are located.
* @property superClassName The name of the generated superclass of the forward declaration.
* @property matchSuperClassName The name of the superclass real declaration corresponding to this synthetic should have.
* @property classKind The class kind of the forward declaration class (class or interface).
*
* Also, fqName and classId of super classes are stored as optimization to avoid allocations and string processing on usage.
*/
enum class NativeForwardDeclarationKind(val packageFqName: FqName, val superClassName: Name, val matchSuperClassName: Name, val classKind: ClassKind) {
Struct(
NativeStandardInteropNames.ForwardDeclarations.cNamesStructsPackage,
NativeStandardInteropNames.COpaque,
NativeStandardInteropNames.CStructVar,
ClassKind.CLASS
),
ObjCClass(
NativeStandardInteropNames.ForwardDeclarations.objCNamesClassesPackage,
NativeStandardInteropNames.ObjCObjectBase,
NativeStandardInteropNames.ObjCObjectBase,
ClassKind.CLASS
),
ObjCProtocol(
NativeStandardInteropNames.ForwardDeclarations.objCNamesProtocolsPackage,
NativeStandardInteropNames.ObjCObject,
NativeStandardInteropNames.ObjCObject,
ClassKind.INTERFACE
)
;
val superClassFqName = NativeStandardInteropNames.cInteropPackage.child(superClassName)
val matchSuperClassFqName = NativeStandardInteropNames.cInteropPackage.child(matchSuperClassName)
val superClassId = ClassId.topLevel(superClassFqName)
val matchSuperClassId = ClassId.topLevel(matchSuperClassFqName)
companion object {
val packageFqNameToKind: Map<FqName, NativeForwardDeclarationKind> = NativeForwardDeclarationKind.entries.associateBy { it.packageFqName }
}
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.name
object NativeStandardInteropNames {
val cInteropPackage = FqName("kotlinx.cinterop")
internal val COpaque = Name.identifier("COpaque")
internal val CStructVar = Name.identifier("CStructVar")
internal val ObjCObjectBase = Name.identifier("ObjCObjectBase")
internal val ObjCObject = Name.identifier("ObjCObject")
object ForwardDeclarations {
private val cNamesPackage = FqName("cnames")
val cNamesStructsPackage = cNamesPackage.child(Name.identifier("structs"))
private val objCNamesPackage = FqName("objcnames")
val objCNamesClassesPackage = objCNamesPackage.child(Name.identifier("classes"))
val objCNamesProtocolsPackage = objCNamesPackage.child(Name.identifier("protocols"))
val syntheticPackages = setOf(cNamesPackage, objCNamesPackage)
}
}