mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-03-10 08:31:29 +00:00
Fix warnings in generator modules
This commit is contained in:
@@ -25,7 +25,7 @@ class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
|
||||
override fun generateBody() {
|
||||
for (kind in PrimitiveType.values()) {
|
||||
val typeLower = kind.name.toLowerCase()
|
||||
val typeLower = kind.name.lowercase()
|
||||
val s = kind.capitalized
|
||||
val defaultValue = when (kind) {
|
||||
PrimitiveType.CHAR -> "null char (`\\u0000')"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
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
|
||||
|
||||
enum class PrimitiveType(val byteSize: Int) {
|
||||
@@ -18,7 +18,7 @@ enum class PrimitiveType(val byteSize: Int) {
|
||||
DOUBLE(8),
|
||||
BOOLEAN(1);
|
||||
|
||||
val capitalized: String get() = name.toLowerCase().capitalize()
|
||||
val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
|
||||
val bitSize = byteSize * 8
|
||||
|
||||
val isFloatingPoint: Boolean get() = this in floatingPoint
|
||||
@@ -38,7 +38,7 @@ enum class UnsignedType {
|
||||
UINT,
|
||||
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 byteSize = (1 shl ordinal)
|
||||
@@ -51,7 +51,7 @@ enum class ProgressionKind {
|
||||
INT,
|
||||
LONG;
|
||||
|
||||
val capitalized: String get() = name.toLowerCase().capitalize()
|
||||
val capitalized: String get() = name.lowercase().replaceFirstChar(Char::uppercase)
|
||||
}
|
||||
|
||||
fun progressionIncrementType(kind: ProgressionKind) = when (kind) {
|
||||
@@ -77,4 +77,4 @@ fun PrintWriter.printDoc(documentation: String, indent: String) {
|
||||
docLines.forEach { this.println("$indent * $it") }
|
||||
this.println("$indent */")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
private fun generateDoc(kind: PrimitiveType) {
|
||||
out.println("/**")
|
||||
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(" */")
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.generators.builtins.unsigned
|
||||
|
||||
|
||||
import org.jetbrains.kotlin.generators.builtins.*
|
||||
import org.jetbrains.kotlin.generators.builtins.PrimitiveType
|
||||
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.numbers.GeneratePrimitives
|
||||
import org.jetbrains.kotlin.generators.builtins.printDoc
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
|
||||
|
||||
fun generateUnsignedTypes(
|
||||
targetDir: File,
|
||||
generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit
|
||||
@@ -134,7 +135,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
||||
if (otherType == type) out.print("override ")
|
||||
out.print("inline operator fun compareTo(other: ${otherType.capitalized}): Int = ")
|
||||
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 {
|
||||
if (maxOf(type, otherType) < UnsignedType.UINT) {
|
||||
out.println("this.toInt().compareTo(other.toInt())")
|
||||
@@ -165,8 +166,8 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
||||
if (type == otherType && type == returnType) {
|
||||
when (name) {
|
||||
"plus", "minus", "times" -> out.println("$className(this.data.$name(other.data))")
|
||||
"div" -> out.println("${type.capitalized.toLowerCase()}Divide(this, other)")
|
||||
"rem" -> out.println("${type.capitalized.toLowerCase()}Remainder(this, other)")
|
||||
"div" -> out.println("${type.capitalized.lowercase()}Divide(this, other)")
|
||||
"rem" -> out.println("${type.capitalized.lowercase()}Remainder(this, other)")
|
||||
else -> error(name)
|
||||
}
|
||||
} else {
|
||||
@@ -348,7 +349,7 @@ class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIns
|
||||
out.print(" public inline fun to$otherName(): $otherName = ")
|
||||
when (type) {
|
||||
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 ->
|
||||
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) {
|
||||
val elementType = type.capitalized
|
||||
val arrayType = elementType + "Array"
|
||||
val arrayTypeOf = elementType.toLowerCase() + "ArrayOf"
|
||||
val arrayTypeOf = elementType.lowercase() + "ArrayOf"
|
||||
val storageElementType = type.asSigned.capitalized
|
||||
val storageArrayType = storageElementType + "Array"
|
||||
override fun generateBody() {
|
||||
|
||||
@@ -44,8 +44,6 @@ import org.jetbrains.kotlinx.serialization.AbstractSerializationPluginDiagnostic
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
generateTestGroupSuite(args) {
|
||||
val excludedFirTestdataPattern = "^(.+)\\.fir\\.kts?\$"
|
||||
|
||||
testGroup("compiler/incremental-compilation-impl/test", "jps-plugin/testData") {
|
||||
fun incrementalJvmTestData(targetBackend: TargetBackend): TestGroup.TestClass.() -> Unit = {
|
||||
model("incremental/pureKotlin", extension = null, recursive = false, targetBackend = targetBackend)
|
||||
|
||||
@@ -35,7 +35,8 @@ fun main(args: Array<String>) {
|
||||
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>()
|
||||
|
||||
@@ -62,7 +63,7 @@ fun main(args: Array<String>) {
|
||||
val platformSuffix = when (val platform = target.platform) {
|
||||
Platform.Common -> ""
|
||||
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")
|
||||
}
|
||||
@@ -71,5 +72,5 @@ fun main(args: Array<String>) {
|
||||
fun File.resolveExistingDir(subpath: String) = resolve(subpath).also { it.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()
|
||||
|
||||
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
|
||||
|
||||
@@ -55,4 +55,4 @@ internal abstract class OneToManyMappingsBuilder(bmpUnicodeDataLines: List<Unico
|
||||
|
||||
abstract fun SpecialCasingLine.mapping(): List<String>?
|
||||
abstract fun UnicodeDataLine.mapping(): String
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ internal abstract class MappingsBuilder {
|
||||
val equivalent = mappingEquivalent(line)?.hexToInt() ?: return
|
||||
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()) {
|
||||
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 {
|
||||
return EqualDistanceMappingPattern.from(charCode, categoryCode, mapping)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ private fun periodPatternCategory(categoryIds: Array<String>): Int {
|
||||
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 shift = 2
|
||||
for (i in gaps.indices) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
@@ -680,7 +680,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
if (primitive == null)
|
||||
"return this.asDynamic().concat(arrayOf(element))"
|
||||
else
|
||||
"return plus(${primitive.name.toLowerCase()}ArrayOf(element))"
|
||||
"return plus(${primitive.name.lowercase()}ArrayOf(element))"
|
||||
}
|
||||
}
|
||||
on(Platform.Native) {
|
||||
@@ -946,7 +946,7 @@ object ArrayOps : TemplateGroupBase() {
|
||||
val f_copyOfRangeJvmImpl = fn("copyOfRangeImpl(fromIndex: Int, toIndex: Int)") {
|
||||
include(InvariantArraysOfObjects, ArraysOfPrimitives)
|
||||
platforms(Platform.JVM)
|
||||
} builderWith { primitive ->
|
||||
} builderWith { _ ->
|
||||
since("1.3")
|
||||
visibility("internal")
|
||||
annotation("@PublishedApi")
|
||||
|
||||
@@ -409,6 +409,7 @@ object Mapping : TemplateGroupBase() {
|
||||
when (containerFamily) {
|
||||
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
|
||||
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
|
||||
else -> {}
|
||||
}
|
||||
} builder {
|
||||
inlineOnly()
|
||||
@@ -447,6 +448,7 @@ object Mapping : TemplateGroupBase() {
|
||||
when (containerFamily) {
|
||||
Iterables -> include(Iterables, Sequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences)
|
||||
Sequences -> include(Sequences, Iterables, ArraysOfObjects)
|
||||
else -> {}
|
||||
}
|
||||
} builder {
|
||||
inlineOnly()
|
||||
|
||||
12
libraries/tools/kotlin-stdlib-gen/src/templates/Util.kt
Normal file
12
libraries/tools/kotlin-stdlib-gen/src/templates/Util.kt
Normal file
@@ -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) {
|
||||
Inline.Only -> builder.append("@kotlin.internal.InlineOnly").append('\n')
|
||||
Inline.YesSuppressWarning -> suppressions.add("NOTHING_TO_INLINE")
|
||||
else -> {}
|
||||
}
|
||||
|
||||
if (suppressions.isNotEmpty()) {
|
||||
|
||||
@@ -213,7 +213,7 @@ class PairPrimitiveMemberDefinition : MemberTemplateDefinition<Pair<PrimitiveTyp
|
||||
}
|
||||
|
||||
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")
|
||||
file.parentFile.mkdirs()
|
||||
FileWriter(file).use { writer ->
|
||||
writer.appendln(COPYRIGHT_NOTICE)
|
||||
writer.appendLine(COPYRIGHT_NOTICE)
|
||||
|
||||
when (target.platform) {
|
||||
Platform.Common, Platform.JVM -> {
|
||||
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 {
|
||||
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("${autoGeneratedWarning("GenerateStandardLib.kt")}\n\n")
|
||||
if (target.platform == Platform.JS) {
|
||||
writer.appendln("import kotlin.js.*")
|
||||
writer.appendLine("import kotlin.js.*")
|
||||
if (sourceFile == SourceFile.Arrays) {
|
||||
writer.appendln("import primitiveArrayConcat")
|
||||
writer.appendln("import withType")
|
||||
writer.appendLine("import primitiveArrayConcat")
|
||||
writer.appendLine("import withType")
|
||||
}
|
||||
}
|
||||
if (target.platform == Platform.Common) {
|
||||
writer.appendln("import kotlin.random.*")
|
||||
writer.appendLine("import kotlin.random.*")
|
||||
}
|
||||
if (sourceFile.packageName == "kotlin.collections") {
|
||||
writer.appendln("import kotlin.ranges.contains")
|
||||
writer.appendln("import kotlin.ranges.reversed")
|
||||
writer.appendLine("import kotlin.ranges.contains")
|
||||
writer.appendLine("import kotlin.ranges.reversed")
|
||||
}
|
||||
|
||||
writer.appendln()
|
||||
writer.appendLine()
|
||||
|
||||
for (f in this) {
|
||||
f.build(writer)
|
||||
|
||||
Reference in New Issue
Block a user