[FIR] add replaceStatements to FirScript

It is required to implement StateKeeper for scripts
statements should be MutableOrEmptyList to avoid CME

^KT-60728
^KT-60519
This commit is contained in:
Dmitrii Gridin
2023-07-25 20:36:03 +02:00
committed by Space Team
parent a2dc6ca8f2
commit 2f57916869
4 changed files with 9 additions and 3 deletions
@@ -41,6 +41,8 @@ abstract class FirScript : FirDeclaration() {
abstract override fun replaceAnnotations(newAnnotations: List<FirAnnotation>)
abstract fun replaceStatements(newStatements: List<FirStatement>)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirScript
abstract fun <D> transformStatements(transformer: FirTransformer<D>, data: D): FirScript
@@ -59,7 +59,7 @@ class FirScriptBuilder : FirAnnotationContainerBuilder {
origin,
attributes,
name,
statements,
statements.toMutableOrEmpty(),
symbol,
parameters,
contextReceivers.toMutableOrEmpty(),
@@ -39,7 +39,7 @@ internal class FirScriptImpl(
override val origin: FirDeclarationOrigin,
override val attributes: FirDeclarationAttributes,
override val name: Name,
override val statements: MutableList<FirStatement>,
override var statements: MutableOrEmptyList<FirStatement>,
override val symbol: FirScriptSymbol,
override val parameters: MutableList<FirVariable>,
override var contextReceivers: MutableOrEmptyList<FirContextReceiver>,
@@ -79,4 +79,8 @@ internal class FirScriptImpl(
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
annotations = newAnnotations.toMutableOrEmpty()
}
override fun replaceStatements(newStatements: List<FirStatement>) {
statements = newStatements.toMutableOrEmpty()
}
}
@@ -489,7 +489,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
script.configure {
+name
+fieldList(statement).withTransform()
+fieldList(statement, withReplace = true, useMutableOrEmpty = true).withTransform()
+symbol("FirScriptSymbol")
+fieldList("parameters", variable, withReplace = false)
+fieldList(contextReceiver, useMutableOrEmpty = true)