FIR: introduce FirLazyBlock node

This commit is contained in:
Ilya Kirillov
2020-10-09 11:30:01 +03:00
parent 864800902b
commit 4fae9cbdb0
19 changed files with 167 additions and 5 deletions
@@ -53,6 +53,8 @@ abstract class FirAnonymousFunction : FirFunction<FirAnonymousFunction>, FirExpr
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
abstract override fun replaceBody(newBody: FirBlock?)
abstract override fun replaceTypeRef(newTypeRef: FirTypeRef)
abstract fun replaceInvocationKind(newInvocationKind: EventOccurrencesRange?)
@@ -53,6 +53,8 @@ abstract class FirConstructor : FirPureAbstractElement(), FirFunction<FirConstru
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
abstract override fun replaceBody(newBody: FirBlock?)
abstract override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirConstructor
abstract override fun <D> transformReceiverTypeRef(transformer: FirTransformer<D>, data: D): FirConstructor
@@ -50,6 +50,8 @@ abstract class FirErrorFunction : FirPureAbstractElement(), FirFunction<FirError
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
abstract override fun replaceBody(newBody: FirBlock?)
abstract override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirErrorFunction
abstract override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirErrorFunction
@@ -48,6 +48,8 @@ interface FirFunction<F : FirFunction<F>> : FirCallableDeclaration<F>, FirTarget
fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
fun replaceBody(newBody: FirBlock?)
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirFunction<F>
override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirFunction<F>
@@ -54,6 +54,8 @@ abstract class FirPropertyAccessor : FirPureAbstractElement(), FirFunction<FirPr
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
abstract override fun replaceBody(newBody: FirBlock?)
abstract override fun replaceContractDescription(newContractDescription: FirContractDescription)
abstract override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirPropertyAccessor
@@ -54,6 +54,8 @@ abstract class FirSimpleFunction : FirPureAbstractElement(), FirFunction<FirSimp
abstract override fun replaceValueParameters(newValueParameters: List<FirValueParameter>)
abstract override fun replaceBody(newBody: FirBlock?)
abstract override fun replaceContractDescription(newContractDescription: FirContractDescription)
abstract override fun <D> transformReturnTypeRef(transformer: FirTransformer<D>, data: D): FirSimpleFunction
@@ -127,6 +127,10 @@ internal class FirAnonymousFunctionImpl(
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {
body = newBody
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {
typeRef = newTypeRef
}
@@ -137,4 +137,8 @@ internal class FirConstructorImpl(
valueParameters.clear()
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {
body = newBody
}
}
@@ -111,4 +111,6 @@ internal class FirErrorFunctionImpl(
valueParameters.clear()
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {}
}
@@ -137,4 +137,8 @@ internal class FirPrimaryConstructor(
valueParameters.clear()
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {
body = newBody
}
}
@@ -136,6 +136,10 @@ open class FirPropertyAccessorImpl @FirImplementationDetail constructor(
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {
body = newBody
}
override fun replaceContractDescription(newContractDescription: FirContractDescription) {
contractDescription = newContractDescription
}
@@ -140,6 +140,10 @@ open class FirSimpleFunctionImpl @FirImplementationDetail constructor(
valueParameters.addAll(newValueParameters)
}
override fun replaceBody(newBody: FirBlock?) {
body = newBody
}
override fun replaceContractDescription(newContractDescription: FirContractDescription) {
contractDescription = newContractDescription
}
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.fir.expressions.builder
import kotlin.contracts.*
import org.jetbrains.kotlin.fir.FirImplementationDetail
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyBlock
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
@FirBuilderDsl
class FirLazyBlockBuilder : FirAnnotationContainerBuilder, FirExpressionBuilder {
override var source: FirSourceElement? = null
@OptIn(FirImplementationDetail::class)
override fun build(): FirBlock {
return FirLazyBlock(
source,
)
}
@Deprecated("Modification of 'annotations' has no impact for FirLazyBlockBuilder", level = DeprecationLevel.HIDDEN)
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
@Deprecated("Modification of 'typeRef' has no impact for FirLazyBlockBuilder", level = DeprecationLevel.HIDDEN)
override var typeRef: FirTypeRef
get() = throw IllegalStateException()
set(value) {
throw IllegalStateException()
}
}
@OptIn(ExperimentalContracts::class)
inline fun buildLazyBlock(init: FirLazyBlockBuilder.() -> Unit = {}): FirBlock {
contract {
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
return FirLazyBlockBuilder().apply(init).build()
}
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2020 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.
*/
package org.jetbrains.kotlin.fir.expressions.impl
import org.jetbrains.kotlin.fir.FirImplementationDetail
import org.jetbrains.kotlin.fir.FirSourceElement
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
import org.jetbrains.kotlin.fir.expressions.FirBlock
import org.jetbrains.kotlin.fir.expressions.FirStatement
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
class FirLazyBlock @FirImplementationDetail constructor(
override val source: FirSourceElement?,
) : FirBlock() {
override val annotations: List<FirAnnotationCall> get() = error("FirLazyBlock should be calculated before accessing")
override val statements: List<FirStatement> get() = error("FirLazyBlock should be calculated before accessing")
override val typeRef: FirTypeRef get() = error("FirLazyBlock should be calculated before accessing")
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirLazyBlock {
transformOtherChildren(transformer, data)
return this
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirLazyBlock {
return this
}
override fun <D> transformStatements(transformer: FirTransformer<D>, data: D): FirLazyBlock {
return this
}
override fun <D> transformOtherChildren(transformer: FirTransformer<D>, data: D): FirLazyBlock {
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
}
@@ -503,8 +503,11 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
anonymousInitializer.body?.renderBody()
}
private fun FirBlock.renderBody(additionalStatements: List<FirStatement> = emptyList()) {
renderInBraces {
private fun FirBlock.renderBody(additionalStatements: List<FirStatement> = emptyList()) = when (this) {
is FirLazyBlock -> {
println(" { LAZY_BLOCK }")
}
else -> renderInBraces {
for (statement in additionalStatements + statements) {
statement.accept(this@FirRenderer)
println()
@@ -79,6 +79,10 @@ class FirSyntheticPropertyAccessor(
contractDescription.accept(visitor, data)
}
override fun replaceBody(newBody: FirBlock?) {
throw AssertionError("Transformation of synthetic property accessor isn't supported")
}
override fun <D> transformChildren(transformer: FirTransformer<D>, data: D): FirPropertyAccessorImpl {
throw AssertionError("Transformation of synthetic property accessor isn't supported")
}
@@ -47,8 +47,8 @@ object FieldSets {
fun symbol(symbolClassName: String, argument: String? = null): Field =
symbolWithPackage("fir.symbols.impl", symbolClassName, argument)
fun body(nullable: Boolean = false) =
field("body", block, nullable)
fun body(nullable: Boolean = false, withReplace: Boolean = false) =
field("body", block, nullable, withReplace = withReplace)
val returnTypeRef =
field("returnTypeRef", typeRef)
@@ -113,6 +113,23 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
publicImplementation()
}
impl(block, "FirLazyBlock") {
val error = """error("FirLazyBlock should be calculated before accessing")"""
default("statements") {
value = error
withGetter = true
}
default("annotations") {
value = error
withGetter = true
}
default("typeRef") {
value = error
withGetter = true
}
publicImplementation()
}
impl(errorLoop) {
default("block", "FirEmptyExpressionBlock()")
default("condition", "FirErrorExpressionImpl(source, ConeStubDiagnostic(diagnostic))")
@@ -102,7 +102,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
parentArg(callableDeclaration, "F", "F")
+symbol("FirFunctionSymbol", "F")
+fieldList(valueParameter, withReplace = true).withTransform()
+body(nullable = true).withTransform()
+body(nullable = true, withReplace = true).withTransform()
}
errorFunction.configure {