backend: move some sources to common packages
This commit is contained in:
committed by
SvyatoslavScherbina
parent
c842b9bc73
commit
6e17507cde
+26
@@ -0,0 +1,26 @@
|
||||
package org.jetbrains.kotlin.backend.common.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
|
||||
/**
|
||||
* @return naturally-ordered list of all parameters available inside the function body.
|
||||
*/
|
||||
internal val CallableDescriptor.allParameters: List<ParameterDescriptor>
|
||||
get() {
|
||||
val receivers = mutableListOf<ParameterDescriptor>()
|
||||
|
||||
if (this is ConstructorDescriptor)
|
||||
receivers.add(this.constructedClass.thisAsReceiverParameter)
|
||||
|
||||
val dispatchReceiverParameter = this.dispatchReceiverParameter
|
||||
if (dispatchReceiverParameter != null)
|
||||
receivers.add(dispatchReceiverParameter)
|
||||
|
||||
val extensionReceiverParameter = this.extensionReceiverParameter
|
||||
if (extensionReceiverParameter != null)
|
||||
receivers.add(extensionReceiverParameter)
|
||||
|
||||
return receivers + this.valueParameters
|
||||
}
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package org.jetbrains.kotlin.backend.konan
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.allValueParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.Lifetime
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.RuntimeAware
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getArguments
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.konan.llvm.isObjectType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -248,7 +248,7 @@ internal class ElementFinderVisitor(
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
declaration.descriptor.allValueParameters.forEach {
|
||||
declaration.descriptor.allParameters.forEach {
|
||||
if (isInteresting(it))
|
||||
parameterRoles.addParameter(it)
|
||||
}
|
||||
|
||||
-18
@@ -121,24 +121,6 @@ internal fun KonanBuiltIns.getKonanInternalFunctions(name: String): List<Functio
|
||||
|
||||
internal fun KotlinType.isUnboundCallableReference() = this.isRepresentedAs(ValueType.UNBOUND_CALLABLE_REFERENCE)
|
||||
|
||||
internal val CallableDescriptor.allValueParameters: List<ParameterDescriptor>
|
||||
get() {
|
||||
val receivers = mutableListOf<ParameterDescriptor>()
|
||||
|
||||
if (this is ConstructorDescriptor)
|
||||
receivers.add(this.constructedClass.thisAsReceiverParameter)
|
||||
|
||||
val dispatchReceiverParameter = this.dispatchReceiverParameter
|
||||
if (dispatchReceiverParameter != null)
|
||||
receivers.add(dispatchReceiverParameter)
|
||||
|
||||
val extensionReceiverParameter = this.extensionReceiverParameter
|
||||
if (extensionReceiverParameter != null)
|
||||
receivers.add(extensionReceiverParameter)
|
||||
|
||||
return receivers + this.valueParameters
|
||||
}
|
||||
|
||||
internal val KotlinType.isFunctionOrKFunctionType: Boolean
|
||||
get() {
|
||||
val kind = constructor.declarationDescriptor?.getFunctionalClassKind()
|
||||
|
||||
-59
@@ -19,65 +19,6 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import java.io.StringWriter
|
||||
|
||||
|
||||
/**
|
||||
* Binds the arguments explicitly represented in the IR to the parameters of the accessed function.
|
||||
* The arguments are to be evaluated in the same order as they appear in the resulting list.
|
||||
*/
|
||||
internal fun IrMemberAccessExpression.getArguments(): List<Pair<ParameterDescriptor, IrExpression>> {
|
||||
val res = mutableListOf<Pair<ParameterDescriptor, IrExpression>>()
|
||||
val descriptor = descriptor
|
||||
|
||||
// TODO: ensure the order below corresponds to the one defined in Kotlin specs.
|
||||
|
||||
dispatchReceiver?.let {
|
||||
res += (descriptor.dispatchReceiverParameter!! to it)
|
||||
}
|
||||
|
||||
extensionReceiver?.let {
|
||||
res += (descriptor.extensionReceiverParameter!! to it)
|
||||
}
|
||||
|
||||
descriptor.valueParameters.forEach {
|
||||
val arg = getValueArgument(it.index)
|
||||
if (arg != null) {
|
||||
res += (it to arg)
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets arguments that are specified by given mapping of parameters.
|
||||
*/
|
||||
internal fun IrMemberAccessExpression.addArguments(args: Map<ParameterDescriptor, IrExpression>) {
|
||||
descriptor.dispatchReceiverParameter?.let {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.dispatchReceiver = arg
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.extensionReceiverParameter?.let {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.extensionReceiver = arg
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.valueParameters.forEach {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.putValueArgument(it.index, arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun IrMemberAccessExpression.addArguments(args: List<Pair<ParameterDescriptor, IrExpression>>) =
|
||||
this.addArguments(args.toMap())
|
||||
|
||||
internal fun IrExpression.isNullConst() = this is IrConst<*> && this.kind == IrConstKind.Null
|
||||
|
||||
fun ir2string(ir: IrElement?): String = ir2stringWhole(ir).takeWhile { it != '\n' }
|
||||
|
||||
fun ir2stringWhole(ir: IrElement?): String {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import llvm.LLVMTypeRef
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.allValueParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isUnit
|
||||
import org.jetbrains.kotlin.backend.konan.isValueType
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
@@ -143,7 +143,7 @@ private fun getStringValue(annotation: AnnotationDescriptor): String? {
|
||||
internal fun RuntimeAware.getLlvmFunctionType(function: FunctionDescriptor): LLVMTypeRef {
|
||||
val original = function.original
|
||||
val returnType = if (original is ConstructorDescriptor) voidType else getLLVMReturnType(original.returnType!!)
|
||||
val paramTypes = ArrayList(original.allValueParameters.map { getLLVMType(it.type) })
|
||||
val paramTypes = ArrayList(original.allParameters.map { getLLVMType(it.type) })
|
||||
if (isObjectType(returnType)) paramTypes.add(kObjHeaderPtrPtr)
|
||||
|
||||
return functionType(returnType, isVarArg = false, paramTypes = *paramTypes.toTypedArray())
|
||||
|
||||
+5
-4
@@ -2,10 +2,10 @@ package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.IrInlineFunctionBody
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getArguments
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ir2string
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptorBase
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
@@ -475,7 +476,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
*/
|
||||
private fun bindParameters(descriptor: FunctionDescriptor?): Map<ParameterDescriptor, LLVMValueRef> {
|
||||
if (descriptor == null) return emptyMap()
|
||||
val parameterDescriptors = descriptor.allValueParameters
|
||||
val parameterDescriptors = descriptor.allParameters
|
||||
return parameterDescriptors.mapIndexed { i, parameterDescriptor ->
|
||||
val parameter = codegen.param(descriptor, i)
|
||||
assert(codegen.getLLVMType(parameterDescriptor.type) == parameter.type)
|
||||
@@ -1553,7 +1554,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
param to evaluateExpression(argExpr)
|
||||
}.toMap()
|
||||
|
||||
val allValueParameters = expression.descriptor.allValueParameters
|
||||
val allValueParameters = expression.descriptor.allParameters
|
||||
|
||||
return allValueParameters.dropWhile { it !in evaluatedArgs }.map {
|
||||
evaluatedArgs[it]!!
|
||||
@@ -1845,7 +1846,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
val constructedClass = codegen.constructedClass!!
|
||||
val thisPtr = currentCodeContext.genGetValue(constructedClass.thisAsReceiverParameter)
|
||||
|
||||
val thisPtrArgType = codegen.getLLVMType(descriptor.allValueParameters[0].type)
|
||||
val thisPtrArgType = codegen.getLLVMType(descriptor.allParameters[0].type)
|
||||
val thisPtrArg = if (thisPtr.type == thisPtrArgType) {
|
||||
thisPtr
|
||||
} else {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package org.jetbrains.kotlin.backend.konan.llvm
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.allValueParameters
|
||||
import org.jetbrains.kotlin.backend.common.descriptors.allParameters
|
||||
import org.jetbrains.kotlin.backend.konan.KonanPlatform
|
||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
|
||||
+1
-1
@@ -5,7 +5,6 @@ import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.ValueType
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isNullConst
|
||||
import org.jetbrains.kotlin.backend.konan.notNullableIsRepresentedAs
|
||||
import org.jetbrains.kotlin.backend.konan.isRepresentedAs
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
@@ -14,6 +13,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
||||
import org.jetbrains.kotlin.ir.util.isNullConst
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
+1
-1
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.backend.konan.lower
|
||||
import org.jetbrains.kotlin.backend.common.BodyLoweringPass
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalFunctions
|
||||
import org.jetbrains.kotlin.backend.konan.ir.isNullConst
|
||||
import org.jetbrains.kotlin.backend.konan.util.atMostOne
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltinOperatorDescriptor
|
||||
@@ -11,6 +10,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBinaryPrimitiveImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl
|
||||
import org.jetbrains.kotlin.ir.util.isNullConst
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.types.typeUtil.isNothing
|
||||
|
||||
+2
-2
@@ -5,8 +5,6 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.getKonanInternalClass
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isFunctionOrKFunctionType
|
||||
import org.jetbrains.kotlin.backend.konan.ir.addArguments
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getArguments
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
@@ -21,6 +19,8 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
||||
import org.jetbrains.kotlin.ir.util.addArguments
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.util.transformFlat
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
|
||||
+1
-1
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.backend.konan.lower
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.isFunctionInvoke
|
||||
import org.jetbrains.kotlin.backend.konan.ir.IrInlineFunctionBody
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getArguments
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
@@ -17,6 +16,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrMemberAccessExpressionBase
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrTypeOperatorCallImpl
|
||||
import org.jetbrains.kotlin.ir.util.DeepCopyIrTree
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,6 @@ import org.jetbrains.kotlin.backend.common.lower.IrBuildingTransformer
|
||||
import org.jetbrains.kotlin.backend.common.lower.at
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.ValueType
|
||||
import org.jetbrains.kotlin.backend.konan.ir.getArguments
|
||||
import org.jetbrains.kotlin.backend.konan.isRepresentedAs
|
||||
import org.jetbrains.kotlin.backend.konan.reportCompilationError
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
@@ -19,6 +18,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
||||
import org.jetbrains.kotlin.ir.util.getArguments
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import org.jetbrains.kotlin.backend.common.FileLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.descriptors.signature2Descriptor
|
||||
import org.jetbrains.kotlin.backend.konan.ir.irLetSequence
|
||||
import org.jetbrains.kotlin.ir.builders.irLetSequence
|
||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
package org.jetbrains.kotlin.ir.builders
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
@@ -14,7 +13,7 @@ inline fun IrBuilderWithScope.irLetSequence(
|
||||
origin: IrStatementOrigin? = null,
|
||||
resultType: KotlinType? = null,
|
||||
body: IrBlockBuilder.(VariableDescriptor) -> Unit
|
||||
): IrExpression = irBlock(startOffset, endOffset, origin, resultType) {
|
||||
): IrExpression = irBlock(startOffset, endOffset, origin, resultType) {
|
||||
val irTemporary = defineTemporary(value, nameHint)
|
||||
this.body(irTemporary)
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
|
||||
/**
|
||||
* Binds the arguments explicitly represented in the IR to the parameters of the accessed function.
|
||||
* The arguments are to be evaluated in the same order as they appear in the resulting list.
|
||||
*/
|
||||
internal fun IrMemberAccessExpression.getArguments(): List<Pair<ParameterDescriptor, IrExpression>> {
|
||||
val res = mutableListOf<Pair<ParameterDescriptor, IrExpression>>()
|
||||
val descriptor = descriptor
|
||||
|
||||
// TODO: ensure the order below corresponds to the one defined in Kotlin specs.
|
||||
|
||||
dispatchReceiver?.let {
|
||||
res += (descriptor.dispatchReceiverParameter!! to it)
|
||||
}
|
||||
|
||||
extensionReceiver?.let {
|
||||
res += (descriptor.extensionReceiverParameter!! to it)
|
||||
}
|
||||
|
||||
descriptor.valueParameters.forEach {
|
||||
val arg = getValueArgument(it.index)
|
||||
if (arg != null) {
|
||||
res += (it to arg)
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets arguments that are specified by given mapping of parameters.
|
||||
*/
|
||||
internal fun IrMemberAccessExpression.addArguments(args: Map<ParameterDescriptor, IrExpression>) {
|
||||
descriptor.dispatchReceiverParameter?.let {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.dispatchReceiver = arg
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.extensionReceiverParameter?.let {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.extensionReceiver = arg
|
||||
}
|
||||
}
|
||||
|
||||
descriptor.valueParameters.forEach {
|
||||
val arg = args[it]
|
||||
if (arg != null) {
|
||||
this.putValueArgument(it.index, arg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun IrMemberAccessExpression.addArguments(args: List<Pair<ParameterDescriptor, IrExpression>>) =
|
||||
this.addArguments(args.toMap())
|
||||
|
||||
internal fun IrExpression.isNullConst() = this is IrConst<*> && this.kind == IrConstKind.Null
|
||||
Reference in New Issue
Block a user