[FIR generator] Use more type-safe field builders

This commit is contained in:
Sergej Jaskiewicz
2023-09-14 12:43:42 +02:00
committed by Space Team
parent 8be455649c
commit a909a28f29
5 changed files with 16 additions and 26 deletions
@@ -162,8 +162,8 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
jump.configure {
withArg("E", targetElement)
+field("target", jumpTargetType.withArgs("E"))
val e = withArg("E", targetElement)
+field("target", jumpTargetType to listOf(e))
}
loopJump.configure {
@@ -227,9 +227,9 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
}
constExpression.configure {
withArg("T")
+field("kind", constKindType.withArgs("T"), withReplace = true)
+field("value", "T", null)
val t = withArg("T")
+field("kind", constKindType to listOf(t), withReplace = true)
+field("value", t)
}
functionCall.configure {
@@ -572,7 +572,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
smartCastExpression.configure {
+field("originalExpression", expression, withReplace = true).withTransform()
+field("typesFromSmartCast", "Collection<ConeKotlinType>", null, customType = coneKotlinTypeType)
+field("typesFromSmartCast", StandardTypes.collection to listOf(coneKotlinTypeType))
+field("smartcastType", typeRef)
+field("smartcastTypeWithoutNullableNothing", typeRef, nullable = true)
+booleanField("isStable")
@@ -748,7 +748,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
whenExpression.configure {
+field("subject", expression, nullable = true).withTransform()
+field("subjectVariable", variable.withArgs("E" to TypeRef.Star), nullable = true)
+field("subjectVariable", variable, nullable = true)
+fieldList("branches", whenBranch).withTransform()
+field("exhaustivenessStatus", exhaustivenessStatusType, nullable = true, withReplace = true)
+booleanField("usedAsExpression")
@@ -49,10 +49,6 @@ abstract class AbstractFieldConfigurator<T : AbstractFirTreeBuilder>(private val
argMap[argument] = type
}
fun TypeRef.withArgs(vararg args: String): Pair<TypeRef, List<TypeRef>> {
return this to args.map { NamedTypeParameterRef(it) }
}
fun needTransformOtherChildren() {
element._needTransformOtherChildren = true
}
@@ -23,10 +23,6 @@ abstract class AbstractFirTreeBuilder {
"Element",
Element.Kind.Other
)
const val string = "String"
const val boolean = "Boolean"
const val int = "Int"
}
val elements = mutableListOf(baseFirElement)
@@ -5,19 +5,13 @@
package org.jetbrains.kotlin.fir.tree.generator.model
import org.jetbrains.kotlin.fir.tree.generator.context.AbstractFirTreeBuilder
import org.jetbrains.kotlin.fir.tree.generator.context.type
import org.jetbrains.kotlin.generators.tree.typeWithArguments
import org.jetbrains.kotlin.generators.tree.Importable
import org.jetbrains.kotlin.generators.tree.NamedTypeParameterRef
import org.jetbrains.kotlin.generators.tree.StandardTypes
import org.jetbrains.kotlin.generators.tree.TypeRef
import org.jetbrains.kotlin.generators.tree.typeWithArguments
// ----------- Simple field -----------
fun field(name: String, type: String, packageName: String?, customType: TypeRef? = null, nullable: Boolean = false, withReplace: Boolean = false): Field {
return SimpleField(name, type, packageName, customType, nullable, withReplace)
}
fun field(name: String, type: TypeRef, nullable: Boolean = false, withReplace: Boolean = false): Field {
return SimpleField(name, type.typeWithArguments, type.packageName, null, nullable, withReplace)
}
@@ -34,15 +28,15 @@ fun field(type: TypeRef, nullable: Boolean = false, withReplace: Boolean = false
}
fun booleanField(name: String, withReplace: Boolean = false): Field {
return field(name, AbstractFirTreeBuilder.boolean, null, withReplace = withReplace)
return field(name, StandardTypes.boolean, withReplace = withReplace)
}
fun stringField(name: String, nullable: Boolean = false): Field {
return field(name, AbstractFirTreeBuilder.string, null, null, nullable)
return field(name, StandardTypes.string, nullable = nullable)
}
fun intField(name: String, withReplace: Boolean = false): Field {
return field(name, AbstractFirTreeBuilder.int, null, withReplace = withReplace)
return field(name, StandardTypes.int, withReplace = withReplace)
}
// ----------- Fir field -----------
@@ -6,5 +6,9 @@
package org.jetbrains.kotlin.generators.tree
object StandardTypes {
val boolean = type<Boolean>()
val string = type<String>()
val int = type<Int>()
val collection = type<Collection<*>>()
val map = type<Map<*, *>>()
}