Move jet.runtime.ArrayIterator to package "kotlin.jvm.internal"

This commit is contained in:
Alexander Udalov
2014-02-13 20:23:19 +04:00
parent 9d9d73268a
commit 19acc8c6c4
9 changed files with 161 additions and 265 deletions
@@ -58,7 +58,7 @@ public class ArrayIterator extends IntrinsicMethod {
assert funDescriptor != null;
ClassDescriptor containingDeclaration = (ClassDescriptor) funDescriptor.getContainingDeclaration().getOriginal();
if (containingDeclaration.equals(KotlinBuiltIns.getInstance().getArray())) {
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
v.invokestatic("kotlin/jvm/internal/InternalPackage", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
return getType(Iterator.class);
}
@@ -68,7 +68,7 @@ public class ArrayIterator extends IntrinsicMethod {
if (containingDeclaration.equals(arrayClass)) {
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
String methodSignature = "([" + asmTypeForPrimitive(jvmPrimitiveType) + ")" + iteratorDesc;
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
v.invokestatic("kotlin/jvm/internal/InternalPackage", "iterator", methodSignature);
return Type.getType(iteratorDesc);
}
}
@@ -1,249 +0,0 @@
/*
* 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 jet.runtime;
import jet.*;
import java.util.Iterator;
public abstract class ArrayIterator<T> implements Iterator<T> {
private final int size;
protected int index;
protected ArrayIterator(int size) {
this.size = size;
}
@Override
public boolean hasNext() {
return index < size;
}
private static class GenericIterator<T> extends ArrayIterator<T> {
private final T[] array;
private GenericIterator(T[] array) {
super(array.length);
this.array = array;
}
@Override
public T next() {
return array[index++];
}
@Override
public void remove() {
throw new UnsupportedOperationException("Mutating method called on a Kotlin Iterator");
}
}
public static <T> Iterator<T> iterator(T[] array) {
return new GenericIterator<T>(array);
}
private static class ArrayByteIterator extends ByteIterator {
private final byte[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayByteIterator(byte[] array) {
this.array = array;
}
@Override
public byte nextByte() {
return array[index++];
}
}
public static ByteIterator iterator(byte[] array) {
return new ArrayByteIterator(array);
}
private static class ArrayShortIterator extends ShortIterator {
private final short[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayShortIterator(short[] array) {
this.array = array;
}
@Override
public short nextShort() {
return array[index++];
}
}
public static ShortIterator iterator(short[] array) {
return new ArrayShortIterator(array);
}
private static class ArrayIntIterator extends IntIterator {
private final int[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayIntIterator(int[] array) {
this.array = array;
}
@Override
public int nextInt() {
return array[index++];
}
}
public static IntIterator iterator(int[] array) {
return new ArrayIntIterator(array);
}
private static class ArrayLongIterator extends LongIterator {
private final long[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayLongIterator(long[] array) {
this.array = array;
}
@Override
public long nextLong() {
return array[index++];
}
}
public static LongIterator iterator(long[] array) {
return new ArrayLongIterator(array);
}
private static class ArrayFloatIterator extends FloatIterator {
private final float[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayFloatIterator(float[] array) {
this.array = array;
}
@Override
public float nextFloat() {
return array[index++];
}
}
public static FloatIterator iterator(float[] array) {
return new ArrayFloatIterator(array);
}
private static class ArrayDoubleIterator extends DoubleIterator {
private final double[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayDoubleIterator(double[] array) {
this.array = array;
}
@Override
public double nextDouble() {
return array[index++];
}
}
public static DoubleIterator iterator(double[] array) {
return new ArrayDoubleIterator(array);
}
private static class ArrayCharacterIterator extends CharIterator {
private final char[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayCharacterIterator(char[] array) {
this.array = array;
}
@Override
public char nextChar() {
return array[index++];
}
}
public static CharIterator iterator(char[] array) {
return new ArrayCharacterIterator(array);
}
private static class ArrayBooleanIterator extends BooleanIterator {
private final boolean[] array;
private int index;
@Override
public boolean hasNext() {
return index < array.length;
}
private ArrayBooleanIterator(boolean[] array) {
this.array = array;
}
@Override
public boolean nextBoolean() {
return array[index++];
}
}
public static BooleanIterator iterator(boolean[] array) {
return new ArrayBooleanIterator(array);
}
}
@@ -0,0 +1,25 @@
/*
* 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.
*/
package kotlin.jvm.internal
private class ArrayIterator<T>(val array: Array<T>) : Iterator<T> {
private var index = 0
override fun hasNext() = index < array.size
override fun next() = array[index++]
}
public fun iterator<T>(array: Array<T>): Iterator<T> = ArrayIterator(array)
@@ -0,0 +1,76 @@
/*
* 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.jvm.internal
private class ArrayByteIterator(private val array: ByteArray) : ByteIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextByte() = array[index++]
}
private class ArrayCharIterator(private val array: CharArray) : CharIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextChar() = array[index++]
}
private class ArrayShortIterator(private val array: ShortArray) : ShortIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextShort() = array[index++]
}
private class ArrayIntIterator(private val array: IntArray) : IntIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextInt() = array[index++]
}
private class ArrayLongIterator(private val array: LongArray) : LongIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextLong() = array[index++]
}
private class ArrayFloatIterator(private val array: FloatArray) : FloatIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextFloat() = array[index++]
}
private class ArrayDoubleIterator(private val array: DoubleArray) : DoubleIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextDouble() = array[index++]
}
private class ArrayBooleanIterator(private val array: BooleanArray) : BooleanIterator() {
private var index = 0
override fun hasNext() = index < array.size
override fun nextBoolean() = array[index++]
}
public fun iterator(array: ByteArray): ByteIterator = ArrayByteIterator(array)
public fun iterator(array: CharArray): CharIterator = ArrayCharIterator(array)
public fun iterator(array: ShortArray): ShortIterator = ArrayShortIterator(array)
public fun iterator(array: IntArray): IntIterator = ArrayIntIterator(array)
public fun iterator(array: LongArray): LongIterator = ArrayLongIterator(array)
public fun iterator(array: FloatArray): FloatIterator = ArrayFloatIterator(array)
public fun iterator(array: DoubleArray): DoubleIterator = ArrayDoubleIterator(array)
public fun iterator(array: BooleanArray): BooleanIterator = ArrayBooleanIterator(array)
@@ -0,0 +1,41 @@
/*
* 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.arrayIterators
import org.jetbrains.jet.generators.builtins.IteratorKind
import org.jetbrains.jet.generators.builtins.generateBuiltIns.*
import java.io.PrintWriter
class GenerateArrayIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun getPackage() = "kotlin.jvm.internal"
override fun generateBody() {
for (kind in IteratorKind.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")
out.println(" override fun hasNext() = index < array.size")
out.println(" override fun next$s() = array[index++]")
out.println("}")
out.println()
}
for (kind in IteratorKind.values()) {
val s = kind.capitalized
out.println("public fun iterator(array: ${s}Array): ${s}Iterator = Array${s}Iterator(array)")
}
}
}
@@ -18,6 +18,19 @@ package org.jetbrains.jet.generators.builtins
import org.jetbrains.jet.generators.builtins.ProgressionKind.*
enum class IteratorKind {
BYTE
CHAR
SHORT
INT
LONG
FLOAT
DOUBLE
BOOLEAN
val capitalized: String get() = name().toLowerCase().capitalize()
}
enum class ProgressionKind {
BYTE
CHAR
@@ -16,6 +16,7 @@
package org.jetbrains.jet.generators.builtins.generateBuiltIns
import org.jetbrains.jet.generators.builtins.arrayIterators.*
import org.jetbrains.jet.generators.builtins.functions.*
import org.jetbrains.jet.generators.builtins.iterators.*
import org.jetbrains.jet.generators.builtins.progressionIterators.*
@@ -58,6 +59,7 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator)
}
generate(File(BUILT_INS_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) }
@@ -16,22 +16,10 @@
package org.jetbrains.jet.generators.builtins.iterators
import org.jetbrains.jet.generators.builtins.IteratorKind
import org.jetbrains.jet.generators.builtins.generateBuiltIns.*
import java.io.PrintWriter
enum class IteratorKind {
BYTE
CHAR
SHORT
INT
LONG
FLOAT
DOUBLE
BOOLEAN
val capitalized: String get() = name().toLowerCase().capitalize()
}
class GenerateIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun generateBody() {
for (kind in IteratorKind.values()) {
@@ -1,6 +1,6 @@
package kotlin2
import jet.runtime.ArrayIterator
import kotlin.jvm.internal.ArrayIterator
/**
* Annotates a class used to implement extension functions