Fixes and cleanup in stdlib generator after builtin renames.
This commit is contained in:
@@ -12,8 +12,6 @@ enum class SourceFile(jvmClassName: String? = null, val multifile: Boolean = tru
|
|||||||
Misc(),
|
Misc(),
|
||||||
;
|
;
|
||||||
|
|
||||||
val name = this.name()
|
|
||||||
|
|
||||||
val jvmClassName = jvmClassName ?: (name.capitalize() + "Kt")
|
val jvmClassName = jvmClassName ?: (name.capitalize() + "Kt")
|
||||||
|
|
||||||
val fileName: String get() = "_${name.capitalize()}.kt"
|
val fileName: String get() = "_${name.capitalize()}.kt"
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ enum class PrimitiveType {
|
|||||||
Float,
|
Float,
|
||||||
Double;
|
Double;
|
||||||
|
|
||||||
val name: String get() = this.name()
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val defaultPrimitives = PrimitiveType.values().toSet()
|
val defaultPrimitives = PrimitiveType.values().toSet()
|
||||||
val numericPrimitives = setOf(Int, Long, Byte, Short, Double, Float)
|
val numericPrimitives = setOf(Int, Long, Byte, Short, Double, Float)
|
||||||
@@ -178,7 +176,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
|
|
||||||
fun instantiate(vararg families: Family = Family.values()): List<ConcreteFunction> {
|
fun instantiate(vararg families: Family = Family.values()): List<ConcreteFunction> {
|
||||||
return families
|
return families
|
||||||
.sortedBy { it.name() }
|
.sortedBy { it.name }
|
||||||
.filter { buildFamilies.contains(it) }
|
.filter { buildFamilies.contains(it) }
|
||||||
.flatMap { family -> instantiate(family) }
|
.flatMap { family -> instantiate(family) }
|
||||||
}
|
}
|
||||||
@@ -187,7 +185,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
val onlyPrimitives = buildFamilyPrimitives[f]
|
val onlyPrimitives = buildFamilyPrimitives[f]
|
||||||
|
|
||||||
if (f.isPrimitiveSpecialization || onlyPrimitives != null) {
|
if (f.isPrimitiveSpecialization || onlyPrimitives != null) {
|
||||||
return (onlyPrimitives ?: buildPrimitives).sortedBy { it.name() }
|
return (onlyPrimitives ?: buildPrimitives).sortedBy { it.name }
|
||||||
.map { primitive -> ConcreteFunction( { build(it, f, primitive) }, sourceFileFor(f) ) }
|
.map { primitive -> ConcreteFunction( { build(it, f, primitive) }, sourceFileFor(f) ) }
|
||||||
} else {
|
} else {
|
||||||
return listOf(ConcreteFunction( { build(it, f, null) }, sourceFileFor(f) ))
|
return listOf(ConcreteFunction( { build(it, f, null) }, sourceFileFor(f) ))
|
||||||
@@ -209,7 +207,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
|
|
||||||
fun build(vararg families: Family = Family.values()): String {
|
fun build(vararg families: Family = Family.values()): String {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
for (family in families.sortedBy { it.name() }) {
|
for (family in families.sortedBy { it.name }) {
|
||||||
if (buildFamilies.contains(family))
|
if (buildFamilies.contains(family))
|
||||||
build(builder, family)
|
build(builder, family)
|
||||||
}
|
}
|
||||||
@@ -219,7 +217,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
fun build(builder: StringBuilder, f: Family) {
|
fun build(builder: StringBuilder, f: Family) {
|
||||||
val onlyPrimitives = buildFamilyPrimitives[f]
|
val onlyPrimitives = buildFamilyPrimitives[f]
|
||||||
if (f.isPrimitiveSpecialization || onlyPrimitives != null) {
|
if (f.isPrimitiveSpecialization || onlyPrimitives != null) {
|
||||||
for (primitive in (onlyPrimitives ?: buildPrimitives).sortedBy { it.name() })
|
for (primitive in (onlyPrimitives ?: buildPrimitives).sortedBy { it.name })
|
||||||
build(builder, f, primitive)
|
build(builder, f, primitive)
|
||||||
} else {
|
} else {
|
||||||
build(builder, f, null)
|
build(builder, f, null)
|
||||||
@@ -237,7 +235,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
val token = t.nextToken()
|
val token = t.nextToken()
|
||||||
answer.append(when (token) {
|
answer.append(when (token) {
|
||||||
"SELF" -> receiver
|
"SELF" -> receiver
|
||||||
"PRIMITIVE" -> primitive?.name() ?: token
|
"PRIMITIVE" -> primitive?.name ?: token
|
||||||
"SUM" -> {
|
"SUM" -> {
|
||||||
when (primitive) {
|
when (primitive) {
|
||||||
PrimitiveType.Byte, PrimitiveType.Short, PrimitiveType.Char -> "Int"
|
PrimitiveType.Byte, PrimitiveType.Short, PrimitiveType.Char -> "Int"
|
||||||
@@ -273,7 +271,7 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
Generic -> "T"
|
Generic -> "T"
|
||||||
Strings -> "Char"
|
Strings -> "Char"
|
||||||
Maps -> "Map.Entry<K, V>"
|
Maps -> "Map.Entry<K, V>"
|
||||||
else -> primitive?.name() ?: token
|
else -> primitive?.name ?: token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"TRange" -> {
|
"TRange" -> {
|
||||||
@@ -307,9 +305,9 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
ArraysOfObjects -> "Array<${isAsteriskOrT.replace("T", "out T")}>"
|
ArraysOfObjects -> "Array<${isAsteriskOrT.replace("T", "out T")}>"
|
||||||
Strings -> "String"
|
Strings -> "String"
|
||||||
Ranges -> "Range<$isAsteriskOrT>"
|
Ranges -> "Range<$isAsteriskOrT>"
|
||||||
ArraysOfPrimitives -> primitive?.let { it.name() + "Array" } ?: throw IllegalArgumentException("Primitive array should specify primitive type")
|
ArraysOfPrimitives -> primitive?.let { it.name + "Array" } ?: throw IllegalArgumentException("Primitive array should specify primitive type")
|
||||||
RangesOfPrimitives -> primitive?.let { it.name() + "Range" } ?: throw IllegalArgumentException("Primitive range should specify primitive type")
|
RangesOfPrimitives -> primitive?.let { it.name + "Range" } ?: throw IllegalArgumentException("Primitive range should specify primitive type")
|
||||||
ProgressionsOfPrimitives -> primitive?.let { it.name() + "Progression" } ?: throw IllegalArgumentException("Primitive progression should specify primitive type")
|
ProgressionsOfPrimitives -> primitive?.let { it.name + "Progression" } ?: throw IllegalArgumentException("Primitive progression should specify primitive type")
|
||||||
Primitives -> primitive?.let { it.name } ?: throw IllegalArgumentException("Primitive should specify primitive type")
|
Primitives -> primitive?.let { it.name } ?: throw IllegalArgumentException("Primitive should specify primitive type")
|
||||||
Generic -> "T"
|
Generic -> "T"
|
||||||
}.let { renderType(it, it) }
|
}.let { renderType(it, it) }
|
||||||
@@ -404,12 +402,12 @@ class GenericFunction(val signature: String, val keyword: String = "fun") {
|
|||||||
if (keyword == "fun") builder.append(" {")
|
if (keyword == "fun") builder.append(" {")
|
||||||
|
|
||||||
val body = (
|
val body = (
|
||||||
customPrimitiveBodies[f to primitive] ?:
|
primitive?.let { customPrimitiveBodies[f to primitive] } ?:
|
||||||
body[f] ?:
|
body[f] ?:
|
||||||
deprecate[f]?.replaceWith?.let { "return $it" } ?:
|
deprecate[f]?.replaceWith?.let { "return $it" } ?:
|
||||||
throw RuntimeException("No body specified for $signature for ${f to primitive}")
|
throw RuntimeException("No body specified for $signature for ${f to primitive}")
|
||||||
).trim('\n')
|
).trim('\n')
|
||||||
val indent: Int = body.takeWhile { it == ' ' }.length()
|
val indent: Int = body.takeWhile { it == ' ' }.length
|
||||||
|
|
||||||
builder.append('\n')
|
builder.append('\n')
|
||||||
body.lineSequence().forEach {
|
body.lineSequence().forEach {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ fun ranges(): List<GenericFunction> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val numericPrimitives = PrimitiveType.numericPrimitives
|
val numericPrimitives = PrimitiveType.numericPrimitives
|
||||||
val numericPermutations = numericPrimitives flatMap { fromType -> numericPrimitives map { toType -> fromType to toType }}
|
val numericPermutations = numericPrimitives.flatMap { fromType -> numericPrimitives.map { toType -> fromType to toType }}
|
||||||
val primitivePermutations = numericPermutations + (PrimitiveType.Char to PrimitiveType.Char)
|
val primitivePermutations = numericPermutations + (PrimitiveType.Char to PrimitiveType.Char)
|
||||||
|
|
||||||
templates addAll primitivePermutations.map { downTo(it.first, it.second) }
|
templates addAll primitivePermutations.map { downTo(it.first, it.second) }
|
||||||
|
|||||||
Reference in New Issue
Block a user