K2 Scripting: wrap script statements into blocks
(reuse anonymous initializers as block wrappers) so the top-level script elements are all declarations now. Rename the property accordingly ( together with the previous commit). It makes script more similar to the class and thus simplify e.g. control flow analysis and resolve code.
This commit is contained in:
committed by
Space Team
parent
c9aee5bf09
commit
eeb723eb01
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirScriptSymbol
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
@@ -30,9 +29,9 @@ abstract class FirScript : FirDeclaration(), FirControlFlowGraphOwner {
|
||||
abstract override val attributes: FirDeclarationAttributes
|
||||
abstract override val controlFlowGraphReference: FirControlFlowGraphReference?
|
||||
abstract val name: Name
|
||||
abstract val declarations: List<FirStatement>
|
||||
abstract val declarations: List<FirDeclaration>
|
||||
abstract override val symbol: FirScriptSymbol
|
||||
abstract val parameters: List<FirVariable>
|
||||
abstract val parameters: List<FirProperty>
|
||||
abstract val contextReceivers: List<FirContextReceiver>
|
||||
abstract val resultPropertyName: Name?
|
||||
|
||||
@@ -47,9 +46,13 @@ abstract class FirScript : FirDeclaration(), FirControlFlowGraphOwner {
|
||||
|
||||
abstract override fun replaceControlFlowGraphReference(newControlFlowGraphReference: FirControlFlowGraphReference?)
|
||||
|
||||
abstract fun replaceDeclarations(newDeclarations: List<FirStatement>)
|
||||
abstract fun replaceDeclarations(newDeclarations: List<FirDeclaration>)
|
||||
|
||||
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirScript
|
||||
|
||||
abstract fun <D> transformDeclarations(transformer: FirTransformer<D>, data: D): FirScript
|
||||
|
||||
abstract fun <D> transformParameters(transformer: FirTransformer<D>, data: D): FirScript
|
||||
|
||||
abstract fun <D> transformContextReceivers(transformer: FirTransformer<D>, data: D): FirScript
|
||||
}
|
||||
|
||||
+3
-4
@@ -19,7 +19,6 @@ import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirScriptImpl
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirScriptSymbol
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
@@ -32,9 +31,9 @@ class FirScriptBuilder : FirAnnotationContainerBuilder {
|
||||
lateinit var origin: FirDeclarationOrigin
|
||||
var attributes: FirDeclarationAttributes = FirDeclarationAttributes()
|
||||
lateinit var name: Name
|
||||
val declarations: MutableList<FirStatement> = mutableListOf()
|
||||
val declarations: MutableList<FirDeclaration> = mutableListOf()
|
||||
lateinit var symbol: FirScriptSymbol
|
||||
val parameters: MutableList<FirVariable> = mutableListOf()
|
||||
val parameters: MutableList<FirProperty> = mutableListOf()
|
||||
val contextReceivers: MutableList<FirContextReceiver> = mutableListOf()
|
||||
var resultPropertyName: Name? = null
|
||||
|
||||
@@ -47,7 +46,7 @@ class FirScriptBuilder : FirAnnotationContainerBuilder {
|
||||
origin,
|
||||
attributes,
|
||||
name,
|
||||
declarations.toMutableOrEmpty(),
|
||||
declarations,
|
||||
symbol,
|
||||
parameters,
|
||||
contextReceivers.toMutableOrEmpty(),
|
||||
|
||||
@@ -16,7 +16,6 @@ import org.jetbrains.kotlin.fir.MutableOrEmptyList
|
||||
import org.jetbrains.kotlin.fir.builder.toMutableOrEmpty
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.expressions.FirStatement
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirScriptSymbol
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
@@ -33,9 +32,9 @@ internal class FirScriptImpl(
|
||||
override val origin: FirDeclarationOrigin,
|
||||
override val attributes: FirDeclarationAttributes,
|
||||
override val name: Name,
|
||||
override var declarations: MutableOrEmptyList<FirStatement>,
|
||||
override val declarations: MutableList<FirDeclaration>,
|
||||
override val symbol: FirScriptSymbol,
|
||||
override val parameters: MutableList<FirVariable>,
|
||||
override val parameters: MutableList<FirProperty>,
|
||||
override var contextReceivers: MutableOrEmptyList<FirContextReceiver>,
|
||||
override val resultPropertyName: Name?,
|
||||
) : FirScript() {
|
||||
@@ -58,8 +57,8 @@ internal class FirScriptImpl(
|
||||
transformAnnotations(transformer, data)
|
||||
controlFlowGraphReference = controlFlowGraphReference?.transform(transformer, data)
|
||||
transformDeclarations(transformer, data)
|
||||
parameters.transformInplace(transformer, data)
|
||||
contextReceivers.transformInplace(transformer, data)
|
||||
transformParameters(transformer, data)
|
||||
transformContextReceivers(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -73,6 +72,16 @@ internal class FirScriptImpl(
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformParameters(transformer: FirTransformer<D>, data: D): FirScriptImpl {
|
||||
parameters.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun <D> transformContextReceivers(transformer: FirTransformer<D>, data: D): FirScriptImpl {
|
||||
contextReceivers.transformInplace(transformer, data)
|
||||
return this
|
||||
}
|
||||
|
||||
override fun replaceAnnotations(newAnnotations: List<FirAnnotation>) {
|
||||
annotations = newAnnotations.toMutableOrEmpty()
|
||||
}
|
||||
@@ -81,7 +90,8 @@ internal class FirScriptImpl(
|
||||
controlFlowGraphReference = newControlFlowGraphReference
|
||||
}
|
||||
|
||||
override fun replaceDeclarations(newDeclarations: List<FirStatement>) {
|
||||
declarations = newDeclarations.toMutableOrEmpty()
|
||||
override fun replaceDeclarations(newDeclarations: List<FirDeclaration>) {
|
||||
declarations.clear()
|
||||
declarations.addAll(newDeclarations)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user