Local delegated properties implementation + some more fixes
This commit is contained in:
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.kotlin.ir.declarations
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||
|
||||
interface IrClass : IrSymbolDeclaration<IrClassSymbol>, IrDeclarationContainer, IrTypeParametersContainer {
|
||||
|
||||
@@ -29,6 +29,7 @@ interface IrDeclarationOrigin {
|
||||
object LOCAL_FUNCTION_FOR_LAMBDA : IrDeclarationOriginImpl("LOCAL_FUNCTION_FOR_LAMBDA")
|
||||
object CATCH_PARAMETER : IrDeclarationOriginImpl("CATCH_PARAMETER")
|
||||
object NEW_INSTANCE_RECEIVER : IrDeclarationOriginImpl("NEW_INSTANCE_RECEIVER")
|
||||
object PRIMARY_CONSTRUCTOR_PARAMETER : IrDeclarationOriginImpl("PRIMARY_CONSTRUCTOR_PARAMETER")
|
||||
object IR_TEMPORARY_VARIABLE : IrDeclarationOriginImpl("IR_TEMPORARY_VARIABLE")
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.utils.SmartList
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class IrClassImpl(
|
||||
startOffset: Int,
|
||||
@@ -62,6 +63,6 @@ class IrClassImpl(
|
||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||
newInstanceReceiver = newInstanceReceiver?.transform(transformer, data)
|
||||
typeParameters.transform { it.transform(transformer, data) }
|
||||
declarations.transform { it.transform(transformer, data) as IrDeclaration }
|
||||
declarations.transform { it.transform(transformer, data) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,14 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
|
||||
interface IrCallableReference : IrMemberAccessExpression {
|
||||
override val descriptor: CallableMemberDescriptor
|
||||
override val descriptor: CallableDescriptor
|
||||
}
|
||||
|
||||
interface IrFunctionReference : IrCallableReference {
|
||||
@@ -37,3 +36,10 @@ interface IrPropertyReference : IrCallableReference {
|
||||
val getter: IrFunctionSymbol?
|
||||
val setter: IrFunctionSymbol?
|
||||
}
|
||||
|
||||
interface IrLocalDelegatedPropertyReference : IrCallableReference {
|
||||
override val descriptor: VariableDescriptorWithAccessors
|
||||
val delegate: IrVariableSymbol
|
||||
val getter: IrFunctionSymbol
|
||||
val setter: IrFunctionSymbol?
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,7 @@ interface IrMemberAccessExpression : IrExpression {
|
||||
var dispatchReceiver: IrExpression?
|
||||
var extensionReceiver: IrExpression?
|
||||
|
||||
val descriptor: CallableMemberDescriptor
|
||||
val descriptor: CallableDescriptor
|
||||
val origin: IrStatementOrigin?
|
||||
|
||||
// NB `typeParameterDescriptor` should be taken from `descriptor.original`
|
||||
|
||||
+5
-48
@@ -17,31 +17,14 @@
|
||||
package org.jetbrains.kotlin.ir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.expressions.IrFunctionReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
abstract class IrCallableReferenceBase(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
numValueArguments: Int,
|
||||
override val origin: IrStatementOrigin? = null
|
||||
) : IrCallableReference,
|
||||
IrCallWithIndexedArgumentsBase(
|
||||
startOffset, endOffset,
|
||||
type,
|
||||
numValueArguments,
|
||||
typeArguments,
|
||||
origin
|
||||
)
|
||||
|
||||
class IrFunctionReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -50,9 +33,10 @@ class IrFunctionReferenceImpl(
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
origin: IrStatementOrigin? = null
|
||||
) : IrFunctionReference,
|
||||
IrCallableReferenceBase(
|
||||
startOffset, endOffset, type, typeArguments,
|
||||
IrCallWithIndexedArgumentsBase(
|
||||
startOffset, endOffset, type,
|
||||
symbol.descriptor.valueParameters.size,
|
||||
typeArguments,
|
||||
origin
|
||||
)
|
||||
{
|
||||
@@ -70,31 +54,4 @@ class IrFunctionReferenceImpl(
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitFunctionReference(this, data)
|
||||
}
|
||||
|
||||
class IrPropertyReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
override val descriptor: PropertyDescriptor,
|
||||
override val field: IrFieldSymbol?,
|
||||
override val getter: IrFunctionSymbol?,
|
||||
override val setter: IrFunctionSymbol?,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
override val origin: IrStatementOrigin? = null
|
||||
) : IrPropertyReference,
|
||||
IrMemberAccessExpressionBase(startOffset, endOffset, type, typeArguments)
|
||||
{
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitPropertyReference(this, data)
|
||||
|
||||
private fun throwNoValueArguments(): Nothing {
|
||||
throw UnsupportedOperationException("Property reference $descriptor has no value arguments")
|
||||
}
|
||||
|
||||
override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments()
|
||||
|
||||
override fun putValueArgument(index: Int, valueArgument: IrExpression?) = throwNoValueArguments()
|
||||
|
||||
override fun removeValueArgument(index: Int) = throwNoValueArguments()
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.descriptors.VariableDescriptorWithAccessors
|
||||
import org.jetbrains.kotlin.ir.expressions.IrLocalDelegatedPropertyReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class IrLocalDelegatedPropertyReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
override val descriptor: VariableDescriptorWithAccessors,
|
||||
override val delegate: IrVariableSymbol,
|
||||
override val getter: IrFunctionSymbol,
|
||||
override val setter: IrFunctionSymbol?,
|
||||
origin: IrStatementOrigin? = null
|
||||
) : IrLocalDelegatedPropertyReference,
|
||||
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, null, origin)
|
||||
{
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitLocalDelegatedPropertyReference(this, data)
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCallableReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
abstract class IrNoArgumentsCallableReferenceBase(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
override val origin: IrStatementOrigin? = null
|
||||
) : IrCallableReference,
|
||||
IrMemberAccessExpressionBase(startOffset, endOffset, type, typeArguments)
|
||||
{
|
||||
private fun throwNoValueArguments(): Nothing {
|
||||
throw UnsupportedOperationException("Property reference $descriptor has no value arguments")
|
||||
}
|
||||
|
||||
override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments()
|
||||
|
||||
override fun putValueArgument(index: Int, valueArgument: IrExpression?) = throwNoValueArguments()
|
||||
|
||||
override fun removeValueArgument(index: Int) = throwNoValueArguments()
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.IrPropertyReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class IrPropertyReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
override val descriptor: PropertyDescriptor,
|
||||
override val field: IrFieldSymbol?,
|
||||
override val getter: IrFunctionSymbol?,
|
||||
override val setter: IrFunctionSymbol?,
|
||||
typeArguments: Map<TypeParameterDescriptor, KotlinType>?,
|
||||
origin: IrStatementOrigin? = null
|
||||
) : IrPropertyReference,
|
||||
IrNoArgumentsCallableReferenceBase(startOffset, endOffset, type, typeArguments, origin)
|
||||
{
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||
visitor.visitPropertyReference(this, data)
|
||||
}
|
||||
@@ -376,7 +376,7 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
|
||||
mapStatementOrigin(expression.origin)
|
||||
).transformValueArguments(expression)
|
||||
|
||||
override fun visitPropertyReference(expression: IrPropertyReference): IrExpression =
|
||||
override fun visitPropertyReference(expression: IrPropertyReference): IrPropertyReference =
|
||||
IrPropertyReferenceImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
@@ -386,7 +386,18 @@ class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrE
|
||||
expression.setter?.let { symbolsRemapper.getReferencedFunction(it) },
|
||||
expression.getTypeArgumentsMap(),
|
||||
mapStatementOrigin(expression.origin)
|
||||
).transformValueArguments(expression)
|
||||
).transformReceiverArguments(expression)
|
||||
|
||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference): IrLocalDelegatedPropertyReference =
|
||||
IrLocalDelegatedPropertyReferenceImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type,
|
||||
expression.descriptor,
|
||||
symbolsRemapper.getReferencedVariable(expression.delegate),
|
||||
symbolsRemapper.getReferencedFunction(expression.getter),
|
||||
expression.setter?.let { symbolsRemapper.getReferencedFunction(it) },
|
||||
mapStatementOrigin(expression.origin)
|
||||
)
|
||||
|
||||
override fun visitClassReference(expression: IrClassReference): IrClassReference =
|
||||
IrClassReferenceImpl(
|
||||
|
||||
@@ -198,6 +198,17 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
|
||||
append(" ")
|
||||
}
|
||||
|
||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: Nothing?): String =
|
||||
buildString {
|
||||
append("LOCAL_DELEGATED_PROPERTY_REFERENCE ")
|
||||
append("'${expression.descriptor.ref()}' ")
|
||||
append("delegate='${expression.delegate.descriptor.ref()}' ")
|
||||
append("getter='${expression.getter.descriptor.ref()}' ")
|
||||
appendNullableAttribute("setter=", expression.setter) { "'${it.descriptor.ref()}'"}
|
||||
append("type=${expression.type.render()} ")
|
||||
append("origin=${expression.origin}")
|
||||
}
|
||||
|
||||
override fun visitClassReference(expression: IrClassReference, data: Nothing?): String =
|
||||
"CLASS_REFERENCE '${expression.descriptor.ref()}' type=${expression.type.render()}"
|
||||
|
||||
|
||||
@@ -16,9 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
inline fun <T> MutableList<T>.transform(transformation: (T) -> T) {
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
|
||||
inline fun <reified T : IrElement> MutableList<T>.transform(transformation: (T) -> IrElement) {
|
||||
forEachIndexed { i, item ->
|
||||
set(i, transformation(item))
|
||||
set(i, transformation(item) as T)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ interface IrElementTransformer<in D> : IrElementVisitor<IrElement, D> {
|
||||
override fun visitCallableReference(expression: IrCallableReference, data: D) = visitMemberAccess(expression, data)
|
||||
override fun visitFunctionReference(expression: IrFunctionReference, data: D) = visitCallableReference(expression, data)
|
||||
override fun visitPropertyReference(expression: IrPropertyReference, data: D) = visitCallableReference(expression, data)
|
||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: D) = visitCallableReference(expression, data)
|
||||
|
||||
override fun visitClassReference(expression: IrClassReference, data: D) = visitDeclarationReference(expression, data)
|
||||
|
||||
|
||||
@@ -175,6 +175,10 @@ abstract class IrElementTransformerVoid : IrElementTransformer<Nothing?> {
|
||||
open fun visitPropertyReference(expression: IrPropertyReference) = visitCallableReference(expression)
|
||||
override final fun visitPropertyReference(expression: IrPropertyReference, data: Nothing?): IrElement = visitPropertyReference(expression)
|
||||
|
||||
open fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference) = visitCallableReference(expression)
|
||||
override final fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: Nothing?) =
|
||||
visitLocalDelegatedPropertyReference(expression)
|
||||
|
||||
open fun visitClassReference(expression: IrClassReference) = visitDeclarationReference(expression)
|
||||
override final fun visitClassReference(expression: IrClassReference, data: Nothing?) = visitClassReference(expression)
|
||||
|
||||
|
||||
@@ -78,6 +78,7 @@ interface IrElementVisitor<out R, in D> {
|
||||
fun visitCallableReference(expression: IrCallableReference, data: D) = visitMemberAccess(expression, data)
|
||||
fun visitFunctionReference(expression: IrFunctionReference, data: D) = visitCallableReference(expression, data)
|
||||
fun visitPropertyReference(expression: IrPropertyReference, data: D) = visitCallableReference(expression, data)
|
||||
fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: D) = visitCallableReference(expression, data)
|
||||
|
||||
fun visitClassReference(expression: IrClassReference, data: D) = visitDeclarationReference(expression, data)
|
||||
|
||||
|
||||
@@ -171,6 +171,9 @@ interface IrElementVisitorVoid : IrElementVisitor<Unit, Nothing?> {
|
||||
fun visitPropertyReference(expression: IrPropertyReference) = visitCallableReference(expression)
|
||||
override fun visitPropertyReference(expression: IrPropertyReference, data: Nothing?) = visitPropertyReference(expression)
|
||||
|
||||
fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference) = visitCallableReference(expression)
|
||||
override fun visitLocalDelegatedPropertyReference(expression: IrLocalDelegatedPropertyReference, data: Nothing?) = visitLocalDelegatedPropertyReference(expression)
|
||||
|
||||
fun visitClassReference(expression: IrClassReference) = visitDeclarationReference(expression)
|
||||
override fun visitClassReference(expression: IrClassReference, data: Nothing?) = visitClassReference(expression)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user