Fix up after the code review. Squash me.
This commit is contained in:
committed by
alexander-gorshenev
parent
d4c34b29c1
commit
bb40d015d0
+1
-1
@@ -296,7 +296,7 @@ internal fun FunctionDescriptor.bridgeDirectionsTo(overriddenDescriptor: Functio
|
|||||||
return ourDirections
|
return ourDirections
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
|
tailrec internal fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
|
||||||
return if (this is PackageFragmentDescriptor) this
|
return if (this is PackageFragmentDescriptor) this
|
||||||
else this.containingDeclaration!!.findPackage()
|
else this.containingDeclaration!!.findPackage()
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-31
@@ -30,7 +30,8 @@ import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.serialization.KonanIr
|
import org.jetbrains.kotlin.serialization.KonanIr
|
||||||
import org.jetbrains.kotlin.serialization.KonanIr.KotlinDescriptor
|
import org.jetbrains.kotlin.serialization.KonanIr.KotlinDescriptor
|
||||||
import org.jetbrains.kotlin.serialization.KonanIr.DeclarationDescriptor.DescriptorCase.*
|
import org.jetbrains.kotlin.serialization.KonanIr.KotlinDescriptor.Kind.*
|
||||||
|
import org.jetbrains.kotlin.serialization.KonanIr.DeclarationDescriptor.*
|
||||||
import org.jetbrains.kotlin.serialization.KonanLinkData
|
import org.jetbrains.kotlin.serialization.KonanLinkData
|
||||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
|
||||||
@@ -83,13 +84,13 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
val index = irProto.index
|
val index = irProto.index
|
||||||
//val localDeserializer = LocalDeclarationDeserializer(parent)
|
//val localDeserializer = LocalDeclarationDeserializer(parent)
|
||||||
val descriptor: DeclarationDescriptor = when(localDeclarationProto.descriptorCase) {
|
val descriptor: DeclarationDescriptor = when(localDeclarationProto.descriptorCase) {
|
||||||
FUNCTION ->
|
DescriptorCase.FUNCTION ->
|
||||||
localDeserializer.deserializeFunction(irProto)
|
localDeserializer.deserializeFunction(irProto)
|
||||||
PROPERTY ->
|
DescriptorCase.PROPERTY ->
|
||||||
localDeserializer.deserializeProperty(irProto)
|
localDeserializer.deserializeProperty(irProto)
|
||||||
CLAZZ ->
|
DescriptorCase.CLAZZ ->
|
||||||
localDeserializer.deserializeClass(irProto)
|
localDeserializer.deserializeClass(irProto)
|
||||||
CONSTRUCTOR ->
|
DescriptorCase.CONSTRUCTOR ->
|
||||||
localDeserializer.deserializeConstructor(irProto)
|
localDeserializer.deserializeConstructor(irProto)
|
||||||
else -> TODO("Unexpected descriptor kind")
|
else -> TODO("Unexpected descriptor kind")
|
||||||
}
|
}
|
||||||
@@ -105,23 +106,11 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
val kind = proto.kind
|
val kind = proto.kind
|
||||||
|
|
||||||
val descriptor = when (kind) {
|
val descriptor = when (kind) {
|
||||||
KonanIr.KotlinDescriptor.Kind.VALUE_PARAMETER,
|
VALUE_PARAMETER, TYPE_PARAMETER, RECEIVER, PROPERTY, VARIABLE ->
|
||||||
KonanIr.KotlinDescriptor.Kind.TYPE_PARAMETER,
|
|
||||||
KonanIr.KotlinDescriptor.Kind.RECEIVER,
|
|
||||||
// Properties can only be found in local
|
|
||||||
// classes, so no need to look for them
|
|
||||||
// in the public descriptor tree.
|
|
||||||
KonanIr.KotlinDescriptor.Kind.PROPERTY,
|
|
||||||
KonanIr.KotlinDescriptor.Kind.VARIABLE ->
|
|
||||||
descriptorIndex[index]!!
|
descriptorIndex[index]!!
|
||||||
|
CLASS, CONSTRUCTOR, FUNCTION, ACCESSOR ->
|
||||||
KonanIr.KotlinDescriptor.Kind.CLASS,
|
|
||||||
KonanIr.KotlinDescriptor.Kind.CONSTRUCTOR,
|
|
||||||
KonanIr.KotlinDescriptor.Kind.FUNCTION,
|
|
||||||
KonanIr.KotlinDescriptor.Kind.ACCESSOR -> {
|
|
||||||
descriptorIndex[index] ?:
|
descriptorIndex[index] ?:
|
||||||
findInTheDescriptorTree(proto)!!
|
findInTheDescriptorTree(proto)!!
|
||||||
}
|
|
||||||
else -> TODO("Unexpected descriptor kind: $kind")
|
else -> TODO("Unexpected descriptor kind: $kind")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,7 +295,7 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
val classOrPackage = proto.classOrPackage
|
val classOrPackage = proto.classOrPackage
|
||||||
val name = proto.name
|
val name = proto.name
|
||||||
when (proto.kind) {
|
when (proto.kind) {
|
||||||
KotlinDescriptor.Kind.CLASS -> {
|
CLASS -> {
|
||||||
val parentScope =
|
val parentScope =
|
||||||
parentMemberScopeByFqNameIndex(classOrPackage)
|
parentMemberScopeByFqNameIndex(classOrPackage)
|
||||||
val clazz = parentScope.getContributedClassifier(
|
val clazz = parentScope.getContributedClassifier(
|
||||||
@@ -314,13 +303,12 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
return listOf(clazz!!)
|
return listOf(clazz!!)
|
||||||
|
|
||||||
}
|
}
|
||||||
KotlinDescriptor.Kind.CONSTRUCTOR -> {
|
CONSTRUCTOR -> {
|
||||||
val parent = parentByFqNameIndex(classOrPackage)
|
val parent = parentByFqNameIndex(classOrPackage)
|
||||||
assert(parent is ClassDescriptor)
|
assert(parent is ClassDescriptor)
|
||||||
return (parent as ClassDescriptor).constructors
|
return (parent as ClassDescriptor).constructors
|
||||||
}
|
}
|
||||||
KotlinDescriptor.Kind.ACCESSOR,
|
ACCESSOR, FUNCTION -> {
|
||||||
KotlinDescriptor.Kind.FUNCTION -> {
|
|
||||||
val parentScope =
|
val parentScope =
|
||||||
parentMemberScopeByFqNameIndex(classOrPackage)
|
parentMemberScopeByFqNameIndex(classOrPackage)
|
||||||
return parentScope.contributedMethods.filter{
|
return parentScope.contributedMethods.filter{
|
||||||
@@ -389,14 +377,10 @@ internal class IrDescriptorDeserializer(val context: Context,
|
|||||||
DeclarationDescriptor {
|
DeclarationDescriptor {
|
||||||
|
|
||||||
return when(proto.kind) {
|
return when(proto.kind) {
|
||||||
KotlinDescriptor.Kind.FUNCTION ->
|
FUNCTION -> selectFunction(matching, proto)
|
||||||
selectFunction(matching, proto)
|
ACCESSOR -> selectAccessor(matching, proto)
|
||||||
KotlinDescriptor.Kind.ACCESSOR ->
|
CONSTRUCTOR -> selectConstructor(matching, proto)
|
||||||
selectAccessor(matching, proto)
|
CLASS -> matching.single()
|
||||||
KotlinDescriptor.Kind.CONSTRUCTOR ->
|
|
||||||
selectConstructor(matching, proto)
|
|
||||||
KotlinDescriptor.Kind.CLASS ->
|
|
||||||
matching.single()
|
|
||||||
else -> TODO("don't know how to select ${proto.kind}")
|
else -> TODO("don't know how to select ${proto.kind}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-8
@@ -295,8 +295,7 @@ class KonanDescriptorSerializer private constructor(
|
|||||||
|
|
||||||
extension.serializeFunction(descriptor, builder)
|
extension.serializeFunction(descriptor, builder)
|
||||||
|
|
||||||
if (extension is IrAwareExtension
|
if (extension is IrAwareExtension && descriptor.needsSerializedIr) {
|
||||||
&& descriptor.needsSerializedIr) {
|
|
||||||
extension.addFunctionIR(builder,
|
extension.addFunctionIR(builder,
|
||||||
extension.serializeInlineBody(descriptor, local))
|
extension.serializeInlineBody(descriptor, local))
|
||||||
}
|
}
|
||||||
@@ -324,8 +323,7 @@ class KonanDescriptorSerializer private constructor(
|
|||||||
|
|
||||||
extension.serializeConstructor(descriptor, builder)
|
extension.serializeConstructor(descriptor, builder)
|
||||||
|
|
||||||
if (extension is IrAwareExtension
|
if (extension is IrAwareExtension && descriptor.needsSerializedIr) {
|
||||||
&& descriptor.needsSerializedIr) {
|
|
||||||
extension.addConstructorIR(builder,
|
extension.addConstructorIR(builder,
|
||||||
extension.serializeInlineBody(descriptor, local))
|
extension.serializeInlineBody(descriptor, local))
|
||||||
}
|
}
|
||||||
@@ -453,10 +451,7 @@ class KonanDescriptorSerializer private constructor(
|
|||||||
return builder
|
return builder
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun typeId(type: KotlinType): Int {
|
public fun typeId(type: KotlinType) = typeTable[type(type)]
|
||||||
val result = typeTable[type(type)]
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun type(type: KotlinType): ProtoBuf.Type.Builder {
|
private fun type(type: KotlinType): ProtoBuf.Type.Builder {
|
||||||
val builder = ProtoBuf.Type.newBuilder()
|
val builder = ProtoBuf.Type.newBuilder()
|
||||||
|
|||||||
+1
-2
@@ -60,8 +60,7 @@ internal class LocalDeclarationSerializer(val context: Context, val rootFunction
|
|||||||
val localSerializer
|
val localSerializer
|
||||||
get() = contextStack.peek()!!
|
get() = contextStack.peek()!!
|
||||||
|
|
||||||
val typeSerializer: ((KotlinType)->Int)
|
fun typeSerializer(type: KotlinType) = localSerializer.typeId(type)
|
||||||
get() = {it -> localSerializer.typeId(it)}
|
|
||||||
|
|
||||||
fun serializeLocalDeclaration(descriptor: DeclarationDescriptor): KonanIr.DeclarationDescriptor {
|
fun serializeLocalDeclaration(descriptor: DeclarationDescriptor): KonanIr.DeclarationDescriptor {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user