Generate docs for floorDiv and mod and improve docs for div and rem

Refactor operator documentation generation for primitives and unsigned
types so that it is easier to specialize it.

Manually sync docs of numeric types in js-ir stdlib.

 KT-26234
This commit is contained in:
Ilya Gorbunov
2021-03-02 09:54:10 +03:00
parent 50d4979531
commit 7e2c365b79
11 changed files with 899 additions and 191 deletions
+13
View File
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.generators.builtins
import org.jetbrains.kotlin.generators.builtins.ProgressionKind.*
import java.io.PrintWriter
enum class PrimitiveType(val byteSize: Int) {
BYTE(1),
@@ -65,3 +66,15 @@ fun hashLong(v: String) = "($v xor ($v ushr 32))"
fun convert(v: String, from: UnsignedType, to: UnsignedType) = if (from == to) v else "$v.to${to.capitalized}()"
fun convert(v: String, from: PrimitiveType, to: PrimitiveType) = if (from == to) v else "$v.to${to.capitalized}()"
fun PrintWriter.printDoc(documentation: String, indent: String) {
val docLines = documentation.lines()
if (docLines.size == 1) {
this.println("$indent/** $documentation */")
} else {
this.println("$indent/**")
docLines.forEach { this.println("$indent * $it") }
this.println("$indent */")
}
}