Minor changes in default arguments lowering
Calls to a function with default args can be not only from function bodies, but for example from initializers
This commit is contained in:
+17
-15
@@ -26,18 +26,18 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
|
||||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
|
||||||
import org.jetbrains.kotlin.ir.util.transformDeclarationsFlat
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
// TODO: fix expect/actual default parameters
|
// TODO: fix expect/actual default parameters
|
||||||
|
|
||||||
open class DefaultArgumentStubGenerator constructor(open val context: CommonBackendContext, private val skipInlineMethods: Boolean = true) :
|
open class DefaultArgumentStubGenerator(
|
||||||
DeclarationContainerLoweringPass {
|
open val context: CommonBackendContext,
|
||||||
|
private val skipInlineMethods: Boolean = true
|
||||||
|
) : DeclarationContainerLoweringPass {
|
||||||
|
|
||||||
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
override fun lower(irDeclarationContainer: IrDeclarationContainer) {
|
||||||
irDeclarationContainer.transformDeclarationsFlat { memberDeclaration ->
|
irDeclarationContainer.transformDeclarationsFlat { memberDeclaration ->
|
||||||
if (memberDeclaration is IrFunction)
|
if (memberDeclaration is IrFunction)
|
||||||
@@ -198,13 +198,13 @@ private fun markerParameterDeclaration(function: IrFunction) =
|
|||||||
|
|
||||||
val DEFAULT_DISPATCH_CALL = object : IrStatementOriginImpl("DEFAULT_DISPATCH_CALL") {}
|
val DEFAULT_DISPATCH_CALL = object : IrStatementOriginImpl("DEFAULT_DISPATCH_CALL") {}
|
||||||
|
|
||||||
open class DefaultParameterInjector constructor(
|
open class DefaultParameterInjector(
|
||||||
val context: CommonBackendContext,
|
val context: CommonBackendContext,
|
||||||
private val skipInline: Boolean = true
|
private val skipInline: Boolean = true
|
||||||
) : BodyLoweringPass {
|
) : FileLoweringPass {
|
||||||
override fun lower(irBody: IrBody) {
|
|
||||||
|
|
||||||
irBody.transformChildrenVoid(object : IrElementTransformerVoid() {
|
override fun lower(irFile: IrFile) {
|
||||||
|
irFile.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
|
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
|
||||||
super.visitDelegatingConstructorCall(expression)
|
super.visitDelegatingConstructorCall(expression)
|
||||||
|
|
||||||
@@ -320,10 +320,12 @@ open class DefaultParameterInjector constructor(
|
|||||||
valueParameterDeclaration to (valueArgument ?: defaultValueArgument)
|
valueParameterDeclaration to (valueArgument ?: defaultValueArgument)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val startOffset = expression.startOffset
|
||||||
|
val endOffset = expression.endOffset
|
||||||
maskValues.forEachIndexed { i, maskValue ->
|
maskValues.forEachIndexed { i, maskValue ->
|
||||||
params += maskParameterDeclaration(realFunction, i) to IrConstImpl.int(
|
params += maskParameterDeclaration(realFunction, i) to IrConstImpl.int(
|
||||||
startOffset = irBody.startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = irBody.endOffset,
|
endOffset = endOffset,
|
||||||
type = context.irBuiltIns.intType,
|
type = context.irBuiltIns.intType,
|
||||||
value = maskValue
|
value = maskValue
|
||||||
)
|
)
|
||||||
@@ -331,14 +333,14 @@ open class DefaultParameterInjector constructor(
|
|||||||
if (expression.symbol is IrConstructorSymbol) {
|
if (expression.symbol is IrConstructorSymbol) {
|
||||||
val defaultArgumentMarker = context.ir.symbols.defaultConstructorMarker
|
val defaultArgumentMarker = context.ir.symbols.defaultConstructorMarker
|
||||||
params += markerParameterDeclaration(realFunction) to IrGetObjectValueImpl(
|
params += markerParameterDeclaration(realFunction) to IrGetObjectValueImpl(
|
||||||
startOffset = irBody.startOffset,
|
startOffset = startOffset,
|
||||||
endOffset = irBody.endOffset,
|
endOffset = endOffset,
|
||||||
type = defaultArgumentMarker.owner.defaultType,
|
type = defaultArgumentMarker.owner.defaultType,
|
||||||
symbol = defaultArgumentMarker
|
symbol = defaultArgumentMarker
|
||||||
)
|
)
|
||||||
} else if (context.ir.shouldGenerateHandlerParameterForDefaultBodyFun()) {
|
} else if (context.ir.shouldGenerateHandlerParameterForDefaultBodyFun()) {
|
||||||
params += realFunction.valueParameters.last() to
|
params += realFunction.valueParameters.last() to
|
||||||
IrConstImpl.constNull(irBody.startOffset, irBody.endOffset, context.irBuiltIns.nothingNType)
|
IrConstImpl.constNull(startOffset, endOffset, context.irBuiltIns.nothingNType)
|
||||||
}
|
}
|
||||||
params.forEach {
|
params.forEach {
|
||||||
log { "descriptor::${realFunction.name.asString()}#${it.first.index}: ${it.first.name.asString()}" }
|
log { "descriptor::${realFunction.name.asString()}#${it.first.index}: ${it.first.name.asString()}" }
|
||||||
|
|||||||
Reference in New Issue
Block a user