Data class members generation.
Builder-style API for desugaring expressions.
This commit is contained in:
committed by
Dmitry Petrov
parent
dc169e98d5
commit
1022725fd1
@@ -42,6 +42,7 @@ enum class IrDeclarationKind {
|
||||
|
||||
enum class IrDeclarationOrigin {
|
||||
DEFINED,
|
||||
GENERATED_DATA_CLASS_MEMBER,
|
||||
LOCAL_FUNCTION_FOR_LAMBDA,
|
||||
IR_TEMPORARY_VARIABLE,
|
||||
}
|
||||
|
||||
@@ -74,6 +74,4 @@ class IrBuiltIns(val builtIns: KotlinBuiltIns) {
|
||||
|
||||
private fun ClassDescriptor.findSingleFunction(name: String): FunctionDescriptor =
|
||||
getMemberScope(TypeSubstitution.EMPTY).getContributedFunctions(Name.identifier(name), NoLookupLocation.FROM_BUILTINS).single()
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.assertCast
|
||||
import org.jetbrains.kotlin.ir.assertDetached
|
||||
@@ -34,6 +35,20 @@ interface IrGeneralCall : IrMemberAccessExpression {
|
||||
fun removeArgument(index: Int)
|
||||
}
|
||||
|
||||
fun <T : IrGeneralCall> T.putArguments(arguments: List<IrExpression>): T {
|
||||
arguments.forEachIndexed { i, irArgument ->
|
||||
putArgument(i, irArgument)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
inline fun <T : IrGeneralCall> T.mapValueParameters(transform: (ValueParameterDescriptor) -> IrExpression): T {
|
||||
descriptor.valueParameters.forEach {
|
||||
putArgument(it.index, transform(it))
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
abstract class IrGeneralCallBase(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
@@ -25,6 +26,9 @@ interface IrThisReference : IrExpression, IrExpressionWithCopy {
|
||||
override fun copy(): IrThisReference
|
||||
}
|
||||
|
||||
val IrThisReference.receiverParameter: ReceiverParameterDescriptor
|
||||
get() = classDescriptor.thisAsReceiverParameter
|
||||
|
||||
class IrThisReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
@@ -36,5 +40,4 @@ class IrThisReferenceImpl(
|
||||
|
||||
override fun copy(): IrThisReference =
|
||||
IrThisReferenceImpl(startOffset, endOffset, type, classDescriptor)
|
||||
|
||||
}
|
||||
+3
-5
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.ir.expressions
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
|
||||
interface IrVariableAccessExpression : IrDeclarationReference {
|
||||
override val descriptor: VariableDescriptor
|
||||
@@ -50,18 +50,16 @@ class IrGetVariableImpl(
|
||||
class IrSetVariableImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
override val descriptor: VariableDescriptor,
|
||||
override val operator: IrOperator?
|
||||
) : IrExpressionBase(startOffset, endOffset, type), IrSetVariable {
|
||||
) : IrExpressionBase(startOffset, endOffset, descriptor.builtIns.unitType), IrSetVariable {
|
||||
constructor(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
descriptor: VariableDescriptor,
|
||||
value: IrExpression,
|
||||
operator: IrOperator?
|
||||
) : this(startOffset, endOffset, type, descriptor, operator) {
|
||||
) : this(startOffset, endOffset, descriptor, operator) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user