FIR2IR: extract 'declareThisReceiverParameter', rename 'setThisReceiver'
This commit is contained in:
+36
-42
@@ -108,13 +108,15 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrClass.declareThisReceiver() {
|
private fun IrDeclaration.declareThisReceiverParameter(
|
||||||
enterScope(descriptor)
|
parent: IrDeclarationParent,
|
||||||
val thisOrigin = IrDeclarationOrigin.INSTANCE_RECEIVER
|
thisType: IrType,
|
||||||
val thisType = IrSimpleTypeImpl(symbol, false, emptyList(), emptyList())
|
thisOrigin: IrDeclarationOrigin,
|
||||||
val parent = this
|
startOffset: Int = this.startOffset,
|
||||||
|
endOffset: Int = this.endOffset
|
||||||
|
): IrValueParameter {
|
||||||
val receiverDescriptor = WrappedReceiverParameterDescriptor()
|
val receiverDescriptor = WrappedReceiverParameterDescriptor()
|
||||||
thisReceiver = irSymbolTable.declareValueParameter(
|
return irSymbolTable.declareValueParameter(
|
||||||
startOffset, endOffset, thisOrigin, receiverDescriptor, thisType
|
startOffset, endOffset, thisOrigin, receiverDescriptor, thisType
|
||||||
) { symbol ->
|
) { symbol ->
|
||||||
IrValueParameterImpl(
|
IrValueParameterImpl(
|
||||||
@@ -126,6 +128,15 @@ class Fir2IrDeclarationStorage(
|
|||||||
receiverDescriptor.bind(this)
|
receiverDescriptor.bind(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun IrClass.setThisReceiver() {
|
||||||
|
enterScope(descriptor)
|
||||||
|
thisReceiver = declareThisReceiverParameter(
|
||||||
|
parent = this,
|
||||||
|
thisType = IrSimpleTypeImpl(symbol, false, emptyList(), emptyList()),
|
||||||
|
thisOrigin = IrDeclarationOrigin.INSTANCE_RECEIVER
|
||||||
|
)
|
||||||
leaveScope(descriptor)
|
leaveScope(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,7 +195,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
parent = getIrExternalPackageFragment(packageFqName)
|
parent = getIrExternalPackageFragment(packageFqName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declareThisReceiver()
|
setThisReceiver()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +229,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
isExternal = false, isInline = false, isExpect = false, isFun = false
|
isExternal = false, isInline = false, isExpect = false, isFun = false
|
||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
declareThisReceiver()
|
setThisReceiver()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.declareSupertypesAndTypeParameters(anonymousObject)
|
}.declareSupertypesAndTypeParameters(anonymousObject)
|
||||||
@@ -238,7 +249,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
isExternal = false, isInline = false, isExpect = false, isFun = false
|
isExternal = false, isInline = false, isExpect = false, isFun = false
|
||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
declareThisReceiver()
|
setThisReceiver()
|
||||||
if (irParent != null) {
|
if (irParent != null) {
|
||||||
this.parent = irParent
|
this.parent = irParent
|
||||||
}
|
}
|
||||||
@@ -345,39 +356,21 @@ class Fir2IrDeclarationStorage(
|
|||||||
val receiverTypeRef = function?.receiverTypeRef
|
val receiverTypeRef = function?.receiverTypeRef
|
||||||
if (receiverTypeRef != null) {
|
if (receiverTypeRef != null) {
|
||||||
extensionReceiverParameter = receiverTypeRef.convertWithOffsets { startOffset, endOffset ->
|
extensionReceiverParameter = receiverTypeRef.convertWithOffsets { startOffset, endOffset ->
|
||||||
val type = receiverTypeRef.toIrType(session, this@Fir2IrDeclarationStorage)
|
declareThisReceiverParameter(
|
||||||
val receiverDescriptor = WrappedReceiverParameterDescriptor()
|
parent,
|
||||||
irSymbolTable.declareValueParameter(
|
thisType = receiverTypeRef.toIrType(session, this@Fir2IrDeclarationStorage),
|
||||||
startOffset, endOffset, thisOrigin,
|
thisOrigin = thisOrigin,
|
||||||
receiverDescriptor, type
|
startOffset = startOffset,
|
||||||
) { symbol ->
|
endOffset = endOffset
|
||||||
IrValueParameterImpl(
|
)
|
||||||
startOffset, endOffset, thisOrigin, symbol,
|
|
||||||
Name.special("<this>"), -1, type,
|
|
||||||
varargElementType = null, isCrossinline = false, isNoinline = false
|
|
||||||
).apply {
|
|
||||||
this.parent = parent
|
|
||||||
receiverDescriptor.bind(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (containingClass != null && !isStatic) {
|
if (containingClass != null && !isStatic) {
|
||||||
val thisType = containingClass.thisReceiver!!.type
|
dispatchReceiverParameter = declareThisReceiverParameter(
|
||||||
val descriptor = WrappedReceiverParameterDescriptor()
|
parent,
|
||||||
dispatchReceiverParameter = irSymbolTable.declareValueParameter(
|
thisType = containingClass.thisReceiver!!.type,
|
||||||
startOffset, endOffset, thisOrigin, descriptor,
|
thisOrigin = thisOrigin
|
||||||
thisType
|
)
|
||||||
) { symbol ->
|
|
||||||
IrValueParameterImpl(
|
|
||||||
startOffset, endOffset, thisOrigin, symbol,
|
|
||||||
Name.special("<this>"), -1, thisType,
|
|
||||||
varargElementType = null, isCrossinline = false, isNoinline = false
|
|
||||||
).apply {
|
|
||||||
this.parent = parent
|
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -582,8 +575,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
|
|
||||||
this.correspondingClass = klass
|
this.correspondingClass = klass
|
||||||
} else if (irParent != null) {
|
} else if (irParent != null) {
|
||||||
this.initializerExpression =
|
this.initializerExpression = IrExpressionBodyImpl(
|
||||||
IrExpressionBodyImpl(IrEnumConstructorCallImpl(startOffset, endOffset, irType, irParent.constructors.first().symbol))
|
IrEnumConstructorCallImpl(startOffset, endOffset, irType, irParent.constructors.first().symbol)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -771,7 +765,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
is FirSimpleFunction -> {
|
is FirSimpleFunction -> {
|
||||||
val irDeclaration = getIrFunction(firDeclaration, irParent, shouldLeaveScope = true).apply {
|
val irDeclaration = getIrFunction(firDeclaration, irParent, shouldLeaveScope = true).apply {
|
||||||
setAndModifyParent(irParent)
|
setAndModifyParent(irParent)
|
||||||
} as IrSimpleFunction
|
}
|
||||||
if (firFunctionSymbol.callableId.isKFunctionInvoke()) {
|
if (firFunctionSymbol.callableId.isKFunctionInvoke()) {
|
||||||
(firFunctionSymbol.overriddenSymbol as? FirNamedFunctionSymbol)?.let {
|
(firFunctionSymbol.overriddenSymbol as? FirNamedFunctionSymbol)?.let {
|
||||||
irDeclaration.overriddenSymbols += (it.toFunctionSymbol(this) as IrSimpleFunctionSymbol)
|
irDeclaration.overriddenSymbols += (it.toFunctionSymbol(this) as IrSimpleFunctionSymbol)
|
||||||
|
|||||||
Reference in New Issue
Block a user