Vararg elements in serialization.
This commit is contained in:
committed by
alexander-gorshenev
parent
2be9953d4f
commit
7d2b794401
+13
@@ -211,6 +211,11 @@ message IrSetVariable {
|
|||||||
required IrExpression value = 2;
|
required IrExpression value = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message IrSpreadElement {
|
||||||
|
required IrExpression expression = 1;
|
||||||
|
required Coordinates coordinates = 2;
|
||||||
|
}
|
||||||
|
|
||||||
message IrStringConcat {
|
message IrStringConcat {
|
||||||
repeated IrExpression argument = 1;
|
repeated IrExpression argument = 1;
|
||||||
}
|
}
|
||||||
@@ -233,6 +238,14 @@ message IrTypeOp {
|
|||||||
|
|
||||||
message IrVararg {
|
message IrVararg {
|
||||||
required KotlinType element_type = 1;
|
required KotlinType element_type = 1;
|
||||||
|
repeated IrVarargElement element = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message IrVarargElement {
|
||||||
|
oneof vararg_element {
|
||||||
|
IrExpression expression = 1;
|
||||||
|
IrSpreadElement spread_element = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message IrWhen {
|
message IrWhen {
|
||||||
|
|||||||
+46
-1
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.serialization.KonanDescriptorSerializer
|
|||||||
import org.jetbrains.kotlin.serialization.KonanIr
|
import org.jetbrains.kotlin.serialization.KonanIr
|
||||||
import org.jetbrains.kotlin.serialization.KonanIr.IrConst.ValueCase.*
|
import org.jetbrains.kotlin.serialization.KonanIr.IrConst.ValueCase.*
|
||||||
import org.jetbrains.kotlin.serialization.KonanIr.IrOperation.OperationCase.*
|
import org.jetbrains.kotlin.serialization.KonanIr.IrOperation.OperationCase.*
|
||||||
|
import org.jetbrains.kotlin.serialization.KonanIr.IrVarargElement.VarargElementCase.*
|
||||||
import org.jetbrains.kotlin.serialization.KonanLinkData
|
import org.jetbrains.kotlin.serialization.KonanLinkData
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassConstructorDescriptor
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
||||||
@@ -346,6 +347,14 @@ internal class IrSerializer(val context: Context,
|
|||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun serializeSpreadElement(element: IrSpreadElement): KonanIr.IrSpreadElement {
|
||||||
|
val coordinates = serializeCoordinates(element.startOffset, element.endOffset)
|
||||||
|
return KonanIr.IrSpreadElement.newBuilder()
|
||||||
|
.setExpression(serializeExpression(element.expression))
|
||||||
|
.setCoordinates(coordinates)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
private fun serializeThrow(expression: IrThrow): KonanIr.IrThrow {
|
private fun serializeThrow(expression: IrThrow): KonanIr.IrThrow {
|
||||||
val proto = KonanIr.IrThrow.newBuilder()
|
val proto = KonanIr.IrThrow.newBuilder()
|
||||||
.setValue(serializeExpression(expression.value))
|
.setValue(serializeExpression(expression.value))
|
||||||
@@ -396,6 +405,21 @@ internal class IrSerializer(val context: Context,
|
|||||||
private fun serializeVararg(expression: IrVararg): KonanIr.IrVararg {
|
private fun serializeVararg(expression: IrVararg): KonanIr.IrVararg {
|
||||||
val proto = KonanIr.IrVararg.newBuilder()
|
val proto = KonanIr.IrVararg.newBuilder()
|
||||||
.setElementType(serializeKotlinType(expression.varargElementType))
|
.setElementType(serializeKotlinType(expression.varargElementType))
|
||||||
|
expression.elements.forEach {
|
||||||
|
proto.addElement(serializeVarargElement(it))
|
||||||
|
}
|
||||||
|
return proto.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun serializeVarargElement(element: IrVarargElement): KonanIr.IrVarargElement {
|
||||||
|
val proto = KonanIr.IrVarargElement.newBuilder()
|
||||||
|
when (element) {
|
||||||
|
is IrExpression
|
||||||
|
-> proto.expression = serializeExpression(element)
|
||||||
|
is IrSpreadElement
|
||||||
|
-> proto.spreadElement = serializeSpreadElement(element)
|
||||||
|
else -> TODO("Unknown vararg element kind")
|
||||||
|
}
|
||||||
return proto.build()
|
return proto.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -935,6 +959,11 @@ internal class IrDeserializer(val context: Context,
|
|||||||
return IrSetVariableImpl(start, end, IrVariableSymbolImpl(descriptor), value, null)
|
return IrSetVariableImpl(start, end, IrVariableSymbolImpl(descriptor), value, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun deserializeSpreadElement(proto: KonanIr.IrSpreadElement): IrSpreadElement {
|
||||||
|
val expression = deserializeExpression(proto.expression)
|
||||||
|
return IrSpreadElementImpl(proto.coordinates.startOffset, proto.coordinates.endOffset, expression)
|
||||||
|
}
|
||||||
|
|
||||||
private fun deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation {
|
private fun deserializeStringConcat(proto: KonanIr.IrStringConcat, start: Int, end: Int, type: KotlinType): IrStringConcatenation {
|
||||||
val argumentProtos = proto.argumentList
|
val argumentProtos = proto.argumentList
|
||||||
val arguments = mutableListOf<IrExpression>()
|
val arguments = mutableListOf<IrExpression>()
|
||||||
@@ -989,7 +1018,23 @@ internal class IrDeserializer(val context: Context,
|
|||||||
|
|
||||||
private fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg {
|
private fun deserializeVararg(proto: KonanIr.IrVararg, start: Int, end: Int, type: KotlinType): IrVararg {
|
||||||
val elementType = deserializeKotlinType(proto.elementType)
|
val elementType = deserializeKotlinType(proto.elementType)
|
||||||
return IrVarargImpl(start, end, type, elementType)
|
|
||||||
|
val elements = mutableListOf<IrVarargElement>()
|
||||||
|
proto.elementList.forEach {
|
||||||
|
elements.add(deserializeVarargElement(it))
|
||||||
|
}
|
||||||
|
return IrVarargImpl(start, end, type, elementType, elements)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun deserializeVarargElement(element: KonanIr.IrVarargElement): IrVarargElement {
|
||||||
|
return when (element.varargElementCase) {
|
||||||
|
EXPRESSION
|
||||||
|
-> deserializeExpression(element.expression)
|
||||||
|
SPREAD_ELEMENT
|
||||||
|
-> deserializeSpreadElement(element.spreadElement)
|
||||||
|
else
|
||||||
|
-> TODO("Unexpected vararg element")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen {
|
private fun deserializeWhen(proto: KonanIr.IrWhen, start: Int, end: Int, type: KotlinType): IrWhen {
|
||||||
|
|||||||
Reference in New Issue
Block a user