[IR] Remove DeclarationDescriptor from IrExpression* tree API

This commit is contained in:
Roman Artemev
2019-10-22 19:28:17 +03:00
committed by romanart
parent d4fc7fcd96
commit ed79ab68ab
39 changed files with 65 additions and 129 deletions
@@ -16,21 +16,15 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
import org.jetbrains.kotlin.ir.symbols.*
interface IrCallableReference : IrMemberAccessExpression {
}
interface IrCallableReference : IrMemberAccessExpression
interface IrFunctionReference : IrCallableReference {
override val descriptor: FunctionDescriptor
override val symbol: IrFunctionSymbol
}
interface IrPropertyReference : IrCallableReference {
override val descriptor: PropertyDescriptor
override val symbol: IrPropertySymbol
val field: IrFieldSymbol?
val getter: IrSimpleFunctionSymbol?
@@ -38,7 +32,6 @@ interface IrPropertyReference : IrCallableReference {
}
interface IrLocalDelegatedPropertyReference : IrCallableReference {
override val descriptor: VariableDescriptorWithAccessors
override val symbol: IrLocalDelegatedPropertySymbol
val delegate: IrVariableSymbol
val getter: IrSimpleFunctionSymbol
@@ -16,13 +16,11 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.types.IrType
interface IrClassReference : IrDeclarationReference {
override val descriptor: ClassifierDescriptor
override val symbol: IrClassifierSymbol
val classType: IrType
}
@@ -5,12 +5,10 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
import org.jetbrains.kotlin.ir.types.IrType
interface IrConstructorCall : IrFunctionAccessExpression {
override val descriptor: ClassConstructorDescriptor
override val symbol: IrConstructorSymbol
val constructorTypeArgumentsCount: Int
@@ -16,21 +16,16 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.ir.symbols.IrSymbol
interface IrDeclarationReference : IrExpression {
val descriptor: DeclarationDescriptor
val symbol: IrSymbol
}
interface IrGetSingletonValue : IrDeclarationReference {
override val descriptor: ClassDescriptor
}
interface IrGetSingletonValue : IrDeclarationReference
interface IrGetObjectValue : IrGetSingletonValue {
override val symbol: IrClassSymbol
@@ -16,11 +16,9 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
interface IrDelegatingConstructorCall : IrFunctionAccessExpression {
override val descriptor: ClassConstructorDescriptor
override val symbol: IrConstructorSymbol
}
@@ -16,11 +16,9 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
interface IrEnumConstructorCall : IrFunctionAccessExpression {
override val descriptor: ClassConstructorDescriptor
override val symbol: IrConstructorSymbol
}
@@ -16,16 +16,12 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
interface IrFieldAccessExpression : IrDeclarationReference {
override val descriptor: PropertyDescriptor
override val symbol: IrFieldSymbol
val superQualifier: ClassDescriptor?
val superQualifierSymbol: IrClassSymbol?
var receiver: IrExpression?
@@ -19,7 +19,6 @@ interface IrMemberAccessExpression : IrExpression, IrDeclarationReference {
var dispatchReceiver: IrExpression?
var extensionReceiver: IrExpression?
override val descriptor: CallableDescriptor
override val symbol: IrSymbol
val origin: IrStatementOrigin?
@@ -67,7 +66,6 @@ fun IrMemberAccessExpression.getTypeArgumentOrDefault(irTypeParameter: IrTypePar
getTypeArgument(irTypeParameter.index) ?: irTypeParameter.defaultType
interface IrFunctionAccessExpression : IrMemberAccessExpression {
override val descriptor: FunctionDescriptor
override val symbol: IrFunctionSymbol
}
@@ -84,6 +82,7 @@ fun IrMemberAccessExpression.removeValueArgument(valueParameterDescriptor: Value
inline fun <T : IrMemberAccessExpression> T.mapTypeParameters(transform: (TypeParameterDescriptor) -> IrType) : T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.typeParameters.forEach {
putTypeArgument(it.index, transform(it))
}
@@ -91,6 +90,7 @@ inline fun <T : IrMemberAccessExpression> T.mapTypeParameters(transform: (TypePa
inline fun <T : IrMemberAccessExpression> T.mapValueParameters(transform: (ValueParameterDescriptor) -> IrExpression?): T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.valueParameters.forEach {
putValueArgument(it.index, transform(it))
}
@@ -98,6 +98,7 @@ inline fun <T : IrMemberAccessExpression> T.mapValueParameters(transform: (Value
inline fun <T : IrMemberAccessExpression> T.mapValueParametersIndexed(transform: (Int, ValueParameterDescriptor) -> IrExpression?): T =
apply {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.valueParameters.forEach {
putValueArgument(it.index, transform(it.index, it))
}
@@ -16,13 +16,10 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.descriptors.ValueDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
interface IrValueAccessExpression : IrDeclarationReference {
override val descriptor: ValueDescriptor
override val symbol: IrValueSymbol
val origin: IrStatementOrigin?
}
@@ -32,7 +29,6 @@ interface IrGetValue : IrValueAccessExpression, IrExpressionWithCopy {
}
interface IrSetVariable : IrValueAccessExpression {
override val descriptor: VariableDescriptor
override val symbol: IrVariableSymbol
var value: IrExpression
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
@@ -50,8 +49,6 @@ class IrCallImpl(
}
}
override val descriptor: FunctionDescriptor get() = symbol.descriptor
constructor(
startOffset: Int,
endOffset: Int,
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.ir.expressions.IrClassReference
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.types.IrType
@@ -28,14 +27,7 @@ class IrClassReferenceImpl(
type: IrType,
symbol: IrClassifierSymbol,
override val classType: IrType
) :
IrTerminalDeclarationReferenceBase<IrClassifierSymbol, ClassifierDescriptor>(
startOffset, endOffset, type,
symbol, symbol.descriptor
),
IrClassReference {
override val descriptor: ClassifierDescriptor get() = symbol.descriptor
) : IrTerminalDeclarationReferenceBase<IrClassifierSymbol>(startOffset, endOffset, type, symbol), IrClassReference {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitClassReference(this, data)
@@ -30,8 +30,6 @@ class IrConstructorCallImpl(
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitConstructorCall(this, data)
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
companion object {
fun fromSymbolDescriptor(
@@ -16,17 +16,15 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrType
abstract class IrDeclarationReferenceBase<out S : IrSymbol, out D : DeclarationDescriptor>(
abstract class IrDeclarationReferenceBase<out S : IrSymbol>(
startOffset: Int,
endOffset: Int,
type: IrType,
override val symbol: S,
override val descriptor: D
override val symbol: S
) :
IrExpressionBase(startOffset, endOffset, type),
IrDeclarationReference
@@ -55,8 +55,6 @@ class IrDelegatingConstructorCallImpl(
typeArgumentsCount: Int
) : this(startOffset, endOffset, type, symbol, typeArgumentsCount, symbol.descriptor.valueParameters.size)
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitDelegatingConstructorCall(this, data)
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.ir.expressions.IrEnumConstructorCall
import org.jetbrains.kotlin.ir.expressions.typeParametersCount
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
@@ -55,8 +54,6 @@ class IrEnumConstructorCallImpl(
typeArgumentsCount: Int
) : this(startOffset, endOffset, type, symbol, typeArgumentsCount, symbol.descriptor.valueParameters.size)
override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitEnumConstructorCall(this, data)
}
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrFieldAccessExpression
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
@@ -35,8 +33,5 @@ abstract class IrFieldExpressionBase(
IrExpressionBase(startOffset, endOffset, type),
IrFieldAccessExpression {
override val descriptor: PropertyDescriptor get() = symbol.descriptor
override val superQualifier: ClassDescriptor? get() = superQualifierSymbol?.descriptor
final override var receiver: IrExpression? = null
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
@@ -51,8 +50,6 @@ class IrFunctionReferenceImpl(
origin: IrStatementOrigin? = null
) : this(startOffset, endOffset, type, symbol, typeArgumentsCount, symbol.descriptor.valueParameters.size, origin)
override val descriptor: FunctionDescriptor get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitFunctionReference(this, data)
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
import org.jetbrains.kotlin.ir.types.IrType
@@ -27,9 +26,7 @@ class IrGetEnumValueImpl(
endOffset: Int,
type: IrType,
symbol: IrEnumEntrySymbol
) :
IrTerminalDeclarationReferenceBase<IrEnumEntrySymbol, ClassDescriptor>(startOffset, endOffset, type, symbol, symbol.descriptor),
IrGetEnumValue {
) : IrTerminalDeclarationReferenceBase<IrEnumEntrySymbol>(startOffset, endOffset, type, symbol), IrGetEnumValue {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
return visitor.visitGetEnumValue(this, data)
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.ir.expressions.IrGetObjectValue
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.IrType
@@ -27,9 +26,7 @@ class IrGetObjectValueImpl(
endOffset: Int,
type: IrType,
symbol: IrClassSymbol
) :
IrTerminalDeclarationReferenceBase<IrClassSymbol, ClassDescriptor>(startOffset, endOffset, type, symbol, symbol.descriptor),
IrGetObjectValue {
) : IrTerminalDeclarationReferenceBase<IrClassSymbol>(startOffset, endOffset, type, symbol), IrGetObjectValue {
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitGetObjectValue(this, data)
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.ValueDescriptor
import org.jetbrains.kotlin.ir.expressions.IrGetValue
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
@@ -19,12 +18,11 @@ class IrGetValueImpl(
symbol: IrValueSymbol,
override val origin: IrStatementOrigin? = null
) :
IrTerminalDeclarationReferenceBase<IrValueSymbol, ValueDescriptor>(
IrTerminalDeclarationReferenceBase<IrValueSymbol>(
startOffset,
endOffset,
type,
symbol,
symbol.descriptor
symbol
),
IrGetValue {
@@ -38,9 +38,6 @@ class IrLocalDelegatedPropertyReferenceImpl(
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, 0, origin),
IrLocalDelegatedPropertyReference {
override val descriptor: VariableDescriptorWithAccessors
get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitLocalDelegatedPropertyReference(this, data)
}
@@ -32,7 +32,7 @@ abstract class IrNoArgumentsCallableReferenceBase(
IrCallableReference {
private fun throwNoValueArguments(): Nothing {
throw UnsupportedOperationException("Property reference $descriptor has no value arguments")
throw UnsupportedOperationException("Property reference ${symbol.descriptor} has no value arguments")
}
override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments()
@@ -57,8 +57,6 @@ class IrPropertyReferenceImpl(
typeArgumentsCount, field, getter, setter, origin
)
override val descriptor: PropertyDescriptor get() = symbol.descriptor
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
visitor.visitPropertyReference(this, data)
}
@@ -46,8 +46,6 @@ class IrSetVariableImpl(
this.value = value
}
override val descriptor: VariableDescriptor get() = symbol.descriptor
override lateinit var value: IrExpression
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
@@ -16,21 +16,19 @@
package org.jetbrains.kotlin.ir.expressions.impl
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
abstract class IrTerminalDeclarationReferenceBase<out S : IrSymbol, out D : DeclarationDescriptor>(
abstract class IrTerminalDeclarationReferenceBase<out S : IrSymbol>(
startOffset: Int,
endOffset: Int,
type: IrType,
symbol: S,
descriptor: D
symbol: S
) :
IrDeclarationReferenceBase<S, D>(startOffset, endOffset, type, symbol, descriptor),
IrDeclarationReferenceBase<S>(startOffset, endOffset, type, symbol),
IrDeclarationReference {
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.utils.DFS
*/
fun IrMemberAccessExpression.getArguments(): List<Pair<ParameterDescriptor, IrExpression>> {
val res = mutableListOf<Pair<ParameterDescriptor, IrExpression>>()
val descriptor = descriptor
val descriptor = symbol.descriptor as CallableDescriptor
// TODO: ensure the order below corresponds to the one defined in Kotlin specs.
@@ -119,6 +119,7 @@ fun IrMemberAccessExpression.getArgumentsWithIr(): List<Pair<IrValueParameter, I
* Sets arguments that are specified by given mapping of parameters.
*/
fun IrMemberAccessExpression.addArguments(args: Map<ParameterDescriptor, IrExpression>) {
val descriptor = symbol.descriptor as CallableDescriptor
descriptor.dispatchReceiverParameter?.let {
val arg = args[it]
if (arg != null) {
@@ -177,7 +178,7 @@ fun IrExpression.coerceToUnitIfNeeded(valueType: IrType, irBuiltIns: IrBuiltIns)
}
fun IrMemberAccessExpression.usesDefaultArguments(): Boolean =
this.descriptor.valueParameters.any { this.getValueArgument(it) == null }
(symbol.descriptor as CallableDescriptor).valueParameters.any { this.getValueArgument(it) == null }
val DeclarationDescriptorWithSource.startOffset: Int? get() = (this.source as? PsiSourceElement)?.psi?.startOffset
val DeclarationDescriptorWithSource.endOffset: Int? get() = (this.source as? PsiSourceElement)?.psi?.endOffset
@@ -383,7 +384,7 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean {
fun IrFunction.effectiveParentDeclaration(): IrDeclaration? =
when (this) {
is IrSimpleFunction -> correspondingProperty ?: parent as? IrDeclaration
is IrSimpleFunction -> correspondingPropertySymbol?.owner ?: parent as? IrDeclaration
else -> parent as? IrDeclaration
}