Fix warnings in generator modules

This commit is contained in:
Alexander Udalov
2021-07-25 14:23:23 +02:00
parent 2ca3adbcb2
commit 0d1380c232
15 changed files with 57 additions and 41 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun generateBody() { override fun generateBody() {
for (kind in PrimitiveType.values()) { for (kind in PrimitiveType.values()) {
val typeLower = kind.name.toLowerCase() val typeLower = kind.name.lowercase()
val s = kind.capitalized val s = kind.capitalized
val defaultValue = when (kind) { val defaultValue = when (kind) {
PrimitiveType.CHAR -> "null char (`\\u0000')" PrimitiveType.CHAR -> "null char (`\\u0000')"
+5 -5
View File
@@ -5,7 +5,7 @@
package org.jetbrains.kotlin.generators.builtins package org.jetbrains.kotlin.generators.builtins
import org.jetbrains.kotlin.generators.builtins.ProgressionKind.* import org.jetbrains.kotlin.generators.builtins.ProgressionKind.CHAR
import java.io.PrintWriter import java.io.PrintWriter
enum class PrimitiveType(val byteSize: Int) { enum class PrimitiveType(val byteSize: Int) {
@@ -18,7 +18,7 @@ enum class PrimitiveType(val byteSize: Int) {
DOUBLE(8), DOUBLE(8),
BOOLEAN(1); BOOLEAN(1);
val capitalized: String get() = name.toLowerCase().capitalize() val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
val bitSize = byteSize * 8 val bitSize = byteSize * 8
val isFloatingPoint: Boolean get() = this in floatingPoint val isFloatingPoint: Boolean get() = this in floatingPoint
@@ -38,7 +38,7 @@ enum class UnsignedType {
UINT, UINT,
ULONG; ULONG;
val capitalized: String get() = name.substring(0, 2) + name.substring(2).toLowerCase() val capitalized: String get() = name.substring(0, 2) + name.substring(2).lowercase()
val asSigned: PrimitiveType = PrimitiveType.valueOf(name.substring(1)) val asSigned: PrimitiveType = PrimitiveType.valueOf(name.substring(1))
val byteSize = (1 shl ordinal) val byteSize = (1 shl ordinal)
@@ -51,7 +51,7 @@ enum class ProgressionKind {
INT, INT,
LONG; LONG;
val capitalized: String get() = name.toLowerCase().capitalize() val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
} }
fun progressionIncrementType(kind: ProgressionKind) = when (kind) { fun progressionIncrementType(kind: ProgressionKind) = when (kind) {
@@ -77,4 +77,4 @@ fun PrintWriter.printDoc(documentation: String, indent: String) {
docLines.forEach { this.println("$indent * $it") } docLines.forEach { this.println("$indent * $it") }
this.println("$indent */") this.println("$indent */")
} }
} }
+1 -1
View File
@@ -195,7 +195,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
private fun generateDoc(kind: PrimitiveType) { private fun generateDoc(kind: PrimitiveType) {
out.println("/**") out.println("/**")
out.println(" * Represents a ${typeDescriptions[kind]}.") out.println(" * Represents a ${typeDescriptions[kind]}.")
out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name.toLowerCase()}`.") out.println(" * On the JVM, non-nullable values of this type are represented as values of the primitive type `${kind.name.lowercase()}`.")
out.println(" */") out.println(" */")
} }
+9 -8
View File
@@ -5,14 +5,15 @@
package org.jetbrains.kotlin.generators.builtins.unsigned package org.jetbrains.kotlin.generators.builtins.unsigned
import org.jetbrains.kotlin.generators.builtins.PrimitiveType
import org.jetbrains.kotlin.generators.builtins.* import org.jetbrains.kotlin.generators.builtins.UnsignedType
import org.jetbrains.kotlin.generators.builtins.convert
import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator
import org.jetbrains.kotlin.generators.builtins.numbers.GeneratePrimitives import org.jetbrains.kotlin.generators.builtins.numbers.GeneratePrimitives
import org.jetbrains.kotlin.generators.builtins.printDoc
import java.io.File import java.io.File
import java.io.PrintWriter import java.io.PrintWriter
fun generateUnsignedTypes( fun generateUnsignedTypes(
targetDir: File, targetDir: File,
generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit
@@ -134,7 +135,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
if (otherType == type) out.print("override ") if (otherType == type) out.print("override ")
out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ") out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ")
if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) { if (otherType == type && maxByDomainCapacity(type, UnsignedType.UINT) == type) {
out.println("${className.toLowerCase()}Compare(this.data, other.data)") out.println("${className.lowercase()}Compare(this.data, other.data)")
} else { } else {
if (maxOf(type, otherType) < UnsignedType.UINT) { if (maxOf(type, otherType) < UnsignedType.UINT) {
out.println("this.toInt().compareTo(other.toInt())") out.println("this.toInt().compareTo(other.toInt())")
@@ -165,8 +166,8 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
if (type == otherType && type == returnType) { if (type == otherType && type == returnType) {
when (name) { when (name) {
"plus", "minus", "times" -> out.println("$className(this.data.$name(other.data))") "plus", "minus", "times" -> out.println("$className(this.data.$name(other.data))")
"div" -> out.println("${type.capitalized.toLowerCase()}Divide(this, other)") "div" -> out.println("${type.capitalized.lowercase()}Divide(this, other)")
"rem" -> out.println("${type.capitalized.toLowerCase()}Remainder(this, other)") "rem" -> out.println("${type.capitalized.lowercase()}Remainder(this, other)")
else -> error(name) else -> error(name)
} }
} else { } else {
@@ -348,7 +349,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
out.print(" public inline fun to$otherName(): $otherName = ") out.print(" public inline fun to$otherName(): $otherName = ")
when (type) { when (type) {
UnsignedType.UINT, UnsignedType.ULONG -> UnsignedType.UINT, UnsignedType.ULONG ->
out.println(if (otherType == PrimitiveType.FLOAT) "this.toDouble().toFloat()" else className.toLowerCase() + "ToDouble(data)") out.println(if (otherType == PrimitiveType.FLOAT) "this.toDouble().toFloat()" else className.lowercase() + "ToDouble(data)")
else -> else ->
out.println("this.toInt().to$otherName()") out.println("this.toInt().to$otherName()")
} }
@@ -466,7 +467,7 @@ class UnsignedIteratorsGenerator(out: PrintWriter) : BuiltInsSourceGenerator(out
class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltInsSourceGenerator(out) { class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltInsSourceGenerator(out) {
val elementType = type.capitalized val elementType = type.capitalized
val arrayType = elementType + "Array" val arrayType = elementType + "Array"
val arrayTypeOf = elementType.toLowerCase() + "ArrayOf" val arrayTypeOf = elementType.lowercase() + "ArrayOf"
val storageElementType = type.asSigned.capitalized val storageElementType = type.asSigned.capitalized
val storageArrayType = storageElementType + "Array" val storageArrayType = storageElementType + "Array"
override fun generateBody() { override fun generateBody() {
@@ -44,8 +44,6 @@ import org.jetbrains.kotlinx.serialization.AbstractSerializationPluginDiagnostic
fun main(args: Array<String>) { fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true") System.setProperty("java.awt.headless", "true")
generateTestGroupSuite(args) { generateTestGroupSuite(args) {
val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$"
testGroup("compiler/incremental-compilation-impl/test", "jps-plugin/testData") { testGroup("compiler/incremental-compilation-impl/test", "jps-plugin/testData") {
fun incrementalJvmTestData(targetBackend: TargetBackend): TestGroup.TestClass.() -> Unit = { fun incrementalJvmTestData(targetBackend: TargetBackend): TestGroup.TestClass.() -> Unit = {
model("incremental/pureKotlin", extension = null, recursive = false, targetBackend = targetBackend) model("incremental/pureKotlin", extension = null, recursive = false, targetBackend = targetBackend)
@@ -35,7 +35,8 @@ fun main(args: Array<String>) {
ComparableOps ComparableOps
) )
COPYRIGHT_NOTICE = readCopyrightNoticeFromProfile { Thread.currentThread().contextClassLoader.getResourceAsStream("apache.xml").reader() } COPYRIGHT_NOTICE =
readCopyrightNoticeFromProfile { Thread.currentThread().contextClassLoader.getResourceAsStream("apache.xml")!!.reader() }
val targetBaseDirs = mutableMapOf<KotlinTarget, File>() val targetBaseDirs = mutableMapOf<KotlinTarget, File>()
@@ -62,7 +63,7 @@ fun main(args: Array<String>) {
val platformSuffix = when (val platform = target.platform) { val platformSuffix = when (val platform = target.platform) {
Platform.Common -> "" Platform.Common -> ""
Platform.Native -> if (target.backend == Backend.Wasm) "Wasm" else "Native" Platform.Native -> if (target.backend == Backend.Wasm) "Wasm" else "Native"
else -> platform.name.toLowerCase().capitalize() else -> platform.name.lowercase().capitalize()
} }
targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt") targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt")
} }
@@ -71,5 +72,5 @@ fun main(args: Array<String>) {
fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.requireExistingDir() } fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.requireExistingDir() }
fun File.requireExistingDir() { fun File.requireExistingDir() {
require(isDirectory) { "Directory $this doesn't exist"} require(isDirectory) { "Directory $this doesn't exist" }
} }
@@ -19,7 +19,7 @@ internal abstract class OneToManyMappingsBuilder(bmpUnicodeDataLines: List<Unico
val charCode = line.char.hexToInt() val charCode = line.char.hexToInt()
check(charCode <= Char.MAX_VALUE.toInt()) { "Handle special casing for the supplementary code point: $line" } check(charCode <= Char.MAX_VALUE.code) { "Handle special casing for the supplementary code point: $line" }
val mapping = mapping(charCode, line) ?: return val mapping = mapping(charCode, line) ?: return
@@ -55,4 +55,4 @@ internal abstract class OneToManyMappingsBuilder(bmpUnicodeDataLines: List<Unico
abstract fun SpecialCasingLine.mapping(): List<String>? abstract fun SpecialCasingLine.mapping(): List<String>?
abstract fun UnicodeDataLine.mapping(): String abstract fun UnicodeDataLine.mapping(): String
} }
@@ -24,7 +24,7 @@ internal abstract class MappingsBuilder {
val equivalent = mappingEquivalent(line)?.hexToInt() ?: return val equivalent = mappingEquivalent(line)?.hexToInt() ?: return
val mapping = equivalent - charCode val mapping = equivalent - charCode
check((charCode > Char.MAX_VALUE.toInt()) == (equivalent > Char.MAX_VALUE.toInt())) { "Handle when equivalent mapping is out of BMP." } check((charCode > Char.MAX_VALUE.code) == (equivalent > Char.MAX_VALUE.code)) { "Handle when equivalent mapping is out of BMP." }
if (patterns.isEmpty()) { if (patterns.isEmpty()) {
patterns.add(createPattern(charCode, line.categoryCode, mapping)) patterns.add(createPattern(charCode, line.categoryCode, mapping))
@@ -69,4 +69,4 @@ internal abstract class MappingsBuilder {
private fun createPattern(charCode: Int, categoryCode: String, mapping: Int): MappingPattern { private fun createPattern(charCode: Int, categoryCode: String, mapping: Int): MappingPattern {
return EqualDistanceMappingPattern.from(charCode, categoryCode, mapping) return EqualDistanceMappingPattern.from(charCode, categoryCode, mapping)
} }
} }
@@ -73,7 +73,7 @@ private fun periodPatternCategory(categoryIds: Array<String>): Int {
return pattern return pattern
} }
private fun gapPatternCategory(start: Int, end: Int, gaps: List<GapRangePattern.Companion.Gap>): Int { private fun gapPatternCategory(start: Int, @Suppress("UNUSED_PARAMETER") end: Int, gaps: List<GapRangePattern.Companion.Gap>): Int {
var pattern = 0 var pattern = 0
var shift = 2 var shift = 2
for (i in gaps.indices) { for (i in gaps.indices) {
@@ -1,4 +1,4 @@
/* /*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/ */
@@ -680,7 +680,7 @@ object ArrayOps : TemplateGroupBase() {
if (primitive == null) if (primitive == null)
"return this.asDynamic().concat(arrayOf(element))" "return this.asDynamic().concat(arrayOf(element))"
else else
"return plus(${primitive.name.toLowerCase()}ArrayOf(element))" "return plus(${primitive.name.lowercase()}ArrayOf(element))"
} }
} }
on(Platform.Native) { on(Platform.Native) {
@@ -946,7 +946,7 @@ object ArrayOps : TemplateGroupBase() {
val f_copyOfRangeJvmImpl = fn("copyOfRangeImpl(fromIndex: Int, toIndex: Int)") { val f_copyOfRangeJvmImpl = fn("copyOfRangeImpl(fromIndex: Int, toIndex: Int)") {
include(InvariantArraysOfObjects, ArraysOfPrimitives) include(InvariantArraysOfObjects, ArraysOfPrimitives)
platforms(Platform.JVM) platforms(Platform.JVM)
} builderWith { primitive -> } builderWith { _ ->
since("1.3") since("1.3")
visibility("internal") visibility("internal")
annotation("@PublishedApi") annotation("@PublishedApi")
@@ -409,6 +409,7 @@ object Mapping : TemplateGroupBase() {
when (containerFamily) { when (containerFamily) {
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences) Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
Sequences -> include(Sequences, Iterables, ArraysOfObjects) Sequences -> include(Sequences, Iterables, ArraysOfObjects)
else -> {}
} }
} builder { } builder {
inlineOnly() inlineOnly()
@@ -447,6 +448,7 @@ object Mapping : TemplateGroupBase() {
when (containerFamily) { when (containerFamily) {
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences) Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
Sequences -> include(Sequences, Iterables, ArraysOfObjects) Sequences -> include(Sequences, Iterables, ArraysOfObjects)
else -> {}
} }
} builder { } builder {
inlineOnly() inlineOnly()
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package templates
fun String.capitalize(): String =
replaceFirstChar(Char::uppercaseChar)
fun String.decapitalize(): String =
replaceFirstChar(Char::lowercaseChar)
@@ -361,6 +361,7 @@ class MemberBuilder(
when (inline) { when (inline) {
Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n') Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n')
Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE") Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE")
else -> {}
} }
if (suppressions.isNotEmpty()) { if (suppressions.isNotEmpty()) {
@@ -213,7 +213,7 @@ class PairPrimitiveMemberDefinition : MemberTemplateDefinition<Pair<PrimitiveTyp
} }
init { init {
builderWith { (p1, p2) -> primitive = p1 } builderWith { (p1, _) -> primitive = p1 }
} }
} }
@@ -75,40 +75,41 @@ fun List<MemberBuilder>.writeTo(file: File, targetedSource: TargetedSourceFile)
println("Generating file: $file") println("Generating file: $file")
file.parentFile.mkdirs() file.parentFile.mkdirs()
FileWriter(file).use { writer -> FileWriter(file).use { writer ->
writer.appendln(COPYRIGHT_NOTICE) writer.appendLine(COPYRIGHT_NOTICE)
when (target.platform) { when (target.platform) {
Platform.Common, Platform.JVM -> { Platform.Common, Platform.JVM -> {
if (sourceFile.multifile) { if (sourceFile.multifile) {
writer.appendln("@file:kotlin.jvm.JvmMultifileClass") writer.appendLine("@file:kotlin.jvm.JvmMultifileClass")
} }
writer.appendln("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")") writer.appendLine("@file:kotlin.jvm.JvmName(\"${sourceFile.jvmClassName}\")")
sourceFile.jvmPackageName?.let { sourceFile.jvmPackageName?.let {
writer.appendln("@file:kotlin.jvm.JvmPackageName(\"$it\")") writer.appendLine("@file:kotlin.jvm.JvmPackageName(\"$it\")")
} }
writer.appendln() writer.appendLine()
} }
else -> {}
} }
writer.append("package ${sourceFile.packageName ?: "kotlin"}\n\n") writer.append("package ${sourceFile.packageName ?: "kotlin"}\n\n")
writer.append("${autoGeneratedWarning("GenerateStandardLib.kt")}\n\n") writer.append("${autoGeneratedWarning("GenerateStandardLib.kt")}\n\n")
if (target.platform == Platform.JS) { if (target.platform == Platform.JS) {
writer.appendln("import kotlin.js.*") writer.appendLine("import kotlin.js.*")
if (sourceFile == SourceFile.Arrays) { if (sourceFile == SourceFile.Arrays) {
writer.appendln("import primitiveArrayConcat") writer.appendLine("import primitiveArrayConcat")
writer.appendln("import withType") writer.appendLine("import withType")
} }
} }
if (target.platform == Platform.Common) { if (target.platform == Platform.Common) {
writer.appendln("import kotlin.random.*") writer.appendLine("import kotlin.random.*")
} }
if (sourceFile.packageName == "kotlin.collections") { if (sourceFile.packageName == "kotlin.collections") {
writer.appendln("import kotlin.ranges.contains") writer.appendLine("import kotlin.ranges.contains")
writer.appendln("import kotlin.ranges.reversed") writer.appendLine("import kotlin.ranges.reversed")
} }
writer.appendln() writer.appendLine()
for (f in this) { for (f in this) {
f.build(writer) f.build(writer)