IR: use buildTypeParameter, minor cleanup
This commit is contained in:
@@ -16,13 +16,11 @@ import org.jetbrains.kotlin.ir.IrElement
|
|||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.builders.Scope
|
import org.jetbrains.kotlin.ir.builders.Scope
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.IrTypeParameterBuilder
|
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.build
|
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildTypeParameter
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.*
|
import org.jetbrains.kotlin.ir.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
@@ -31,7 +29,6 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
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.IrTypeParameterSymbolImpl
|
|
||||||
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.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
@@ -175,18 +172,15 @@ fun IrValueParameter.copyTo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
|
||||||
fun IrTypeParameter.copyToWithoutSuperTypes(
|
fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||||
target: IrTypeParametersContainer,
|
target: IrTypeParametersContainer,
|
||||||
index: Int = this.index,
|
index: Int = this.index,
|
||||||
origin: IrDeclarationOrigin = this.origin
|
origin: IrDeclarationOrigin = this.origin
|
||||||
): IrTypeParameter {
|
): IrTypeParameter = buildTypeParameter(target) {
|
||||||
val descriptor = WrappedTypeParameterDescriptor(symbol.descriptor.annotations, symbol.descriptor.source)
|
updateFrom(this@copyToWithoutSuperTypes)
|
||||||
val symbol = IrTypeParameterSymbolImpl(descriptor)
|
this.name = this@copyToWithoutSuperTypes.name
|
||||||
return IrTypeParameterImpl(startOffset, endOffset, origin, symbol, name, index, isReified, variance).also { copied ->
|
this.origin = origin
|
||||||
descriptor.bind(copied)
|
this.index = index
|
||||||
copied.parent = target
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
@@ -637,15 +631,10 @@ private fun IrSimpleFunction.copyAndRenameConflictingTypeParametersFrom(
|
|||||||
contextType.name.asString()
|
contextType.name.asString()
|
||||||
}
|
}
|
||||||
|
|
||||||
val newTypeParameter = IrTypeParameterBuilder().run {
|
newParameters.add(buildTypeParameter(this) {
|
||||||
updateFrom(contextType)
|
updateFrom(contextType)
|
||||||
name = Name.identifier(newName)
|
name = Name.identifier(newName)
|
||||||
build()
|
})
|
||||||
}.also {
|
|
||||||
it.parent = this
|
|
||||||
}
|
|
||||||
|
|
||||||
newParameters.add(newTypeParameter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typeParameters = typeParameters + newParameters
|
typeParameters = typeParameters + newParameters
|
||||||
|
|||||||
+10
-3
@@ -300,7 +300,8 @@ fun IrSimpleFunction.addExtensionReceiver(type: IrType, origin: IrDeclarationOri
|
|||||||
this.origin = origin
|
this.origin = origin
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrTypeParameterBuilder.build(): IrTypeParameter {
|
@PublishedApi
|
||||||
|
internal fun IrTypeParameterBuilder.buildTypeParameter(parent: IrDeclarationParent): IrTypeParameter {
|
||||||
val wrappedDescriptor = WrappedTypeParameterDescriptor()
|
val wrappedDescriptor = WrappedTypeParameterDescriptor()
|
||||||
return IrTypeParameterImpl(
|
return IrTypeParameterImpl(
|
||||||
startOffset, endOffset, origin,
|
startOffset, endOffset, origin,
|
||||||
@@ -309,18 +310,24 @@ fun IrTypeParameterBuilder.build(): IrTypeParameter {
|
|||||||
).also {
|
).also {
|
||||||
wrappedDescriptor.bind(it)
|
wrappedDescriptor.bind(it)
|
||||||
it.superTypes.addAll(superTypes)
|
it.superTypes.addAll(superTypes)
|
||||||
|
it.parent = parent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun buildTypeParameter(parent: IrDeclarationParent, builder: IrTypeParameterBuilder.() -> Unit): IrTypeParameter =
|
||||||
|
IrTypeParameterBuilder().run {
|
||||||
|
builder()
|
||||||
|
buildTypeParameter(parent)
|
||||||
|
}
|
||||||
|
|
||||||
inline fun IrTypeParametersContainer.addTypeParameter(builder: IrTypeParameterBuilder.() -> Unit): IrTypeParameter =
|
inline fun IrTypeParametersContainer.addTypeParameter(builder: IrTypeParameterBuilder.() -> Unit): IrTypeParameter =
|
||||||
IrTypeParameterBuilder().run {
|
IrTypeParameterBuilder().run {
|
||||||
builder()
|
builder()
|
||||||
if (index == UNDEFINED_PARAMETER_INDEX) {
|
if (index == UNDEFINED_PARAMETER_INDEX) {
|
||||||
index = typeParameters.size
|
index = typeParameters.size
|
||||||
}
|
}
|
||||||
build().also { typeParameter ->
|
buildTypeParameter(this@addTypeParameter).also { typeParameter ->
|
||||||
typeParameters += typeParameter
|
typeParameters += typeParameter
|
||||||
typeParameter.parent = this@addTypeParameter
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,22 +14,18 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrAnonymousInitializerImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrAnonymousInitializerImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.types.Variance
|
|
||||||
|
|
||||||
object JsIrBuilder {
|
object JsIrBuilder {
|
||||||
|
|
||||||
@@ -67,22 +63,6 @@ object JsIrBuilder {
|
|||||||
this.type = type
|
this.type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildTypeParameter(name: Name, index: Int, isReified: Boolean, variance: Variance = Variance.INVARIANT): IrTypeParameter {
|
|
||||||
val descriptor = WrappedTypeParameterDescriptor()
|
|
||||||
return IrTypeParameterImpl(
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
UNDEFINED_OFFSET,
|
|
||||||
SYNTHESIZED_DECLARATION,
|
|
||||||
IrTypeParameterSymbolImpl(descriptor),
|
|
||||||
name,
|
|
||||||
index,
|
|
||||||
isReified,
|
|
||||||
variance
|
|
||||||
).also {
|
|
||||||
descriptor.bind(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun buildFunction(
|
fun buildFunction(
|
||||||
name: String,
|
name: String,
|
||||||
returnType: IrType,
|
returnType: IrType,
|
||||||
|
|||||||
Reference in New Issue
Block a user