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.functionName
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.annotations.Annotations
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.types.KotlinType
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.util.*
import kotlin.reflect.KProperty
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")
val kClass: ClassDescriptor by ClassLookup(kotlinReflectScope)
@@ -156,11 +174,9 @@ class ReflectionTypes(module: ModuleDescriptor) {
annotations: Annotations,
receiverType: KotlinType?,
parameterTypes: List<KotlinType>,
parameterNames: List<Name>?,
returnType: KotlinType,
builtIns: KotlinBuiltIns
returnType: KotlinType
): KotlinType {
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, parameterNames, returnType, builtIns)
val arguments = getFunctionTypeArgumentProjections(receiverType, parameterTypes, returnType)
val classDescriptor = getKFunction(arguments.size - 1 /* return type */)
return KotlinTypeFactory.simpleNotNullType(annotations, classDescriptor, arguments)
}
@@ -146,9 +146,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
annotations = Annotations.EMPTY,
receiverType = receiverType,
parameterTypes = listOf(),
parameterNames = null,
returnType = propertyDescriptor.type,
builtIns = context.builtIns)
returnType = propertyDescriptor.type)
val getterCallableReference = IrCallableReferenceImpl(startOffset, endOffset, getterKFunctionType, getter, null).apply {
dispatchReceiver = expression.dispatchReceiver
extensionReceiver = expression.extensionReceiver
@@ -161,9 +159,7 @@ internal class PropertyDelegationLowering(val context: Context) : FileLoweringPa
annotations = Annotations.EMPTY,
receiverType = receiverType,
parameterTypes = listOf(propertyDescriptor.type),
parameterNames = null,
returnType = context.builtIns.unitType,
builtIns = context.builtIns)
returnType = context.builtIns.unitType)
IrCallableReferenceImpl(startOffset, endOffset, setterKFunctionType, it, null).apply {
dispatchReceiver = expression.dispatchReceiver
extensionReceiver = expression.extensionReceiver