Remove unused IR-related code
This commit is contained in:
committed by
SvyatoslavScherbina
parent
0757bfb927
commit
2678cd7d3c
-9
@@ -25,19 +25,10 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.konan.target.KonanTarget
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal fun KonanSymbols.getTypeConversion(actualType: IrType, expectedType: IrType): IrSimpleFunctionSymbol? =
|
||||
getTypeConversionImpl(actualType.getInlinedClassNative(), expectedType.getInlinedClassNative())
|
||||
|
||||
internal fun KonanSymbols.getTypeConversion(actualType: KotlinType, expectedType: KotlinType): IrSimpleFunctionSymbol? {
|
||||
// TODO: rework all usages and remove this method.
|
||||
val actualInlinedClass = actualType.getInlinedClass()?.let { context.ir.get(it) }
|
||||
val expectedInlinedClass = expectedType.getInlinedClass()?.let { context.ir.get(it) }
|
||||
|
||||
return getTypeConversionImpl(actualInlinedClass, expectedInlinedClass)
|
||||
}
|
||||
|
||||
private fun KonanSymbols.getTypeConversionImpl(
|
||||
actualInlinedClass: IrClass?,
|
||||
expectedInlinedClass: IrClass?
|
||||
|
||||
-4
@@ -43,7 +43,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -271,9 +270,6 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
var serializedLinkData: LinkData? = null
|
||||
var dataFlowGraph: ByteArray? = null
|
||||
|
||||
@Deprecated("")
|
||||
lateinit var psi2IrGeneratorContext: GeneratorContext
|
||||
|
||||
val librariesWithDependencies by lazy {
|
||||
config.librariesWithDependencies(moduleDescriptor)
|
||||
}
|
||||
|
||||
-7
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.backend.konan
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.lower.*
|
||||
import org.jetbrains.kotlin.backend.common.phaser.*
|
||||
import org.jetbrains.kotlin.backend.konan.ir.ModuleIndex
|
||||
import org.jetbrains.kotlin.backend.konan.lower.*
|
||||
import org.jetbrains.kotlin.backend.konan.lower.ExpectDeclarationsRemoving
|
||||
import org.jetbrains.kotlin.backend.konan.lower.FinallyBlocksLowering
|
||||
@@ -118,12 +117,6 @@ internal val validateIrModulePhase = makeKonanModuleOpPhase(
|
||||
description = "Validate generated module"
|
||||
)
|
||||
|
||||
internal val moduleIndexForCodegenPhase = makeKonanModuleOpPhase(
|
||||
{ context, irModule -> context.ir.moduleIndexForCodegen = ModuleIndex(irModule) },
|
||||
name = "ModuleIndexForCodeGen",
|
||||
description = "Generate module index for codegen"
|
||||
)
|
||||
|
||||
/* IrFile phases */
|
||||
|
||||
internal val lateinitPhase = makeKonanFileLoweringPhase(
|
||||
|
||||
-3
@@ -95,8 +95,6 @@ internal val psiToIrPhase = konanUnitPhase(
|
||||
val translator = Psi2IrTranslator(config.configuration.languageVersionSettings,
|
||||
Psi2IrConfiguration(false))
|
||||
val generatorContext = translator.createGeneratorContext(moduleDescriptor, bindingContext, symbolTable)
|
||||
@Suppress("DEPRECATION")
|
||||
psi2IrGeneratorContext = generatorContext
|
||||
|
||||
val forwardDeclarationsModuleDescriptor = moduleDescriptor.allDependencyModules.firstOrNull { it.isForwardDeclarationModule }
|
||||
|
||||
@@ -331,7 +329,6 @@ val toplevelPhase: CompilerPhase<*, Unit, Unit> = namedUnitPhase(
|
||||
allLoweringsPhase then // Lower current module first.
|
||||
dependenciesLowerPhase then // Then lower all libraries in topological order.
|
||||
// With that we guarantee that inline functions are unlowered while being inlined.
|
||||
moduleIndexForCodegenPhase then
|
||||
bitcodePhase then
|
||||
produceOutputPhase then
|
||||
verifyBitcodePhase then
|
||||
|
||||
+1
-81
@@ -19,20 +19,11 @@ import org.jetbrains.kotlin.config.coroutinesPackageFqName
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -46,83 +37,12 @@ import kotlin.properties.Delegates
|
||||
internal class KonanIr(context: Context, irModule: IrModuleFragment): Ir<Context>(context, irModule) {
|
||||
|
||||
val propertiesWithBackingFields = mutableSetOf<PropertyDescriptor>()
|
||||
val classesDelegatedBackingFields = mutableMapOf<ClassDescriptor, MutableList<PropertyDescriptor>>()
|
||||
|
||||
val originalModuleIndex = ModuleIndex(irModule)
|
||||
|
||||
lateinit var moduleIndexForCodegen: ModuleIndex
|
||||
|
||||
override var symbols: KonanSymbols by Delegates.notNull()
|
||||
|
||||
fun get(descriptor: FunctionDescriptor): IrFunction {
|
||||
return moduleIndexForCodegen.functions[descriptor]
|
||||
?: symbols.lazySymbolTable.referenceFunction(descriptor).owner
|
||||
}
|
||||
|
||||
fun get(descriptor: ClassDescriptor): IrClass {
|
||||
return moduleIndexForCodegen.classes[descriptor]
|
||||
?: symbols.lazySymbolTable.referenceClass(descriptor)
|
||||
.also {
|
||||
if (!it.isBound)
|
||||
error(descriptor)
|
||||
}
|
||||
.owner
|
||||
}
|
||||
|
||||
fun getFromCurrentModule(descriptor: ClassDescriptor): IrClass = moduleIndexForCodegen.classes[descriptor]!!
|
||||
|
||||
fun getFromCurrentModule(descriptor: FunctionDescriptor): IrFunction = moduleIndexForCodegen.functions[descriptor]!!
|
||||
|
||||
fun getEnumEntryFromCurrentModule(descriptor: ClassDescriptor): IrEnumEntry =
|
||||
originalModuleIndex.enumEntries[descriptor] ?: error(descriptor)
|
||||
|
||||
fun getEnumEntry(descriptor: ClassDescriptor): IrEnumEntry {
|
||||
assert(descriptor.kind == ClassKind.ENUM_ENTRY)
|
||||
|
||||
return originalModuleIndex.enumEntries[descriptor]
|
||||
?: symbols.lazySymbolTable.referenceEnumEntry(descriptor).owner
|
||||
}
|
||||
|
||||
fun translateErased(type: KotlinType): IrSimpleType = symbols.symbolTable.translateErased(type)
|
||||
|
||||
fun translateBroken(type: KotlinType): IrType {
|
||||
val declarationDescriptor = type.constructor.declarationDescriptor
|
||||
return when (declarationDescriptor) {
|
||||
is ClassDescriptor -> {
|
||||
val classifier = IrClassSymbolImpl(declarationDescriptor)
|
||||
val typeArguments = type.arguments.map {
|
||||
if (it.isStarProjection) {
|
||||
IrStarProjectionImpl
|
||||
} else {
|
||||
makeTypeProjection(translateBroken(it.type), it.projectionKind)
|
||||
}
|
||||
}
|
||||
IrSimpleTypeImpl(
|
||||
classifier,
|
||||
type.isMarkedNullable,
|
||||
typeArguments,
|
||||
emptyList()
|
||||
)
|
||||
}
|
||||
is TypeParameterDescriptor -> IrSimpleTypeImpl(
|
||||
IrTypeParameterSymbolImpl(declarationDescriptor),
|
||||
type.isMarkedNullable,
|
||||
emptyList(),
|
||||
emptyList()
|
||||
)
|
||||
else -> error(declarationDescriptor ?: "null")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class KonanSymbols(context: Context, val symbolTable: SymbolTable, val lazySymbolTable: ReferenceSymbolTable): Symbols<Context>(context, lazySymbolTable) {
|
||||
|
||||
private val isInitializedPropertyDescriptor = builtInsPackage("kotlin")
|
||||
.getContributedVariables(Name.identifier("isInitialized"), NoLookupLocation.FROM_BACKEND).single {
|
||||
it.extensionReceiverParameter.let {
|
||||
it != null && TypeUtils.getClassDescriptor(it.type) == context.reflectionTypes.kProperty0
|
||||
} && !it.isExpect
|
||||
}
|
||||
internal class KonanSymbols(context: Context, private val symbolTable: SymbolTable, lazySymbolTable: ReferenceSymbolTable): Symbols<Context>(context, lazySymbolTable) {
|
||||
|
||||
val entryPoint = findMainEntryPoint(context)?.let { symbolTable.referenceSimpleFunction(it) }
|
||||
|
||||
|
||||
+4
-21
@@ -6,7 +6,6 @@
|
||||
package org.jetbrains.kotlin.backend.konan.ir
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -16,43 +15,29 @@ import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
class ModuleIndex(val module: IrModuleFragment) {
|
||||
|
||||
var currentFile: IrFile? = null
|
||||
/**
|
||||
* Contains all classes declared in [module]
|
||||
*/
|
||||
val classes: Map<ClassDescriptor, IrClass>
|
||||
|
||||
val enumEntries: Map<ClassDescriptor, IrEnumEntry>
|
||||
|
||||
/**
|
||||
* Contains all functions declared in [module]
|
||||
*/
|
||||
val functions = mutableMapOf<FunctionDescriptor, IrFunction>()
|
||||
val functions: Map<FunctionDescriptor, IrFunction>
|
||||
|
||||
init {
|
||||
val map = mutableMapOf<ClassDescriptor, IrClass>()
|
||||
enumEntries = mutableMapOf()
|
||||
classes = mutableMapOf()
|
||||
functions = mutableMapOf()
|
||||
|
||||
module.acceptVoid(object : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitFile(declaration: IrFile) {
|
||||
currentFile = declaration
|
||||
super.visitFile(declaration)
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
super.visitClass(declaration)
|
||||
|
||||
map[declaration.descriptor] = declaration
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(declaration: IrEnumEntry) {
|
||||
super.visitEnumEntry(declaration)
|
||||
|
||||
enumEntries[declaration.descriptor] = declaration
|
||||
classes[declaration.descriptor] = declaration
|
||||
}
|
||||
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
@@ -60,7 +45,5 @@ class ModuleIndex(val module: IrModuleFragment) {
|
||||
functions[declaration.descriptor] = declaration
|
||||
}
|
||||
})
|
||||
|
||||
classes = map
|
||||
}
|
||||
}
|
||||
|
||||
-373
@@ -1,373 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.pop
|
||||
import org.jetbrains.kotlin.backend.common.push
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.backend.konan.ir.typeWithStarProjections
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.toKotlinType
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
|
||||
private fun IrModuleFragment.mergeFrom(other: IrModuleFragment): Unit {
|
||||
assert(this.files.isEmpty())
|
||||
assert(other.files.isEmpty())
|
||||
}
|
||||
|
||||
private class DeclarationSymbolCollector : IrElementVisitorVoid {
|
||||
|
||||
val descriptorToSymbol = mutableMapOf<DeclarationDescriptor, IrSymbol>()
|
||||
|
||||
fun register(symbol: IrSymbol) {
|
||||
descriptorToSymbol[symbol.descriptor] = symbol
|
||||
}
|
||||
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
|
||||
if (element is IrSymbolOwner && element !is IrAnonymousInitializer) {
|
||||
register(element.symbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class IrUnboundSymbolReplacer(
|
||||
val symbolTable: ReferenceSymbolTable,
|
||||
val descriptorToSymbol: Map<DeclarationDescriptor, IrSymbol>,
|
||||
val context: Context
|
||||
) : IrElementTransformerVoid() {
|
||||
|
||||
private val localDescriptorToSymbol = mutableMapOf<DeclarationDescriptor, MutableList<IrSymbol>>()
|
||||
|
||||
private inline fun <R> withLocal(symbol: IrSymbol?, block: () -> R): R {
|
||||
if (symbol == null) return block()
|
||||
|
||||
val locals = localDescriptorToSymbol.getOrPut(symbol.descriptor) { mutableListOf() }
|
||||
locals.add(symbol)
|
||||
return try {
|
||||
block()
|
||||
} finally {
|
||||
locals.removeAt(locals.lastIndex)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified D : DeclarationDescriptor, reified S : IrSymbol> S.replace(
|
||||
referenceSymbol: (ReferenceSymbolTable, D) -> S): S? {
|
||||
|
||||
if (this.isBound) {
|
||||
return null
|
||||
}
|
||||
|
||||
localDescriptorToSymbol[this.descriptor]?.lastOrNull()?.let {
|
||||
return it as S
|
||||
}
|
||||
|
||||
|
||||
descriptorToSymbol[this.descriptor]?.let {
|
||||
return it as S
|
||||
}
|
||||
|
||||
return referenceSymbol(symbolTable, this.descriptor as D)
|
||||
}
|
||||
|
||||
private inline fun <reified D : DeclarationDescriptor, reified S : IrSymbol> S.replaceOrSame(
|
||||
referenceSymbol: (ReferenceSymbolTable, D) -> S): S = this.replace(referenceSymbol) ?: this
|
||||
|
||||
private inline fun <reified S : IrSymbol> S.replaceLocal(): S? {
|
||||
return if (this.isBound) {
|
||||
null
|
||||
} else {
|
||||
(localDescriptorToSymbol[this.descriptor]?.lastOrNull() ?: descriptorToSymbol[this.descriptor]) as S
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||
val symbol = expression.symbol.replaceLocal() ?: return super.visitGetValue(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrGetValueImpl(startOffset, endOffset, expression.type, symbol, origin)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitSetVariable(expression: IrSetVariable): IrExpression {
|
||||
val symbol = expression.symbol.replaceLocal() ?: return super.visitSetVariable(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrSetVariableImpl(startOffset, endOffset, expression.type, symbol, value, origin)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitGetObjectValue(expression: IrGetObjectValue): IrExpression {
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceClass) ?:
|
||||
return super.visitGetObjectValue(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrGetObjectValueImpl(startOffset, endOffset, type, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitGetEnumValue(expression: IrGetEnumValue): IrExpression {
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceEnumEntry) ?:
|
||||
return super.visitGetEnumValue(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrGetEnumValueImpl(startOffset, endOffset, type, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitClassReference(expression: IrClassReference): IrExpression {
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceClassifier)
|
||||
?: return super.visitClassReference(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrClassReferenceImpl(startOffset, endOffset, type, symbol, symbol.typeWithStarProjections)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass): IrStatement {
|
||||
withLocal(declaration.thisReceiver?.symbol) {
|
||||
return super.visitClass(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitGetField(expression: IrGetField): IrExpression {
|
||||
val symbol = expression.symbol.replaceOrSame(ReferenceSymbolTable::referenceField)
|
||||
|
||||
val superQualifierSymbol = expression.superQualifierSymbol?.replaceOrSame(ReferenceSymbolTable::referenceClass)
|
||||
|
||||
if (symbol == expression.symbol && superQualifierSymbol == expression.superQualifierSymbol) {
|
||||
return super.visitGetField(expression)
|
||||
}
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrGetFieldImpl(startOffset, endOffset, symbol, type, receiver, origin, superQualifierSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitSetField(expression: IrSetField): IrExpression {
|
||||
val symbol = expression.symbol.replaceOrSame(ReferenceSymbolTable::referenceField)
|
||||
|
||||
val superQualifierSymbol = expression.superQualifierSymbol?.replaceOrSame(ReferenceSymbolTable::referenceClass)
|
||||
|
||||
if (symbol == expression.symbol && superQualifierSymbol == expression.superQualifierSymbol) {
|
||||
return super.visitSetField(expression)
|
||||
}
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrSetFieldImpl(startOffset, endOffset, symbol, receiver, value, type, origin, superQualifierSymbol)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitCall(expression: IrCall): IrExpression {
|
||||
expression.replaceTypeArguments()
|
||||
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceFunction) ?: expression.symbol
|
||||
|
||||
val superQualifierSymbol = expression.superQualifierSymbol?.replaceOrSame(ReferenceSymbolTable::referenceClass)
|
||||
|
||||
if (symbol == expression.symbol && superQualifierSymbol == expression.superQualifierSymbol) {
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
|
||||
expression.transformChildrenVoid()
|
||||
return with(expression) {
|
||||
IrCallImpl(startOffset, endOffset, type, symbol, descriptor,
|
||||
typeArgumentsCount,
|
||||
origin, superQualifierSymbol).also {
|
||||
|
||||
it.copyArgumentsFrom(this)
|
||||
it.copyTypeArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrMemberAccessExpression.replaceTypeArguments() {
|
||||
repeat(typeArgumentsCount) {
|
||||
putTypeArgument(it, getTypeArgument(it)?.toKotlinType()?.let { context.ir.translateErased(it) })
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrMemberAccessExpressionBase.copyArgumentsFrom(original: IrMemberAccessExpression) {
|
||||
dispatchReceiver = original.dispatchReceiver
|
||||
extensionReceiver = original.extensionReceiver
|
||||
original.descriptor.valueParameters.forEachIndexed { index, _ ->
|
||||
putValueArgument(index, original.getValueArgument(index))
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitEnumConstructorCall(expression: IrEnumConstructorCall): IrExpression {
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceConstructor) ?:
|
||||
return super.visitEnumConstructorCall(expression)
|
||||
|
||||
return with(expression) {
|
||||
IrEnumConstructorCallImpl(startOffset, endOffset, expression.type, symbol, 0).also {
|
||||
it.copyArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrExpression {
|
||||
expression.replaceTypeArguments()
|
||||
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceConstructor) ?:
|
||||
return super.visitDelegatingConstructorCall(expression)
|
||||
|
||||
expression.transformChildrenVoid()
|
||||
return with(expression) {
|
||||
IrDelegatingConstructorCallImpl(startOffset, endOffset, type, symbol, descriptor, typeArgumentsCount).also {
|
||||
it.copyArgumentsFrom(this)
|
||||
it.copyTypeArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitFunctionReference(expression: IrFunctionReference): IrExpression {
|
||||
expression.replaceTypeArguments()
|
||||
|
||||
val symbol = expression.symbol.replace(ReferenceSymbolTable::referenceFunction) ?:
|
||||
return super.visitFunctionReference(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrFunctionReferenceImpl(startOffset, endOffset, type, symbol, descriptor, 0).also {
|
||||
it.copyArgumentsFrom(this)
|
||||
it.copyTypeArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression {
|
||||
expression.replaceTypeArguments()
|
||||
|
||||
val field = expression.field?.replaceOrSame(ReferenceSymbolTable::referenceField)
|
||||
val getter = expression.getter?.replace(ReferenceSymbolTable::referenceSimpleFunction) ?: expression.getter
|
||||
val setter = expression.setter?.replace(ReferenceSymbolTable::referenceSimpleFunction) ?: expression.setter
|
||||
|
||||
if (field == expression.field && getter == expression.getter && setter == expression.setter) {
|
||||
return super.visitPropertyReference(expression)
|
||||
}
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrPropertyReferenceImpl(startOffset, endOffset, type, descriptor, 0,
|
||||
field,
|
||||
getter,
|
||||
setter,
|
||||
origin).also {
|
||||
|
||||
it.copyArgumentsFrom(this)
|
||||
it.copyTypeArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference): IrExpression {
|
||||
val delegate = expression.delegate.replaceOrSame(ReferenceSymbolTable::referenceVariable)
|
||||
val getter = expression.getter.replace(ReferenceSymbolTable::referenceSimpleFunction) ?: expression.getter
|
||||
val setter = expression.setter?.replace(ReferenceSymbolTable::referenceSimpleFunction) ?: expression.setter
|
||||
|
||||
if (delegate == expression.delegate && getter == expression.getter && setter == expression.setter) {
|
||||
return super.visitLocalDelegatedPropertyReference(expression)
|
||||
}
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
return with(expression) {
|
||||
IrLocalDelegatedPropertyReferenceImpl(startOffset, endOffset, type, symbol,
|
||||
delegate, getter, setter, origin).also {
|
||||
|
||||
it.copyArgumentsFrom(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val returnTargetStack = mutableListOf<IrReturnTargetSymbol>()
|
||||
|
||||
override fun visitFunction(declaration: IrFunction): IrStatement {
|
||||
returnTargetStack.push(declaration.symbol)
|
||||
try {
|
||||
if (declaration is IrSimpleFunction) {
|
||||
declaration.overriddenSymbols.forEachIndexed { index, symbol ->
|
||||
val newSymbol = symbol.replace(ReferenceSymbolTable::referenceSimpleFunction)
|
||||
if (newSymbol != null) {
|
||||
declaration.overriddenSymbols[index] = newSymbol
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
withLocal(declaration.dispatchReceiverParameter?.symbol) {
|
||||
withLocal(declaration.extensionReceiverParameter?.symbol) {
|
||||
return super.visitFunction(declaration)
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
returnTargetStack.pop()
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitBlock(expression: IrBlock): IrExpression {
|
||||
if (expression is IrReturnableBlock) {
|
||||
returnTargetStack.push(expression.symbol)
|
||||
try {
|
||||
return super.visitBlock(expression)
|
||||
} finally {
|
||||
returnTargetStack.pop()
|
||||
}
|
||||
} else {
|
||||
return super.visitBlock(expression)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitReturn(expression: IrReturn): IrExpression {
|
||||
if (expression.returnTargetSymbol.isBound) {
|
||||
return super.visitReturn(expression)
|
||||
}
|
||||
|
||||
val returnTargetSymbol = returnTargetStack.last { it.descriptor == expression.returnTarget }
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
return with(expression) {
|
||||
IrReturnImpl(startOffset, endOffset, type, returnTargetSymbol, value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrExpression {
|
||||
val classSymbol = expression.classSymbol.replace(ReferenceSymbolTable::referenceClass) ?:
|
||||
return super.visitInstanceInitializerCall(expression)
|
||||
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
return with(expression) {
|
||||
IrInstanceInitializerCallImpl(startOffset, endOffset, classSymbol, type)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitTypeOperator(expression: IrTypeOperatorCall): IrExpression {
|
||||
expression.transformChildrenVoid(this)
|
||||
|
||||
return with(expression) {
|
||||
val newTypeOperand = context.ir.translateErased(typeOperand.toKotlinType())
|
||||
IrTypeOperatorCallImpl(startOffset, endOffset, type, operator, newTypeOperand).also {
|
||||
it.argument = argument
|
||||
it.typeOperandClassifier = newTypeOperand.classifier
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user