kotlin.reflect.jvm.internal.impl.resolve.jvm.inlineClassManglingRules.kt Maven / Gradle / Ivy
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package kotlin.reflect.jvm.internal.impl.resolve.jvm
import kotlin.reflect.jvm.internal.impl.descriptors.*
import kotlin.reflect.jvm.internal.impl.load.kotlin.getRepresentativeUpperBound
import kotlin.reflect.jvm.internal.impl.resolve.DescriptorUtils
import kotlin.reflect.jvm.internal.impl.resolve.descriptorUtil.fqNameSafe
import kotlin.reflect.jvm.internal.impl.resolve.descriptorUtil.fqNameUnsafe
import kotlin.reflect.jvm.internal.impl.resolve.isInlineClass
import kotlin.reflect.jvm.internal.impl.resolve.isInlineClassType
import kotlin.reflect.jvm.internal.impl.types.KotlinType
import java.security.MessageDigest
import java.util.*
fun shouldHideConstructorDueToInlineClassTypeValueParameters(descriptor: CallableMemberDescriptor): Boolean {
val constructorDescriptor = descriptor as? ClassConstructorDescriptor ?: return false
if (Visibilities.isPrivate(constructorDescriptor.visibility)) return false
if (constructorDescriptor.constructedClass.isInline) return false
if (DescriptorUtils.isSealedClass(constructorDescriptor.constructedClass)) return false
// TODO inner class in inline class
return constructorDescriptor.valueParameters.any { it.type.requiresFunctionNameMangling() }
}
fun requiresFunctionNameMangling(valueParameterTypes: List): Boolean {
return valueParameterTypes.any { it.requiresFunctionNameMangling() }
}
fun DeclarationDescriptor.isInlineClassThatRequiresMangling(): Boolean =
isInlineClass() && !isDontMangleClass(this as ClassDescriptor)
fun KotlinType.isInlineClassThatRequiresMangling() =
constructor.declarationDescriptor?.isInlineClassThatRequiresMangling() == true
private fun KotlinType.requiresFunctionNameMangling() =
isInlineClassThatRequiresMangling() || isTypeParameterWithUpperBoundThatRequiresMangling()
private fun isDontMangleClass(classDescriptor: ClassDescriptor) =
classDescriptor.fqNameSafe == DescriptorUtils.RESULT_FQ_NAME
private fun KotlinType.isTypeParameterWithUpperBoundThatRequiresMangling(): Boolean {
val descriptor = constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
return getRepresentativeUpperBound(descriptor).requiresFunctionNameMangling()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy