[Native] Move addTopLevelInitializer from IrUtils2
This function is actually used only in `InteropLowering` and it is too specific to be included into utils.
This commit is contained in:
+30
-4
@@ -27,17 +27,16 @@ import org.jetbrains.kotlin.ir.IrStatement
|
|||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrDelegatingConstructorCallImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
|
|
||||||
import org.jetbrains.kotlin.ir.util.toIrConst
|
import org.jetbrains.kotlin.ir.util.toIrConst
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
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.*
|
||||||
@@ -149,6 +148,8 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
|
|||||||
private val eagerTopLevelInitializers = mutableListOf<IrExpression>()
|
private val eagerTopLevelInitializers = mutableListOf<IrExpression>()
|
||||||
private val newTopLevelDeclarations = mutableListOf<IrDeclaration>()
|
private val newTopLevelDeclarations = mutableListOf<IrDeclaration>()
|
||||||
|
|
||||||
|
private var topLevelInitializersCounter = 0
|
||||||
|
|
||||||
override val irFile: IrFile
|
override val irFile: IrFile
|
||||||
get() = currentFile
|
get() = currentFile
|
||||||
|
|
||||||
@@ -168,6 +169,31 @@ private class InteropLoweringPart1(val generationState: NativeGenerationState) :
|
|||||||
newTopLevelDeclarations.clear()
|
newTopLevelDeclarations.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun IrFile.addTopLevelInitializer(expression: IrExpression, context: KonanBackendContext, threadLocal: Boolean, eager: Boolean) {
|
||||||
|
val irField = IrFieldImpl(
|
||||||
|
expression.startOffset, expression.endOffset,
|
||||||
|
IrDeclarationOrigin.DEFINED,
|
||||||
|
IrFieldSymbolImpl(),
|
||||||
|
"topLevelInitializer${topLevelInitializersCounter++}".synthesizedName,
|
||||||
|
expression.type,
|
||||||
|
DescriptorVisibilities.PRIVATE,
|
||||||
|
isFinal = true,
|
||||||
|
isExternal = false,
|
||||||
|
isStatic = true,
|
||||||
|
).apply {
|
||||||
|
expression.setDeclarationsParent(this)
|
||||||
|
|
||||||
|
if (threadLocal)
|
||||||
|
annotations += buildSimpleAnnotation(context.irBuiltIns, startOffset, endOffset, context.ir.symbols.threadLocal.owner)
|
||||||
|
|
||||||
|
if (eager)
|
||||||
|
annotations += buildSimpleAnnotation(context.irBuiltIns, startOffset, endOffset, context.ir.symbols.eagerInitialization.owner)
|
||||||
|
|
||||||
|
initializer = IrExpressionBodyImpl(startOffset, endOffset, expression)
|
||||||
|
}
|
||||||
|
addChild(irField)
|
||||||
|
}
|
||||||
|
|
||||||
private fun IrBuilderWithScope.callAlloc(classPtr: IrExpression): IrExpression =
|
private fun IrBuilderWithScope.callAlloc(classPtr: IrExpression): IrExpression =
|
||||||
irCall(symbols.interopAllocObjCObject).apply {
|
irCall(symbols.interopAllocObjCObject).apply {
|
||||||
putValueArgument(0, classPtr)
|
putValueArgument(0, classPtr)
|
||||||
|
|||||||
+2
-45
@@ -5,59 +5,16 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.util
|
package org.jetbrains.kotlin.ir.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.konan.KonanBackendContext
|
|
||||||
import org.jetbrains.kotlin.backend.konan.descriptors.synthesizedName
|
|
||||||
import org.jetbrains.kotlin.backend.konan.ir.buildSimpleAnnotation
|
|
||||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.IrFileEntry
|
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
|
||||||
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildVariable
|
import org.jetbrains.kotlin.ir.builders.declarations.buildVariable
|
||||||
import org.jetbrains.kotlin.ir.builders.parent
|
import org.jetbrains.kotlin.ir.builders.parent
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstantValue
|
import org.jetbrains.kotlin.ir.expressions.IrConstantValue
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCatchImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrCatchImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.calls.checkers.isRestrictsSuspensionReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|
||||||
|
|
||||||
private var topLevelInitializersCounter = 0
|
|
||||||
|
|
||||||
internal fun IrFile.addTopLevelInitializer(expression: IrExpression, context: KonanBackendContext, threadLocal: Boolean, eager: Boolean) {
|
|
||||||
val irField = IrFieldImpl(
|
|
||||||
expression.startOffset, expression.endOffset,
|
|
||||||
IrDeclarationOrigin.DEFINED,
|
|
||||||
IrFieldSymbolImpl(),
|
|
||||||
"topLevelInitializer${topLevelInitializersCounter++}".synthesizedName,
|
|
||||||
expression.type,
|
|
||||||
DescriptorVisibilities.PRIVATE,
|
|
||||||
isFinal = true,
|
|
||||||
isExternal = false,
|
|
||||||
isStatic = true,
|
|
||||||
).apply {
|
|
||||||
expression.setDeclarationsParent(this)
|
|
||||||
|
|
||||||
if (threadLocal)
|
|
||||||
annotations += buildSimpleAnnotation(context.irBuiltIns, startOffset, endOffset, context.ir.symbols.threadLocal.owner)
|
|
||||||
|
|
||||||
if (eager)
|
|
||||||
annotations += buildSimpleAnnotation(context.irBuiltIns, startOffset, endOffset, context.ir.symbols.eagerInitialization.owner)
|
|
||||||
|
|
||||||
initializer = IrExpressionBodyImpl(startOffset, endOffset, expression)
|
|
||||||
}
|
|
||||||
addChild(irField)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun IrBuilderWithScope.irCatch() =
|
fun IrBuilderWithScope.irCatch() =
|
||||||
IrCatchImpl(
|
IrCatchImpl(
|
||||||
|
|||||||
Reference in New Issue
Block a user