JS IC: IC lowerings prototype
This commit is contained in:
committed by
teamcityserver
parent
525c5b886f
commit
20088994c1
+51
-21
@@ -9,11 +9,13 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrBlockBody
|
||||
import org.jetbrains.kotlin.ir.expressions.persistent.PersistentIrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrPublicSymbolBase
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -24,8 +26,24 @@ class PersistentIrFactory : IrFactory {
|
||||
|
||||
override var stageController = StageController()
|
||||
|
||||
val allDeclarations = mutableListOf<IrDeclaration>()
|
||||
|
||||
val allBodies = mutableListOf<IrBody>()
|
||||
|
||||
private fun IrDeclaration.register() {
|
||||
allDeclarations += this
|
||||
}
|
||||
|
||||
fun declarationSignature(declaration: IrDeclaration): IdSignature? {
|
||||
return (declaration as? PersistentIrDeclarationBase<*>)?.signature ?: declaration.symbol.signature
|
||||
}
|
||||
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
fun currentSignature(declaration: IrDeclaration): IdSignature? = null
|
||||
internal fun currentSignature(declaration: IrDeclaration): IdSignature? {
|
||||
val parentSig = stageController.currentDeclaration?.let { declarationSignature(it) } ?: return null
|
||||
|
||||
return stageController.createSignature(parentSig)
|
||||
}
|
||||
|
||||
override fun createAnonymousInitializer(
|
||||
startOffset: Int,
|
||||
@@ -34,7 +52,7 @@ class PersistentIrFactory : IrFactory {
|
||||
symbol: IrAnonymousInitializerSymbol,
|
||||
isStatic: Boolean,
|
||||
): IrAnonymousInitializer =
|
||||
PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic, this)
|
||||
PersistentIrAnonymousInitializer(startOffset, endOffset, origin, symbol, isStatic, this).also { it.register() }
|
||||
|
||||
override fun createClass(
|
||||
startOffset: Int,
|
||||
@@ -58,7 +76,7 @@ class PersistentIrFactory : IrFactory {
|
||||
startOffset, endOffset, origin, symbol, name, kind, visibility, modality,
|
||||
isCompanion, isInner, isData, isExternal, isInline, isExpect, isFun, source,
|
||||
this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createConstructor(
|
||||
startOffset: Int,
|
||||
@@ -77,7 +95,7 @@ class PersistentIrFactory : IrFactory {
|
||||
PersistentIrConstructor(
|
||||
startOffset, endOffset, origin, symbol, name, visibility, returnType, isInline, isExternal, isPrimary, isExpect,
|
||||
containerSource, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createEnumEntry(
|
||||
startOffset: Int,
|
||||
@@ -86,14 +104,14 @@ class PersistentIrFactory : IrFactory {
|
||||
symbol: IrEnumEntrySymbol,
|
||||
name: Name,
|
||||
): IrEnumEntry =
|
||||
PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name, this)
|
||||
PersistentIrEnumEntry(startOffset, endOffset, origin, symbol, name, this).also { it.register() }
|
||||
|
||||
override fun createErrorDeclaration(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
descriptor: DeclarationDescriptor?,
|
||||
): IrErrorDeclaration =
|
||||
PersistentIrErrorDeclaration(startOffset, endOffset, descriptor, this)
|
||||
PersistentIrErrorDeclaration(startOffset, endOffset, descriptor, this).also { it.register() }
|
||||
|
||||
override fun createField(
|
||||
startOffset: Int,
|
||||
@@ -107,7 +125,7 @@ class PersistentIrFactory : IrFactory {
|
||||
isExternal: Boolean,
|
||||
isStatic: Boolean,
|
||||
): IrField =
|
||||
PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic, this)
|
||||
PersistentIrField(startOffset, endOffset, origin, symbol, name, type, visibility, isFinal, isExternal, isStatic, this).also { it.register() }
|
||||
|
||||
override fun createFunction(
|
||||
startOffset: Int,
|
||||
@@ -132,7 +150,7 @@ class PersistentIrFactory : IrFactory {
|
||||
startOffset, endOffset, origin, symbol, name, visibility, modality, returnType,
|
||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, isFakeOverride,
|
||||
containerSource, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createFakeOverrideFunction(
|
||||
startOffset: Int,
|
||||
@@ -153,7 +171,7 @@ class PersistentIrFactory : IrFactory {
|
||||
PersistentIrFakeOverrideFunction(
|
||||
startOffset, endOffset, origin, name, visibility, modality, returnType,
|
||||
isInline, isExternal, isTailrec, isSuspend, isOperator, isInfix, isExpect, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createLocalDelegatedProperty(
|
||||
startOffset: Int,
|
||||
@@ -166,7 +184,7 @@ class PersistentIrFactory : IrFactory {
|
||||
): IrLocalDelegatedProperty =
|
||||
PersistentIrLocalDelegatedProperty(
|
||||
startOffset, endOffset, origin, symbol, name, type, isVar, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createProperty(
|
||||
startOffset: Int,
|
||||
@@ -189,7 +207,7 @@ class PersistentIrFactory : IrFactory {
|
||||
startOffset, endOffset, origin, symbol, name, visibility, modality,
|
||||
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect, isFakeOverride,
|
||||
containerSource, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createFakeOverrideProperty(
|
||||
startOffset: Int,
|
||||
@@ -209,7 +227,7 @@ class PersistentIrFactory : IrFactory {
|
||||
startOffset, endOffset, origin, name, visibility, modality,
|
||||
isVar, isConst, isLateinit, isDelegated, isExternal, isExpect,
|
||||
this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createTypeAlias(
|
||||
startOffset: Int,
|
||||
@@ -221,7 +239,7 @@ class PersistentIrFactory : IrFactory {
|
||||
isActual: Boolean,
|
||||
origin: IrDeclarationOrigin,
|
||||
): IrTypeAlias =
|
||||
PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin, this)
|
||||
PersistentIrTypeAlias(startOffset, endOffset, symbol, name, visibility, expandedType, isActual, origin, this).also { it.register() }
|
||||
|
||||
override fun createTypeParameter(
|
||||
startOffset: Int,
|
||||
@@ -233,7 +251,7 @@ class PersistentIrFactory : IrFactory {
|
||||
isReified: Boolean,
|
||||
variance: Variance,
|
||||
): IrTypeParameter =
|
||||
PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance, this)
|
||||
PersistentIrTypeParameter(startOffset, endOffset, origin, symbol, name, index, isReified, variance, this).also { it.register() }
|
||||
|
||||
override fun createValueParameter(
|
||||
startOffset: Int,
|
||||
@@ -251,44 +269,56 @@ class PersistentIrFactory : IrFactory {
|
||||
): IrValueParameter =
|
||||
PersistentIrValueParameter(
|
||||
startOffset, endOffset, origin, symbol, name, index, type, varargElementType, isCrossinline, isNoinline, isHidden, isAssignable, this
|
||||
)
|
||||
).also { it.register() }
|
||||
|
||||
override fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
initializer: IrExpressionBody.() -> Unit,
|
||||
): IrExpressionBody =
|
||||
PersistentIrExpressionBody(startOffset, endOffset, this, initializer)
|
||||
PersistentIrExpressionBody(startOffset, endOffset, this, initializer).also {
|
||||
allBodies += it
|
||||
}
|
||||
|
||||
override fun createExpressionBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
expression: IrExpression,
|
||||
): IrExpressionBody =
|
||||
PersistentIrExpressionBody(startOffset, endOffset, expression, this)
|
||||
PersistentIrExpressionBody(startOffset, endOffset, expression, this).also {
|
||||
allBodies += it
|
||||
}
|
||||
|
||||
override fun createExpressionBody(
|
||||
expression: IrExpression,
|
||||
): IrExpressionBody =
|
||||
PersistentIrExpressionBody(expression, this)
|
||||
PersistentIrExpressionBody(expression, this).also {
|
||||
allBodies += it
|
||||
}
|
||||
|
||||
override fun createBlockBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
): IrBlockBody =
|
||||
PersistentIrBlockBody(startOffset, endOffset, this)
|
||||
PersistentIrBlockBody(startOffset, endOffset, this).also {
|
||||
allBodies += it
|
||||
}
|
||||
|
||||
override fun createBlockBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
statements: List<IrStatement>,
|
||||
): IrBlockBody =
|
||||
PersistentIrBlockBody(startOffset, endOffset, statements, this)
|
||||
PersistentIrBlockBody(startOffset, endOffset, statements, this).also {
|
||||
allBodies += it
|
||||
}
|
||||
|
||||
override fun createBlockBody(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
initializer: IrBlockBody.() -> Unit,
|
||||
): IrBlockBody =
|
||||
PersistentIrBlockBody(startOffset, endOffset, this, initializer)
|
||||
PersistentIrBlockBody(startOffset, endOffset, this, initializer).also {
|
||||
allBodies += it
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user