Removed usage of Kotlin.BuiltIns

This commit is contained in:
Igor Chevdar
2017-03-07 17:28:28 +03:00
parent 532cab42a7
commit 6bb32743fd
2 changed files with 24 additions and 12 deletions
@@ -9,8 +9,6 @@ import org.jetbrains.kotlin.backend.konan.llvm.Llvm
import org.jetbrains.kotlin.backend.konan.llvm.LlvmDeclarations import org.jetbrains.kotlin.backend.konan.llvm.LlvmDeclarations
import org.jetbrains.kotlin.backend.konan.llvm.functionName import org.jetbrains.kotlin.backend.konan.llvm.functionName
import org.jetbrains.kotlin.backend.konan.llvm.verifyModule import org.jetbrains.kotlin.backend.konan.llvm.verifyModule
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.getFunctionTypeArgumentProjections
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
@@ -27,7 +25,11 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.utils.addIfNotNull
import java.lang.System.out import java.lang.System.out
import java.util.*
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
internal class SpecialDescriptorsFactory(val context: Context) { internal class SpecialDescriptorsFactory(val context: Context) {
@@ -139,6 +141,22 @@ class ReflectionTypes(module: ModuleDescriptor) {
} }
} }
private fun getFunctionTypeArgumentProjections(
receiverType: KotlinType?,
parameterTypes: List<KotlinType>,
returnType: KotlinType
): List<TypeProjection> {
val arguments = ArrayList<TypeProjection>(parameterTypes.size + (if (receiverType != null) 1 else 0) + 1)
arguments.addIfNotNull(receiverType?.asTypeProjection())
parameterTypes.mapTo(arguments, KotlinType::asTypeProjection)
arguments.add(returnType.asTypeProjection())
return arguments
}
fun getKFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KFunction$n") fun getKFunction(n: Int): ClassDescriptor = find(kotlinReflectScope, "KFunction$n")
val kClass: ClassDescriptor by ClassLookup(kotlinReflectScope) val kClass: ClassDescriptor by ClassLookup(kotlinReflectScope)
@@ -156,11 +174,9 @@ class ReflectionTypes(module: ModuleDescriptor) {
annotations: Annotations, annotations: Annotations,
receiverType: KotlinType?, receiverType: KotlinType?,
parameterTypes: List<KotlinType>, parameterTypes: List<KotlinType>,
parameterNames: List<Name>?, returnType: KotlinType
returnType: KotlinType,
builtIns: KotlinBuiltIns
): KotlinType { ): KotlinType {
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, parameterNames, returnType, builtIns) val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
val classDescriptor = getKFunction(arguments.size - 1 /* return type */) val classDescriptor = getKFunction(arguments.size - 1 /* return type */)
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments) return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
} }
@@ -146,9 +146,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
annotations = Annotations.EMPTY, annotations = Annotations.EMPTY,
receiverType = receiverType, receiverType = receiverType,
parameterTypes = listOf(), parameterTypes = listOf(),
parameterNames = null, returnType = propertyDescriptor.type)
returnType = propertyDescriptor.type,
builtIns = context.builtIns)
val getterCallableReference = IrCallableReferenceImpl(startOffset, endOffset, getterKFunctionType, getter, null).apply { val getterCallableReference = IrCallableReferenceImpl(startOffset, endOffset, getterKFunctionType, getter, null).apply {
dispatchReceiver = expression.dispatchReceiver dispatchReceiver = expression.dispatchReceiver
extensionReceiver = expression.extensionReceiver extensionReceiver = expression.extensionReceiver
@@ -161,9 +159,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
annotations = Annotations.EMPTY, annotations = Annotations.EMPTY,
receiverType = receiverType, receiverType = receiverType,
parameterTypes = listOf(propertyDescriptor.type), parameterTypes = listOf(propertyDescriptor.type),
parameterNames = null, returnType = context.builtIns.unitType)
returnType = context.builtIns.unitType,
builtIns = context.builtIns)
IrCallableReferenceImpl(startOffset, endOffset, setterKFunctionType, it, null).apply { IrCallableReferenceImpl(startOffset, endOffset, setterKFunctionType, it, null).apply {
dispatchReceiver = expression.dispatchReceiver dispatchReceiver = expression.dispatchReceiver
extensionReceiver = expression.extensionReceiver extensionReceiver = expression.extensionReceiver