[FIR/IR generator] Rename field's needAcceptAndTransform to isChild

This better describes the semantics.
This commit is contained in:
Sergej Jaskiewicz
2023-11-29 13:08:00 +01:00
committed by Space Team
parent 02052421e6
commit d0f87f9aba
8 changed files with 37 additions and 35 deletions
@@ -68,7 +68,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
}
default("delegate") {
needAcceptAndTransform = false
isChild = false
}
}
@@ -88,14 +88,14 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(annotationCall) {
commonAnnotationConfig()
default("argumentMapping") {
needAcceptAndTransform = false
isChild = false
}
}
impl(errorAnnotationCall) {
commonAnnotationConfig()
default("argumentMapping") {
needAcceptAndTransform = false
isChild = false
}
default("annotationResolvePhase") {
value = "FirAnnotationResolvePhase.Types"
@@ -513,7 +513,7 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
impl(resolvedTypeRef) {
publicImplementation()
default("delegatedTypeRef") {
needAcceptAndTransform = false
isChild = false
}
}
@@ -127,7 +127,7 @@ class FieldWithDefault(override val origin: Field) : Field(), AbstractFieldWithD
it.isMutable = isMutable
it.withGetter = withGetter
it.fromDelegate = fromDelegate
it.needAcceptAndTransform = needAcceptAndTransform
it.isChild = isChild
}
}
}
@@ -104,8 +104,7 @@ object IrTree : AbstractTreeBuilder() {
+descriptor("DeclarationDescriptor")
+field("origin", type(Packages.declarations, "IrDeclarationOrigin"))
+field("parent", declarationParent) {
needAcceptAndTransform = false
+field("parent", declarationParent, isChild = false) {
skipInIrFactory()
}
+factory
@@ -316,13 +315,11 @@ object IrTree : AbstractTreeBuilder() {
idempotence invariant and can contain a chain of declarations.
""".trimIndent()
+field("attributeOwnerId", attributeContainer) {
needAcceptAndTransform = false
+field("attributeOwnerId", attributeContainer, isChild = false) {
skipInIrFactory()
}
// null <=> this element wasn't inlined
+field("originalBeforeInline", attributeContainer, nullable = true) {
needAcceptAndTransform = false
+field("originalBeforeInline", attributeContainer, nullable = true, isChild = false) {
skipInIrFactory()
}
}
@@ -552,9 +549,7 @@ object IrTree : AbstractTreeBuilder() {
+listField("importedScripts", scriptSymbolType, mutability = Var, nullable = true)
+listField("earlierScripts", scriptSymbolType, mutability = Var, nullable = true)
+field("targetClass", classSymbolType, nullable = true)
+field("constructor", constructor, nullable = true) { // K1
needAcceptAndTransform = false
}
+field("constructor", constructor, nullable = true, isChild = false) // K1
}
val simpleFunction: Element by element(Declaration) {
isLeaf = true
@@ -645,9 +640,7 @@ object IrTree : AbstractTreeBuilder() {
parent(metadataSourceOwner)
+symbol(fileSymbolType)
+field("module", moduleFragment) {
needAcceptAndTransform = false
}
+field("module", moduleFragment, isChild = false)
+field("fileEntry", type(Packages.tree, "IrFileEntry"))
}
@@ -659,13 +652,11 @@ object IrTree : AbstractTreeBuilder() {
parent(varargElement)
parent(attributeContainer)
+field("attributeOwnerId", attributeContainer) {
needAcceptAndTransform = false
+field("attributeOwnerId", attributeContainer, isChild = false) {
baseDefaultValue = "this"
skipInIrFactory()
}
+field("originalBeforeInline", attributeContainer, nullable = true) {
needAcceptAndTransform = false
+field("originalBeforeInline", attributeContainer, nullable = true, isChild = false) {
baseDefaultValue = "null"
skipInIrFactory()
}
@@ -884,9 +875,7 @@ object IrTree : AbstractTreeBuilder() {
parent(expression)
+field("loop", loop) {
needAcceptAndTransform = false
}
+field("loop", loop, isChild = false)
+field("label", string, nullable = true) {
baseDefaultValue = "null"
}
@@ -75,9 +75,13 @@ abstract class AbstractTreeBuilder {
type: TypeRefWithNullability,
nullable: Boolean = false,
mutable: Boolean = true,
isChild: Boolean = true,
initializer: SingleField.() -> Unit = {}
): SingleField {
return SingleField(name, type.copy(nullable), mutable).apply(initializer)
return SingleField(name, type.copy(nullable), mutable).apply {
this.isChild = isChild
initializer()
}
}
protected fun listField(
@@ -85,6 +89,7 @@ abstract class AbstractTreeBuilder {
baseType: TypeRef,
nullable: Boolean = false,
mutability: ListField.Mutability,
isChild: Boolean = true,
initializer: ListField.() -> Unit = {}
): ListField {
val listType = when (mutability) {
@@ -98,7 +103,10 @@ abstract class AbstractTreeBuilder {
listType = listType,
isNullable = nullable,
mutable = mutability == ListField.Mutability.Var,
).apply(initializer)
).apply(initializer).apply {
this.isChild = isChild
initializer()
}
}
fun build(): Model {
@@ -158,7 +158,7 @@ sealed class Field(
val useInIrFactoryStrategy: UseFieldAsParameterInIrFactoryStrategy
get() = customUseInIrFactoryStrategy
?: if (needAcceptAndTransform && containsElement) {
?: if (isChild && containsElement) {
UseFieldAsParameterInIrFactoryStrategy.No
} else {
UseFieldAsParameterInIrFactoryStrategy.Yes(null)
@@ -57,11 +57,14 @@ abstract class AbstractField<Field : AbstractField<Field>> {
var useInBaseTransformerDetection = true
/**
* Whether a visitor should be run on this field in the generated `acceptChildren` in `transformChildren` method.
* Whether this field semantically represents a reference to a child node of the tree.
*
* This may have the effect of including or excluding this field from visiting it by visitors in the generated
* `acceptChildren` and `transformChildren` methods (child fields are always visited in those methods).
*
* Only has effect if [containsElement] is `true`.
*/
var needAcceptAndTransform: Boolean = true
var isChild: Boolean = true
open val overriddenTypes: MutableSet<TypeRefWithNullability> = mutableSetOf()
@@ -103,7 +106,7 @@ abstract class AbstractField<Field : AbstractField<Field>> {
copy.visibility = visibility
copy.fromParent = fromParent
copy.useInBaseTransformerDetection = useInBaseTransformerDetection
copy.needAcceptAndTransform = needAcceptAndTransform
copy.isChild = isChild
copy.overriddenTypes += overriddenTypes
}
}
@@ -37,7 +37,7 @@ interface FieldContainer<out Field : AbstractField<*>> {
*/
val walkableChildren: List<Field>
get() = allFields
.filter { it.containsElement && !it.withGetter && it.needAcceptAndTransform }
.filter { it.containsElement && !it.withGetter && it.isChild }
.reorderFieldsIfNecessary(childrenOrderOverride)
/**
@@ -378,16 +378,18 @@ abstract class AbstractImplementationConfigurator<Implementation, Element, Imple
}
/**
* Allows to exclude this field from visiting it by visitors in the generated `acceptChildren` and `transformChildren`
* methods.
* Whether this field semantically represents a reference to a child node of the tree.
*
* This has the effect of including or excluding this field from visiting it by visitors in the generated
* `acceptChildren` and `transformChildren` methods (child fields are always visited in those methods)
*/
var needAcceptAndTransform: Boolean = true
var isChild: Boolean = true
fun applyConfiguration() {
field.withGetter = withGetter
field.customSetter = customSetter
isMutable?.let { field.isMutable = it }
field.needAcceptAndTransform = needAcceptAndTransform
field.isChild = isChild
when {
value != null -> field.defaultValueInImplementation = value