Add new IR node IrInlinedFunctionBlock
This node will represent inlined in IR function.
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// This file was generated automatically. See compiler/ir/ir.tree/tree-generator/ReadMe.md.
|
||||||
|
// DO NOT MODIFY IT MANUALLY.
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.ir.expressions
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A leaf IR tree element.
|
||||||
|
* @sample org.jetbrains.kotlin.ir.generator.IrTree.inlinedFunctionBlock
|
||||||
|
*/
|
||||||
|
abstract class IrInlinedFunctionBlock : IrBlock() {
|
||||||
|
abstract var inlineCall: IrFunctionAccessExpression
|
||||||
|
|
||||||
|
abstract var inlinedElement: IrElement
|
||||||
|
}
|
||||||
@@ -17,11 +17,10 @@
|
|||||||
package org.jetbrains.kotlin.ir.expressions.impl
|
package org.jetbrains.kotlin.ir.expressions.impl
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
@@ -83,3 +82,24 @@ class IrReturnableBlockImpl(
|
|||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class IrInlinedFunctionBlockImpl(
|
||||||
|
override val startOffset: Int,
|
||||||
|
override val endOffset: Int,
|
||||||
|
override var type: IrType,
|
||||||
|
override var inlineCall: IrFunctionAccessExpression,
|
||||||
|
override var inlinedElement: IrElement,
|
||||||
|
override var origin: IrStatementOrigin? = null,
|
||||||
|
) : IrInlinedFunctionBlock() {
|
||||||
|
constructor(
|
||||||
|
startOffset: Int,
|
||||||
|
endOffset: Int,
|
||||||
|
type: IrType,
|
||||||
|
inlineCall: IrFunctionAccessExpression,
|
||||||
|
inlinedElement: IrElement,
|
||||||
|
origin: IrStatementOrigin?,
|
||||||
|
statements: List<IrStatement>,
|
||||||
|
) : this(startOffset, endOffset, type, inlineCall, inlinedElement, origin) {
|
||||||
|
this.statements.addAll(statements)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,9 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.ir.util
|
package org.jetbrains.kotlin.ir.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.*
|
||||||
import org.jetbrains.kotlin.ir.IrStatement
|
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
@@ -462,6 +460,14 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
expression.statements.map { it.transform() },
|
expression.statements.map { it.transform() },
|
||||||
expression.inlineFunctionSymbol
|
expression.inlineFunctionSymbol
|
||||||
).copyAttributes(expression)
|
).copyAttributes(expression)
|
||||||
|
else if (expression is IrInlinedFunctionBlock)
|
||||||
|
IrInlinedFunctionBlockImpl(
|
||||||
|
expression.startOffset, expression.endOffset,
|
||||||
|
expression.type.remapType(),
|
||||||
|
expression.inlineCall, expression.inlinedElement,
|
||||||
|
mapStatementOrigin(expression.origin),
|
||||||
|
statements = expression.statements.map { it.transform() },
|
||||||
|
).copyAttributes(expression)
|
||||||
else
|
else
|
||||||
IrBlockImpl(
|
IrBlockImpl(
|
||||||
expression.startOffset, expression.endOffset,
|
expression.startOffset, expression.endOffset,
|
||||||
|
|||||||
@@ -293,6 +293,14 @@ class DumpIrTreeVisitor(
|
|||||||
private fun IrMemberAccessExpression<*>.renderTypeArgument(index: Int): String =
|
private fun IrMemberAccessExpression<*>.renderTypeArgument(index: Int): String =
|
||||||
getTypeArgument(index)?.render() ?: "<none>"
|
getTypeArgument(index)?.render() ?: "<none>"
|
||||||
|
|
||||||
|
override fun visitBlock(expression: IrBlock, data: String) {
|
||||||
|
if (expression !is IrInlinedFunctionBlock) return super.visitBlock(expression, data)
|
||||||
|
expression.dumpLabeledElementWith(data) {
|
||||||
|
expression.inlinedElement.dumpInternal("inlinedElement")
|
||||||
|
super.visitBlock(expression, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitGetField(expression: IrGetField, data: String) {
|
override fun visitGetField(expression: IrGetField, data: String) {
|
||||||
expression.dumpLabeledElementWith(data) {
|
expression.dumpLabeledElementWith(data) {
|
||||||
expression.receiver?.accept(this, "receiver")
|
expression.receiver?.accept(this, "receiver")
|
||||||
|
|||||||
@@ -357,8 +357,14 @@ class RenderIrElementVisitor(normalizeNames: Boolean = false, private val verbos
|
|||||||
override fun visitSpreadElement(spread: IrSpreadElement, data: Nothing?): String =
|
override fun visitSpreadElement(spread: IrSpreadElement, data: Nothing?): String =
|
||||||
"SPREAD_ELEMENT"
|
"SPREAD_ELEMENT"
|
||||||
|
|
||||||
override fun visitBlock(expression: IrBlock, data: Nothing?): String =
|
override fun visitBlock(expression: IrBlock, data: Nothing?): String {
|
||||||
"${if (expression is IrReturnableBlock) "RETURNABLE_" else ""}BLOCK type=${expression.type.render()} origin=${expression.origin}"
|
val prefix = when (expression) {
|
||||||
|
is IrReturnableBlock -> "RETURNABLE_"
|
||||||
|
is IrInlinedFunctionBlock -> "INLINED_"
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
return "${prefix}BLOCK type=${expression.type.render()} origin=${expression.origin}"
|
||||||
|
}
|
||||||
|
|
||||||
override fun visitComposite(expression: IrComposite, data: Nothing?): String =
|
override fun visitComposite(expression: IrComposite, data: Nothing?): String =
|
||||||
"COMPOSITE type=${expression.type.render()} origin=${expression.origin}"
|
"COMPOSITE type=${expression.type.render()} origin=${expression.origin}"
|
||||||
|
|||||||
@@ -920,7 +920,11 @@ private class KotlinLikeDumper(val p: Printer, val options: KotlinLikeDumpOption
|
|||||||
// TODO special blocks using `origin`
|
// TODO special blocks using `origin`
|
||||||
// TODO inlineFunctionSymbol for IrReturnableBlock
|
// TODO inlineFunctionSymbol for IrReturnableBlock
|
||||||
// TODO no tests for IrReturnableBlock?
|
// TODO no tests for IrReturnableBlock?
|
||||||
val kind = if (expression is IrReturnableBlock) "RETURNABLE BLOCK" else "BLOCK"
|
val kind = when (expression) {
|
||||||
|
is IrReturnableBlock -> "RETURNABLE BLOCK"
|
||||||
|
is IrInlinedFunctionBlock -> "INLINED FUNCTION BLOCK"
|
||||||
|
else -> "BLOCK"
|
||||||
|
}
|
||||||
// it's not valid kotlin
|
// it's not valid kotlin
|
||||||
expression.printStatementContainer("{ // $kind", "}", data)
|
expression.printStatementContainer("{ // $kind", "}", data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -643,6 +643,12 @@ object IrTree : AbstractTreeBuilder() {
|
|||||||
+symbol(returnableBlockSymbolType)
|
+symbol(returnableBlockSymbolType)
|
||||||
+field("inlineFunctionSymbol", functionSymbolType, nullable = true)
|
+field("inlineFunctionSymbol", functionSymbolType, nullable = true)
|
||||||
}
|
}
|
||||||
|
val inlinedFunctionBlock: ElementConfig by element(Expression) {
|
||||||
|
parent(block)
|
||||||
|
|
||||||
|
+field("inlineCall", functionAccessExpression)
|
||||||
|
+field("inlinedElement", rootElement)
|
||||||
|
}
|
||||||
val syntheticBody: ElementConfig by element(Expression) {
|
val syntheticBody: ElementConfig by element(Expression) {
|
||||||
visitorParent = body
|
visitorParent = body
|
||||||
visitorParam = "body"
|
visitorParam = "body"
|
||||||
|
|||||||
Reference in New Issue
Block a user