IR: make IrMemberAccessExpression and subtypes classes
Merge IrMemberAccessExpressionBase into IrMemberAccessExpression, and IrCallWithIndexedArgumentsBase into IrFunctionAccessExpression (extract the latter into a separate file).
This commit is contained in:
@@ -18,6 +18,9 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
|
||||
interface IrCall : IrFunctionAccessExpression {
|
||||
val superQualifierSymbol: IrClassSymbol?
|
||||
abstract class IrCall(
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
) : IrFunctionAccessExpression(typeArgumentsCount, valueArgumentsCount) {
|
||||
abstract val superQualifierSymbol: IrClassSymbol?
|
||||
}
|
||||
|
||||
+18
-12
@@ -19,12 +19,12 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
interface IrCallableReference<S : IrSymbol> : IrMemberAccessExpression<S> {
|
||||
val referencedName: Name
|
||||
abstract class IrCallableReference<S : IrSymbol>(typeArgumentsCount: Int) : IrMemberAccessExpression<S>(typeArgumentsCount) {
|
||||
abstract val referencedName: Name
|
||||
}
|
||||
|
||||
interface IrFunctionReference : IrCallableReference<IrFunctionSymbol> {
|
||||
val reflectionTarget: IrFunctionSymbol?
|
||||
abstract class IrFunctionReference(typeArgumentsCount: Int) : IrCallableReference<IrFunctionSymbol>(typeArgumentsCount) {
|
||||
abstract val reflectionTarget: IrFunctionSymbol?
|
||||
}
|
||||
|
||||
val IrFunctionReference.isWithReflection: Boolean
|
||||
@@ -33,14 +33,20 @@ val IrFunctionReference.isWithReflection: Boolean
|
||||
val IrFunctionReference.isAdapterWithReflection: Boolean
|
||||
get() = reflectionTarget != null && reflectionTarget != symbol
|
||||
|
||||
interface IrPropertyReference : IrCallableReference<IrPropertySymbol> {
|
||||
val field: IrFieldSymbol?
|
||||
val getter: IrSimpleFunctionSymbol?
|
||||
val setter: IrSimpleFunctionSymbol?
|
||||
abstract class IrPropertyReference(typeArgumentsCount: Int) : IrCallableReference<IrPropertySymbol>(typeArgumentsCount) {
|
||||
abstract val field: IrFieldSymbol?
|
||||
abstract val getter: IrSimpleFunctionSymbol?
|
||||
abstract val setter: IrSimpleFunctionSymbol?
|
||||
|
||||
override val valueArgumentsCount: Int
|
||||
get() = 0
|
||||
}
|
||||
|
||||
interface IrLocalDelegatedPropertyReference : IrCallableReference<IrLocalDelegatedPropertySymbol> {
|
||||
val delegate: IrVariableSymbol
|
||||
val getter: IrSimpleFunctionSymbol
|
||||
val setter: IrSimpleFunctionSymbol?
|
||||
abstract class IrLocalDelegatedPropertyReference : IrCallableReference<IrLocalDelegatedPropertySymbol>(0) {
|
||||
abstract val delegate: IrVariableSymbol
|
||||
abstract val getter: IrSimpleFunctionSymbol
|
||||
abstract val setter: IrSimpleFunctionSymbol?
|
||||
|
||||
override val valueArgumentsCount: Int
|
||||
get() = 0
|
||||
}
|
||||
|
||||
@@ -8,10 +8,13 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
|
||||
interface IrConstructorCall : IrFunctionAccessExpression {
|
||||
override val symbol: IrConstructorSymbol
|
||||
abstract class IrConstructorCall(
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
) : IrFunctionAccessExpression(typeArgumentsCount, valueArgumentsCount) {
|
||||
abstract override val symbol: IrConstructorSymbol
|
||||
|
||||
val constructorTypeArgumentsCount: Int
|
||||
abstract val constructorTypeArgumentsCount: Int
|
||||
|
||||
class ConstructorTypeArguments(internal val irConstructorCall: IrConstructorCall) : AbstractList<IrType?>() {
|
||||
override val size: Int
|
||||
@@ -76,4 +79,4 @@ var IrConstructorCall.outerClassReceiver: IrExpression?
|
||||
get() = dispatchReceiver
|
||||
set(value) {
|
||||
dispatchReceiver = value
|
||||
}
|
||||
}
|
||||
|
||||
+5
-3
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
|
||||
interface IrDelegatingConstructorCall : IrFunctionAccessExpression {
|
||||
override val symbol: IrConstructorSymbol
|
||||
abstract class IrDelegatingConstructorCall(
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
) : IrFunctionAccessExpression(typeArgumentsCount, valueArgumentsCount) {
|
||||
abstract override val symbol: IrConstructorSymbol
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -18,7 +18,9 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
|
||||
|
||||
interface IrEnumConstructorCall : IrFunctionAccessExpression {
|
||||
override val symbol: IrConstructorSymbol
|
||||
abstract class IrEnumConstructorCall(
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
) : IrFunctionAccessExpression(typeArgumentsCount, valueArgumentsCount) {
|
||||
abstract override val symbol: IrConstructorSymbol
|
||||
}
|
||||
|
||||
+9
-17
@@ -1,30 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* Copyright 2010-2020 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.expressions.impl
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
|
||||
abstract class IrCallWithIndexedArgumentsBase(
|
||||
abstract class IrFunctionAccessExpression(
|
||||
typeArgumentsCount: Int,
|
||||
final override val valueArgumentsCount: Int,
|
||||
) : IrMemberAccessExpressionBase<IrFunctionSymbol>(typeArgumentsCount) {
|
||||
) : IrMemberAccessExpression<IrFunctionSymbol>(typeArgumentsCount) {
|
||||
private val argumentsByParameterIndex: Array<IrExpression?> = arrayOfNulls(valueArgumentsCount)
|
||||
|
||||
override fun getValueArgument(index: Int): IrExpression? {
|
||||
@@ -57,3 +46,6 @@ abstract class IrCallWithIndexedArgumentsBase(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun IrFunctionAccessExpression.putArgument(parameter: IrValueParameter, argument: IrExpression) =
|
||||
putArgument(symbol.owner, parameter, argument)
|
||||
+46
-22
@@ -5,33 +5,62 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBase
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
interface IrMemberAccessExpression<S : IrSymbol> : IrDeclarationReference {
|
||||
var dispatchReceiver: IrExpression?
|
||||
var extensionReceiver: IrExpression?
|
||||
|
||||
override val symbol: S
|
||||
|
||||
val origin: IrStatementOrigin?
|
||||
|
||||
abstract class IrMemberAccessExpression<S : IrSymbol>(
|
||||
val typeArgumentsCount: Int
|
||||
fun getTypeArgument(index: Int): IrType?
|
||||
fun putTypeArgument(index: Int, type: IrType?)
|
||||
) : IrExpressionBase(), IrDeclarationReference {
|
||||
var dispatchReceiver: IrExpression? = null
|
||||
var extensionReceiver: IrExpression? = null
|
||||
|
||||
val valueArgumentsCount: Int
|
||||
fun getValueArgument(index: Int): IrExpression?
|
||||
fun putValueArgument(index: Int, valueArgument: IrExpression?)
|
||||
fun removeValueArgument(index: Int)
|
||||
abstract override val symbol: S
|
||||
|
||||
abstract val origin: IrStatementOrigin?
|
||||
abstract val valueArgumentsCount: Int
|
||||
|
||||
abstract fun getValueArgument(index: Int): IrExpression?
|
||||
abstract fun putValueArgument(index: Int, valueArgument: IrExpression?)
|
||||
abstract fun removeValueArgument(index: Int)
|
||||
|
||||
private val typeArgumentsByIndex = arrayOfNulls<IrType>(typeArgumentsCount)
|
||||
|
||||
fun getTypeArgument(index: Int): IrType? {
|
||||
if (index >= typeArgumentsCount) {
|
||||
throw AssertionError("$this: No such type argument slot: $index")
|
||||
}
|
||||
return typeArgumentsByIndex[index]
|
||||
}
|
||||
|
||||
fun putTypeArgument(index: Int, type: IrType?) {
|
||||
if (index >= typeArgumentsCount) {
|
||||
throw AssertionError("$this: No such type argument slot: $index")
|
||||
}
|
||||
typeArgumentsByIndex[index] = type
|
||||
}
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
dispatchReceiver?.accept(visitor, data)
|
||||
extensionReceiver?.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
dispatchReceiver = dispatchReceiver?.transform(transformer, data)
|
||||
extensionReceiver = extensionReceiver?.transform(transformer, data)
|
||||
}
|
||||
}
|
||||
|
||||
fun IrMemberAccessExpression<*>.getTypeArgument(typeParameterDescriptor: TypeParameterDescriptor): IrType? =
|
||||
@@ -66,8 +95,6 @@ val CallableDescriptor.typeParametersCount: Int
|
||||
fun IrMemberAccessExpression<*>.getTypeArgumentOrDefault(irTypeParameter: IrTypeParameter) =
|
||||
getTypeArgument(irTypeParameter.index) ?: irTypeParameter.defaultType
|
||||
|
||||
interface IrFunctionAccessExpression : IrMemberAccessExpression<IrFunctionSymbol>
|
||||
|
||||
fun IrMemberAccessExpression<*>.getValueArgument(valueParameterDescriptor: ValueParameterDescriptor) =
|
||||
getValueArgument(valueParameterDescriptor.index)
|
||||
|
||||
@@ -112,6 +139,3 @@ fun IrMemberAccessExpression<*>.putArgument(callee: IrFunction, parameter: IrVal
|
||||
callee.extensionReceiverParameter -> extensionReceiver = argument
|
||||
else -> putValueArgument(parameter.index, argument)
|
||||
}
|
||||
|
||||
fun IrFunctionAccessExpression.putArgument(parameter: IrValueParameter, argument: IrExpression) =
|
||||
putArgument(symbol.owner, parameter, argument)
|
||||
|
||||
@@ -36,7 +36,7 @@ class IrCallImpl(
|
||||
valueArgumentsCount: Int,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
override val superQualifierSymbol: IrClassSymbol? = null
|
||||
) : IrCallWithIndexedArgumentsBase(typeArgumentsCount, valueArgumentsCount), IrCall {
|
||||
) : IrCall(typeArgumentsCount, valueArgumentsCount) {
|
||||
init {
|
||||
if (symbol is IrConstructorSymbol) {
|
||||
throw AssertionError("Should be IrConstructorCall: ${this.render()}")
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ class IrConstructorCallImpl(
|
||||
override val constructorTypeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
) : IrCallWithIndexedArgumentsBase(typeArgumentsCount, valueArgumentsCount), IrConstructorCall {
|
||||
) : IrConstructorCall(typeArgumentsCount, valueArgumentsCount) {
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitConstructorCall(this, data)
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class IrDelegatingConstructorCallImpl(
|
||||
override val symbol: IrConstructorSymbol,
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int
|
||||
) : IrCallWithIndexedArgumentsBase(typeArgumentsCount, valueArgumentsCount), IrDelegatingConstructorCall {
|
||||
) : IrDelegatingConstructorCall(typeArgumentsCount, valueArgumentsCount) {
|
||||
override val origin: IrStatementOrigin?
|
||||
get() = null
|
||||
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ class IrEnumConstructorCallImpl(
|
||||
override val symbol: IrConstructorSymbol,
|
||||
typeArgumentsCount: Int,
|
||||
valueArgumentsCount: Int
|
||||
) : IrCallWithIndexedArgumentsBase(typeArgumentsCount, valueArgumentsCount), IrEnumConstructorCall {
|
||||
) : IrEnumConstructorCall(typeArgumentsCount, valueArgumentsCount) {
|
||||
override val origin: IrStatementOrigin?
|
||||
get() = null
|
||||
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class IrFunctionReferenceImpl(
|
||||
override val valueArgumentsCount: Int,
|
||||
override val reflectionTarget: IrFunctionSymbol? = symbol,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
) : IrMemberAccessExpressionBase<IrFunctionSymbol>(typeArgumentsCount), IrFunctionReference {
|
||||
) : IrFunctionReference(typeArgumentsCount) {
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class IrLocalDelegatedPropertyReferenceImpl(
|
||||
override val getter: IrSimpleFunctionSymbol,
|
||||
override val setter: IrSimpleFunctionSymbol?,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
) : IrMemberAccessExpressionBase<IrLocalDelegatedPropertySymbol>(0), IrLocalDelegatedPropertyReference {
|
||||
) : IrLocalDelegatedPropertyReference() {
|
||||
override val valueArgumentsCount: Int
|
||||
get() = 0
|
||||
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
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 IrMemberAccessExpressionBase<S : IrSymbol>(
|
||||
final override val typeArgumentsCount: Int
|
||||
) : IrExpressionBase(), IrMemberAccessExpression<S> {
|
||||
override var dispatchReceiver: IrExpression? = null
|
||||
override var extensionReceiver: IrExpression? = null
|
||||
|
||||
private val typeArgumentsByIndex = arrayOfNulls<IrType>(typeArgumentsCount)
|
||||
|
||||
override fun getTypeArgument(index: Int): IrType? {
|
||||
if (index >= typeArgumentsCount) {
|
||||
throw AssertionError("$this: No such type argument slot: $index")
|
||||
}
|
||||
return typeArgumentsByIndex[index]
|
||||
}
|
||||
|
||||
override fun putTypeArgument(index: Int, type: IrType?) {
|
||||
if (index >= typeArgumentsCount) {
|
||||
throw AssertionError("$this: No such type argument slot: $index")
|
||||
}
|
||||
typeArgumentsByIndex[index] = type
|
||||
}
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
dispatchReceiver?.accept(visitor, data)
|
||||
extensionReceiver?.accept(visitor, data)
|
||||
}
|
||||
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
dispatchReceiver = dispatchReceiver?.transform(transformer, data)
|
||||
extensionReceiver = extensionReceiver?.transform(transformer, data)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -36,7 +36,7 @@ class IrPropertyReferenceImpl(
|
||||
override val getter: IrSimpleFunctionSymbol?,
|
||||
override val setter: IrSimpleFunctionSymbol?,
|
||||
override val origin: IrStatementOrigin? = null,
|
||||
) : IrMemberAccessExpressionBase<IrPropertySymbol>(typeArgumentsCount), IrPropertyReference {
|
||||
) : IrPropertyReference(typeArgumentsCount) {
|
||||
override val valueArgumentsCount: Int
|
||||
get() = 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user