FIR: add FirLazyExpression node

This commit is contained in:
Ilya Kirillov
2020-10-08 13:33:37 +03:00
parent 71b5b6df7c
commit 7c1170722f
4 changed files with 101 additions and 1 deletions
@@ -0,0 +1,46 @@
/*
* 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.FirExpression
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyExpression
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 FirLazyExpressionBuilder : FirAnnotationContainerBuilder {
override var source: FirSourceElement? = null
@OptIn(FirImplementationDetail::class)
override fun build(): FirExpression {
return FirLazyExpression(
source,
)
}
@Deprecated("Modification of 'annotations' has no impact for FirLazyExpressionBuilder", level = DeprecationLevel.HIDDEN)
override val annotations: MutableList<FirAnnotationCall> = mutableListOf()
}
@OptIn(ExperimentalContracts::class)
inline fun buildLazyExpression(init: FirLazyExpressionBuilder.() -> Unit = {}): FirExpression {
contract {
callsInPlace(init, kotlin.contracts.InvocationKind.EXACTLY_ONCE)
}
return FirLazyExpressionBuilder().apply(init).build()
}
@@ -0,0 +1,38 @@
/*
* 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.FirExpression
import org.jetbrains.kotlin.fir.types.FirTypeRef
import org.jetbrains.kotlin.fir.visitors.*
/*
* This file was generated automatically
* DO NOT MODIFY IT MANUALLY
*/
class FirLazyExpression @FirImplementationDetail constructor(
override val source: FirSourceElement?,
) : FirExpression() {
override val typeRef: FirTypeRef get() = error("FirLazyExpression should be calculated before accessing")
override val annotations: List<FirAnnotationCall> get() = error("FirLazyExpression 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): FirLazyExpression {
return this
}
override fun <D> transformAnnotations(transformer: FirTransformer<D>, data: D): FirLazyExpression {
return this
}
override fun replaceTypeRef(newTypeRef: FirTypeRef) {}
}
@@ -726,10 +726,13 @@ class FirRenderer(builder: StringBuilder, private val mode: RenderMode = RenderM
}
override fun visitExpression(expression: FirExpression) {
expression.annotations.renderAnnotations()
if (expression !is FirLazyExpression) {
expression.annotations.renderAnnotations()
}
print(
when (expression) {
is FirExpressionStub -> "STUB"
is FirLazyExpression -> "LAZY_EXPRESSION"
is FirUnitExpression -> "Unit"
is FirElseIfTrueCondition -> "else"
is FirNoReceiverExpression -> ""
@@ -140,6 +140,19 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
publicImplementation()
}
impl(expression, "FirLazyExpression") {
val error = """error("FirLazyExpression should be calculated before accessing")"""
default("typeRef") {
value = error
withGetter = true
}
default("annotations") {
value = error
withGetter = true
}
publicImplementation()
}
impl(functionCall) {
kind = OpenClass
}