[IR] Move isAssignable to IrValueDeclaration.

This commit is contained in:
Mads Ager
2020-10-06 18:14:45 +02:00
committed by Alexander Udalov
parent af0999ec6f
commit 3817aa32a1
4 changed files with 9 additions and 19 deletions
@@ -16,4 +16,6 @@ abstract class IrValueDeclaration : IrDeclarationBase(), IrDeclarationWithName,
abstract override val symbol: IrValueSymbol
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.
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?
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -61,6 +61,12 @@ class IrVariableImpl(
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
get() = error("Create IrVariableImpl directly")
@@ -34,21 +34,8 @@ class IrSetValueImpl(
override val origin: IrStatementOrigin?
) : IrSetValue() {
companion object {
private fun isVariableOrAssignable(symbol: IrValueSymbol): Boolean {
val declaration = symbol.owner
return if (declaration is IrValueParameter) {
declaration.isAssignable
} else {
true
}
}
}
init {
assert(isVariableOrAssignable(symbol)) {
"Only IrVariables and assignable IrValueParameters can be set"
}
assert(symbol.owner.isAssignable) { "Only assignable IrValues can be set" }
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {