Slightly lighter weight when constructs.

This commit is contained in:
Alexander Gorshenev
2017-04-13 22:07:54 +03:00
committed by alexander-gorshenev
parent 2ad0be6182
commit ce85975fac
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.ir.expressions.impl.*
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.KonanLinkData import org.jetbrains.kotlin.serialization.KonanLinkData
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
@@ -152,17 +153,15 @@ internal class IrSerializer(val context: Context,
return proto.build() return proto.build()
} }
fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive { fun irCallToPrimitiveKind(call: IrCall): KonanIr.IrCall.Primitive = when (call) {
return when (call) { is IrNullaryPrimitiveImpl
is IrNullaryPrimitiveImpl -> KonanIr.IrCall.Primitive.NULLARY
-> return KonanIr.IrCall.Primitive.NULLARY is IrUnaryPrimitiveImpl
is IrUnaryPrimitiveImpl -> KonanIr.IrCall.Primitive.UNARY
-> return KonanIr.IrCall.Primitive.UNARY is IrBinaryPrimitiveImpl
is IrBinaryPrimitiveImpl -> KonanIr.IrCall.Primitive.BINARY
-> return KonanIr.IrCall.Primitive.BINARY else
else -> KonanIr.IrCall.Primitive.NOT_PRIMITIVE
-> return KonanIr.IrCall.Primitive.NOT_PRIMITIVE
}
} }
fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon { fun serializeMemberAccessCommon(call: IrMemberAccessExpression): KonanIr.MemberAccessCommon {
@@ -307,24 +306,22 @@ internal class IrSerializer(val context: Context,
return proto.build() return proto.build()
} }
fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator { fun serializeTypeOperator(operator: IrTypeOperator): KonanIr.IrTypeOperator = when (operator) {
when (operator) { IrTypeOperator.CAST
IrTypeOperator.CAST -> KonanIr.IrTypeOperator.CAST
-> return KonanIr.IrTypeOperator.CAST IrTypeOperator.IMPLICIT_CAST
IrTypeOperator.IMPLICIT_CAST -> KonanIr.IrTypeOperator.IMPLICIT_CAST
-> return KonanIr.IrTypeOperator.IMPLICIT_CAST IrTypeOperator.IMPLICIT_NOTNULL
IrTypeOperator.IMPLICIT_NOTNULL -> KonanIr.IrTypeOperator.IMPLICIT_NOTNULL
-> return KonanIr.IrTypeOperator.IMPLICIT_NOTNULL IrTypeOperator.IMPLICIT_COERCION_TO_UNIT
IrTypeOperator.IMPLICIT_COERCION_TO_UNIT -> KonanIr.IrTypeOperator.IMPLICIT_COERCION_TO_UNIT
-> return KonanIr.IrTypeOperator.IMPLICIT_COERCION_TO_UNIT IrTypeOperator.SAFE_CAST
IrTypeOperator.SAFE_CAST -> KonanIr.IrTypeOperator.SAFE_CAST
-> return KonanIr.IrTypeOperator.SAFE_CAST IrTypeOperator.INSTANCEOF
IrTypeOperator.INSTANCEOF -> KonanIr.IrTypeOperator.INSTANCEOF
-> return KonanIr.IrTypeOperator.INSTANCEOF IrTypeOperator.NOT_INSTANCEOF
IrTypeOperator.NOT_INSTANCEOF -> KonanIr.IrTypeOperator.NOT_INSTANCEOF
-> return KonanIr.IrTypeOperator.NOT_INSTANCEOF else -> TODO("Unknown type operator")
else -> TODO("Unknown type operator")
}
} }
fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp { fun serializeTypeOp(expression: IrTypeOperatorCall): KonanIr.IrTypeOp {
@@ -882,73 +879,72 @@ internal class IrDeserializer(val context: Context,
NULL NULL
-> IrConstImpl.constNull(start, end, type) -> IrConstImpl.constNull(start, end, type)
BOOLEAN BOOLEAN
-> IrConstImpl.boolean(start, end, type, proto.getBoolean()) -> IrConstImpl.boolean(start, end, type, proto.boolean)
BYTE BYTE
-> IrConstImpl.byte(start, end, type, proto.getByte().toByte()) -> IrConstImpl.byte(start, end, type, proto.byte.toByte())
SHORT SHORT
-> IrConstImpl.short(start, end, type, proto.getShort().toShort()) -> IrConstImpl.short(start, end, type, proto.short.toShort())
INT INT
-> IrConstImpl.int(start, end, type, proto.getInt()) -> IrConstImpl.int(start, end, type, proto.int)
LONG LONG
-> IrConstImpl.long(start, end, type, proto.getLong()) -> IrConstImpl.long(start, end, type, proto.long)
STRING STRING
-> IrConstImpl.string(start, end, type, proto.getString()) -> IrConstImpl.string(start, end, type, proto.string)
FLOAT FLOAT
-> IrConstImpl.float(start, end, type, proto.getFloat()) -> IrConstImpl.float(start, end, type, proto.float)
DOUBLE DOUBLE
-> IrConstImpl.double(start, end, type, proto.getDouble()) -> IrConstImpl.double(start, end, type, proto.double)
else -> { else -> {
TODO("Not all const types have been implemented") TODO("Not all const types have been implemented")
} }
} }
fun deserializeOperation(proto: KonanIr.IrOperation, start: Int, end: Int, type: KotlinType): IrExpression { fun deserializeOperation(proto: KonanIr.IrOperation, start: Int, end: Int, type: KotlinType): IrExpression =
when { when (proto.operationCase) {
proto.hasBlock() BLOCK
-> return deserializeBlock(proto.getBlock(), start, end, type) -> deserializeBlock(proto.block, start, end, type)
proto.hasBreak() BREAK
-> return deserializeBreak(proto.getBreak(), start, end, type) -> deserializeBreak(proto.getBreak(), start, end, type)
proto.hasCall() CALL
-> return deserializeCall(proto.getCall(), start, end, type) -> deserializeCall(proto.call, start, end, type)
proto.hasCallableReference() CALLABLE_REFERENCE
-> return deserializeCallableReference(proto.getCallableReference(), start, end, type) -> deserializeCallableReference(proto.callableReference, start, end, type)
proto.hasConst() CONST
-> return deserializeConst(proto.getConst(), start, end, type) -> deserializeConst(proto.const, start, end, type)
proto.hasContinue() CONTINUE
-> return deserializeContinue(proto.getContinue(), start, end, type) -> deserializeContinue(proto.getContinue(), start, end, type)
proto.hasDelegatingConstructorCall() DELEGATING_CONSTRUCTOR_CALL
-> return deserializeDelegatingConstructorCall(proto.getDelegatingConstructorCall(), start, end, type) -> deserializeDelegatingConstructorCall(proto.delegatingConstructorCall, start, end, type)
proto.hasGetValue() GET_VALUE
-> return deserializeGetValue(proto.getGetValue(), start, end, type) -> deserializeGetValue(proto.getValue, start, end, type)
proto.hasGetEnumValue() GET_ENUM_VALUE
-> return deserializeGetEnumValue(proto.getGetEnumValue(), start, end, type) -> deserializeGetEnumValue(proto.getEnumValue, start, end, type)
proto.hasGetObject() GET_OBJECT
-> return deserializeGetObject(proto.getGetObject(), start, end, type) -> deserializeGetObject(proto.getObject, start, end, type)
proto.hasInstanceInitializerCall() INSTANCE_INITIALIZER_CALL
-> return deserializeInstanceInitializerCall(proto.getInstanceInitializerCall(), start, end, type) -> deserializeInstanceInitializerCall(proto.instanceInitializerCall, start, end, type)
proto.hasReturn() RETURN
-> return deserializeReturn(proto.getReturn(), start, end, type) -> deserializeReturn(proto.getReturn(), start, end, type)
proto.hasSetVariable() SET_VARIABLE
-> return deserializeSetVariable(proto.getSetVariable(), start, end, type) -> deserializeSetVariable(proto.setVariable, start, end, type)
proto.hasStringConcat() STRING_CONCAT
-> return deserializeStringConcat(proto.getStringConcat(), start, end, type) -> deserializeStringConcat(proto.stringConcat, start, end, type)
proto.hasThrow() THROW
-> return deserializeThrow(proto.getThrow(), start, end, type) -> deserializeThrow(proto.getThrow(), start, end, type)
proto.hasTry() TRY
-> return deserializeTry(proto.getTry(), start, end, type) -> deserializeTry(proto.getTry(), start, end, type)
proto.hasTypeOp() TYPE_OP
-> return deserializeTypeOp(proto.getTypeOp(), start, end, type) -> deserializeTypeOp(proto.typeOp, start, end, type)
proto.hasVararg() VARARG
-> return deserializeVararg(proto.getVararg(), start, end, type) -> deserializeVararg(proto.vararg, start, end, type)
proto.hasWhen() WHEN
-> return deserializeWhen(proto.getWhen(), start, end, type) -> deserializeWhen(proto.getWhen(), start, end, type)
proto.hasWhile() WHILE
-> return deserializeWhile(proto.getWhile(), start, end, type) -> deserializeWhile(proto.getWhile(), start, end, type)
else -> { else -> {
TODO("Expression deserialization not implemented}") TODO("Expression deserialization not implemented}")
} }
} }
}
fun deserializeExpression(proto: KonanIr.IrExpression): IrExpression { fun deserializeExpression(proto: KonanIr.IrExpression): IrExpression {
val start = proto.getCoordinates().getStartOffset() val start = proto.getCoordinates().getStartOffset()