[Generator] Rename additionalDoc, put its content before annotations

This commit is contained in:
Ilya Gorbunov
2023-08-28 21:20:38 +02:00
committed by Space Team
parent cd392ebe69
commit 60bbd08569
6 changed files with 12 additions and 12 deletions
@@ -419,7 +419,7 @@ class JsCharGenerator(writer: PrintWriter) : CharGenerator(writer) {
}
override fun MethodBuilder.modifyGeneratedToString() {
additionalDoc = "TODO implicit usages of toString and valueOf must be covered in DCE"
additionalComments = "TODO implicit usages of toString and valueOf must be covered in DCE"
annotations += "Suppress(\"JS_NAME_PROHIBITED_FOR_OVERRIDE\")"
annotations += "JsName(\"toString\")"
"return js(\"String\").fromCharCode(value).unsafeCast<String>()".addAsMultiLineBody()
@@ -146,7 +146,7 @@ class JsPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(write
if (thisKind == PrimitiveType.LONG) {
method {
additionalDoc = """
additionalComments = """
This method is used by JavaScript to convert objects of type Long to primitives.
This is essential for the JavaScript interop.
JavaScript functions that expect `number` are imported in Kotlin as expecting `kotlin.Number`
@@ -120,7 +120,7 @@ class WasmPrimitivesGenerator(writer: PrintWriter) : BasePrimitivesGenerator(wri
override fun MethodBuilder.modifyGeneratedUnaryOperation(thisKind: PrimitiveType) {
if (thisKind == PrimitiveType.INT && methodName == "dec") {
additionalDoc = "TODO: Fix test compiler/testData/codegen/box/functions/invoke/invoke.kt with inline dec"
additionalComments = "TODO: Fix test compiler/testData/codegen/box/functions/invoke/invoke.kt with inline dec"
} else {
modifySignature { isInline = true }
}
+7 -7
View File
@@ -40,7 +40,7 @@ internal interface PrimitiveBuilder {
internal abstract class AnnotatedAndDocumented {
private var doc: String? = null
val annotations: MutableList<String> = mutableListOf()
var additionalDoc: String? = null
var additionalComments: String? = null
fun appendDoc(doc: String) {
if (this.doc == null) {
@@ -55,15 +55,15 @@ internal abstract class AnnotatedAndDocumented {
appendLine(doc!!.printAsDoc(forceMultiLineDoc))
}
if (annotations.isNotEmpty()) {
appendLine(annotations.joinToString(separator = END_LINE) { "@$it" })
}
if (additionalDoc != null) {
additionalDoc!!.lines().forEach { line ->
if (additionalComments != null) {
additionalComments!!.lines().forEach { line ->
appendLine("// $line")
}
}
if (annotations.isNotEmpty()) {
appendLine(annotations.joinToString(separator = END_LINE) { "@$it" })
}
}
private fun String.printAsDoc(forceMultiLine: Boolean = false): String {
+1 -1
View File
@@ -106,10 +106,10 @@ internal constructor(private val value: Int) : Comparable<Char> {
@kotlin.internal.IntrinsicConstEvaluation
public fun toDouble(): Double = value.toDouble()
// TODO implicit usages of toString and valueOf must be covered in DCE
@kotlin.internal.IntrinsicConstEvaluation
@Suppress("JS_NAME_PROHIBITED_FOR_OVERRIDE")
@JsName("toString")
// TODO implicit usages of toString and valueOf must be covered in DCE
public override fun toString(): String {
return js("String").fromCharCode(value).unsafeCast<String>()
}
@@ -1578,13 +1578,13 @@ public class Long internal constructor(internal val low: Int, internal val high:
public override fun hashCode(): Int = hashCode(this)
@JsName("valueOf")
// This method is used by JavaScript to convert objects of type Long to primitives.
// This is essential for the JavaScript interop.
// JavaScript functions that expect `number` are imported in Kotlin as expecting `kotlin.Number`
// (in our standard library, and also in user projects if they use Dukat for generating external declarations).
// Because `kotlin.Number` is a supertype of `Long` too, there has to be a way for JS to know how to handle Longs.
// See KT-50202
@JsName("valueOf")
internal fun valueOf(): Double = toDouble()
}