Iterator.hasNext() becomes property

This commit is contained in:
Alex Tkachman
2011-10-23 20:20:41 +02:00
parent 5b1d6052d5
commit 2010d770b5
10 changed files with 157 additions and 123 deletions
@@ -277,14 +277,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
v.mark(begin);
v.load(iteratorVar, asmIterType);
FunctionDescriptor hND;
if(hasNextDescriptor instanceof FunctionDescriptor) {
hND = (FunctionDescriptor) hasNextDescriptor;
FunctionDescriptor hND = (FunctionDescriptor) hasNextDescriptor;
invokeFunctionNoParams(hND, Type.BOOLEAN_TYPE, v);
}
else {
hND = ((PropertyDescriptor) hasNextDescriptor).getGetter();
// hND = ((PropertyDescriptor) hasNextDescriptor).getGetter();
// if(hND != null)
// invokeFunctionNoParams(hND, Type.BOOLEAN_TYPE, v);
// else
intermediateValueForProperty((PropertyDescriptor) hasNextDescriptor, false, false).put(Type.BOOLEAN_TYPE, v);
}
invokeFunctionNoParams(hND, Type.BOOLEAN_TYPE, v);
v.ifeq(end);
myMap.enter(parameterDescriptor, asmParamType.getSize());
+2 -2
View File
@@ -41,8 +41,8 @@ fun Any?.equals(other : Any?) : Boolean// = this === other
fun Any?.toString() : String// = this === other
trait Iterator<out T> {
fun next() : T
fun hasNext() : Boolean
fun next() : T
val hasNext : Boolean
}
trait Iterable<out T> {
@@ -88,7 +88,8 @@ class MyCollection2(): Iterable<Int> {
var k : Int = 5
override fun next() : Int = k--
override fun hasNext() = k > 0
override val hasNext : Boolean
get() = k > 0
}
}
@@ -99,7 +100,8 @@ class MyCollection3() {
var k : Int = 5
fun next() : Int? = k--
fun hasNext() = k > 0
val hasNext : Boolean
get() = k > 0
}
}
@@ -56,42 +56,42 @@ public class ArrayGenTest extends CodegenTestCase {
}
public void testIterator () throws Exception {
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testPrimitiveIterator () throws Exception {
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testLongIterator () throws Exception {
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testCharIterator () throws Exception {
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testArrayIndices () throws Exception {
loadText("fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
}
public void testCharIndices () throws Exception {
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext) { java.lang.System.out?.println(x.next()) } }");
System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);