Store source file info in klib. (#2243)
This commit is contained in:
@@ -32,6 +32,7 @@ extend Constructor {
|
||||
extend Function {
|
||||
repeated Annotation function_annotation = 170;
|
||||
optional InlineIrBody inline_ir_body = 171;
|
||||
optional int32 function_file = 172;
|
||||
}
|
||||
|
||||
extend Property {
|
||||
@@ -41,6 +42,7 @@ extend Property {
|
||||
optional Annotation.Argument.Value compile_time_value = 173;
|
||||
optional InlineIrBody inline_getter_ir_body = 174;
|
||||
optional InlineIrBody inline_setter_ir_body = 175;
|
||||
optional int32 property_file = 176;
|
||||
}
|
||||
|
||||
extend EnumEntry {
|
||||
@@ -95,5 +97,6 @@ message LinkDataLibrary {
|
||||
required string module_name = 1;
|
||||
repeated string package_fragment_name = 2;
|
||||
repeated string empty_package = 3;
|
||||
repeated string file = 4;
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -2,11 +2,10 @@ package org.jetbrains.kotlin.konan.library.resolver.impl
|
||||
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.konan.library.resolver.KonanResolvedLibrary
|
||||
import org.jetbrains.kotlin.serialization.konan.SourceFileMap
|
||||
import org.jetbrains.kotlin.serialization.konan.parseModuleHeader
|
||||
|
||||
internal class KonanResolvedLibraryImpl(
|
||||
override val library: KonanLibrary
|
||||
): KonanResolvedLibrary {
|
||||
internal class KonanResolvedLibraryImpl(override val library: KonanLibrary): KonanResolvedLibrary {
|
||||
|
||||
private val _resolvedDependencies = mutableListOf<KonanResolvedLibrary>()
|
||||
private val _emptyPackages by lazy { parseModuleHeader(library.moduleHeaderData).emptyPackageList }
|
||||
|
||||
+22
@@ -1,8 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.kotlin.serialization.konan
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.konan.library.resolver.KonanResolvedLibrary
|
||||
import org.jetbrains.kotlin.konan.library.resolver.PackageAccessedHandler
|
||||
import org.jetbrains.kotlin.konan.library.resolver.impl.KonanResolvedLibraryImpl
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -14,6 +21,17 @@ import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getName
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
|
||||
private val KonanLibrary.fileSources: SourceFileMap get() {
|
||||
val result = SourceFileMap()
|
||||
val proto = parseModuleHeader(moduleHeaderData)
|
||||
proto.fileList.forEachIndexed { index, it ->
|
||||
result.provide(it, index, this)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
class KonanPackageFragment(
|
||||
fqName: FqName,
|
||||
private val library: KonanLibrary,
|
||||
@@ -23,6 +41,10 @@ class KonanPackageFragment(
|
||||
partName: String
|
||||
) : DeserializedPackageFragment(fqName, storageManager, module) {
|
||||
|
||||
val sourceFileMap: SourceFileMap by lazy {
|
||||
library.fileSources
|
||||
}
|
||||
|
||||
lateinit var components: DeserializationComponents
|
||||
|
||||
override fun initialize(components: DeserializationComponents) {
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
package org.jetbrains.kotlin.serialization.konan
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.SourceFile
|
||||
import org.jetbrains.kotlin.konan.library.KonanLibrary
|
||||
import org.jetbrains.kotlin.konan.library.resolver.KonanResolvedLibrary
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment
|
||||
|
||||
private class DeserializedSourceFile(
|
||||
val name_: String, val index: Int, val library: KonanLibrary) : SourceFile {
|
||||
override fun getName(): String? = name_
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is DeserializedSourceFile && library == other.library && index == other.index
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return library.hashCode() xor index
|
||||
}
|
||||
}
|
||||
|
||||
class SourceFileMap {
|
||||
private val sourceToIndex = mutableMapOf<SourceFile, Int>()
|
||||
private val indexToSource = mutableMapOf<Int, SourceFile>()
|
||||
|
||||
fun assign(file: SourceFile): Int {
|
||||
return sourceToIndex.getOrPut(file) {
|
||||
sourceToIndex.size
|
||||
}
|
||||
}
|
||||
|
||||
fun provide(fileName: String, index: Int, library: KonanLibrary) {
|
||||
assert(indexToSource[index] == null)
|
||||
indexToSource[index] = DeserializedSourceFile(fileName, index, library)
|
||||
}
|
||||
|
||||
fun sourceFile(index: Int): SourceFile =
|
||||
indexToSource[index] ?: throw Error("Unknown file for $index")
|
||||
|
||||
fun filesAndClear() =
|
||||
sourceToIndex.keys.sortedBy {
|
||||
sourceToIndex[it]
|
||||
}.also{
|
||||
clear()
|
||||
}
|
||||
|
||||
|
||||
fun clear() {
|
||||
sourceToIndex.clear()
|
||||
indexToSource.clear()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user