Fix up after the code review. Squash me.

This commit is contained in:
Alexander Gorshenev
2017-05-17 16:46:47 +03:00
committed by alexander-gorshenev
parent d4c34b29c1
commit bb40d015d0
4 changed files with 20 additions and 42 deletions
@@ -296,7 +296,7 @@ internal fun FunctionDescriptor.bridgeDirectionsTo(overriddenDescriptor: Functio
return ourDirections
}
internal fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
tailrec internal fun DeclarationDescriptor.findPackage(): PackageFragmentDescriptor {
return if (this is PackageFragmentDescriptor) this
else this.containingDeclaration!!.findPackage()
}
@@ -30,7 +30,8 @@ import org.jetbrains.kotlin.resolve.calls.tasks.createSynthesizedInvokes
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.serialization.KonanIr
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.ProtoBuf
import org.jetbrains.kotlin.serialization.deserialization.NameResolver
@@ -83,13 +84,13 @@ internal class IrDescriptorDeserializer(val context: Context,
val index = irProto.index
//val localDeserializer = LocalDeclarationDeserializer(parent)
val descriptor: DeclarationDescriptor = when(localDeclarationProto.descriptorCase) {
FUNCTION ->
DescriptorCase.FUNCTION ->
localDeserializer.deserializeFunction(irProto)
PROPERTY ->
DescriptorCase.PROPERTY ->
localDeserializer.deserializeProperty(irProto)
CLAZZ ->
DescriptorCase.CLAZZ ->
localDeserializer.deserializeClass(irProto)
CONSTRUCTOR ->
DescriptorCase.CONSTRUCTOR ->
localDeserializer.deserializeConstructor(irProto)
else -> TODO("Unexpected descriptor kind")
}
@@ -105,23 +106,11 @@ internal class IrDescriptorDeserializer(val context: Context,
val kind = proto.kind
val descriptor = when (kind) {
KonanIr.KotlinDescriptor.Kind.VALUE_PARAMETER,
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 ->
VALUE_PARAMETER, TYPE_PARAMETER, RECEIVER, PROPERTY, VARIABLE ->
descriptorIndex[index]!!
KonanIr.KotlinDescriptor.Kind.CLASS,
KonanIr.KotlinDescriptor.Kind.CONSTRUCTOR,
KonanIr.KotlinDescriptor.Kind.FUNCTION,
KonanIr.KotlinDescriptor.Kind.ACCESSOR -> {
CLASS, CONSTRUCTOR, FUNCTION, ACCESSOR ->
descriptorIndex[index] ?:
findInTheDescriptorTree(proto)!!
}
else -> TODO("Unexpected descriptor kind: $kind")
}
@@ -306,7 +295,7 @@ internal class IrDescriptorDeserializer(val context: Context,
val classOrPackage = proto.classOrPackage
val name = proto.name
when (proto.kind) {
KotlinDescriptor.Kind.CLASS -> {
CLASS -> {
val parentScope =
parentMemberScopeByFqNameIndex(classOrPackage)
val clazz = parentScope.getContributedClassifier(
@@ -314,13 +303,12 @@ internal class IrDescriptorDeserializer(val context: Context,
return listOf(clazz!!)
}
KotlinDescriptor.Kind.CONSTRUCTOR -> {
CONSTRUCTOR -> {
val parent = parentByFqNameIndex(classOrPackage)
assert(parent is ClassDescriptor)
return (parent as ClassDescriptor).constructors
}
KotlinDescriptor.Kind.ACCESSOR,
KotlinDescriptor.Kind.FUNCTION -> {
ACCESSOR, FUNCTION -> {
val parentScope =
parentMemberScopeByFqNameIndex(classOrPackage)
return parentScope.contributedMethods.filter{
@@ -389,14 +377,10 @@ internal class IrDescriptorDeserializer(val context: Context,
DeclarationDescriptor {
return when(proto.kind) {
KotlinDescriptor.Kind.FUNCTION ->
selectFunction(matching, proto)
KotlinDescriptor.Kind.ACCESSOR ->
selectAccessor(matching, proto)
KotlinDescriptor.Kind.CONSTRUCTOR ->
selectConstructor(matching, proto)
KotlinDescriptor.Kind.CLASS ->
matching.single()
FUNCTION -> selectFunction(matching, proto)
ACCESSOR -> selectAccessor(matching, proto)
CONSTRUCTOR -> selectConstructor(matching, proto)
CLASS -> matching.single()
else -> TODO("don't know how to select ${proto.kind}")
}
}
@@ -295,8 +295,7 @@ class KonanDescriptorSerializer private constructor(
extension.serializeFunction(descriptor, builder)
if (extension is IrAwareExtension
&& descriptor.needsSerializedIr) {
if (extension is IrAwareExtension && descriptor.needsSerializedIr) {
extension.addFunctionIR(builder,
extension.serializeInlineBody(descriptor, local))
}
@@ -324,8 +323,7 @@ class KonanDescriptorSerializer private constructor(
extension.serializeConstructor(descriptor, builder)
if (extension is IrAwareExtension
&& descriptor.needsSerializedIr) {
if (extension is IrAwareExtension && descriptor.needsSerializedIr) {
extension.addConstructorIR(builder,
extension.serializeInlineBody(descriptor, local))
}
@@ -453,10 +451,7 @@ class KonanDescriptorSerializer private constructor(
return builder
}
public fun typeId(type: KotlinType): Int {
val result = typeTable[type(type)]
return result
}
public fun typeId(type: KotlinType) = typeTable[type(type)]
private fun type(type: KotlinType): ProtoBuf.Type.Builder {
val builder = ProtoBuf.Type.newBuilder()
@@ -60,8 +60,7 @@ internal class LocalDeclarationSerializer(val context: Context, val rootFunction
val localSerializer
get() = contextStack.peek()!!
val typeSerializer: ((KotlinType)->Int)
get() = {it -> localSerializer.typeId(it)}
fun typeSerializer(type: KotlinType) = localSerializer.typeId(type)
fun serializeLocalDeclaration(descriptor: DeclarationDescriptor): KonanIr.DeclarationDescriptor {