[IR] Move IrValueDeclaration.isAssignable to extension property
to remove custom logic from generated classes, in particular to simplify source generator itself.
This commit is contained in:
committed by
Space Team
parent
ddcef6396e
commit
5e9c3025bb
+2
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.expressions.IrSetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrSetValueImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.util.isAssignable
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
|
||||
abstract class AbstractValueRemapper : IrElementTransformerVoid() {
|
||||
|
||||
@@ -23,6 +23,4 @@ interface IrValueDeclaration : IrDeclarationWithName, IrSymbolOwner {
|
||||
override val symbol: IrValueSymbol
|
||||
|
||||
var type: IrType
|
||||
|
||||
val isAssignable: Boolean
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ abstract class IrValueParameter : IrDeclarationBase(), IrValueDeclaration {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
abstract override val descriptor: ParameterDescriptor
|
||||
|
||||
abstract val isAssignable: Boolean
|
||||
|
||||
abstract override val symbol: IrValueParameterSymbol
|
||||
|
||||
abstract var index: Int
|
||||
|
||||
@@ -11,7 +11,6 @@ package org.jetbrains.kotlin.ir.declarations
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrSetValue
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
@@ -33,14 +32,6 @@ abstract class IrVariable : IrDeclarationBase(), IrValueDeclaration {
|
||||
|
||||
abstract var initializer: IrExpression?
|
||||
|
||||
/**
|
||||
* Variables are assignable by default. This means that they can be used in [IrSetValue].
|
||||
* Variables are assigned in the IR even though they are not 'var' in the input. Hence
|
||||
* the separate assignability flag.
|
||||
*/
|
||||
override val isAssignable: Boolean
|
||||
get() = true
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitVariable(this, data)
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.IrElementConstructorIndicator
|
||||
import org.jetbrains.kotlin.ir.util.isAssignable
|
||||
|
||||
class IrSetValueImpl internal constructor(
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2024 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.
|
||||
*/
|
||||
|
||||
@@ -1590,4 +1590,14 @@ fun IrElement.sourceElement(): AbstractKtSourceElement? =
|
||||
else null
|
||||
|
||||
fun IrFunction.isTopLevelInPackage(name: String, packageFqName: FqName) =
|
||||
this.name.asString() == name && parent.kotlinFqName == packageFqName
|
||||
this.name.asString() == name && parent.kotlinFqName == packageFqName
|
||||
|
||||
val IrValueDeclaration.isAssignable: Boolean
|
||||
get() = when (this) {
|
||||
is IrValueParameter -> isAssignable
|
||||
// Variables are assignable by default. This means that they can be used in [IrSetValue].
|
||||
// Variables are assigned in the IR even though they are not 'var' in the input. Hence
|
||||
// the separate assignability flag.
|
||||
is IrVariable -> true
|
||||
else -> error("Unexpected IrValueDeclaration class $this")
|
||||
}
|
||||
@@ -194,7 +194,6 @@ object IrTree : AbstractTreeBuilder() {
|
||||
+descriptor("ValueDescriptor")
|
||||
+symbol(valueSymbolType)
|
||||
+field("type", irTypeType)
|
||||
+field("isAssignable", boolean, mutable = false)
|
||||
}
|
||||
val valueParameter: Element by element(Declaration) {
|
||||
needTransformMethod()
|
||||
@@ -203,6 +202,7 @@ object IrTree : AbstractTreeBuilder() {
|
||||
parent(valueDeclaration)
|
||||
|
||||
+descriptor("ParameterDescriptor")
|
||||
+field("isAssignable", boolean, mutable = false)
|
||||
+symbol(valueParameterSymbolType)
|
||||
+field("index", int)
|
||||
+field("varargElementType", irTypeType, nullable = true)
|
||||
@@ -597,16 +597,6 @@ object IrTree : AbstractTreeBuilder() {
|
||||
+field("isConst", boolean)
|
||||
+field("isLateinit", boolean)
|
||||
+field("initializer", expression, nullable = true)
|
||||
+field("isAssignable", boolean, mutable = false) {
|
||||
defaultValueInBase = "true"
|
||||
withGetter = true
|
||||
additionalImports.add(setValue)
|
||||
kDoc = """
|
||||
Variables are assignable by default. This means that they can be used in [${setValue.typeName}].
|
||||
Variables are assigned in the IR even though they are not 'var' in the input. Hence
|
||||
the separate assignability flag.
|
||||
""".trimIndent()
|
||||
}
|
||||
}
|
||||
val packageFragment: Element by element(Declaration) {
|
||||
ownsChildren = false
|
||||
|
||||
Reference in New Issue
Block a user