[Commonizer] Rename: Cir<Entity>.build<Entity> to Cir<Entity>.serialize<Entity>
This commit is contained in:
+8
-8
@@ -68,7 +68,7 @@ private class CirTreeSerializationVisitor(
|
|||||||
|
|
||||||
addEmptyFragments(fragments)
|
addEmptyFragments(fragments)
|
||||||
|
|
||||||
return cirModule.buildModule(fragments)
|
return cirModule.serializeModule(fragments)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPackageNode(
|
override fun visitPackageNode(
|
||||||
@@ -118,7 +118,7 @@ private class CirTreeSerializationVisitor(
|
|||||||
property
|
property
|
||||||
}
|
}
|
||||||
|
|
||||||
return cirPackage.buildModuleFragment(classConsumer.allClasses, topLevelTypeAliases, topLevelFunctions, topLevelProperties)
|
return cirPackage.serializePackage(classConsumer.allClasses, topLevelTypeAliases, topLevelFunctions, topLevelProperties)
|
||||||
} finally {
|
} finally {
|
||||||
// Important: clean-up class consumer every time when leaving package
|
// Important: clean-up class consumer every time when leaving package
|
||||||
classConsumer.reset()
|
classConsumer.reset()
|
||||||
@@ -129,14 +129,14 @@ private class CirTreeSerializationVisitor(
|
|||||||
node: CirPropertyNode,
|
node: CirPropertyNode,
|
||||||
propertyContext: CirTreeSerializationContext
|
propertyContext: CirTreeSerializationContext
|
||||||
): KmProperty? {
|
): KmProperty? {
|
||||||
return propertyContext.get<CirProperty>(node)?.buildProperty(propertyContext)
|
return propertyContext.get<CirProperty>(node)?.serializeProperty(propertyContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunctionNode(
|
override fun visitFunctionNode(
|
||||||
node: CirFunctionNode,
|
node: CirFunctionNode,
|
||||||
functionContext: CirTreeSerializationContext
|
functionContext: CirTreeSerializationContext
|
||||||
): KmFunction? {
|
): KmFunction? {
|
||||||
return functionContext.get<CirFunction>(node)?.buildFunction(functionContext)
|
return functionContext.get<CirFunction>(node)?.serializeFunction(functionContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassNode(
|
override fun visitClassNode(
|
||||||
@@ -176,14 +176,14 @@ private class CirTreeSerializationVisitor(
|
|||||||
property
|
property
|
||||||
}
|
}
|
||||||
|
|
||||||
return cirClass.buildClass(classContext, fullClassName, directNestedClasses, nestedConstructors, nestedFunctions, nestedProperties)
|
return cirClass.serializeClass(classContext, fullClassName, directNestedClasses, nestedConstructors, nestedFunctions, nestedProperties)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassConstructorNode(
|
override fun visitClassConstructorNode(
|
||||||
node: CirClassConstructorNode,
|
node: CirClassConstructorNode,
|
||||||
constructorContext: CirTreeSerializationContext
|
constructorContext: CirTreeSerializationContext
|
||||||
): KmConstructor? {
|
): KmConstructor? {
|
||||||
return constructorContext.get<CirClassConstructor>(node)?.buildClassConstructor(constructorContext)
|
return constructorContext.get<CirClassConstructor>(node)?.serializeConstructor(constructorContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitTypeAliasNode(
|
override fun visitTypeAliasNode(
|
||||||
@@ -193,10 +193,10 @@ private class CirTreeSerializationVisitor(
|
|||||||
val cirClassifier = typeAliasContext.get<CirClassifier>(node) ?: return null
|
val cirClassifier = typeAliasContext.get<CirClassifier>(node) ?: return null
|
||||||
|
|
||||||
return when (cirClassifier) {
|
return when (cirClassifier) {
|
||||||
is CirTypeAlias -> cirClassifier.buildTypeAlias(typeAliasContext)
|
is CirTypeAlias -> cirClassifier.serializeTypeAlias(typeAliasContext)
|
||||||
is CirClass -> {
|
is CirClass -> {
|
||||||
val fullClassName = typeAliasContext.currentPath.toString()
|
val fullClassName = typeAliasContext.currentPath.toString()
|
||||||
cirClassifier.buildClass(typeAliasContext, fullClassName, emptyList(), emptyList(), emptyList(), emptyList())
|
cirClassifier.serializeClass(typeAliasContext, fullClassName, emptyList(), emptyList(), emptyList(), emptyList())
|
||||||
}
|
}
|
||||||
else -> error("Unexpected CIR classifier: ${cirClassifier::class.java}, $cirClassifier")
|
else -> error("Unexpected CIR classifier: ${cirClassifier::class.java}, $cirClassifier")
|
||||||
}
|
}
|
||||||
|
|||||||
+70
-70
@@ -17,7 +17,7 @@ import org.jetbrains.kotlin.descriptors.commonizer.utils.SPECIAL_CLASS_WITHOUT_S
|
|||||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
import org.jetbrains.kotlin.descriptors.commonizer.utils.compactMap
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
internal fun CirModule.buildModule(
|
internal fun CirModule.serializeModule(
|
||||||
fragments: Collection<KmModuleFragment>
|
fragments: Collection<KmModuleFragment>
|
||||||
): KlibModuleMetadata = KlibModuleMetadata(
|
): KlibModuleMetadata = KlibModuleMetadata(
|
||||||
name = name.toStrippedString(),
|
name = name.toStrippedString(),
|
||||||
@@ -25,7 +25,7 @@ internal fun CirModule.buildModule(
|
|||||||
annotations = emptyList()
|
annotations = emptyList()
|
||||||
)
|
)
|
||||||
|
|
||||||
internal fun CirPackage.buildModuleFragment(
|
internal fun CirPackage.serializePackage(
|
||||||
allClasses: Collection<KmClass>,
|
allClasses: Collection<KmClass>,
|
||||||
topLevelTypeAliases: Collection<KmTypeAlias>,
|
topLevelTypeAliases: Collection<KmTypeAlias>,
|
||||||
topLevelFunctions: Collection<KmFunction>,
|
topLevelFunctions: Collection<KmFunction>,
|
||||||
@@ -69,7 +69,7 @@ internal fun addEmptyFragments(fragments: MutableCollection<KmModuleFragment>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirClass.buildClass(
|
internal fun CirClass.serializeClass(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
className: ClassName,
|
className: ClassName,
|
||||||
directNestedClasses: Collection<KmClass>,
|
directNestedClasses: Collection<KmClass>,
|
||||||
@@ -78,8 +78,8 @@ internal fun CirClass.buildClass(
|
|||||||
nestedProperties: Collection<KmProperty>
|
nestedProperties: Collection<KmProperty>
|
||||||
): KmClass = KmClass().also { clazz ->
|
): KmClass = KmClass().also { clazz ->
|
||||||
clazz.flags = classFlags(isExpect = context.isCommon)
|
clazz.flags = classFlags(isExpect = context.isCommon)
|
||||||
annotations.mapTo(clazz.annotations) { it.buildAnnotation() }
|
annotations.mapTo(clazz.annotations) { it.serializeAnnotation() }
|
||||||
typeParameters.buildTypeParameters(context, output = clazz.typeParameters)
|
typeParameters.serializeTypeParameters(context, output = clazz.typeParameters)
|
||||||
clazz.name = className
|
clazz.name = className
|
||||||
|
|
||||||
clazz.constructors += nestedConstructors
|
clazz.constructors += nestedConstructors
|
||||||
@@ -101,9 +101,9 @@ internal fun CirClass.buildClass(
|
|||||||
|
|
||||||
val supertypes = supertypes
|
val supertypes = supertypes
|
||||||
if (supertypes.isEmpty() && className !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES)
|
if (supertypes.isEmpty() && className !in SPECIAL_CLASS_WITHOUT_SUPERTYPES_CLASS_NAMES)
|
||||||
clazz.supertypes += CirStandardTypes.ANY.buildType(context)
|
clazz.supertypes += CirStandardTypes.ANY.serializeClassType(context)
|
||||||
else
|
else
|
||||||
supertypes.mapTo(clazz.supertypes) { it.buildType(context) }
|
supertypes.mapTo(clazz.supertypes) { it.serializeType(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classConsumer: ClassConsumer) {
|
internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classConsumer: ClassConsumer) {
|
||||||
@@ -124,29 +124,29 @@ internal fun linkSealedClassesWithSubclasses(packageName: CirPackageName, classC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirClassConstructor.buildClassConstructor(
|
internal fun CirClassConstructor.serializeConstructor(
|
||||||
context: CirTreeSerializationContext
|
context: CirTreeSerializationContext
|
||||||
): KmConstructor = KmConstructor(
|
): KmConstructor = KmConstructor(
|
||||||
flags = classConstructorFlags()
|
flags = classConstructorFlags()
|
||||||
).also { constructor ->
|
).also { constructor ->
|
||||||
annotations.mapTo(constructor.annotations) { it.buildAnnotation() }
|
annotations.mapTo(constructor.annotations) { it.serializeAnnotation() }
|
||||||
// TODO: nowhere to write constructor type parameters
|
// TODO: nowhere to write constructor type parameters
|
||||||
valueParameters.mapTo(constructor.valueParameters) { it.buildValueParameter(context) }
|
valueParameters.mapTo(constructor.valueParameters) { it.serializeValueParameter(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirTypeAlias.buildTypeAlias(
|
internal fun CirTypeAlias.serializeTypeAlias(
|
||||||
context: CirTreeSerializationContext
|
context: CirTreeSerializationContext
|
||||||
): KmTypeAlias = KmTypeAlias(
|
): KmTypeAlias = KmTypeAlias(
|
||||||
flags = typeAliasFlags(),
|
flags = typeAliasFlags(),
|
||||||
name = name.name
|
name = name.name
|
||||||
).also { typeAlias ->
|
).also { typeAlias ->
|
||||||
annotations.mapTo(typeAlias.annotations) { it.buildAnnotation() }
|
annotations.mapTo(typeAlias.annotations) { it.serializeAnnotation() }
|
||||||
typeParameters.buildTypeParameters(context, output = typeAlias.typeParameters)
|
typeParameters.serializeTypeParameters(context, output = typeAlias.typeParameters)
|
||||||
typeAlias.underlyingType = underlyingType.buildType(context, expansion = ONLY_ABBREVIATIONS)
|
typeAlias.underlyingType = underlyingType.serializeType(context, expansion = ONLY_ABBREVIATIONS)
|
||||||
typeAlias.expandedType = underlyingType.buildType(context, expansion = FOR_TOP_LEVEL_TYPE)
|
typeAlias.expandedType = underlyingType.serializeType(context, expansion = FOR_TOP_LEVEL_TYPE)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirProperty.buildProperty(
|
internal fun CirProperty.serializeProperty(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
): KmProperty = KmProperty(
|
): KmProperty = KmProperty(
|
||||||
flags = propertyFlags(isExpect = context.isCommon && !isLiftedUp),
|
flags = propertyFlags(isExpect = context.isCommon && !isLiftedUp),
|
||||||
@@ -154,56 +154,56 @@ internal fun CirProperty.buildProperty(
|
|||||||
getterFlags = getter?.propertyAccessorFlags(this, this) ?: NO_FLAGS,
|
getterFlags = getter?.propertyAccessorFlags(this, this) ?: NO_FLAGS,
|
||||||
setterFlags = setter?.let { setter -> setter.propertyAccessorFlags(setter, this) } ?: NO_FLAGS
|
setterFlags = setter?.let { setter -> setter.propertyAccessorFlags(setter, this) } ?: NO_FLAGS
|
||||||
).also { property ->
|
).also { property ->
|
||||||
annotations.mapTo(property.annotations) { it.buildAnnotation() }
|
annotations.mapTo(property.annotations) { it.serializeAnnotation() }
|
||||||
getter?.annotations?.mapTo(property.getterAnnotations) { it.buildAnnotation() }
|
getter?.annotations?.mapTo(property.getterAnnotations) { it.serializeAnnotation() }
|
||||||
setter?.annotations?.mapTo(property.setterAnnotations) { it.buildAnnotation() }
|
setter?.annotations?.mapTo(property.setterAnnotations) { it.serializeAnnotation() }
|
||||||
// TODO unclear where to write backing/delegate field annotations, see KT-44625
|
// TODO unclear where to write backing/delegate field annotations, see KT-44625
|
||||||
property.compileTimeValue = compileTimeInitializer.takeIf { it !is CirConstantValue.NullValue }?.buildAnnotationArgument()
|
property.compileTimeValue = compileTimeInitializer.takeIf { it !is CirConstantValue.NullValue }?.serializeConstantValue()
|
||||||
typeParameters.buildTypeParameters(context, output = property.typeParameters)
|
typeParameters.serializeTypeParameters(context, output = property.typeParameters)
|
||||||
extensionReceiver?.let { receiver ->
|
extensionReceiver?.let { receiver ->
|
||||||
// TODO nowhere to write receiver annotations, see KT-42490
|
// TODO nowhere to write receiver annotations, see KT-42490
|
||||||
property.receiverParameterType = receiver.type.buildType(context)
|
property.receiverParameterType = receiver.type.serializeType(context)
|
||||||
}
|
}
|
||||||
setter?.takeIf { !it.isDefault }?.let { setter ->
|
setter?.takeIf { !it.isDefault }?.let { setter ->
|
||||||
property.setterParameter = object : CirValueParameter {
|
property.setterParameter = object : CirValueParameter {
|
||||||
override val annotations get() = setter.parameterAnnotations
|
override val annotations get() = setter.parameterAnnotations
|
||||||
override val name get() = DEFAULT_SETTER_VALUE_NAME
|
override val name get() = DEFAULT_SETTER_VALUE_NAME
|
||||||
override val returnType get() = this@buildProperty.returnType
|
override val returnType get() = this@serializeProperty.returnType
|
||||||
override val varargElementType: CirType? get() = null
|
override val varargElementType: CirType? get() = null
|
||||||
override val declaresDefaultValue get() = false
|
override val declaresDefaultValue get() = false
|
||||||
override val isCrossinline get() = false
|
override val isCrossinline get() = false
|
||||||
override val isNoinline get() = false
|
override val isNoinline get() = false
|
||||||
}.buildValueParameter(context)
|
}.serializeValueParameter(context)
|
||||||
}
|
}
|
||||||
property.returnType = returnType.buildType(context)
|
property.returnType = returnType.serializeType(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirFunction.buildFunction(
|
internal fun CirFunction.serializeFunction(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
): KmFunction = KmFunction(
|
): KmFunction = KmFunction(
|
||||||
flags = functionFlags(isExpect = context.isCommon && kind != CallableMemberDescriptor.Kind.SYNTHESIZED),
|
flags = functionFlags(isExpect = context.isCommon && kind != CallableMemberDescriptor.Kind.SYNTHESIZED),
|
||||||
name = name.name
|
name = name.name
|
||||||
).also { function ->
|
).also { function ->
|
||||||
annotations.mapTo(function.annotations) { it.buildAnnotation() }
|
annotations.mapTo(function.annotations) { it.serializeAnnotation() }
|
||||||
typeParameters.buildTypeParameters(context, output = function.typeParameters)
|
typeParameters.serializeTypeParameters(context, output = function.typeParameters)
|
||||||
valueParameters.mapTo(function.valueParameters) { it.buildValueParameter(context) }
|
valueParameters.mapTo(function.valueParameters) { it.serializeValueParameter(context) }
|
||||||
extensionReceiver?.let { receiver ->
|
extensionReceiver?.let { receiver ->
|
||||||
// TODO nowhere to write receiver annotations, see KT-42490
|
// TODO nowhere to write receiver annotations, see KT-42490
|
||||||
function.receiverParameterType = receiver.type.buildType(context)
|
function.receiverParameterType = receiver.type.serializeType(context)
|
||||||
}
|
}
|
||||||
function.returnType = returnType.buildType(context)
|
function.returnType = returnType.serializeType(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirAnnotation.buildAnnotation(): KmAnnotation {
|
private fun CirAnnotation.serializeAnnotation(): KmAnnotation {
|
||||||
val arguments = LinkedHashMap<String, KmAnnotationArgument<*>>(constantValueArguments.size + annotationValueArguments.size, 1F)
|
val arguments = LinkedHashMap<String, KmAnnotationArgument<*>>(constantValueArguments.size + annotationValueArguments.size, 1F)
|
||||||
|
|
||||||
constantValueArguments.forEach { (name: CirName, value: CirConstantValue<*>) ->
|
constantValueArguments.forEach { (name: CirName, value: CirConstantValue<*>) ->
|
||||||
arguments[name.name] = value.buildAnnotationArgument()
|
arguments[name.name] = value.serializeConstantValue()
|
||||||
?: error("Unexpected <null> constant value inside of $this")
|
?: error("Unexpected <null> constant value inside of $this")
|
||||||
}
|
}
|
||||||
|
|
||||||
annotationValueArguments.forEach { (name: CirName, nested: CirAnnotation) ->
|
annotationValueArguments.forEach { (name: CirName, nested: CirAnnotation) ->
|
||||||
arguments[name.name] = KmAnnotationArgument.AnnotationValue(nested.buildAnnotation())
|
arguments[name.name] = KmAnnotationArgument.AnnotationValue(nested.serializeAnnotation())
|
||||||
}
|
}
|
||||||
|
|
||||||
return KmAnnotation(
|
return KmAnnotation(
|
||||||
@@ -212,7 +212,7 @@ private fun CirAnnotation.buildAnnotation(): KmAnnotation {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirConstantValue<*>.buildAnnotationArgument(): KmAnnotationArgument<*>? = when (this) {
|
private fun CirConstantValue<*>.serializeConstantValue(): KmAnnotationArgument<*>? = when (this) {
|
||||||
is CirConstantValue.StringValue -> KmAnnotationArgument.StringValue(value)
|
is CirConstantValue.StringValue -> KmAnnotationArgument.StringValue(value)
|
||||||
is CirConstantValue.CharValue -> KmAnnotationArgument.CharValue(value)
|
is CirConstantValue.CharValue -> KmAnnotationArgument.CharValue(value)
|
||||||
|
|
||||||
@@ -234,24 +234,24 @@ private fun CirConstantValue<*>.buildAnnotationArgument(): KmAnnotationArgument<
|
|||||||
is CirConstantValue.NullValue -> null
|
is CirConstantValue.NullValue -> null
|
||||||
|
|
||||||
is CirConstantValue.ArrayValue -> KmAnnotationArgument.ArrayValue(value.compactMap { element ->
|
is CirConstantValue.ArrayValue -> KmAnnotationArgument.ArrayValue(value.compactMap { element ->
|
||||||
element.buildAnnotationArgument() ?: error("Unexpected <null> constant value inside of $this")
|
element.serializeConstantValue() ?: error("Unexpected <null> constant value inside of $this")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirValueParameter.buildValueParameter(
|
private fun CirValueParameter.serializeValueParameter(
|
||||||
context: CirTreeSerializationContext
|
context: CirTreeSerializationContext
|
||||||
): KmValueParameter = KmValueParameter(
|
): KmValueParameter = KmValueParameter(
|
||||||
flags = valueParameterFlags(),
|
flags = valueParameterFlags(),
|
||||||
name = name.name
|
name = name.name
|
||||||
).also { parameter ->
|
).also { parameter ->
|
||||||
annotations.mapTo(parameter.annotations) { it.buildAnnotation() }
|
annotations.mapTo(parameter.annotations) { it.serializeAnnotation() }
|
||||||
parameter.type = returnType.buildType(context)
|
parameter.type = returnType.serializeType(context)
|
||||||
varargElementType?.let { varargElementType ->
|
varargElementType?.let { varargElementType ->
|
||||||
parameter.varargElementType = varargElementType.buildType(context)
|
parameter.varargElementType = varargElementType.serializeType(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<CirTypeParameter>.buildTypeParameters(
|
private fun List<CirTypeParameter>.serializeTypeParameters(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
output: MutableList<KmTypeParameter>
|
output: MutableList<KmTypeParameter>
|
||||||
) {
|
) {
|
||||||
@@ -260,80 +260,80 @@ private fun List<CirTypeParameter>.buildTypeParameters(
|
|||||||
flags = cirTypeParameter.typeParameterFlags(),
|
flags = cirTypeParameter.typeParameterFlags(),
|
||||||
name = cirTypeParameter.name.name,
|
name = cirTypeParameter.name.name,
|
||||||
id = context.typeParameterIndexOffset + index,
|
id = context.typeParameterIndexOffset + index,
|
||||||
variance = cirTypeParameter.variance.buildVariance()
|
variance = cirTypeParameter.variance.serializeVariance()
|
||||||
).also { parameter ->
|
).also { parameter ->
|
||||||
cirTypeParameter.upperBounds.mapTo(parameter.upperBounds) { it.buildType(context) }
|
cirTypeParameter.upperBounds.mapTo(parameter.upperBounds) { it.serializeType(context) }
|
||||||
cirTypeParameter.annotations.mapTo(parameter.annotations) { it.buildAnnotation() }
|
cirTypeParameter.annotations.mapTo(parameter.annotations) { it.serializeAnnotation() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirType.buildType(
|
private fun CirType.serializeType(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion = FOR_TOP_LEVEL_TYPE
|
expansion: TypeAliasExpansion = FOR_TOP_LEVEL_TYPE
|
||||||
): KmType = when (this) {
|
): KmType = when (this) {
|
||||||
is CirClassType -> buildType(context, expansion)
|
is CirClassType -> serializeClassType(context, expansion)
|
||||||
is CirTypeAliasType -> buildType(context, expansion)
|
is CirTypeAliasType -> serializeTypeAliasType(context, expansion)
|
||||||
is CirTypeParameterType -> buildType()
|
is CirTypeParameterType -> serializeTypeParameterType()
|
||||||
is CirFlexibleType -> {
|
is CirFlexibleType -> {
|
||||||
lowerBound.buildType(context, expansion).also {
|
lowerBound.serializeType(context, expansion).also {
|
||||||
it.flexibleTypeUpperBound = KmFlexibleTypeUpperBound(
|
it.flexibleTypeUpperBound = KmFlexibleTypeUpperBound(
|
||||||
type = upperBound.buildType(context, expansion),
|
type = upperBound.serializeType(context, expansion),
|
||||||
typeFlexibilityId = DynamicTypeDeserializer.id
|
typeFlexibilityId = DynamicTypeDeserializer.id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirTypeParameterType.buildType(): KmType =
|
private fun CirTypeParameterType.serializeTypeParameterType(): KmType =
|
||||||
KmType(typeFlags()).also { type ->
|
KmType(typeFlags()).also { type ->
|
||||||
type.classifier = KmClassifier.TypeParameter(index)
|
type.classifier = KmClassifier.TypeParameter(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirClassType.buildType(
|
private fun CirClassType.serializeClassType(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion
|
expansion: TypeAliasExpansion = FOR_TOP_LEVEL_TYPE
|
||||||
): KmType = KmType(typeFlags()).also { type ->
|
): KmType = KmType(typeFlags()).also { type ->
|
||||||
type.classifier = KmClassifier.Class(classifierId.toString())
|
type.classifier = KmClassifier.Class(classifierId.toString())
|
||||||
arguments.mapTo(type.arguments) { it.buildArgument(context, expansion) }
|
arguments.mapTo(type.arguments) { it.serializeArgument(context, expansion) }
|
||||||
outerType?.let { type.outerType = it.buildType(context, expansion) }
|
outerType?.let { type.outerType = it.serializeClassType(context, expansion) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirTypeAliasType.buildType(
|
private fun CirTypeAliasType.serializeTypeAliasType(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion
|
expansion: TypeAliasExpansion
|
||||||
): KmType = when (expansion) {
|
): KmType = when (expansion) {
|
||||||
ONLY_ABBREVIATIONS -> buildAbbreviationType(context, expansion)
|
ONLY_ABBREVIATIONS -> serializeAbbreviationType(context, expansion)
|
||||||
EXPANDED_WITHOUT_ABBREVIATIONS -> buildExpandedType(context, expansion)
|
EXPANDED_WITHOUT_ABBREVIATIONS -> serializeExpandedType(context, expansion)
|
||||||
FOR_TOP_LEVEL_TYPE -> buildExpandedType(context, EXPANDED_WITHOUT_ABBREVIATIONS).apply {
|
FOR_TOP_LEVEL_TYPE -> serializeExpandedType(context, EXPANDED_WITHOUT_ABBREVIATIONS).apply {
|
||||||
abbreviatedType = buildAbbreviationType(context, expansion)
|
abbreviatedType = serializeAbbreviationType(context, expansion)
|
||||||
}
|
}
|
||||||
FOR_NESTED_TYPE -> buildExpandedType(context, expansion).apply {
|
FOR_NESTED_TYPE -> serializeExpandedType(context, expansion).apply {
|
||||||
abbreviatedType = buildAbbreviationType(context, expansion)
|
abbreviatedType = serializeAbbreviationType(context, expansion)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirTypeAliasType.buildAbbreviationType(
|
private fun CirTypeAliasType.serializeAbbreviationType(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion
|
expansion: TypeAliasExpansion
|
||||||
): KmType {
|
): KmType {
|
||||||
val abbreviationType = KmType(typeFlags())
|
val abbreviationType = KmType(typeFlags())
|
||||||
abbreviationType.classifier = KmClassifier.TypeAlias(classifierId.toString())
|
abbreviationType.classifier = KmClassifier.TypeAlias(classifierId.toString())
|
||||||
arguments.mapTo(abbreviationType.arguments) { it.buildArgument(context, expansion) }
|
arguments.mapTo(abbreviationType.arguments) { it.serializeArgument(context, expansion) }
|
||||||
return abbreviationType
|
return abbreviationType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UnnecessaryVariable")
|
@Suppress("UnnecessaryVariable")
|
||||||
private fun CirTypeAliasType.buildExpandedType(
|
private fun CirTypeAliasType.serializeExpandedType(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion
|
expansion: TypeAliasExpansion
|
||||||
): KmType {
|
): KmType {
|
||||||
val cirExpandedType = computeExpandedType(underlyingType)
|
val cirExpandedType = computeExpandedType(underlyingType)
|
||||||
val expandedType = cirExpandedType.buildType(context, expansion)
|
val expandedType = cirExpandedType.serializeClassType(context, expansion)
|
||||||
return expandedType
|
return expandedType
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun CirTypeProjection.buildArgument(
|
private fun CirTypeProjection.serializeArgument(
|
||||||
context: CirTreeSerializationContext,
|
context: CirTreeSerializationContext,
|
||||||
expansion: TypeAliasExpansion
|
expansion: TypeAliasExpansion
|
||||||
): KmTypeProjection {
|
): KmTypeProjection {
|
||||||
@@ -341,14 +341,14 @@ private fun CirTypeProjection.buildArgument(
|
|||||||
return when (this) {
|
return when (this) {
|
||||||
CirStarTypeProjection -> KmTypeProjection.STAR
|
CirStarTypeProjection -> KmTypeProjection.STAR
|
||||||
is CirRegularTypeProjection -> KmTypeProjection(
|
is CirRegularTypeProjection -> KmTypeProjection(
|
||||||
variance = projectionKind.buildVariance(),
|
variance = projectionKind.serializeVariance(),
|
||||||
type = type.buildType(context, effectiveExpansion)
|
type = type.serializeType(context, effectiveExpansion)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
private inline fun Variance.buildVariance(): KmVariance = when (this) {
|
private inline fun Variance.serializeVariance(): KmVariance = when (this) {
|
||||||
Variance.INVARIANT -> KmVariance.INVARIANT
|
Variance.INVARIANT -> KmVariance.INVARIANT
|
||||||
Variance.IN_VARIANCE -> KmVariance.IN
|
Variance.IN_VARIANCE -> KmVariance.IN
|
||||||
Variance.OUT_VARIANCE -> KmVariance.OUT
|
Variance.OUT_VARIANCE -> KmVariance.OUT
|
||||||
|
|||||||
Reference in New Issue
Block a user