IR: annotations are represented as IrConstructorCall elements
Also, they are rendered somewhat nicer
This commit is contained in:
+80
-62
@@ -83,9 +83,9 @@ abstract class IrModuleDeserializer(
|
||||
|
||||
}
|
||||
|
||||
fun deserializeAnnotations(annotations: KotlinIr.Annotations): List<IrCall> {
|
||||
fun deserializeAnnotations(annotations: KotlinIr.Annotations): List<IrConstructorCall> {
|
||||
return annotations.annotationList.map {
|
||||
deserializeCall(it, 0, 0, builtIns.unitType) // TODO: need a proper deserialization here
|
||||
deserializeConstructorCall(it, 0, 0, builtIns.unitType) // TODO: need a proper deserialization here
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +243,19 @@ abstract class IrModuleDeserializer(
|
||||
return IrClassReferenceImpl(start, end, type, symbol, classType)
|
||||
}
|
||||
|
||||
private fun deserializeConstructorCall(proto: KotlinIr.IrConstructorCall, start: Int, end: Int, type: IrType): IrConstructorCall {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrConstructorSymbol
|
||||
return IrConstructorCallImpl(
|
||||
start, end, type,
|
||||
symbol, symbol.descriptor,
|
||||
typeArgumentsCount = proto.memberAccess.typeArguments.typeArgumentCount,
|
||||
constructorTypeArgumentsCount = proto.constructorTypeArgumentsCount,
|
||||
valueArgumentsCount = proto.memberAccess.valueArgumentCount
|
||||
).also {
|
||||
deserializeMemberAccessCommon(it, proto.memberAccess)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deserializeCall(proto: KotlinIr.IrCall, start: Int, end: Int, type: IrType): IrCall {
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrFunctionSymbol
|
||||
|
||||
@@ -415,11 +428,11 @@ abstract class IrModuleDeserializer(
|
||||
val getter = if (proto.hasGetter()) deserializeIrSymbol(proto.getter) as IrSimpleFunctionSymbol else null
|
||||
val setter = if (proto.hasSetter()) deserializeIrSymbol(proto.setter) as IrSimpleFunctionSymbol else null
|
||||
val descriptor =
|
||||
if (proto.hasDescriptorReference())
|
||||
deserializeDescriptorReference(proto.descriptorReference) as PropertyDescriptor
|
||||
else
|
||||
field?.descriptor as? WrappedPropertyDescriptor // If field's descriptor coincides with property's.
|
||||
?: getterToPropertyDescriptorMap.getOrPut(getter!!) { WrappedPropertyDescriptor() }
|
||||
if (proto.hasDescriptorReference())
|
||||
deserializeDescriptorReference(proto.descriptorReference) as PropertyDescriptor
|
||||
else
|
||||
field?.descriptor as? WrappedPropertyDescriptor // If field's descriptor coincides with property's.
|
||||
?: getterToPropertyDescriptorMap.getOrPut(getter!!) { WrappedPropertyDescriptor() }
|
||||
|
||||
val callable = IrPropertyReferenceImpl(
|
||||
start, end, type,
|
||||
@@ -573,10 +586,10 @@ abstract class IrModuleDeserializer(
|
||||
// we create the loop before deserializing the body, so that
|
||||
// IrBreak statements have something to put into 'loop' field.
|
||||
private fun deserializeDoWhile(proto: KotlinIr.IrDoWhile, start: Int, end: Int, type: IrType) =
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) { IrDoWhileLoopImpl(start, end, type, null) })
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) { IrDoWhileLoopImpl(start, end, type, null) })
|
||||
|
||||
private fun deserializeWhile(proto: KotlinIr.IrWhile, start: Int, end: Int, type: IrType) =
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) { IrWhileLoopImpl(start, end, type, null) })
|
||||
deserializeLoop(proto.loop, deserializeLoopHeader(proto.loop.loopId) { IrWhileLoopImpl(start, end, type, null) })
|
||||
|
||||
private fun deserializeDynamicMemberExpression(proto: KotlinIr.IrDynamicMemberExpression, start: Int, end: Int, type: IrType) =
|
||||
IrDynamicMemberExpressionImpl(start, end, type, deserializeString(proto.memberName), deserializeExpression(proto.receiver))
|
||||
@@ -741,6 +754,8 @@ abstract class IrModuleDeserializer(
|
||||
-> deserializeDynamicMemberExpression(proto.dynamicMember, start, end, type)
|
||||
DYNAMIC_OPERATOR
|
||||
-> deserializeDynamicOperatorExpression(proto.dynamicOperator, start, end, type)
|
||||
CONSTRUCTOR_CALL
|
||||
-> deserializeConstructorCall(proto.constructorCall, start, end, type)
|
||||
OPERATION_NOT_SET
|
||||
-> error("Expression deserialization not implemented: ${proto.operationCase}")
|
||||
}
|
||||
@@ -834,20 +849,22 @@ abstract class IrModuleDeserializer(
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrClassSymbol
|
||||
|
||||
val modality = deserializeModality(proto.modality)
|
||||
val clazz = symbolTable.declareClass(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
symbol.descriptor, modality) {
|
||||
val clazz = symbolTable.declareClass(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
symbol.descriptor, modality
|
||||
) {
|
||||
IrClassImpl(
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.name),
|
||||
deserializeClassKind(proto.kind),
|
||||
deserializeVisibility(proto.visibility),
|
||||
modality,
|
||||
proto.isCompanion,
|
||||
proto.isInner,
|
||||
proto.isData,
|
||||
proto.isExternal,
|
||||
proto.isInline
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.name),
|
||||
deserializeClassKind(proto.kind),
|
||||
deserializeVisibility(proto.visibility),
|
||||
modality,
|
||||
proto.isCompanion,
|
||||
proto.isInner,
|
||||
proto.isData,
|
||||
proto.isExternal,
|
||||
proto.isInline
|
||||
)
|
||||
}
|
||||
|
||||
@@ -901,19 +918,19 @@ abstract class IrModuleDeserializer(
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrSimpleFunctionSymbol
|
||||
|
||||
val function = symbolTable.declareSimpleFunction(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
symbol.descriptor, {
|
||||
IrFunctionImpl(
|
||||
start, end, origin, it,
|
||||
deserializeName(proto.base.name),
|
||||
deserializeVisibility(proto.base.visibility),
|
||||
deserializeModality(proto.modality),
|
||||
deserializeIrType(proto.base.returnType),
|
||||
proto.base.isInline,
|
||||
proto.base.isExternal,
|
||||
proto.isTailrec,
|
||||
proto.isSuspend
|
||||
)
|
||||
})
|
||||
symbol.descriptor, {
|
||||
IrFunctionImpl(
|
||||
start, end, origin, it,
|
||||
deserializeName(proto.base.name),
|
||||
deserializeVisibility(proto.base.visibility),
|
||||
deserializeModality(proto.modality),
|
||||
deserializeIrType(proto.base.returnType),
|
||||
proto.base.isInline,
|
||||
proto.base.isExternal,
|
||||
proto.isTailrec,
|
||||
proto.isSuspend
|
||||
)
|
||||
})
|
||||
|
||||
deserializeIrFunctionBase(proto.base, function as IrFunctionBase, start, end, origin)
|
||||
val overridden = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
||||
@@ -1010,19 +1027,19 @@ abstract class IrModuleDeserializer(
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrConstructorSymbol
|
||||
|
||||
val constructor = symbolTable.declareConstructor(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irrelevantOrigin,
|
||||
symbol.descriptor, {
|
||||
IrConstructorImpl(
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.base.name),
|
||||
deserializeVisibility(proto.base.visibility),
|
||||
deserializeIrType(proto.base.returnType),
|
||||
proto.base.isInline,
|
||||
proto.base.isExternal,
|
||||
proto.isPrimary
|
||||
)
|
||||
symbol.descriptor, {
|
||||
IrConstructorImpl(
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.base.name),
|
||||
deserializeVisibility(proto.base.visibility),
|
||||
deserializeIrType(proto.base.returnType),
|
||||
proto.base.isInline,
|
||||
proto.base.isExternal,
|
||||
proto.isPrimary
|
||||
)
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
deserializeIrFunctionBase(proto.base, constructor as IrFunctionBase, start, end, origin)
|
||||
return constructor
|
||||
@@ -1033,21 +1050,22 @@ abstract class IrModuleDeserializer(
|
||||
val symbol = deserializeIrSymbol(proto.symbol) as IrFieldSymbol
|
||||
val type = deserializeIrType(proto.type)
|
||||
val field = symbolTable.declareField(UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
irrelevantOrigin,
|
||||
symbol.descriptor,
|
||||
type,
|
||||
{ IrFieldImpl(
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.name),
|
||||
type,
|
||||
deserializeVisibility(proto.visibility),
|
||||
proto.isFinal,
|
||||
proto.isExternal,
|
||||
proto.isStatic
|
||||
)
|
||||
}
|
||||
UNDEFINED_OFFSET,
|
||||
irrelevantOrigin,
|
||||
symbol.descriptor,
|
||||
type,
|
||||
{
|
||||
IrFieldImpl(
|
||||
start, end, origin,
|
||||
it,
|
||||
deserializeName(proto.name),
|
||||
type,
|
||||
deserializeVisibility(proto.visibility),
|
||||
proto.isFinal,
|
||||
proto.isExternal,
|
||||
proto.isStatic
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
val initializer = if (proto.hasInitializer()) deserializeExpression(proto.initializer) else null
|
||||
|
||||
+11
-4
@@ -173,10 +173,10 @@ open class IrModuleSerializer(
|
||||
Variance.INVARIANT -> KotlinIr.IrTypeVariance.INV
|
||||
}
|
||||
|
||||
fun serializeAnnotations(annotations: List<IrCall>): KotlinIr.Annotations {
|
||||
fun serializeAnnotations(annotations: List<IrConstructorCall>): KotlinIr.Annotations {
|
||||
val proto = KotlinIr.Annotations.newBuilder()
|
||||
annotations.forEach {
|
||||
proto.addAnnotation(serializeCall(it))
|
||||
proto.addAnnotation(serializeConstructorCall(it))
|
||||
}
|
||||
return proto.build()
|
||||
}
|
||||
@@ -245,12 +245,12 @@ open class IrModuleSerializer(
|
||||
}
|
||||
|
||||
// This is just IrType repacked as a data class, good to address a hash map.
|
||||
data class IrTypeKey (
|
||||
data class IrTypeKey(
|
||||
val kind: IrTypeKind,
|
||||
val classifier: IrClassifierSymbol?,
|
||||
val hasQuestionMark: Boolean?,
|
||||
val arguments: List<IrTypeArgumentKey>?,
|
||||
val annotations: List<IrCall>
|
||||
val annotations: List<IrConstructorCall>
|
||||
)
|
||||
|
||||
data class IrTypeArgumentKey (
|
||||
@@ -399,6 +399,13 @@ open class IrModuleSerializer(
|
||||
return proto.build()
|
||||
}
|
||||
|
||||
private fun serializeConstructorCall(call: IrConstructorCall): KotlinIr.IrConstructorCall =
|
||||
KotlinIr.IrConstructorCall.newBuilder().apply {
|
||||
symbol = serializeIrSymbol(call.symbol)
|
||||
constructorTypeArgumentsCount = call.constructorTypeArgumentsCount
|
||||
memberAccess = serializeMemberAccessCommon(call)
|
||||
}.build()
|
||||
|
||||
private fun serializeFunctionReference(callable: IrFunctionReference): KotlinIr.IrFunctionReference {
|
||||
val proto = KotlinIr.IrFunctionReference.newBuilder()
|
||||
.setSymbol(serializeIrSymbol(callable.symbol))
|
||||
|
||||
Reference in New Issue
Block a user