[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:
committed by
Space Team
parent
0179b45840
commit
ef9413108b
@@ -16,6 +16,7 @@ dependencies {
|
||||
api(project(":compiler:fir:checkers:checkers.native"))
|
||||
api(project(":js:js.frontend"))
|
||||
|
||||
implementation(project(":core:compiler.common.native"))
|
||||
implementation(project(":compiler:fir:resolve"))
|
||||
implementation(project(":compiler:fir:fir-serialization"))
|
||||
implementation(project(":compiler:fir:fir2ir:jvm-backend"))
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.fir.types.constructClassType
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.includedForwardDeclarations
|
||||
import org.jetbrains.kotlin.library.isInterop
|
||||
import org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -41,7 +41,7 @@ class NativeForwardDeclarationsSymbolProvider(
|
||||
private val kotlinLibraries: Collection<KotlinLibrary>,
|
||||
) : FirSymbolProvider(session) {
|
||||
private companion object {
|
||||
private val validPackages = ForwardDeclarationKind.packageFqNameToKind.keys
|
||||
private val validPackages = NativeForwardDeclarationKind.packageFqNameToKind.keys
|
||||
}
|
||||
|
||||
private val includedForwardDeclarations: Set<ClassId> by lazy {
|
||||
@@ -77,7 +77,7 @@ class NativeForwardDeclarationsSymbolProvider(
|
||||
session.firCachesFactory.createCache(::createSyntheticForwardDeclarationClass)
|
||||
|
||||
private fun createSyntheticForwardDeclarationClass(classId: ClassId): FirClassLikeSymbol<*>? {
|
||||
val forwardDeclarationKind = ForwardDeclarationKind.packageFqNameToKind[classId.packageFqName] ?: return null
|
||||
val forwardDeclarationKind = NativeForwardDeclarationKind.packageFqNameToKind[classId.packageFqName] ?: return null
|
||||
|
||||
val symbol = FirRegularClassSymbol(classId)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":compiler:frontend"))
|
||||
compileOnly(project(":core:deserialization"))
|
||||
compileOnly(project(":core:compiler.common.native"))
|
||||
compileOnly(project(":compiler:serialization"))
|
||||
|
||||
api(kotlinStdlib())
|
||||
|
||||
+2
-10
@@ -9,8 +9,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.PlatformDependentTypeTransformer
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.types.SimpleType
|
||||
import org.jetbrains.kotlin.types.SupposititiousSimpleType
|
||||
|
||||
@@ -31,13 +30,6 @@ class NativeTypeTransformer : PlatformDependentTypeTransformer {
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val cNames = FqName("cnames")
|
||||
private val cNamesStructs = cNames.child(Name.identifier("structs"))
|
||||
|
||||
private val objCNames = FqName("objcnames")
|
||||
private val objCNamesClasses = objCNames.child(Name.identifier("classes"))
|
||||
private val objCNamesProtocols = objCNames.child(Name.identifier("protocols"))
|
||||
|
||||
private val forwardPackagesSet = setOf(cNamesStructs, objCNamesClasses, objCNamesProtocols)
|
||||
private val forwardPackagesSet = NativeForwardDeclarationKind.entries.map { it.packageFqName }.toSet()
|
||||
}
|
||||
}
|
||||
+9
-37
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.library.exportForwardDeclarations
|
||||
import org.jetbrains.kotlin.library.isInterop
|
||||
import org.jetbrains.kotlin.library.metadata.*
|
||||
import org.jetbrains.kotlin.library.packageFqName
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
@@ -138,7 +139,7 @@ class ClassifierAliasingPackageFragmentDescriptor(
|
||||
targets: List<KlibMetadataPackageFragment>,
|
||||
module: ModuleDescriptor,
|
||||
private val checker: ExportedForwardDeclarationChecker,
|
||||
) : PackageFragmentDescriptorImpl(module, checker.fqName) {
|
||||
) : PackageFragmentDescriptorImpl(module, checker.declKind.packageFqName) {
|
||||
private val memberScope = object : MemberScopeImpl() {
|
||||
override fun getContributedClassifier(name: Name, location: LookupLocation) =
|
||||
targets.firstNotNullOfOrNull {
|
||||
@@ -169,43 +170,14 @@ class ClassifierAliasingPackageFragmentDescriptor(
|
||||
* we need to check declaration type before returning the result of lookup.
|
||||
* See KT-49034.
|
||||
*/
|
||||
enum class ExportedForwardDeclarationChecker(val fqName: FqName) {
|
||||
enum class ExportedForwardDeclarationChecker(val declKind: NativeForwardDeclarationKind) {
|
||||
|
||||
Struct(ForwardDeclarationsFqNames.cNamesStructs) {
|
||||
override fun check(classifierDescriptor: ClassifierDescriptor): Boolean =
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.kind.isClass &&
|
||||
classifierDescriptor.isCStructVar()
|
||||
|
||||
},
|
||||
ObjCClass(ForwardDeclarationsFqNames.objCNamesClasses) {
|
||||
override fun check(classifierDescriptor: ClassifierDescriptor): Boolean =
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.kind.isClass &&
|
||||
classifierDescriptor.isObjCObjectBase()
|
||||
},
|
||||
ObjCProtocol(ForwardDeclarationsFqNames.objCNamesProtocols) {
|
||||
override fun check(classifierDescriptor: ClassifierDescriptor): Boolean =
|
||||
classifierDescriptor is ClassDescriptor && classifierDescriptor.kind.isInterface &&
|
||||
classifierDescriptor.isObjCObject()
|
||||
}
|
||||
Struct(NativeForwardDeclarationKind.Struct),
|
||||
ObjCClass(NativeForwardDeclarationKind.ObjCClass),
|
||||
ObjCProtocol(NativeForwardDeclarationKind.ObjCProtocol)
|
||||
;
|
||||
|
||||
abstract fun check(classifierDescriptor: ClassifierDescriptor): Boolean
|
||||
|
||||
companion object {
|
||||
private val cStructVarFqName = FqName("kotlinx.cinterop.CStructVar")
|
||||
private val objCObjectBaseFqName = FqName("kotlinx.cinterop.ObjCObjectBase")
|
||||
private val objCObjectFqName = FqName("kotlinx.cinterop.ObjCObject")
|
||||
|
||||
// We can stop at ObjCObjectBase when checking Obj-C classes.
|
||||
// Checking @ExternalObjCClass would be faster, but this annotation is not commonized. See KT-57541.
|
||||
private fun ClassifierDescriptor.isObjCObjectBase(): Boolean =
|
||||
getAllSuperClassifiers().any { it.fqNameSafe == objCObjectBaseFqName }
|
||||
|
||||
// For protocols, we have to go all the way up to ObjCObject.
|
||||
private fun ClassifierDescriptor.isObjCObject(): Boolean =
|
||||
getAllSuperClassifiers().any { it.fqNameSafe == objCObjectFqName }
|
||||
|
||||
private fun ClassifierDescriptor.isCStructVar(): Boolean =
|
||||
getAllSuperClassifiers().any { it.fqNameSafe == cStructVarFqName }
|
||||
}
|
||||
fun check(classifierDescriptor: ClassifierDescriptor): Boolean = classifierDescriptor is ClassDescriptor &&
|
||||
classifierDescriptor.kind == declKind.classKind &&
|
||||
classifierDescriptor.getAllSuperClassifiers().any { it.fqNameSafe == declKind.matchSuperClassFqName }
|
||||
}
|
||||
|
||||
+6
-10
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.metadata.*
|
||||
import org.jetbrains.kotlin.library.unresolvedDependencies
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.parentOrNull
|
||||
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||
@@ -194,22 +194,18 @@ class KlibMetadataModuleDescriptorFactoryImpl(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptorImpl
|
||||
): PackageFragmentProviderImpl {
|
||||
fun createPackage(fqName: FqName, supertypeName: String, classKind: ClassKind) =
|
||||
fun createPackage(kind: NativeForwardDeclarationKind) =
|
||||
ForwardDeclarationsPackageFragmentDescriptor(
|
||||
storageManager,
|
||||
module,
|
||||
fqName,
|
||||
Name.identifier(supertypeName),
|
||||
classKind,
|
||||
kind.packageFqName,
|
||||
kind.superClassName,
|
||||
kind.classKind,
|
||||
isExpect = true
|
||||
)
|
||||
|
||||
val packageFragmentProvider = PackageFragmentProviderImpl(
|
||||
listOf(
|
||||
createPackage(ForwardDeclarationsFqNames.cNamesStructs, "COpaque", ClassKind.CLASS),
|
||||
createPackage(ForwardDeclarationsFqNames.objCNamesClasses, "ObjCObjectBase", ClassKind.CLASS),
|
||||
createPackage(ForwardDeclarationsFqNames.objCNamesProtocols, "ObjCObject", ClassKind.INTERFACE)
|
||||
)
|
||||
NativeForwardDeclarationKind.entries.map { createPackage(it) }
|
||||
)
|
||||
return packageFragmentProvider
|
||||
}
|
||||
|
||||
+15
-30
@@ -17,9 +17,7 @@ import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.metadata.*
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolveResult
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.*
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||
@@ -121,18 +119,18 @@ class KlibResolvedModuleDescriptorsFactoryImpl(
|
||||
|
||||
val module = createDescriptorOptionalBuiltsIns(FORWARD_DECLARATIONS_MODULE_NAME, storageManager, builtIns, SyntheticModulesOrigin)
|
||||
|
||||
fun createPackage(forwardDeclarationKind: ForwardDeclarationKind) =
|
||||
fun createPackage(forwardDeclarationKind: NativeForwardDeclarationKind) =
|
||||
ForwardDeclarationsPackageFragmentDescriptor(
|
||||
storageManager,
|
||||
module,
|
||||
forwardDeclarationKind.packageFqName,
|
||||
Name.identifier(forwardDeclarationKind.superClassName),
|
||||
forwardDeclarationKind.superClassName,
|
||||
forwardDeclarationKind.classKind,
|
||||
isExpect
|
||||
)
|
||||
|
||||
val packageFragmentProvider = PackageFragmentProviderImpl(
|
||||
ForwardDeclarationKind.values().map { createPackage(it) }
|
||||
NativeForwardDeclarationKind.entries.map { createPackage(it) }
|
||||
)
|
||||
|
||||
module.initialize(packageFragmentProvider)
|
||||
@@ -184,7 +182,7 @@ class ForwardDeclarationsPackageFragmentDescriptor(
|
||||
private val declarations = storageManager.createMemoizedFunction(this::createDeclaration)
|
||||
|
||||
private val supertype by storageManager.createLazyValue {
|
||||
val descriptor = builtIns.builtInsModule.getPackage(ForwardDeclarationsFqNames.cInterop)
|
||||
val descriptor = builtIns.builtInsModule.getPackage(NativeStandardInteropNames.cInteropPackage)
|
||||
.memberScope
|
||||
.getContributedClassifier(supertypeName, NoLookupLocation.FROM_BACKEND) as ClassDescriptor
|
||||
|
||||
@@ -218,31 +216,18 @@ class ForwardDeclarationsPackageFragmentDescriptor(
|
||||
override fun getMemberScope(): MemberScope = memberScope
|
||||
}
|
||||
|
||||
// TODO decouple and move interop-specific logic back to Kotlin/Native.
|
||||
|
||||
@Deprecated(
|
||||
level = DeprecationLevel.ERROR,
|
||||
message = "This class was moved to org.jetbrains.kotlin.name.NativeStandardInteropNames.ForwardDeclarations",
|
||||
)
|
||||
object ForwardDeclarationsFqNames {
|
||||
|
||||
internal val cInterop = FqName("kotlinx.cinterop")
|
||||
internal val cInterop = NativeStandardInteropNames.cInteropPackage
|
||||
|
||||
private val cNames = FqName("cnames")
|
||||
internal val cNamesStructs = cNames.child(Name.identifier("structs"))
|
||||
internal val cNamesStructs = NativeStandardInteropNames.ForwardDeclarations.cNamesStructsPackage
|
||||
internal val objCNamesClasses = NativeStandardInteropNames.ForwardDeclarations.objCNamesClassesPackage
|
||||
internal val objCNamesProtocols = NativeStandardInteropNames.ForwardDeclarations.objCNamesProtocolsPackage
|
||||
|
||||
private val objCNames = FqName("objcnames")
|
||||
internal val objCNamesClasses = objCNames.child(Name.identifier("classes"))
|
||||
internal val objCNamesProtocols = objCNames.child(Name.identifier("protocols"))
|
||||
|
||||
val syntheticPackages = setOf(cNames, objCNames)
|
||||
}
|
||||
|
||||
enum class ForwardDeclarationKind(val packageFqName: FqName, val superClassName: String, val classKind: ClassKind) {
|
||||
CNAMES_STRUCTS(ForwardDeclarationsFqNames.cNamesStructs, "COpaque", ClassKind.CLASS),
|
||||
OBJCNAMES_CLASSES(ForwardDeclarationsFqNames.objCNamesClasses, "ObjCObjectBase", ClassKind.CLASS),
|
||||
OBJCNAMES_PROTOCOLS(ForwardDeclarationsFqNames.objCNamesProtocols, "ObjCObject", ClassKind.INTERFACE)
|
||||
|
||||
;
|
||||
|
||||
val superClassId = ClassId.topLevel(ForwardDeclarationsFqNames.cInterop.child(Name.identifier(superClassName)))
|
||||
|
||||
companion object {
|
||||
val packageFqNameToKind: Map<FqName, ForwardDeclarationKind> = ForwardDeclarationKind.values().associateBy { it.packageFqName }
|
||||
}
|
||||
val syntheticPackages = NativeStandardInteropNames.ForwardDeclarations.syntheticPackages
|
||||
}
|
||||
+1
@@ -29,4 +29,5 @@ typealias ForwardDeclarationsPackageFragmentDescriptor = org.jetbrains.kotlin.li
|
||||
"This object has been moved from package org.jetbrains.kotlin.serialization.konan.impl to package org.jetbrains.kotlin.library.metadata.impl",
|
||||
ReplaceWith("org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationsFqNames")
|
||||
)
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
typealias ForwardDeclarationsFqNames = org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationsFqNames
|
||||
|
||||
+49
@@ -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 }
|
||||
}
|
||||
}
|
||||
+26
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -157,6 +157,7 @@ dependencies {
|
||||
compilerImplementation project(":kotlin-compiler")
|
||||
compilerApi project(":native:kotlin-native-utils")
|
||||
compilerApi project(":core:descriptors")
|
||||
compilerApi project(":core:compiler.common.native")
|
||||
compilerApi project(":compiler:ir.tree")
|
||||
compilerApi project(":compiler:ir.backend.common")
|
||||
compilerApi project(":compiler:util")
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ import org.jetbrains.kotlin.ir.types.IrTypeSystemContextImpl
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.library.metadata.KlibMetadataFactories
|
||||
import org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.name.*
|
||||
|
||||
internal val KlibFactories = KlibMetadataFactories(::KonanBuiltIns, DynamicTypeDeserializer, PlatformDependentTypeTransformer.None)
|
||||
|
||||
@@ -111,7 +111,7 @@ internal fun PhaseContext.fir2Ir(
|
||||
}
|
||||
// This packages exists in all platform libraries, but can contain only synthetic declarations.
|
||||
// These declarations are not really located in klib, so we don't need to depend on klib to use them.
|
||||
removeAll(ForwardDeclarationKind.values().map { it.packageFqName })
|
||||
removeAll(NativeForwardDeclarationKind.entries.map { it.packageFqName })
|
||||
}.toList()
|
||||
|
||||
|
||||
|
||||
+5
-3
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBasedClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition
|
||||
@@ -37,7 +38,6 @@ internal val objCDirectFqName = interopPackageName.child(Name.identifier("ObjCDi
|
||||
internal val objCMethodFqName = interopPackageName.child(Name.identifier("ObjCMethod"))
|
||||
internal val objCConstructorFqName = FqName("kotlinx.cinterop.ObjCConstructor")
|
||||
internal val objCFactoryFqName = interopPackageName.child(Name.identifier("ObjCFactory"))
|
||||
private val objcnamesForwardDeclarationsPackageName = Name.identifier("objcnames")
|
||||
|
||||
fun ClassDescriptor.isObjCClass(): Boolean =
|
||||
this.containingDeclaration.fqNameSafe != interopPackageName &&
|
||||
@@ -64,8 +64,10 @@ fun IrClass.isExternalObjCClass(): Boolean = this.isObjCClass() &&
|
||||
it.annotations.hasAnnotation(externalObjCClassFqName)
|
||||
}
|
||||
|
||||
fun ClassDescriptor.isObjCForwardDeclaration(): Boolean =
|
||||
this.findPackage().fqName.startsWith(objcnamesForwardDeclarationsPackageName)
|
||||
fun ClassDescriptor.isObjCForwardDeclaration(): Boolean = when (NativeForwardDeclarationKind.packageFqNameToKind[findPackage().fqName]) {
|
||||
null, NativeForwardDeclarationKind.Struct -> false
|
||||
NativeForwardDeclarationKind.ObjCProtocol, NativeForwardDeclarationKind.ObjCClass -> true
|
||||
}
|
||||
|
||||
fun IrClass.isObjCForwardDeclaration(): Boolean =
|
||||
getPackageFragment().packageFqName.startsWith(objcnamesForwardDeclarationsPackageName)
|
||||
|
||||
+2
-9
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.backend.konan.descriptors.isFromInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.interop.IrProviderForCEnumAndCStructStubs
|
||||
import org.jetbrains.kotlin.backend.konan.ir.konanLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isFromInteropLibrary
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isFromInteropLibraryByDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.konan.isNativeStdlib
|
||||
@@ -58,6 +57,7 @@ import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.library.metadata.DeserializedKlibModuleOrigin
|
||||
import org.jetbrains.kotlin.library.metadata.klibModuleOrigin
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.NativeForwardDeclarationKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -472,12 +472,7 @@ internal class KonanIrLinker(
|
||||
) : KotlinIrLinker(currentModule, messageLogger, builtIns, symbolTable, exportedDependencies) {
|
||||
|
||||
companion object {
|
||||
private val C_NAMES_NAME = Name.identifier("cnames")
|
||||
private val OBJC_NAMES_NAME = Name.identifier("objcnames")
|
||||
|
||||
val FORWARD_DECLARATION_ORIGIN = object : IrDeclarationOriginImpl("FORWARD_DECLARATION_ORIGIN") {}
|
||||
|
||||
const val offset = SYNTHETIC_OFFSET
|
||||
}
|
||||
|
||||
override fun isBuiltInModule(moduleDescriptor: ModuleDescriptor): Boolean = moduleDescriptor.isNativeStdlib()
|
||||
@@ -1111,9 +1106,7 @@ internal class KonanIrLinker(
|
||||
|
||||
private fun IdSignature.isForwardDeclarationSignature(): Boolean {
|
||||
if (isPubliclyVisible) {
|
||||
return packageFqName().run {
|
||||
startsWith(C_NAMES_NAME) || startsWith(OBJC_NAMES_NAME)
|
||||
}
|
||||
return packageFqName() in NativeForwardDeclarationKind.packageFqNameToKind
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -27,6 +27,7 @@ dependencies {
|
||||
compileOnly(project(":compiler:cli-common"))
|
||||
compileOnly(project(":compiler:ir.serialization.common"))
|
||||
compileOnly(project(":compiler:frontend"))
|
||||
compileOnly(project(":core:compiler.common.native"))
|
||||
compileOnly(project(":native:frontend.native"))
|
||||
compileOnly(project(":kotlin-util-klib-metadata"))
|
||||
compileOnly(intellijCore())
|
||||
|
||||
@@ -10,10 +10,7 @@ import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirEntityId
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirName
|
||||
import org.jetbrains.kotlin.commonizer.cir.CirPackageName
|
||||
import org.jetbrains.kotlin.library.metadata.impl.ForwardDeclarationsFqNames
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.*
|
||||
|
||||
internal val DEPRECATED_ANNOTATION_FQN: FqName = FqName(Deprecated::class.java.name)
|
||||
internal const val DEPRECATED_ANNOTATION_FULL_NAME: ClassName = "kotlin/Deprecated"
|
||||
@@ -38,19 +35,19 @@ private val STANDARD_KOTLIN_PACKAGES: List<CirPackageName> = listOf(
|
||||
CirPackageName.create("kotlinx")
|
||||
)
|
||||
|
||||
private val KOTLIN_NATIVE_SYNTHETIC_PACKAGES: List<CirPackageName> = ForwardDeclarationsFqNames.syntheticPackages
|
||||
private val KOTLIN_NATIVE_SYNTHETIC_PACKAGES: List<CirPackageName> = NativeStandardInteropNames.ForwardDeclarations.syntheticPackages
|
||||
.map { packageFqName ->
|
||||
check(!packageFqName.isRoot)
|
||||
CirPackageName.create(packageFqName)
|
||||
}
|
||||
|
||||
internal val CNAMES_STRUCTS_PACKAGE = CirPackageName.create("cnames.structs")
|
||||
internal val CNAMES_STRUCTS_PACKAGE = CirPackageName.create(NativeForwardDeclarationKind.Struct.packageFqName)
|
||||
|
||||
internal val OBJCNAMES_CLASSES_PACKAGE = CirPackageName.create("objcnames.classes")
|
||||
internal val OBJCNAMES_CLASSES_PACKAGE = CirPackageName.create(NativeForwardDeclarationKind.ObjCClass.packageFqName)
|
||||
|
||||
internal val OBJCNAMES_PROTOCOLS_PACKAGE = CirPackageName.create("objcnames.protocols")
|
||||
internal val OBJCNAMES_PROTOCOLS_PACKAGE = CirPackageName.create(NativeForwardDeclarationKind.ObjCProtocol.packageFqName)
|
||||
|
||||
private val CINTEROP_PACKAGE: CirPackageName = CirPackageName.create("kotlinx.cinterop")
|
||||
private val CINTEROP_PACKAGE: CirPackageName = CirPackageName.create(NativeStandardInteropNames.cInteropPackage)
|
||||
|
||||
private val OBJC_INTEROP_CALLABLE_ANNOTATIONS: List<CirName> = listOf(
|
||||
CirName.create("ObjCMethod"),
|
||||
|
||||
Reference in New Issue
Block a user