psi2ir: generate IrConstructorCall elements in IR builder helpers
This commit is contained in:
+1
-1
@@ -275,7 +275,7 @@ class DataClassMembersGenerator(
|
||||
private fun MemberFunctionBuilder.getHashCodeOf(kotlinType: KotlinType, irValue: IrExpression): IrExpression {
|
||||
val hashCodeFunctionDescriptor = getHashCodeFunction(kotlinType)
|
||||
val hashCodeFunctionSymbol = declarationGenerator.context.symbolTable.referenceFunction(hashCodeFunctionDescriptor.original)
|
||||
return irCall(hashCodeFunctionSymbol, hashCodeFunctionDescriptor, context.irBuiltIns.intType).apply {
|
||||
return irCall(hashCodeFunctionSymbol, context.irBuiltIns.intType).apply {
|
||||
if (descriptor.dispatchReceiverParameter != null) {
|
||||
dispatchReceiver = irValue
|
||||
} else {
|
||||
|
||||
+3
-4
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.psi2ir.generators
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtObjectLiteralExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
@@ -36,7 +36,7 @@ class LocalClassGenerator(statementGenerator: StatementGenerator) : StatementGen
|
||||
irBlock.statements.add(irClass)
|
||||
|
||||
val objectConstructor = irClass.descriptor.unsubstitutedPrimaryConstructor
|
||||
?: throw AssertionError("Object literal should have a primary constructor: ${irClass.descriptor}")
|
||||
?: throw AssertionError("Object literal should have a primary constructor: ${irClass.descriptor}")
|
||||
assert(objectConstructor.dispatchReceiverParameter == null) {
|
||||
"Object literal constructor should have no dispatch receiver parameter: $objectConstructor"
|
||||
}
|
||||
@@ -48,10 +48,9 @@ class LocalClassGenerator(statementGenerator: StatementGenerator) : StatementGen
|
||||
}
|
||||
|
||||
irBlock.statements.add(
|
||||
IrCallImpl(
|
||||
IrConstructorCallImpl.fromSymbolDescriptor(
|
||||
startOffset, endOffset, objectLiteralType,
|
||||
context.symbolTable.referenceConstructor(objectConstructor),
|
||||
objectConstructor,
|
||||
IrStatementOrigin.OBJECT_LITERAL
|
||||
)
|
||||
)
|
||||
|
||||
@@ -203,7 +203,8 @@ fun IrBuilderWithScope.irGet(type: IrType, receiver: IrExpression?, getterSymbol
|
||||
IrGetterCallImpl(
|
||||
startOffset, endOffset,
|
||||
type,
|
||||
getterSymbol, getterSymbol.descriptor,
|
||||
getterSymbol as IrSimpleFunctionSymbol,
|
||||
getterSymbol.descriptor,
|
||||
typeArgumentsCount = 0,
|
||||
dispatchReceiver = receiver,
|
||||
extensionReceiver = null,
|
||||
@@ -214,7 +215,8 @@ fun IrBuilderWithScope.irSet(type: IrType, receiver: IrExpression?, getterSymbol
|
||||
IrSetterCallImpl(
|
||||
startOffset, endOffset,
|
||||
type,
|
||||
getterSymbol, getterSymbol.descriptor,
|
||||
getterSymbol as IrSimpleFunctionSymbol,
|
||||
getterSymbol.descriptor,
|
||||
typeArgumentsCount = 0,
|
||||
dispatchReceiver = receiver,
|
||||
extensionReceiver = null,
|
||||
@@ -222,42 +224,72 @@ fun IrBuilderWithScope.irSet(type: IrType, receiver: IrExpression?, getterSymbol
|
||||
origin = IrStatementOrigin.EQ
|
||||
)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, type: IrType, typeArguments: List<IrType> = emptyList()): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, type, callee, callee.descriptor).apply {
|
||||
fun IrBuilderWithScope.irCall(
|
||||
callee: IrFunctionSymbol,
|
||||
type: IrType,
|
||||
typeArguments: List<IrType>
|
||||
): IrMemberAccessExpression =
|
||||
irCall(callee, type).apply {
|
||||
typeArguments.forEachIndexed { index, irType ->
|
||||
this.putTypeArgument(index, irType)
|
||||
}
|
||||
}
|
||||
|
||||
fun IrBuilderWithScope.irCallConstructor(callee: IrConstructorSymbol, typeArguments: List<IrType>): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, callee.owner.returnType, callee, callee.descriptor, typeArguments.size, callee.owner.valueParameters.size).apply {
|
||||
typeArguments.forEachIndexed { index, irType ->
|
||||
this.putTypeArgument(index, irType)
|
||||
}
|
||||
TODO("IrConstructorCall")
|
||||
// IrCallImpl(startOffset, endOffset, callee.owner.returnType, callee, callee.descriptor, typeArguments.size, callee.owner.valueParameters.size).apply {
|
||||
// typeArguments.forEachIndexed { index, irType ->
|
||||
// this.putTypeArgument(index, irType)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrSimpleFunctionSymbol, type: IrType): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, type, callee, callee.descriptor)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrConstructorSymbol, type: IrType): IrConstructorCall =
|
||||
IrConstructorCallImpl.fromSymbolDescriptor(startOffset, endOffset, type, callee)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, type: IrType): IrMemberAccessExpression =
|
||||
when (callee) {
|
||||
is IrConstructorSymbol -> irCall(callee, type)
|
||||
is IrSimpleFunctionSymbol -> irCall(callee, type)
|
||||
else -> throw AssertionError("Unexpected callee: $callee")
|
||||
}
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, callee.owner.returnType, callee, callee.descriptor)
|
||||
fun IrBuilderWithScope.irCall(callee: IrSimpleFunctionSymbol): IrCall =
|
||||
irCall(callee, callee.owner.returnType)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrConstructorSymbol): IrConstructorCall =
|
||||
irCall(callee, callee.owner.returnType)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol): IrMemberAccessExpression =
|
||||
irCall(callee, callee.owner.returnType)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, descriptor: FunctionDescriptor, type: IrType): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, type, callee, descriptor)
|
||||
IrCallImpl(startOffset, endOffset, type, callee as IrSimpleFunctionSymbol, descriptor)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunction): IrCall =
|
||||
irCall(callee.symbol, callee.descriptor, callee.returnType)
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunction): IrMemberAccessExpression =
|
||||
irCall(callee.symbol)
|
||||
|
||||
fun IrBuilderWithScope.irCall(callee: IrFunction, origin: IrStatementOrigin): IrCall =
|
||||
IrCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor, origin)
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, callee.returnType,
|
||||
callee.symbol as IrSimpleFunctionSymbol,
|
||||
callee.descriptor, origin
|
||||
)
|
||||
|
||||
fun IrBuilderWithScope.irDelegatingConstructorCall(callee: IrConstructor): IrDelegatingConstructorCall =
|
||||
IrDelegatingConstructorCallImpl(startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor,
|
||||
callee.parentAsClass.typeParameters.size, callee.valueParameters.size)
|
||||
IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset, callee.returnType, callee.symbol, callee.descriptor,
|
||||
callee.parentAsClass.typeParameters.size, callee.valueParameters.size
|
||||
)
|
||||
|
||||
fun IrBuilderWithScope.irCallOp(
|
||||
callee: IrFunctionSymbol,
|
||||
type: IrType,
|
||||
dispatchReceiver: IrExpression,
|
||||
argument: IrExpression? = null
|
||||
): IrCall =
|
||||
): IrMemberAccessExpression =
|
||||
irCall(callee, type).apply {
|
||||
this.dispatchReceiver = dispatchReceiver
|
||||
if (argument != null)
|
||||
|
||||
Reference in New Issue
Block a user