IR: remove convenience factory for IrTypeAliasImpl

This commit is contained in:
Alexander Udalov
2020-07-06 22:35:46 +02:00
parent fd83596c91
commit 19ec8646b8
3 changed files with 18 additions and 42 deletions
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.psi2ir.generators package org.jetbrains.kotlin.psi2ir.generators
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
@@ -79,20 +82,17 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
fun generateClassOrObjectDeclaration(ktClassOrObject: KtPureClassOrObject): IrClass = fun generateClassOrObjectDeclaration(ktClassOrObject: KtPureClassOrObject): IrClass =
ClassGenerator(this).generateClass(ktClassOrObject) ClassGenerator(this).generateClass(ktClassOrObject)
private fun generateTypeAliasDeclaration(ktTypeAlias: KtTypeAlias): IrTypeAlias { private fun generateTypeAliasDeclaration(ktTypeAlias: KtTypeAlias): IrTypeAlias =
val typeAliasDescriptor = getOrFail(BindingContext.TYPE_ALIAS, ktTypeAlias) with(getOrFail(BindingContext.TYPE_ALIAS, ktTypeAlias)) {
val irTypeAlias = context.symbolTable.declareTypeAlias(typeAliasDescriptor) { symbol -> context.symbolTable.declareTypeAlias(this) { symbol ->
IrTypeAliasImpl.fromSymbolDescriptor( IrTypeAliasImpl(
ktTypeAlias.startOffsetSkippingComments, ktTypeAlias.endOffset, ktTypeAlias.startOffsetSkippingComments, ktTypeAlias.endOffset, symbol,
symbol, name, visibility, expandedType.toIrType(), isActual, IrDeclarationOrigin.DEFINED
typeAliasDescriptor.expandedType.toIrType(), )
IrDeclarationOrigin.DEFINED, }.also {
typeAliasDescriptor generateGlobalTypeParametersDeclarations(it, declaredTypeParameters)
) }
} }
generateGlobalTypeParametersDeclarations(irTypeAlias, typeAliasDescriptor.declaredTypeParameters)
return irTypeAlias
}
fun generateGlobalTypeParametersDeclarations( fun generateGlobalTypeParametersDeclarations(
irTypeParametersOwner: IrTypeParametersContainer, irTypeParametersOwner: IrTypeParametersContainer,
@@ -110,14 +110,10 @@ class StandaloneDeclarationGenerator(private val context: GeneratorContext) {
origin: IrDeclarationOrigin, origin: IrDeclarationOrigin,
descriptor: TypeAliasDescriptor, descriptor: TypeAliasDescriptor,
symbol: IrTypeAliasSymbol symbol: IrTypeAliasSymbol
): IrTypeAlias { ): IrTypeAlias = with(descriptor) {
val irAlias = IrTypeAliasImpl.fromSymbolDescriptor( IrTypeAliasImpl(startOffset, endOffset, symbol, name, visibility, expandedType.toIrType(), isActual, origin).also {
startOffset, endOffset, symbol, descriptor.expandedType.toIrType(), origin, descriptor generateGlobalTypeParametersDeclarations(it, declaredTypeParameters)
) }
generateGlobalTypeParametersDeclarations(irAlias, descriptor.declaredTypeParameters)
return irAlias
} }
protected fun declareParameter(descriptor: ParameterDescriptor, ktElement: KtPureElement?, irOwnerElement: IrElement): IrValueParameter { protected fun declareParameter(descriptor: ParameterDescriptor, ktElement: KtPureElement?, irOwnerElement: IrElement): IrValueParameter {
@@ -61,24 +61,4 @@ class IrTypeAliasImpl(
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) { override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
typeParameters = typeParameters.transformIfNeeded(transformer, data) typeParameters = typeParameters.transformIfNeeded(transformer, data)
} }
companion object {
fun fromSymbolDescriptor(
startOffset: Int,
endOffset: Int,
symbol: IrTypeAliasSymbol,
expandedType: IrType,
origin: IrDeclarationOrigin,
descriptor: TypeAliasDescriptor
) =
IrTypeAliasImpl(
startOffset, endOffset,
symbol,
descriptor.name,
descriptor.visibility,
expandedType,
descriptor.isActual,
origin
)
}
} }