Generate built-in sources of arrays
Extract Array class into a separate file, move arrayOfNulls to Library.kt, fix formatting and generate Arrays.kt
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package kotlin
|
||||
|
||||
public class Array<reified T>(public val size: Int, init: Function1<Int, T>) {
|
||||
public fun get(index: Int): T
|
||||
public fun set(index: Int, value: T): Unit
|
||||
|
||||
public fun iterator(): Iterator<T>
|
||||
|
||||
public val indices: IntRange
|
||||
}
|
||||
@@ -1,84 +1,92 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Auto-generated file. DO NOT EDIT!
|
||||
|
||||
package kotlin
|
||||
|
||||
public fun arrayOfNulls<T>(size : Int) : Array<T?>
|
||||
public class ByteArray(public val size: Int) {
|
||||
public fun get(index: Int): Byte
|
||||
public fun set(index: Int, value: Byte): Unit
|
||||
|
||||
public class Array<reified T>(public val size : Int, init : Function1<Int, T>) {
|
||||
public fun get(index : Int) : T
|
||||
public fun set(index : Int, value : T) : Unit
|
||||
public fun iterator(): ByteIterator
|
||||
|
||||
public fun iterator() : Iterator<T>
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class ByteArray(public val size : Int) {
|
||||
public fun get(index : Int) : Byte
|
||||
public fun set(index : Int, value : Byte) : Unit
|
||||
public class CharArray(public val size: Int) {
|
||||
public fun get(index: Int): Char
|
||||
public fun set(index: Int, value: Char): Unit
|
||||
|
||||
public fun iterator() : ByteIterator
|
||||
public fun iterator(): CharIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class ShortArray(public val size : Int) {
|
||||
public fun get(index : Int) : Short
|
||||
public fun set(index : Int, value : Short) : Unit
|
||||
public class ShortArray(public val size: Int) {
|
||||
public fun get(index: Int): Short
|
||||
public fun set(index: Int, value: Short): Unit
|
||||
|
||||
public fun iterator() : ShortIterator
|
||||
public fun iterator(): ShortIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class IntArray(public val size : Int) {
|
||||
public fun get(index : Int) : Int
|
||||
public fun set(index : Int, value : Int) : Unit
|
||||
public class IntArray(public val size: Int) {
|
||||
public fun get(index: Int): Int
|
||||
public fun set(index: Int, value: Int): Unit
|
||||
|
||||
public fun iterator() : IntIterator
|
||||
public fun iterator(): IntIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class LongArray(public val size : Int) {
|
||||
public fun get(index : Int) : Long
|
||||
public fun set(index : Int, value : Long) : Unit
|
||||
public class LongArray(public val size: Int) {
|
||||
public fun get(index: Int): Long
|
||||
public fun set(index: Int, value: Long): Unit
|
||||
|
||||
public fun iterator() : LongIterator
|
||||
public fun iterator(): LongIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class FloatArray(public val size : Int) {
|
||||
public fun get(index : Int) : Float
|
||||
public fun set(index : Int, value : Float) : Unit
|
||||
public class FloatArray(public val size: Int) {
|
||||
public fun get(index: Int): Float
|
||||
public fun set(index: Int, value: Float): Unit
|
||||
|
||||
public fun iterator() : FloatIterator
|
||||
public fun iterator(): FloatIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class DoubleArray(public val size : Int) {
|
||||
public fun get(index : Int) : Double
|
||||
public fun set(index : Int, value : Double) : Unit
|
||||
public class DoubleArray(public val size: Int) {
|
||||
public fun get(index: Int): Double
|
||||
public fun set(index: Int, value: Double): Unit
|
||||
|
||||
public fun iterator() : DoubleIterator
|
||||
public fun iterator(): DoubleIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class CharArray(public val size : Int) {
|
||||
public fun get(index : Int) : Char
|
||||
public fun set(index : Int, value : Char) : Unit
|
||||
public class BooleanArray(public val size: Int) {
|
||||
public fun get(index: Int): Boolean
|
||||
public fun set(index: Int, value: Boolean): Unit
|
||||
|
||||
public fun iterator() : CharIterator
|
||||
public fun iterator(): BooleanIterator
|
||||
|
||||
public val indices : IntRange
|
||||
public val indices: IntRange
|
||||
}
|
||||
|
||||
public class BooleanArray(public val size : Int) {
|
||||
public fun get(index : Int) : Boolean
|
||||
public fun set(index : Int, value : Boolean) : Unit
|
||||
|
||||
public fun iterator() : BooleanIterator
|
||||
|
||||
public val indices : IntRange
|
||||
}
|
||||
|
||||
@@ -8,3 +8,5 @@ public fun Any?.equals(other: Any?): Boolean
|
||||
public fun Any?.toString(): String
|
||||
|
||||
public fun String?.plus(other: Any?): String
|
||||
|
||||
public fun arrayOfNulls<T>(size: Int): Array<T?>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.generators.builtins.arrayIterators
|
||||
|
||||
import org.jetbrains.jet.generators.builtins.IteratorKind
|
||||
import org.jetbrains.jet.generators.builtins.PrimitiveType
|
||||
import org.jetbrains.jet.generators.builtins.generateBuiltIns.*
|
||||
import java.io.PrintWriter
|
||||
|
||||
@@ -24,7 +24,7 @@ class GenerateArrayIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
override fun getPackage() = "kotlin.jvm.internal"
|
||||
|
||||
override fun generateBody() {
|
||||
for (kind in IteratorKind.values()) {
|
||||
for (kind in PrimitiveType.values()) {
|
||||
val s = kind.capitalized
|
||||
out.println("private class Array${s}Iterator(private val array: ${s}Array) : ${s}Iterator() {")
|
||||
out.println(" private var index = 0")
|
||||
@@ -33,7 +33,7 @@ class GenerateArrayIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
out.println("}")
|
||||
out.println()
|
||||
}
|
||||
for (kind in IteratorKind.values()) {
|
||||
for (kind in PrimitiveType.values()) {
|
||||
val s = kind.capitalized
|
||||
out.println("public fun iterator(array: ${s}Array): ${s}Iterator = Array${s}Iterator(array)")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.generators.builtins.arrays
|
||||
|
||||
import org.jetbrains.jet.generators.builtins.PrimitiveType
|
||||
import org.jetbrains.jet.generators.builtins.generateBuiltIns.*
|
||||
import java.io.PrintWriter
|
||||
|
||||
class GenerateArrays(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
override fun getPackage() = "kotlin"
|
||||
|
||||
override fun generateBody() {
|
||||
for (kind in PrimitiveType.values()) {
|
||||
val s = kind.capitalized
|
||||
out.println("public class ${s}Array(public val size: Int) {")
|
||||
out.println(" public fun get(index: Int): $s")
|
||||
out.println(" public fun set(index: Int, value: $s): Unit")
|
||||
out.println()
|
||||
out.println(" public fun iterator(): ${s}Iterator")
|
||||
out.println()
|
||||
out.println(" public val indices: IntRange")
|
||||
out.println("}")
|
||||
out.println()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.generators.builtins
|
||||
|
||||
import org.jetbrains.jet.generators.builtins.ProgressionKind.*
|
||||
|
||||
enum class IteratorKind {
|
||||
enum class PrimitiveType {
|
||||
BYTE
|
||||
CHAR
|
||||
SHORT
|
||||
@@ -40,7 +40,7 @@ enum class ProgressionKind {
|
||||
FLOAT
|
||||
DOUBLE
|
||||
|
||||
val capitalized = name().toLowerCase().capitalize()
|
||||
val capitalized: String get() = name().toLowerCase().capitalize()
|
||||
}
|
||||
|
||||
fun progressionIncrementType(kind: ProgressionKind) = when (kind) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.generators.builtins.generateBuiltIns
|
||||
|
||||
import org.jetbrains.jet.generators.builtins.arrays.*
|
||||
import org.jetbrains.jet.generators.builtins.arrayIterators.*
|
||||
import org.jetbrains.jet.generators.builtins.functions.*
|
||||
import org.jetbrains.jet.generators.builtins.iterators.*
|
||||
@@ -28,7 +29,8 @@ import java.io.File
|
||||
fun assertExists(file: File): Unit =
|
||||
if (!file.exists()) error("Output dir does not exist: ${file.getAbsolutePath()}")
|
||||
|
||||
val BUILT_INS_DIR = File("core/builtins/src/kotlin/")
|
||||
val BUILT_INS_NATIVE_DIR = File("core/builtins/native/kotlin/")
|
||||
val BUILT_INS_SRC_DIR = File("core/builtins/src/kotlin/")
|
||||
val RUNTIME_JVM_DIR = File("core/runtime.jvm/src/kotlin/")
|
||||
|
||||
abstract class BuiltInsSourceGenerator(val out: PrintWriter) {
|
||||
@@ -50,19 +52,21 @@ abstract class BuiltInsSourceGenerator(val out: PrintWriter) {
|
||||
}
|
||||
|
||||
fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit) {
|
||||
assertExists(BUILT_INS_DIR)
|
||||
assertExists(BUILT_INS_NATIVE_DIR)
|
||||
assertExists(BUILT_INS_SRC_DIR)
|
||||
assertExists(RUNTIME_JVM_DIR)
|
||||
|
||||
for (kind in FunctionKind.values()) {
|
||||
generate(File(BUILT_INS_DIR, kind.getFileName())) { GenerateFunctions(it, kind) }
|
||||
generate(File(BUILT_INS_SRC_DIR, kind.getFileName())) { GenerateFunctions(it, kind) }
|
||||
generate(File(RUNTIME_JVM_DIR, kind.getImplFileName()), { GenerateFunctionsImpl(it, kind) })
|
||||
}
|
||||
|
||||
generate(File(BUILT_INS_DIR, "Iterators.kt")) { GenerateIterators(it) }
|
||||
generate(File(BUILT_INS_NATIVE_DIR, "Arrays.kt")) { GenerateArrays(it) }
|
||||
generate(File(BUILT_INS_SRC_DIR, "Iterators.kt")) { GenerateIterators(it) }
|
||||
generate(File(RUNTIME_JVM_DIR, "jvm/internal/ArrayIterators.kt")) { GenerateArrayIterators(it) }
|
||||
generate(File(BUILT_INS_DIR, "ProgressionIterators.kt")) { GenerateProgressionIterators(it) }
|
||||
generate(File(BUILT_INS_DIR, "Progressions.kt")) { GenerateProgressions(it) }
|
||||
generate(File(BUILT_INS_DIR, "Ranges.kt")) { GenerateRanges(it) }
|
||||
generate(File(BUILT_INS_SRC_DIR, "ProgressionIterators.kt")) { GenerateProgressionIterators(it) }
|
||||
generate(File(BUILT_INS_SRC_DIR, "Progressions.kt")) { GenerateProgressions(it) }
|
||||
generate(File(BUILT_INS_SRC_DIR, "Ranges.kt")) { GenerateRanges(it) }
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.generators.builtins.iterators
|
||||
|
||||
import org.jetbrains.jet.generators.builtins.IteratorKind
|
||||
import org.jetbrains.jet.generators.builtins.PrimitiveType
|
||||
import org.jetbrains.jet.generators.builtins.generateBuiltIns.*
|
||||
import java.io.PrintWriter
|
||||
|
||||
class GenerateIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
override fun generateBody() {
|
||||
for (kind in IteratorKind.values()) {
|
||||
for (kind in PrimitiveType.values()) {
|
||||
val s = kind.capitalized
|
||||
out.println("public abstract class ${s}Iterator : Iterator<$s> {")
|
||||
out.println(" override final fun next() = next$s()")
|
||||
|
||||
Reference in New Issue
Block a user