[IR] Move isAssignable to IrValueDeclaration.
This commit is contained in:
committed by
Alexander Udalov
parent
af0999ec6f
commit
3817aa32a1
@@ -16,4 +16,6 @@ abstract class IrValueDeclaration : IrDeclarationBase(), IrDeclarationWithName,
|
|||||||
|
|
||||||
abstract override val symbol: IrValueSymbol
|
abstract override val symbol: IrValueSymbol
|
||||||
abstract var type: IrType
|
abstract var type: IrType
|
||||||
|
|
||||||
|
abstract val isAssignable: Boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,11 +39,6 @@ abstract class IrValueParameter : IrValueDeclaration(), IrSymbolDeclaration<IrVa
|
|||||||
// Once we are able to load any top-level declaration from klib this hack should be deprecated and removed.
|
// Once we are able to load any top-level declaration from klib this hack should be deprecated and removed.
|
||||||
abstract val isHidden: Boolean
|
abstract val isHidden: Boolean
|
||||||
|
|
||||||
// Parameters are not assignable by default. However, in the IR, assignments to parameters are used
|
|
||||||
// to implement default argument stubs. If the default value is to be used, the value is assigned
|
|
||||||
// to the parameter.
|
|
||||||
abstract val isAssignable: Boolean
|
|
||||||
|
|
||||||
abstract var defaultValue: IrExpressionBody?
|
abstract var defaultValue: IrExpressionBody?
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ class IrVariableImpl(
|
|||||||
|
|
||||||
override var initializer: IrExpression? = null
|
override var initializer: IrExpression? = null
|
||||||
|
|
||||||
|
// 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 val factory: IrFactory
|
override val factory: IrFactory
|
||||||
get() = error("Create IrVariableImpl directly")
|
get() = error("Create IrVariableImpl directly")
|
||||||
|
|
||||||
|
|||||||
@@ -34,21 +34,8 @@ class IrSetValueImpl(
|
|||||||
override val origin: IrStatementOrigin?
|
override val origin: IrStatementOrigin?
|
||||||
) : IrSetValue() {
|
) : IrSetValue() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private fun isVariableOrAssignable(symbol: IrValueSymbol): Boolean {
|
|
||||||
val declaration = symbol.owner
|
|
||||||
return if (declaration is IrValueParameter) {
|
|
||||||
declaration.isAssignable
|
|
||||||
} else {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
assert(isVariableOrAssignable(symbol)) {
|
assert(symbol.owner.isAssignable) { "Only assignable IrValues can be set" }
|
||||||
"Only IrVariables and assignable IrValueParameters can be set"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||||
|
|||||||
Reference in New Issue
Block a user