FIR: pass name resolver to annotation deserializer separately
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1bb4b32c91
commit
4bcba000fd
+5
-5
@@ -9,14 +9,14 @@ import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.deserialization.AbstractAnnotationDeserializer
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmNameResolver
|
||||
|
||||
class JvmBinaryAnnotationDeserializer(
|
||||
session: FirSession, nameResolver: JvmNameResolver
|
||||
) : AbstractAnnotationDeserializer(session, nameResolver) {
|
||||
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type): List<FirAnnotationCall> {
|
||||
session: FirSession
|
||||
) : AbstractAnnotationDeserializer(session) {
|
||||
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
val annotations = typeProto.getExtension(JvmProtoBuf.typeAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -103,7 +103,7 @@ class KotlinDeserializedJvmSymbolsProvider(
|
||||
packageProto,
|
||||
FirDeserializationContext.createForPackage(
|
||||
packageFqName, packageProto, nameResolver, session,
|
||||
JvmBinaryAnnotationDeserializer(session, nameResolver)
|
||||
JvmBinaryAnnotationDeserializer(session)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -313,7 +313,7 @@ class KotlinDeserializedJvmSymbolsProvider(
|
||||
val symbol = FirClassSymbol(classId)
|
||||
deserializeClassToSymbol(
|
||||
classId, classProto, symbol, nameResolver, session,
|
||||
JvmBinaryAnnotationDeserializer(session, nameResolver),
|
||||
JvmBinaryAnnotationDeserializer(session),
|
||||
parentContext, this::findAndDeserializeClass
|
||||
)
|
||||
classesCache[classId] = symbol
|
||||
|
||||
+14
-15
@@ -30,44 +30,43 @@ import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||
|
||||
abstract class AbstractAnnotationDeserializer(
|
||||
private val session: FirSession,
|
||||
private val nameResolver: NameResolver
|
||||
private val session: FirSession
|
||||
) {
|
||||
protected val protocol = BuiltInSerializerProtocol
|
||||
|
||||
fun loadClassAnnotations(classProto: ProtoBuf.Class): List<FirAnnotationCall> {
|
||||
fun loadClassAnnotations(classProto: ProtoBuf.Class, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) return emptyList()
|
||||
val annotations = classProto.getExtension(protocol.classAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
fun loadFunctionAnnotations(functionProto: ProtoBuf.Function): List<FirAnnotationCall> {
|
||||
fun loadFunctionAnnotations(functionProto: ProtoBuf.Function, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(functionProto.flags)) return emptyList()
|
||||
val annotations = functionProto.getExtension(protocol.functionAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
fun loadPropertyAnnotations(propertyProto: ProtoBuf.Property): List<FirAnnotationCall> {
|
||||
fun loadPropertyAnnotations(propertyProto: ProtoBuf.Property, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(propertyProto.flags)) return emptyList()
|
||||
val annotations = propertyProto.getExtension(protocol.propertyAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
fun loadConstructorAnnotations(constructorProto: ProtoBuf.Constructor): List<FirAnnotationCall> {
|
||||
fun loadConstructorAnnotations(constructorProto: ProtoBuf.Constructor, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(constructorProto.flags)) return emptyList()
|
||||
val annotations = constructorProto.getExtension(protocol.constructorAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
fun loadValueParameterAnnotations(valueParameterProto: ProtoBuf.ValueParameter): List<FirAnnotationCall> {
|
||||
fun loadValueParameterAnnotations(valueParameterProto: ProtoBuf.ValueParameter, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(valueParameterProto.flags)) return emptyList()
|
||||
val annotations = valueParameterProto.getExtension(protocol.parameterAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
|
||||
abstract fun loadTypeAnnotations(typeProto: ProtoBuf.Type): List<FirAnnotationCall>
|
||||
abstract fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List<FirAnnotationCall>
|
||||
|
||||
fun deserializeAnnotation(proto: ProtoBuf.Annotation): FirAnnotationCall {
|
||||
fun deserializeAnnotation(proto: ProtoBuf.Annotation, nameResolver: NameResolver): FirAnnotationCall {
|
||||
val classId = nameResolver.getClassId(proto.id)
|
||||
val lookupTag = ConeClassLikeLookupTagImpl(classId)
|
||||
val symbol = lookupTag.toSymbol(session)
|
||||
@@ -117,7 +116,7 @@ abstract class AbstractAnnotationDeserializer(
|
||||
DOUBLE -> const(IrConstKind.Double, value.doubleValue)
|
||||
BOOLEAN -> const(IrConstKind.Boolean, (value.intValue != 0L))
|
||||
STRING -> const(IrConstKind.String, nameResolver.getString(value.stringValue))
|
||||
ANNOTATION -> deserializeAnnotation(value.annotation)
|
||||
ANNOTATION -> deserializeAnnotation(value.annotation, nameResolver)
|
||||
CLASS -> FirGetClassCallImpl(session, null).apply {
|
||||
val classId = nameResolver.getClassId(value.classId)
|
||||
val lookupTag = ConeClassLikeLookupTagImpl(classId)
|
||||
|
||||
+2
-2
@@ -52,10 +52,10 @@ fun deserializeClassToSymbol(
|
||||
classId.relativeClassName
|
||||
) ?: FirDeserializationContext.createForClass(
|
||||
classId, classProto, nameResolver, session,
|
||||
defaultAnnotationDeserializer ?: FirBuiltinAnnotationDeserializer(session, nameResolver)
|
||||
defaultAnnotationDeserializer ?: FirBuiltinAnnotationDeserializer(session)
|
||||
)
|
||||
typeParameters += context.typeDeserializer.ownTypeParameters.map { it.firUnsafe() }
|
||||
annotations += context.annotationDeserializer.loadClassAnnotations(classProto)
|
||||
annotations += context.annotationDeserializer.loadClassAnnotations(classProto, context.nameResolver)
|
||||
|
||||
val typeDeserializer = context.typeDeserializer
|
||||
val classDeserializer = context.memberDeserializer
|
||||
|
||||
+4
-4
@@ -12,12 +12,12 @@ import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
|
||||
class FirBuiltinAnnotationDeserializer(
|
||||
session: FirSession, nameResolver: NameResolver
|
||||
) : AbstractAnnotationDeserializer(session, nameResolver) {
|
||||
session: FirSession
|
||||
) : AbstractAnnotationDeserializer(session) {
|
||||
|
||||
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type): List<FirAnnotationCall> {
|
||||
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||
if (!Flags.HAS_ANNOTATIONS.get(typeProto.flags)) return emptyList()
|
||||
val annotations = typeProto.getExtension(protocol.typeAnnotation).orEmpty()
|
||||
return annotations.map { deserializeAnnotation(it) }
|
||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -181,7 +181,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
null
|
||||
).apply {
|
||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.firUnsafe() }
|
||||
annotations += c.annotationDeserializer.loadPropertyAnnotations(proto)
|
||||
annotations += c.annotationDeserializer.loadPropertyAnnotations(proto, local.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,12 +217,12 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
Flags.IS_TAILREC.get(flags),
|
||||
Flags.IS_EXTERNAL_FUNCTION.get(flags),
|
||||
Flags.IS_SUSPEND.get(flags),
|
||||
proto.receiverType(c.typeTable)?.toTypeRef(local),
|
||||
proto.returnType(c.typeTable).toTypeRef(local)
|
||||
proto.receiverType(local.typeTable)?.toTypeRef(local),
|
||||
proto.returnType(local.typeTable).toTypeRef(local)
|
||||
).apply {
|
||||
typeParameters += local.typeDeserializer.ownTypeParameters.map { it.firUnsafe() }
|
||||
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
||||
annotations += local.annotationDeserializer.loadFunctionAnnotations(proto)
|
||||
annotations += local.annotationDeserializer.loadFunctionAnnotations(proto, local.nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
}.apply {
|
||||
this.typeParameters += typeParameters
|
||||
valueParameters += local.memberDeserializer.valueParameters(proto.valueParameterList)
|
||||
annotations += local.annotationDeserializer.loadConstructorAnnotations(proto)
|
||||
annotations += local.annotationDeserializer.loadConstructorAnnotations(proto, local.nameResolver)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -299,7 +299,7 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
Flags.IS_NOINLINE.get(flags),
|
||||
proto.varargElementType(c.typeTable) != null
|
||||
).apply {
|
||||
annotations += c.annotationDeserializer.loadValueParameterAnnotations(proto)
|
||||
annotations += c.annotationDeserializer.loadValueParameterAnnotations(proto, c.nameResolver)
|
||||
}
|
||||
}.toList()
|
||||
}
|
||||
@@ -307,8 +307,8 @@ class FirMemberDeserializer(private val c: FirDeserializationContext) {
|
||||
private fun ProtoBuf.Type.toTypeRef(context: FirDeserializationContext): FirTypeRef {
|
||||
val coneType = context.typeDeserializer.type(this)
|
||||
return FirResolvedTypeRefImpl(
|
||||
c.session, null, coneType,
|
||||
c.annotationDeserializer.loadTypeAnnotations(this)
|
||||
context.session, null, coneType,
|
||||
context.annotationDeserializer.loadTypeAnnotations(this, context.nameResolver)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -68,7 +68,7 @@ class FirLibrarySymbolProviderImpl(val session: FirSession) : FirSymbolProvider
|
||||
private val memberDeserializer by lazy {
|
||||
FirDeserializationContext.createForPackage(
|
||||
fqName, packageProto.`package`, nameResolver, session,
|
||||
FirBuiltinAnnotationDeserializer(session, nameResolver)
|
||||
FirBuiltinAnnotationDeserializer(session)
|
||||
).memberDeserializer
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user