Support for default arguments
This commit is contained in:
committed by
KonstantinAnisimov
parent
bb91ebbfd9
commit
d45f3fe678
+18
-21
@@ -98,7 +98,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------//
|
//-------------------------------------------------------------------------//
|
||||||
|
|
||||||
fun getArguments(irCall: IrCall): MutableMap<ValueDescriptor, IrExpression> {
|
fun getArguments(irCall: IrCall, declaration: IrFunction): MutableMap<ValueDescriptor, IrExpression> {
|
||||||
val result = mutableMapOf<ValueDescriptor, IrExpression>()
|
val result = mutableMapOf<ValueDescriptor, IrExpression>()
|
||||||
val descriptor = irCall.descriptor.original
|
val descriptor = irCall.descriptor.original
|
||||||
|
|
||||||
@@ -110,10 +110,13 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
|
|||||||
result += (descriptor.extensionReceiverParameter!! to it)
|
result += (descriptor.extensionReceiverParameter!! to it)
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.valueParameters.forEach {
|
descriptor.valueParameters.forEach { parameter ->
|
||||||
val arg = irCall.getValueArgument(it.index)
|
val argument = irCall.getValueArgument(parameter.index)
|
||||||
if (arg != null) {
|
if (argument != null) {
|
||||||
result += (it to arg)
|
result += (parameter to argument)
|
||||||
|
} else {
|
||||||
|
val defaultArgument = declaration.getDefault(parameter)!!.expression
|
||||||
|
result += (parameter to defaultArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +170,7 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
|
|||||||
val inlineBody = IrInlineFunctionBody(startOffset, endOffset, returnType, null, statements)
|
val inlineBody = IrInlineFunctionBody(startOffset, endOffset, returnType, null, statements)
|
||||||
|
|
||||||
val evaluationStatements = mutableListOf<IrStatement>()
|
val evaluationStatements = mutableListOf<IrStatement>()
|
||||||
val parametersOld = getArguments(irCall) // Create map call_site_argument -> inline_function_parameter.
|
val parametersOld = getArguments(irCall, copyFuncDeclaration) // Create map call_site_argument -> inline_function_parameter.
|
||||||
val parameterToArgument = evaluateParameters(parametersOld, evaluationStatements)
|
val parameterToArgument = evaluateParameters(parametersOld, evaluationStatements)
|
||||||
val lambdaInliner = LambdaInliner(parameterToArgument)
|
val lambdaInliner = LambdaInliner(parameterToArgument)
|
||||||
inlineBody.transformChildrenVoid(lambdaInliner)
|
inlineBody.transformChildrenVoid(lambdaInliner)
|
||||||
@@ -433,21 +436,15 @@ internal class FunctionInlining(val context: Context): IrElementTransformerVoid(
|
|||||||
class InlineCopyIr() : DeepCopyIrTree() {
|
class InlineCopyIr() : DeepCopyIrTree() {
|
||||||
|
|
||||||
override fun visitBlock(expression: IrBlock): IrBlock {
|
override fun visitBlock(expression: IrBlock): IrBlock {
|
||||||
return when(expression) {
|
return if(expression is IrInlineFunctionBody) {
|
||||||
is IrInlineFunctionBody ->
|
IrInlineFunctionBody(
|
||||||
IrInlineFunctionBody(
|
expression.startOffset, expression.endOffset,
|
||||||
expression.startOffset, expression.endOffset,
|
expression.type,
|
||||||
expression.type,
|
mapStatementOrigin(expression.origin),
|
||||||
mapStatementOrigin(expression.origin),
|
expression.statements.map { it.transform(this, null) }
|
||||||
expression.statements.map { it.transform(this, null) }
|
)
|
||||||
)
|
} else {
|
||||||
|
super.visitBlock(expression)
|
||||||
else -> IrBlockImpl(
|
|
||||||
expression.startOffset, expression.endOffset,
|
|
||||||
expression.type,
|
|
||||||
mapStatementOrigin(expression.origin),
|
|
||||||
expression.statements.map { it.transform(this, null) }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user