[JVM_IR] Override visitInlinedFunctionBlock in ExpressionCodegen
This commit is contained in:
+14
-14
@@ -403,11 +403,6 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This block must be executed after `writeLocalVariablesInTable`
|
|
||||||
if (expression is IrInlinedFunctionBlock) {
|
|
||||||
lineNumberMapper.afterIrInline(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSynthesizedInitBlock) {
|
if (isSynthesizedInitBlock) {
|
||||||
expression.markLineNumber(startOffset = false)
|
expression.markLineNumber(startOffset = false)
|
||||||
mv.nop()
|
mv.nop()
|
||||||
@@ -461,13 +456,15 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateInlinedFunctionBlock(inlinedBlock: IrInlinedFunctionBlock, data: BlockInfo): PromisedValue {
|
override fun visitInlinedFunctionBlock(inlinedBlock: IrInlinedFunctionBlock, data: BlockInfo): PromisedValue {
|
||||||
|
val info = BlockInfo(data)
|
||||||
|
|
||||||
val inlineCall = inlinedBlock.inlineCall
|
val inlineCall = inlinedBlock.inlineCall
|
||||||
val callee = inlinedBlock.inlineDeclaration as? IrFunction
|
val callee = inlinedBlock.inlineDeclaration as? IrFunction
|
||||||
|
|
||||||
// 1. Evaluate NON DEFAULT arguments from inline function call
|
// 1. Evaluate NON DEFAULT arguments from inline function call
|
||||||
inlinedBlock.getNonDefaultAdditionalStatementsFromInlinedBlock().forEach { exp ->
|
inlinedBlock.getNonDefaultAdditionalStatementsFromInlinedBlock().forEach { exp ->
|
||||||
exp.accept(this, data).discard()
|
exp.accept(this, info).discard()
|
||||||
}
|
}
|
||||||
|
|
||||||
lineNumberMapper.beforeIrInline(inlinedBlock)
|
lineNumberMapper.beforeIrInline(inlinedBlock)
|
||||||
@@ -476,7 +473,7 @@ class ExpressionCodegen(
|
|||||||
inlineCall.markLineNumber(startOffset = true)
|
inlineCall.markLineNumber(startOffset = true)
|
||||||
mv.nop()
|
mv.nop()
|
||||||
|
|
||||||
lineNumberMapper.buildSmapFor(inlinedBlock, inlinedBlock.buildOrGetClassSMAP(data), data)
|
lineNumberMapper.buildSmapFor(inlinedBlock, inlinedBlock.buildOrGetClassSMAP(info), info)
|
||||||
|
|
||||||
if (inlineCall.usesDefaultArguments()) {
|
if (inlineCall.usesDefaultArguments()) {
|
||||||
// $default function has first LN pointing to original callee
|
// $default function has first LN pointing to original callee
|
||||||
@@ -486,7 +483,7 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
// 2. Evaluate DEFAULT arguments from inline function call
|
// 2. Evaluate DEFAULT arguments from inline function call
|
||||||
inlinedBlock.getDefaultAdditionalStatementsFromInlinedBlock().forEach { exp ->
|
inlinedBlock.getDefaultAdditionalStatementsFromInlinedBlock().forEach { exp ->
|
||||||
exp.accept(this, data).discard()
|
exp.accept(this, info).discard()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inlineCall.usesDefaultArguments()) {
|
if (inlineCall.usesDefaultArguments()) {
|
||||||
@@ -497,7 +494,7 @@ class ExpressionCodegen(
|
|||||||
// 3. Evaluate statements from inline function body
|
// 3. Evaluate statements from inline function body
|
||||||
val result = inlinedBlock.getOriginalStatementsFromInlinedBlock().fold(unitValue) { prev, exp ->
|
val result = inlinedBlock.getOriginalStatementsFromInlinedBlock().fold(unitValue) { prev, exp ->
|
||||||
prev.discard()
|
prev.discard()
|
||||||
exp.accept(this, data)
|
exp.accept(this, info)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callee != null && (inlinedBlock.inlinedElement !is IrCallableReference<*> || callee.isInline)) {
|
if (callee != null && (inlinedBlock.inlinedElement !is IrCallableReference<*> || callee.isInline)) {
|
||||||
@@ -518,7 +515,13 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
lineNumberMapper.dropCurrentSmap()
|
lineNumberMapper.dropCurrentSmap()
|
||||||
|
|
||||||
return result
|
return result.materialized().also {
|
||||||
|
if (info.variables.isNotEmpty()) {
|
||||||
|
writeLocalVariablesInTable(info, markNewLabel())
|
||||||
|
}
|
||||||
|
// This block must be executed after `writeLocalVariablesInTable`
|
||||||
|
lineNumberMapper.afterIrInline(inlinedBlock)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,9 +561,6 @@ class ExpressionCodegen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun visitStatementContainer(container: IrStatementContainer, data: BlockInfo): PromisedValue {
|
private fun visitStatementContainer(container: IrStatementContainer, data: BlockInfo): PromisedValue {
|
||||||
if (container is IrInlinedFunctionBlock) {
|
|
||||||
return generateInlinedFunctionBlock(container, data)
|
|
||||||
}
|
|
||||||
return container.statements.fold(unitValue) { prev, exp ->
|
return container.statements.fold(unitValue) { prev, exp ->
|
||||||
prev.discard()
|
prev.discard()
|
||||||
exp.accept(this, data)
|
exp.accept(this, data)
|
||||||
|
|||||||
Reference in New Issue
Block a user