Remove "Iterator.iterator()" intrinsic, add stdlib function
This commit is contained in:
@@ -122,7 +122,6 @@ public class IntrinsicMethods {
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("identityEquals"), 1, IDENTITY_EQUALS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("plus"), 1, STRING_PLUS);
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("arrayOfNulls"), 1, new NewArray());
|
||||
intrinsicsMap.registerIntrinsic(BUILT_INS_PACKAGE_FQ_NAME, Name.identifier("iterator"), 0, new IteratorIterator());
|
||||
|
||||
for (PrimitiveType type : PrimitiveType.values()) {
|
||||
declareIntrinsicFunction(type.getTypeName(), Name.identifier("compareTo"), 1, new CompareTo());
|
||||
|
||||
@@ -1,44 +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 org.jetbrains.jet.codegen.intrinsics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IteratorIterator extends IntrinsicMethod {
|
||||
@NotNull
|
||||
@Override
|
||||
public Type generateImpl(
|
||||
@NotNull ExpressionCodegen codegen,
|
||||
@NotNull InstructionAdapter v,
|
||||
@NotNull Type returnType,
|
||||
@Nullable PsiElement element,
|
||||
@Nullable List<JetExpression> arguments,
|
||||
StackValue receiver
|
||||
) {
|
||||
receiver.put(returnType, v);
|
||||
return returnType;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package-fragment jet
|
||||
public fun </*0*/ T> arrayOfNulls(/*0*/ size: jet.Int): jet.Array<T?>
|
||||
public fun jet.Any?.equals(/*0*/ other: jet.Any?): jet.Boolean
|
||||
public fun jet.Any?.identityEquals(/*0*/ other: jet.Any?): jet.Boolean
|
||||
public fun </*0*/ T> jet.Iterator<T>.iterator(): jet.Iterator<T>
|
||||
public fun jet.String?.plus(/*0*/ other: jet.Any?): jet.String
|
||||
public fun jet.Any?.toString(): jet.String
|
||||
|
||||
|
||||
@@ -9,8 +9,6 @@ public trait MutableIterator<out T> : Iterator<T> {
|
||||
public fun remove(): Unit
|
||||
}
|
||||
|
||||
public fun <T> Iterator<T>.iterator(): Iterator<T>
|
||||
|
||||
public trait ListIterator<out T> : Iterator<T> {
|
||||
// Query Operations
|
||||
override fun next(): T
|
||||
|
||||
@@ -2,7 +2,7 @@ class MyClass {
|
||||
val i = 1
|
||||
}
|
||||
|
||||
deprecated("Use A instead") fun MyClass.rangeTo(i: MyClass): IntIterator {
|
||||
deprecated("Use A instead") fun MyClass.rangeTo(i: MyClass): Iterable<Int> {
|
||||
i.i
|
||||
throw Exception()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ fun main(it: Iterator<Any>) {
|
||||
}
|
||||
|
||||
// MULTIRESOLVE
|
||||
// REF: (for Iterator<T> in jet).iterator()
|
||||
// REF: (for jet.Iterator<T> in jet).iterator()
|
||||
// REF: (in jet.Iterator).hasNext()
|
||||
// REF: (in jet.Iterator).next()
|
||||
|
||||
@@ -186,17 +186,7 @@ public final class MiscTest extends AbstractExpressionTest {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testIterableExtension() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testIterationOverIterator() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
public void testStringInterpolationEvaluationOrder() throws Exception {
|
||||
fooBoxTest();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package foo
|
||||
|
||||
import java.util.*
|
||||
import java.lang.*
|
||||
|
||||
public inline fun <T, C: MutableCollection<in T>> Iterator<T>.takeWhileTo(result: C, predicate: (T) -> Boolean) : C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
fun box(): Any? {
|
||||
val c = ArrayList<Int>()
|
||||
for (i in 0..5) {
|
||||
c.add(i)
|
||||
}
|
||||
|
||||
val d = ArrayList<Int>()
|
||||
|
||||
c.iterator().takeWhileTo(d, {i -> i < 4 })
|
||||
return d.size() == 4
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package foo
|
||||
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): Boolean {
|
||||
val c = ArrayList<Int>()
|
||||
for (i in 0..5) {
|
||||
c.add(i)
|
||||
}
|
||||
|
||||
var s = ""
|
||||
for (i in c.iterator()) {
|
||||
s = s + i.toString()
|
||||
}
|
||||
|
||||
return s == "012345"
|
||||
}
|
||||
@@ -4,6 +4,11 @@ import kotlin.support.*
|
||||
import java.util.Collections
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Returns the given iterator itself. This allows to use an instance of iterator in a ranged for-loop
|
||||
*/
|
||||
public fun <T> Iterator<T>.iterator(): Iterator<T> = this
|
||||
|
||||
/**
|
||||
* Returns an iterator which invokes the function to calculate the next value on each iteration until the function returns *null*
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@ package iterators
|
||||
import kotlin.test.assertEquals
|
||||
import org.junit.Test as test
|
||||
import kotlin.test.fails
|
||||
import java.util.ArrayList
|
||||
|
||||
fun fibonacci(): Iterator<Int> {
|
||||
// fibonacci terms
|
||||
@@ -87,4 +88,25 @@ class IteratorsTest {
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().skip(7).makeString(limit = 10))
|
||||
assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().skip(3).skip(4).makeString(limit = 10))
|
||||
}
|
||||
|
||||
test fun iterationOverIterator() {
|
||||
val c = arrayList(0, 1, 2, 3, 4, 5)
|
||||
var s = ""
|
||||
for (i in c.iterator()) {
|
||||
s = s + i.toString()
|
||||
}
|
||||
assertEquals("012345", s)
|
||||
}
|
||||
|
||||
private fun <T, C : MutableCollection<in T>> Iterator<T>.takeWhileTo(result: C, predicate: (T) -> Boolean): C {
|
||||
for (element in this) if (predicate(element)) result.add(element) else break
|
||||
return result
|
||||
}
|
||||
|
||||
test fun iterableExtension() {
|
||||
val c = arrayList(0, 1, 2, 3, 4, 5)
|
||||
val d = ArrayList<Int>()
|
||||
c.iterator().takeWhileTo(d, {i -> i < 4 })
|
||||
assertEquals(4, d.size())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user