[FIR generator] Use more type-safe field builders
This commit is contained in:
committed by
Space Team
parent
8be455649c
commit
a909a28f29
+7
-7
@@ -162,8 +162,8 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
}
|
}
|
||||||
|
|
||||||
jump.configure {
|
jump.configure {
|
||||||
withArg("E", targetElement)
|
val e = withArg("E", targetElement)
|
||||||
+field("target", jumpTargetType.withArgs("E"))
|
+field("target", jumpTargetType to listOf(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
loopJump.configure {
|
loopJump.configure {
|
||||||
@@ -227,9 +227,9 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
}
|
}
|
||||||
|
|
||||||
constExpression.configure {
|
constExpression.configure {
|
||||||
withArg("T")
|
val t = withArg("T")
|
||||||
+field("kind", constKindType.withArgs("T"), withReplace = true)
|
+field("kind", constKindType to listOf(t), withReplace = true)
|
||||||
+field("value", "T", null)
|
+field("value", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
functionCall.configure {
|
functionCall.configure {
|
||||||
@@ -572,7 +572,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
|
|
||||||
smartCastExpression.configure {
|
smartCastExpression.configure {
|
||||||
+field("originalExpression", expression, withReplace = true).withTransform()
|
+field("originalExpression", expression, withReplace = true).withTransform()
|
||||||
+field("typesFromSmartCast", "Collection<ConeKotlinType>", null, customType = coneKotlinTypeType)
|
+field("typesFromSmartCast", StandardTypes.collection to listOf(coneKotlinTypeType))
|
||||||
+field("smartcastType", typeRef)
|
+field("smartcastType", typeRef)
|
||||||
+field("smartcastTypeWithoutNullableNothing", typeRef, nullable = true)
|
+field("smartcastTypeWithoutNullableNothing", typeRef, nullable = true)
|
||||||
+booleanField("isStable")
|
+booleanField("isStable")
|
||||||
@@ -748,7 +748,7 @@ object NodeConfigurator : AbstractFieldConfigurator<FirTreeBuilder>(FirTreeBuild
|
|||||||
|
|
||||||
whenExpression.configure {
|
whenExpression.configure {
|
||||||
+field("subject", expression, nullable = true).withTransform()
|
+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()
|
+fieldList("branches", whenBranch).withTransform()
|
||||||
+field("exhaustivenessStatus", exhaustivenessStatusType, nullable = true, withReplace = true)
|
+field("exhaustivenessStatus", exhaustivenessStatusType, nullable = true, withReplace = true)
|
||||||
+booleanField("usedAsExpression")
|
+booleanField("usedAsExpression")
|
||||||
|
|||||||
-4
@@ -49,10 +49,6 @@ abstract class AbstractFieldConfigurator<T : AbstractFirTreeBuilder>(private val
|
|||||||
argMap[argument] = type
|
argMap[argument] = type
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TypeRef.withArgs(vararg args: String): Pair<TypeRef, List<TypeRef>> {
|
|
||||||
return this to args.map { NamedTypeParameterRef(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun needTransformOtherChildren() {
|
fun needTransformOtherChildren() {
|
||||||
element._needTransformOtherChildren = true
|
element._needTransformOtherChildren = true
|
||||||
}
|
}
|
||||||
|
|||||||
-4
@@ -23,10 +23,6 @@ abstract class AbstractFirTreeBuilder {
|
|||||||
"Element",
|
"Element",
|
||||||
Element.Kind.Other
|
Element.Kind.Other
|
||||||
)
|
)
|
||||||
|
|
||||||
const val string = "String"
|
|
||||||
const val boolean = "Boolean"
|
|
||||||
const val int = "Int"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val elements = mutableListOf(baseFirElement)
|
val elements = mutableListOf(baseFirElement)
|
||||||
|
|||||||
+5
-11
@@ -5,19 +5,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.tree.generator.model
|
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.NamedTypeParameterRef
|
||||||
|
import org.jetbrains.kotlin.generators.tree.StandardTypes
|
||||||
import org.jetbrains.kotlin.generators.tree.TypeRef
|
import org.jetbrains.kotlin.generators.tree.TypeRef
|
||||||
|
import org.jetbrains.kotlin.generators.tree.typeWithArguments
|
||||||
|
|
||||||
// ----------- Simple field -----------
|
// ----------- 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 {
|
fun field(name: String, type: TypeRef, nullable: Boolean = false, withReplace: Boolean = false): Field {
|
||||||
return SimpleField(name, type.typeWithArguments, type.packageName, null, nullable, withReplace)
|
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 {
|
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 {
|
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 {
|
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 -----------
|
// ----------- Fir field -----------
|
||||||
|
|||||||
+4
@@ -6,5 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.generators.tree
|
package org.jetbrains.kotlin.generators.tree
|
||||||
|
|
||||||
object StandardTypes {
|
object StandardTypes {
|
||||||
|
val boolean = type<Boolean>()
|
||||||
|
val string = type<String>()
|
||||||
|
val int = type<Int>()
|
||||||
|
val collection = type<Collection<*>>()
|
||||||
val map = type<Map<*, *>>()
|
val map = type<Map<*, *>>()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user