Use file symbol instead of a file name string in IrReturnableBlockImpl
This commit is contained in:
committed by
alexander-gorshenev
parent
e2106d4d08
commit
888641e7f1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrReturnTarget
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
|
||||
interface IrContainerExpression : IrExpression, IrStatementContainer {
|
||||
@@ -37,5 +38,6 @@ interface IrComposite : IrContainerExpression {
|
||||
|
||||
interface IrReturnableBlock : IrBlock, IrSymbolOwner, IrReturnTarget {
|
||||
override val symbol: IrReturnableBlockSymbol
|
||||
val sourceFileSymbol: IrFileSymbol?
|
||||
val sourceFileName: String
|
||||
}
|
||||
@@ -18,9 +18,11 @@ package org.jetbrains.kotlin.ir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFile
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
||||
import org.jetbrains.kotlin.ir.expressions.IrReturnableBlock
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFileSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrReturnableBlockSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrReturnableBlockSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -63,14 +65,13 @@ fun IrBlockImpl.inlineStatement(statement: IrStatement) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class IrReturnableBlockImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: IrType,
|
||||
override val symbol: IrReturnableBlockSymbol,
|
||||
origin: IrStatementOrigin? = null,
|
||||
override val sourceFileName: String = "no source file"
|
||||
override val sourceFileSymbol: IrFileSymbol? = null
|
||||
) :
|
||||
IrContainerExpressionBase(startOffset, endOffset, type, origin),
|
||||
IrReturnableBlock {
|
||||
@@ -84,8 +85,8 @@ class IrReturnableBlockImpl(
|
||||
symbol: IrReturnableBlockSymbol,
|
||||
origin: IrStatementOrigin?,
|
||||
statements: List<IrStatement>,
|
||||
sourceFileName: String = "no source file"
|
||||
) : this(startOffset, endOffset, type, symbol, origin, sourceFileName) {
|
||||
sourceFileSymbol: IrFileSymbol? = null
|
||||
) : this(startOffset, endOffset, type, symbol, origin, sourceFileSymbol) {
|
||||
this.statements.addAll(statements)
|
||||
}
|
||||
|
||||
@@ -95,8 +96,8 @@ class IrReturnableBlockImpl(
|
||||
type: IrType,
|
||||
descriptor: FunctionDescriptor,
|
||||
origin: IrStatementOrigin? = null,
|
||||
sourceFileName: String = "no source file"
|
||||
) : this(startOffset, endOffset, type, IrReturnableBlockSymbolImpl(descriptor), origin, sourceFileName)
|
||||
sourceFileSymbol: IrFileSymbol? = null
|
||||
) : this(startOffset, endOffset, type, IrReturnableBlockSymbolImpl(descriptor), origin, sourceFileSymbol)
|
||||
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
@@ -105,8 +106,8 @@ class IrReturnableBlockImpl(
|
||||
descriptor: FunctionDescriptor,
|
||||
origin: IrStatementOrigin?,
|
||||
statements: List<IrStatement>,
|
||||
sourceFileName: String = "no source file"
|
||||
) : this(startOffset, endOffset, type, descriptor, origin, sourceFileName) {
|
||||
sourceFileSymbol: IrFileSymbol? = null
|
||||
) : this(startOffset, endOffset, type, descriptor, origin, sourceFileSymbol) {
|
||||
this.statements.addAll(statements)
|
||||
}
|
||||
|
||||
@@ -114,6 +115,8 @@ class IrReturnableBlockImpl(
|
||||
symbol.bind(this)
|
||||
}
|
||||
|
||||
override val sourceFileName: String = sourceFileSymbol?.owner?.fileEntry?.name ?: "no source file"
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitBlock(this, data)
|
||||
|
||||
|
||||
@@ -383,7 +383,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
symbolRemapper.getReferencedReturnableBlock(expression.symbol),
|
||||
mapStatementOrigin(expression.origin),
|
||||
expression.statements.map { it.transform() },
|
||||
expression.sourceFileName
|
||||
expression.sourceFileSymbol
|
||||
)
|
||||
else
|
||||
IrBlockImpl(
|
||||
|
||||
@@ -569,3 +569,12 @@ private fun IrCall.copyTypeAndValueArgumentsFrom(
|
||||
putValueArgument(toValueArgumentIndex++, call.getValueArgument(fromValueArgumentIndex++))
|
||||
}
|
||||
}
|
||||
|
||||
val IrDeclaration.file: IrFile get() = parent.let {
|
||||
when (it) {
|
||||
is IrFile -> it
|
||||
is IrPackageFragment -> TODO("Unknown file")
|
||||
is IrDeclaration -> it.file
|
||||
else -> TODO("Unexpected declaration parent")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user