[IR] Move IrFactory#createExpressionBody overloads to extension methods
This is to prepare for IrFactory auto-generation (KT-59308).
This commit is contained in:
committed by
Space Team
parent
ea8b482f4f
commit
3f6420c5b9
@@ -210,16 +210,6 @@ interface IrFactory {
|
||||
fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
initializer: IrExpressionBody.() -> Unit,
|
||||
): IrExpressionBody
|
||||
|
||||
fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
expression: IrExpression,
|
||||
): IrExpressionBody
|
||||
|
||||
fun createExpressionBody(
|
||||
expression: IrExpression,
|
||||
): IrExpressionBody
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
|
||||
fun IrFactory.createExpressionBody(expression: IrExpression): IrExpressionBody =
|
||||
createExpressionBody(expression.startOffset, expression.endOffset, expression)
|
||||
@@ -251,13 +251,6 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
||||
isCrossinline, isNoinline, isHidden, isAssignable, factory = this
|
||||
)
|
||||
|
||||
override fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
initializer: IrExpressionBody.() -> Unit,
|
||||
): IrExpressionBody =
|
||||
IrExpressionBodyImpl(startOffset, endOffset, initializer)
|
||||
|
||||
override fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -265,11 +258,6 @@ abstract class AbstractIrFactoryImpl : IrFactory {
|
||||
): IrExpressionBody =
|
||||
IrExpressionBodyImpl(startOffset, endOffset, expression)
|
||||
|
||||
override fun createExpressionBody(
|
||||
expression: IrExpression,
|
||||
): IrExpressionBody =
|
||||
IrExpressionBodyImpl(expression)
|
||||
|
||||
override fun createBlockBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
|
||||
@@ -9,10 +9,7 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
import org.jetbrains.kotlin.ir.declarations.MetadataSource
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
|
||||
+1
-10
@@ -24,20 +24,11 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
class IrExpressionBodyImpl(
|
||||
override val startOffset: Int,
|
||||
override val endOffset: Int,
|
||||
initializer: (IrExpressionBody.() -> Unit)? = null
|
||||
override var expression: IrExpression,
|
||||
) : IrExpressionBody() {
|
||||
init {
|
||||
initializer?.invoke(this)
|
||||
}
|
||||
|
||||
constructor(startOffset: Int, endOffset: Int, expression: IrExpression) : this(startOffset, endOffset) {
|
||||
this.expression = expression
|
||||
}
|
||||
|
||||
constructor(expression: IrExpression) : this(expression.startOffset, expression.endOffset, expression)
|
||||
|
||||
override lateinit var expression: IrExpression
|
||||
|
||||
override val factory: IrFactory
|
||||
get() = IrFactoryImpl
|
||||
}
|
||||
|
||||
@@ -790,10 +790,12 @@ fun IrValueParameter.copyTo(
|
||||
): IrValueParameter {
|
||||
val symbol = IrValueParameterSymbolImpl()
|
||||
val defaultValueCopy = defaultValue?.let { originalDefault ->
|
||||
factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) {
|
||||
expression = originalDefault.expression.deepCopyWithVariables().also {
|
||||
it.patchDeclarationParents(irFunction)
|
||||
}
|
||||
factory.createExpressionBody(
|
||||
startOffset = originalDefault.startOffset,
|
||||
endOffset = originalDefault.endOffset,
|
||||
expression = originalDefault.expression.deepCopyWithVariables(),
|
||||
).apply {
|
||||
expression.patchDeclarationParents(irFunction)
|
||||
}
|
||||
}
|
||||
return factory.createValueParameter(
|
||||
|
||||
Reference in New Issue
Block a user