[IR] Refactoring

This commit is contained in:
Roman Artemev
2019-08-08 15:56:51 +03:00
committed by romanart
parent ea42eb6a5c
commit b7b951c8c8
@@ -165,13 +165,13 @@ abstract class IrFileDeserializer(
return result return result
} }
fun deserializeIrTypeVariance(variance: ProtoTypeVariance) = when (variance) { private fun deserializeIrTypeVariance(variance: ProtoTypeVariance) = when (variance) {
ProtoTypeVariance.IN -> Variance.IN_VARIANCE ProtoTypeVariance.IN -> Variance.IN_VARIANCE
ProtoTypeVariance.OUT -> Variance.OUT_VARIANCE ProtoTypeVariance.OUT -> Variance.OUT_VARIANCE
ProtoTypeVariance.INV -> Variance.INVARIANT ProtoTypeVariance.INV -> Variance.INVARIANT
} }
fun deserializeIrTypeArgument(proto: ProtoTypeArgument) = when (proto.kindCase) { private fun deserializeIrTypeArgument(proto: ProtoTypeArgument) = when (proto.kindCase) {
STAR -> IrStarProjectionImpl STAR -> IrStarProjectionImpl
TYPE -> makeTypeProjection( TYPE -> makeTypeProjection(
deserializeIrType(proto.type.type), deserializeIrTypeVariance(proto.type.variance) deserializeIrType(proto.type.type), deserializeIrTypeVariance(proto.type.variance)
@@ -186,31 +186,28 @@ abstract class IrFileDeserializer(
} }
} }
open fun getPrimitiveTypeOrNull(symbol: IrClassifierSymbol, hasQuestionMark: Boolean): IrSimpleType? = null private fun deserializeSimpleType(proto: ProtoSimpleType): IrSimpleType {
fun deserializeSimpleType(proto: ProtoSimpleType): IrSimpleType {
val symbol = deserializeIrSymbol(proto.classifier) as? IrClassifierSymbol val symbol = deserializeIrSymbol(proto.classifier) as? IrClassifierSymbol
?: error("could not convert sym to ClassifierSymbol") ?: error("could not convert sym to ClassifierSymbol")
logger.log { "deserializeSimpleType: symbol=$symbol" } logger.log { "deserializeSimpleType: symbol=$symbol" }
val result = getPrimitiveTypeOrNull(symbol, proto.hasQuestionMark) ?: run { val arguments = proto.argumentList.map { deserializeIrTypeArgument(it) }
val arguments = proto.argumentList.map { deserializeIrTypeArgument(it) } val annotations = deserializeAnnotations(proto.annotations)
val annotations = deserializeAnnotations(proto.annotations)
IrSimpleTypeImpl( val result: IrSimpleType = IrSimpleTypeImpl(
null, null,
symbol, symbol,
proto.hasQuestionMark, proto.hasQuestionMark,
arguments, arguments,
annotations, annotations,
if (proto.hasAbbreviation()) deserializeTypeAbbreviation(proto.abbreviation) else null if (proto.hasAbbreviation()) deserializeTypeAbbreviation(proto.abbreviation) else null
) )
}
logger.log { "ir_type = $result; render = ${result.render()}" } logger.log { "ir_type = $result; render = ${result.render()}" }
return result return result
} }
fun deserializeTypeAbbreviation(proto: ProtoTypeAbbreviation): IrTypeAbbreviation = private fun deserializeTypeAbbreviation(proto: ProtoTypeAbbreviation): IrTypeAbbreviation =
IrTypeAbbreviationImpl( IrTypeAbbreviationImpl(
deserializeIrSymbol(proto.typeAlias).let { deserializeIrSymbol(proto.typeAlias).let {
it as? IrTypeAliasSymbol it as? IrTypeAliasSymbol
@@ -221,12 +218,12 @@ abstract class IrFileDeserializer(
deserializeAnnotations(proto.annotations) deserializeAnnotations(proto.annotations)
) )
fun deserializeDynamicType(proto: ProtoDynamicType): IrDynamicType { private fun deserializeDynamicType(proto: ProtoDynamicType): IrDynamicType {
val annotations = deserializeAnnotations(proto.annotations) val annotations = deserializeAnnotations(proto.annotations)
return IrDynamicTypeImpl(null, annotations, Variance.INVARIANT) return IrDynamicTypeImpl(null, annotations, Variance.INVARIANT)
} }
fun deserializeErrorType(proto: ProtoErrorType): IrErrorType { private fun deserializeErrorType(proto: ProtoErrorType): IrErrorType {
val annotations = deserializeAnnotations(proto.annotations) val annotations = deserializeAnnotations(proto.annotations)
return IrErrorTypeImpl(null, annotations, Variance.INVARIANT) return IrErrorTypeImpl(null, annotations, Variance.INVARIANT)
} }