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