[Native] Export KDoc into generated native header
This commit is contained in:
@@ -74,6 +74,7 @@ internal class K2MetadataKlibSerializer(private val metadataVersion: BuiltInsBin
|
||||
configuration.languageVersionSettings,
|
||||
metadataVersion,
|
||||
project,
|
||||
exportKDoc = false,
|
||||
skipExpects = false,
|
||||
includeOnlyModuleContent = true
|
||||
).serializeModule(module)
|
||||
|
||||
+10
@@ -15,6 +15,8 @@ import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassConstructorDescriptor
|
||||
|
||||
internal val DeclarationDescriptor.isExpectMember: Boolean
|
||||
get() = this is MemberDescriptor && this.isExpect
|
||||
@@ -51,3 +53,11 @@ fun CallableMemberDescriptor.findSourceFile(): SourceFile {
|
||||
else -> TODO()
|
||||
}
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.extractSerializedKdocString(): String? = when (this) {
|
||||
is DeserializedClassDescriptor -> classProto.getExtension(KlibMetadataProtoBuf.classKdoc)
|
||||
is DeserializedSimpleFunctionDescriptor -> proto.getExtension(KlibMetadataProtoBuf.functionKdoc)
|
||||
is DeserializedPropertyDescriptor -> proto.getExtension(KlibMetadataProtoBuf.propertyKdoc)
|
||||
is DeserializedClassConstructorDescriptor -> proto.getExtension(KlibMetadataProtoBuf.constructorKdoc)
|
||||
else -> null
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,9 +24,10 @@ class KlibMetadataIncrementalSerializer(
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
metadataVersion: BinaryVersion,
|
||||
project: Project,
|
||||
exportKDoc: Boolean,
|
||||
skipExpects: Boolean,
|
||||
allowErrorTypes: Boolean = false
|
||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, project, skipExpects, allowErrorTypes = allowErrorTypes) {
|
||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, project, exportKDoc, skipExpects, allowErrorTypes = allowErrorTypes) {
|
||||
|
||||
fun serializePackageFragment(
|
||||
module: ModuleDescriptor,
|
||||
|
||||
+2
-1
@@ -24,10 +24,11 @@ class KlibMetadataMonolithicSerializer(
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
metadataVersion: BinaryVersion,
|
||||
project: Project?,
|
||||
exportKDoc: Boolean,
|
||||
skipExpects: Boolean,
|
||||
includeOnlyModuleContent: Boolean = false,
|
||||
allowErrorTypes: Boolean = false
|
||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, project, skipExpects, includeOnlyModuleContent, allowErrorTypes) {
|
||||
) : KlibMetadataSerializer(languageVersionSettings, metadataVersion, project, exportKDoc, skipExpects, includeOnlyModuleContent, allowErrorTypes) {
|
||||
|
||||
private fun serializePackageFragment(fqName: FqName, module: ModuleDescriptor): List<ProtoBuf.PackageFragment> {
|
||||
|
||||
|
||||
+3
-1
@@ -34,6 +34,7 @@ abstract class KlibMetadataSerializer(
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val metadataVersion: BinaryVersion,
|
||||
val project: Project?,
|
||||
val exportKDoc: Boolean = false,
|
||||
val skipExpects: Boolean = false,
|
||||
val includeOnlyModuleContent: Boolean = false,
|
||||
private val allowErrorTypes: Boolean
|
||||
@@ -53,7 +54,8 @@ abstract class KlibMetadataSerializer(
|
||||
languageVersionSettings,
|
||||
metadataVersion,
|
||||
ApproximatingStringTable(),
|
||||
allowErrorTypes
|
||||
allowErrorTypes,
|
||||
exportKDoc
|
||||
)
|
||||
return SerializerContext(
|
||||
extension,
|
||||
|
||||
+33
-1
@@ -18,12 +18,19 @@ import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
||||
import org.jetbrains.kotlin.serialization.StringTableImpl
|
||||
import org.jetbrains.kotlin.types.FlexibleType
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPrimaryConstructor
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
|
||||
class KlibMetadataSerializerExtension(
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
override val metadataVersion: BinaryVersion,
|
||||
override val stringTable: StringTableImpl,
|
||||
private val allowErrorTypes: Boolean
|
||||
private val allowErrorTypes: Boolean,
|
||||
private val exportKDoc: Boolean
|
||||
) : KotlinSerializerExtensionBase(KlibMetadataSerializerProtocol) {
|
||||
override fun shouldUseTypeTable(): Boolean = true
|
||||
|
||||
@@ -47,10 +54,20 @@ class KlibMetadataSerializerExtension(
|
||||
childSerializer: DescriptorSerializer
|
||||
) {
|
||||
descriptorFileId(descriptor)?.let { proto.setExtension(KlibMetadataProtoBuf.classFile, it) }
|
||||
if (exportKDoc) descriptor.findKDocString()?.let { proto.setExtension(KlibMetadataProtoBuf.classKdoc, it) }
|
||||
super.serializeClass(descriptor, proto, versionRequirementTable, childSerializer)
|
||||
childSerializer.typeTable.serialize()?.let { proto.mergeTypeTable(it) }
|
||||
}
|
||||
|
||||
override fun serializeConstructor(
|
||||
descriptor: ConstructorDescriptor,
|
||||
proto: ProtoBuf.Constructor.Builder,
|
||||
childSerializer: DescriptorSerializer
|
||||
) {
|
||||
if (exportKDoc) descriptor.findKDocString()?.let { proto.setExtension(KlibMetadataProtoBuf.constructorKdoc, it) }
|
||||
super.serializeConstructor(descriptor, proto, childSerializer)
|
||||
}
|
||||
|
||||
override fun serializeProperty(
|
||||
descriptor: PropertyDescriptor,
|
||||
proto: ProtoBuf.Property.Builder,
|
||||
@@ -58,6 +75,7 @@ class KlibMetadataSerializerExtension(
|
||||
childSerializer: DescriptorSerializer
|
||||
) {
|
||||
descriptorFileId(descriptor)?.let { proto.setExtension(KlibMetadataProtoBuf.propertyFile, it) }
|
||||
if (exportKDoc) descriptor.findKDocString()?.let { proto.setExtension(KlibMetadataProtoBuf.propertyKdoc, it) }
|
||||
super.serializeProperty(descriptor, proto, versionRequirementTable, childSerializer)
|
||||
}
|
||||
|
||||
@@ -68,9 +86,23 @@ class KlibMetadataSerializerExtension(
|
||||
childSerializer: DescriptorSerializer
|
||||
) {
|
||||
descriptorFileId(descriptor)?.let { proto.setExtension(KlibMetadataProtoBuf.functionFile, it) }
|
||||
if (exportKDoc) descriptor.findKDocString()?.let { proto.setExtension(KlibMetadataProtoBuf.functionKdoc, it) }
|
||||
super.serializeFunction(descriptor, proto, versionRequirementTable, childSerializer)
|
||||
}
|
||||
|
||||
override fun releaseCoroutines() =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
|
||||
}
|
||||
|
||||
fun DeclarationDescriptorWithSource.findKDocString(): String? {
|
||||
val psi = source.getPsi()
|
||||
if (psi is KtDeclaration) {
|
||||
if (psi is KtPrimaryConstructor)
|
||||
return null // to be rendered with class itself
|
||||
val kdoc = psi.docComment
|
||||
if (kdoc != null) {
|
||||
return kdoc.getDefaultSection().parent.text
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -599,6 +599,7 @@ private fun KlibMetadataIncrementalSerializer(configuration: CompilerConfigurati
|
||||
languageVersionSettings = configuration.languageVersionSettings,
|
||||
metadataVersion = configuration.metadataVersion,
|
||||
project = project,
|
||||
exportKDoc = false,
|
||||
skipExpects = !configuration.expectActualLinker,
|
||||
allowErrorTypes = allowErrors
|
||||
)
|
||||
|
||||
@@ -78,6 +78,7 @@ object KlibTestUtil {
|
||||
val serializer = KlibMetadataMonolithicSerializer(
|
||||
languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT,
|
||||
metadataVersion = KlibMetadataVersion.INSTANCE,
|
||||
exportKDoc = false,
|
||||
skipExpects = false,
|
||||
project = null
|
||||
)
|
||||
|
||||
@@ -60,17 +60,20 @@ extend org.jetbrains.kotlin.metadata.Package {
|
||||
extend org.jetbrains.kotlin.metadata.Class {
|
||||
repeated org.jetbrains.kotlin.metadata.Annotation class_annotation = 170;
|
||||
optional int32 class_file = 175 [(org.jetbrains.kotlin.metadata.skip_in_comparison) = true];
|
||||
optional string class_kdoc = 176;
|
||||
optional DescriptorUniqId class_uniq_id = 171;
|
||||
}
|
||||
|
||||
extend org.jetbrains.kotlin.metadata.Constructor {
|
||||
repeated org.jetbrains.kotlin.metadata.Annotation constructor_annotation = 170;
|
||||
optional string constructor_kdoc = 173;
|
||||
optional DescriptorUniqId constructor_uniq_id = 172;
|
||||
}
|
||||
|
||||
extend org.jetbrains.kotlin.metadata.Function {
|
||||
repeated org.jetbrains.kotlin.metadata.Annotation function_annotation = 170;
|
||||
optional int32 function_file = 172 [(org.jetbrains.kotlin.metadata.skip_in_comparison) = true];
|
||||
optional string function_kdoc = 174;
|
||||
optional DescriptorUniqId function_uniq_id = 173;
|
||||
}
|
||||
|
||||
@@ -80,6 +83,7 @@ extend org.jetbrains.kotlin.metadata.Property {
|
||||
repeated org.jetbrains.kotlin.metadata.Annotation property_setter_annotation = 178;
|
||||
optional org.jetbrains.kotlin.metadata.Annotation.Argument.Value compile_time_value = 173;
|
||||
optional int32 property_file = 176 [(org.jetbrains.kotlin.metadata.skip_in_comparison) = true];
|
||||
optional string property_kdoc = 180;
|
||||
optional DescriptorUniqId property_uniq_id = 179;
|
||||
}
|
||||
|
||||
|
||||
+69
-1
@@ -10,17 +10,21 @@ public final class KlibMetadataProtoBuf {
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.packageFqName);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.classAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.classFile);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.classKdoc);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.classUniqId);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.constructorAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.constructorKdoc);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.constructorUniqId);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.functionAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.functionFile);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.functionKdoc);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.functionUniqId);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertyAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertyGetterAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertySetterAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.compileTimeValue);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertyFile);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertyKdoc);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.propertyUniqId);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.enumEntryAnnotation);
|
||||
registry.add(org.jetbrains.kotlin.library.metadata.KlibMetadataProtoBuf.enumEntryOrdinal);
|
||||
@@ -2561,6 +2565,22 @@ public final class KlibMetadataProtoBuf {
|
||||
175,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.INT32,
|
||||
java.lang.Integer.class);
|
||||
public static final int CLASS_KDOC_FIELD_NUMBER = 176;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Class { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Class,
|
||||
java.lang.String> classKdoc = org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Class.getDefaultInstance(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
176,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.STRING,
|
||||
java.lang.String.class);
|
||||
public static final int CLASS_UNIQ_ID_FIELD_NUMBER = 171;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Class { ... }</code>
|
||||
@@ -2593,6 +2613,22 @@ public final class KlibMetadataProtoBuf {
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.MESSAGE,
|
||||
false,
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Annotation.class);
|
||||
public static final int CONSTRUCTOR_KDOC_FIELD_NUMBER = 173;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Constructor { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Constructor,
|
||||
java.lang.String> constructorKdoc = org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Constructor.getDefaultInstance(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
173,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.STRING,
|
||||
java.lang.String.class);
|
||||
public static final int CONSTRUCTOR_UNIQ_ID_FIELD_NUMBER = 172;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Constructor { ... }</code>
|
||||
@@ -2641,6 +2677,22 @@ public final class KlibMetadataProtoBuf {
|
||||
172,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.INT32,
|
||||
java.lang.Integer.class);
|
||||
public static final int FUNCTION_KDOC_FIELD_NUMBER = 174;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Function { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Function,
|
||||
java.lang.String> functionKdoc = org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Function.getDefaultInstance(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
174,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.STRING,
|
||||
java.lang.String.class);
|
||||
public static final int FUNCTION_UNIQ_ID_FIELD_NUMBER = 173;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Function { ... }</code>
|
||||
@@ -2737,6 +2789,22 @@ public final class KlibMetadataProtoBuf {
|
||||
176,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.INT32,
|
||||
java.lang.Integer.class);
|
||||
public static final int PROPERTY_KDOC_FIELD_NUMBER = 180;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Property { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension<
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Property,
|
||||
java.lang.String> propertyKdoc = org.jetbrains.kotlin.protobuf.GeneratedMessageLite
|
||||
.newSingularGeneratedExtension(
|
||||
org.jetbrains.kotlin.metadata.ProtoBuf.Property.getDefaultInstance(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
180,
|
||||
org.jetbrains.kotlin.protobuf.WireFormat.FieldType.STRING,
|
||||
java.lang.String.class);
|
||||
public static final int PROPERTY_UNIQ_ID_FIELD_NUMBER = 179;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.kotlin.metadata.Property { ... }</code>
|
||||
@@ -2958,4 +3026,4 @@ public final class KlibMetadataProtoBuf {
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,6 +173,8 @@ class K2Native : CLICompiler<K2NativeCompilerArguments>() {
|
||||
put(OVERRIDE_CLANG_OPTIONS, arguments.clangOptions.toNonNullList())
|
||||
put(ALLOCATION_MODE, arguments.allocator)
|
||||
|
||||
put(EXPORT_KDOC, arguments.exportKDoc)
|
||||
|
||||
put(PRINT_IR, arguments.printIr)
|
||||
put(PRINT_IR_WITH_DESCRIPTORS, arguments.printIrWithDescriptors)
|
||||
put(PRINT_DESCRIPTORS, arguments.printDescriptors)
|
||||
|
||||
+3
@@ -181,6 +181,9 @@ class K2NativeCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var libraryToAddToCache: String? = null
|
||||
|
||||
@Argument(value = "-Xexport-kdoc", description = "Export KDoc in framework header")
|
||||
var exportKDoc: Boolean = false
|
||||
|
||||
@Argument(value = "-Xprint-bitcode", deprecatedName = "--print_bitcode", description = "Print llvm bitcode")
|
||||
var printBitCode: Boolean = false
|
||||
|
||||
|
||||
+3
@@ -399,6 +399,9 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
|
||||
printIr()
|
||||
printBitCode()
|
||||
}
|
||||
|
||||
fun shouldExportKDoc() = config.configuration.getBoolean(KonanConfigKeys.EXPORT_KDOC)
|
||||
|
||||
fun shouldVerifyBitCode() = config.configuration.getBoolean(KonanConfigKeys.VERIFY_BITCODE)
|
||||
|
||||
fun shouldPrintBitCode() = config.configuration.getBoolean(KonanConfigKeys.PRINT_BITCODE)
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ internal fun ComponentProvider.postprocessComponents(context: Context, files: Co
|
||||
context.frontendServices = this.get<FrontendServices>()
|
||||
|
||||
context.config.configuration.get(KonanConfigKeys.EMIT_LAZY_OBJC_HEADER_FILE)?.let {
|
||||
this.get<ObjCExportLazy>().dumpObjCHeader(files, it)
|
||||
this.get<ObjCExportLazy>().dumpObjCHeader(files, it, context.shouldExportKDoc())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -94,7 +94,9 @@ class KonanConfigKeys {
|
||||
= CompilerConfigurationKey.create("arguments for clang")
|
||||
val ALLOCATION_MODE: CompilerConfigurationKey<String>
|
||||
= CompilerConfigurationKey.create("allocation mode")
|
||||
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
|
||||
val EXPORT_KDOC: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("export KDoc into klib and framework")
|
||||
val PRINT_BITCODE: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("print bitcode")
|
||||
val PRINT_DESCRIPTORS: CompilerConfigurationKey<Boolean>
|
||||
= CompilerConfigurationKey.create("print descriptors")
|
||||
|
||||
+1
@@ -181,6 +181,7 @@ internal val serializerPhase = konanUnitPhase(
|
||||
this.config.configuration.languageVersionSettings,
|
||||
config.configuration.get(CommonConfigurationKeys.METADATA_VERSION)!!,
|
||||
config.project,
|
||||
exportKDoc = this.shouldExportKDoc(),
|
||||
!expectActualLinker, includeOnlyModuleContent = true)
|
||||
serializedMetadata = serializer.serializeModule(moduleDescriptor)
|
||||
},
|
||||
|
||||
+3
-1
@@ -981,6 +981,8 @@ abstract class ObjCExportHeaderGenerator internal constructor(
|
||||
private val extensions = mutableMapOf<ClassDescriptor, MutableList<CallableMemberDescriptor>>()
|
||||
private val topLevel = mutableMapOf<SourceFile, MutableList<CallableMemberDescriptor>>()
|
||||
|
||||
open val shouldExportKDoc = false
|
||||
|
||||
fun build(): List<String> = mutableListOf<String>().apply {
|
||||
addImports(foundationImports)
|
||||
addImports(getAdditionalImports())
|
||||
@@ -1013,7 +1015,7 @@ abstract class ObjCExportHeaderGenerator internal constructor(
|
||||
add("")
|
||||
|
||||
stubs.forEach {
|
||||
addAll(StubRenderer.render(it))
|
||||
addAll(StubRenderer.render(it, shouldExportKDoc))
|
||||
add("")
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -23,6 +23,9 @@ internal class ObjCExportHeaderGeneratorImpl(
|
||||
namer: ObjCExportNamer,
|
||||
objcGenerics: Boolean
|
||||
) : ObjCExportHeaderGenerator(moduleDescriptors, mapper, namer, objcGenerics, ProblemCollector(context)) {
|
||||
|
||||
override val shouldExportKDoc = context.shouldExportKDoc()
|
||||
|
||||
private class ProblemCollector(val context: Context) : ObjCExportProblemCollector {
|
||||
override fun reportWarning(text: String) {
|
||||
context.reportCompilationWarning(text)
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ package org.jetbrains.kotlin.backend.konan.objcexport
|
||||
import org.jetbrains.kotlin.konan.file.File
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
internal fun ObjCExportLazy.dumpObjCHeader(files: Collection<KtFile>, outputFile: String) {
|
||||
internal fun ObjCExportLazy.dumpObjCHeader(files: Collection<KtFile>, outputFile: String, shouldExportKDoc: Boolean) {
|
||||
val lines = (this.generateBase() + files.flatMap { this.translate(it) })
|
||||
.flatMap { StubRenderer.render(it) + listOf("") }
|
||||
.flatMap { StubRenderer.render(it, shouldExportKDoc) + listOf("") }
|
||||
|
||||
File(outputFile).writeLines(lines)
|
||||
}
|
||||
+25
-6
@@ -6,18 +6,32 @@
|
||||
package org.jetbrains.kotlin.backend.konan.objcexport
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
|
||||
import org.jetbrains.kotlin.backend.common.serialization.extractSerializedKdocString
|
||||
import org.jetbrains.kotlin.backend.common.serialization.metadata.findKDocString
|
||||
|
||||
object StubRenderer {
|
||||
fun render(stub: Stub<*>): List<String> = collect {
|
||||
fun render(stub: Stub<*>): List<String> = render(stub, false)
|
||||
internal fun render(stub: Stub<*>, shouldExportKDoc: Boolean): List<String> = collect {
|
||||
stub.run {
|
||||
this.comment?.let { comment ->
|
||||
val kDoc = if (shouldExportKDoc) {
|
||||
this.descriptor?.extractKDocString()
|
||||
} else null
|
||||
kDoc?.let {
|
||||
+"" // Probably makes the output more readable.
|
||||
+it // Let's try to keep non-trivial kdoc formatting intact
|
||||
}
|
||||
|
||||
this.comment?.let { comment ->
|
||||
kDoc?: let { +"" } // Probably makes the output more readable.
|
||||
+"/**"
|
||||
comment.contentLines.forEach {
|
||||
+" $it"
|
||||
}
|
||||
+"*/"
|
||||
}
|
||||
|
||||
when (this) {
|
||||
is ObjCProtocol -> {
|
||||
attributes.forEach {
|
||||
@@ -25,7 +39,7 @@ object StubRenderer {
|
||||
}
|
||||
+renderProtocolHeader()
|
||||
+"@required"
|
||||
renderMembers(this)
|
||||
renderMembers(this, shouldExportKDoc)
|
||||
+"@end;"
|
||||
}
|
||||
is ObjCInterface -> {
|
||||
@@ -33,7 +47,7 @@ object StubRenderer {
|
||||
+renderAttribute(it)
|
||||
}
|
||||
+renderInterfaceHeader()
|
||||
renderMembers(this)
|
||||
renderMembers(this, shouldExportKDoc)
|
||||
+"@end;"
|
||||
}
|
||||
is ObjCMethod -> {
|
||||
@@ -168,9 +182,9 @@ object StubRenderer {
|
||||
appendSuperProtocols(this@renderInterfaceHeader)
|
||||
}
|
||||
|
||||
private fun Collector.renderMembers(clazz: ObjCClass<*>) {
|
||||
private fun Collector.renderMembers(clazz: ObjCClass<*>, shouldExportKDoc: Boolean) {
|
||||
clazz.members.forEach {
|
||||
+render(it)
|
||||
+render(it, shouldExportKDoc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,3 +216,8 @@ internal fun formatGenerics(buffer: Appendable, generics:List<String>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.extractKDocString(): String? {
|
||||
return (this as? DeclarationDescriptorWithSource)?.findKDocString()
|
||||
?: extractSerializedKdocString()
|
||||
}
|
||||
|
||||
|
||||
@@ -247,7 +247,7 @@ void processUnhandledKotlinException(KRef throwable) {
|
||||
|
||||
RUNTIME_NORETURN void TerminateWithUnhandledException(KRef throwable) {
|
||||
concurrentTerminateWrapper([=]() {
|
||||
processUnhandledKotlinException(throwable);
|
||||
processUnhandledKotlinException(throwable);
|
||||
konan::abort();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,6 +118,7 @@ internal class MockModulesProvider private constructor(
|
||||
val SERIALIZER = KlibMetadataMonolithicSerializer(
|
||||
languageVersionSettings = LanguageVersionSettingsImpl.DEFAULT,
|
||||
metadataVersion = KlibMetadataVersion.INSTANCE,
|
||||
exportKDoc = false,
|
||||
skipExpects = false,
|
||||
project = null,
|
||||
includeOnlyModuleContent = true,
|
||||
|
||||
Reference in New Issue
Block a user