Do not call deprecated public getProgressionFinalElement, call internal getProgressionLastElement instead.

ProgressionIterators do not compute final element by themselves, but use one computed by Progression.
Update testdata for LoadBuiltinsTest
This commit is contained in:
Ilya Gorbunov
2015-11-13 06:00:38 +03:00
parent 96f301fdec
commit 3f4430087e
6 changed files with 78 additions and 75 deletions
+11 -11
View File
@@ -150,9 +150,9 @@ public abstract class ByteIterator : kotlin.Iterator<kotlin.Byte> {
} }
internal final class ByteProgressionIterator : kotlin.ByteIterator { internal final class ByteProgressionIterator : kotlin.ByteIterator {
/*primary*/ public constructor ByteProgressionIterator(/*0*/ start: kotlin.Byte, /*1*/ end: kotlin.Byte, /*2*/ increment: kotlin.Int) /*primary*/ public constructor ByteProgressionIterator(/*0*/ first: kotlin.Byte, /*1*/ last: kotlin.Byte, /*2*/ increment: kotlin.Int)
private final val finalElement: kotlin.Byte private final val finalElement: kotlin.Int
private final fun <get-finalElement>(): kotlin.Byte private final fun <get-finalElement>(): kotlin.Int
private final var hasNext: kotlin.Boolean private final var hasNext: kotlin.Boolean
private final fun <get-hasNext>(): kotlin.Boolean private final fun <get-hasNext>(): kotlin.Boolean
private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit
@@ -252,9 +252,9 @@ public open class CharProgression : kotlin.Progression<kotlin.Char> {
} }
internal final class CharProgressionIterator : kotlin.CharIterator { internal final class CharProgressionIterator : kotlin.CharIterator {
/*primary*/ public constructor CharProgressionIterator(/*0*/ start: kotlin.Char, /*1*/ end: kotlin.Char, /*2*/ increment: kotlin.Int) /*primary*/ public constructor CharProgressionIterator(/*0*/ first: kotlin.Char, /*1*/ last: kotlin.Char, /*2*/ increment: kotlin.Int)
private final val finalElement: kotlin.Char private final val finalElement: kotlin.Int
private final fun <get-finalElement>(): kotlin.Char private final fun <get-finalElement>(): kotlin.Int
private final var hasNext: kotlin.Boolean private final var hasNext: kotlin.Boolean
private final fun <get-hasNext>(): kotlin.Boolean private final fun <get-hasNext>(): kotlin.Boolean
private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit
@@ -671,7 +671,7 @@ public open class IntProgression : kotlin.Progression<kotlin.Int> {
} }
internal final class IntProgressionIterator : kotlin.IntIterator { internal final class IntProgressionIterator : kotlin.IntIterator {
/*primary*/ public constructor IntProgressionIterator(/*0*/ start: kotlin.Int, /*1*/ end: kotlin.Int, /*2*/ increment: kotlin.Int) /*primary*/ public constructor IntProgressionIterator(/*0*/ first: kotlin.Int, /*1*/ last: kotlin.Int, /*2*/ increment: kotlin.Int)
private final val finalElement: kotlin.Int private final val finalElement: kotlin.Int
private final fun <get-finalElement>(): kotlin.Int private final fun <get-finalElement>(): kotlin.Int
private final var hasNext: kotlin.Boolean private final var hasNext: kotlin.Boolean
@@ -861,7 +861,7 @@ public open class LongProgression : kotlin.Progression<kotlin.Long> {
} }
internal final class LongProgressionIterator : kotlin.LongIterator { internal final class LongProgressionIterator : kotlin.LongIterator {
/*primary*/ public constructor LongProgressionIterator(/*0*/ start: kotlin.Long, /*1*/ end: kotlin.Long, /*2*/ increment: kotlin.Long) /*primary*/ public constructor LongProgressionIterator(/*0*/ first: kotlin.Long, /*1*/ last: kotlin.Long, /*2*/ increment: kotlin.Long)
private final val finalElement: kotlin.Long private final val finalElement: kotlin.Long
private final fun <get-finalElement>(): kotlin.Long private final fun <get-finalElement>(): kotlin.Long
private final var hasNext: kotlin.Boolean private final var hasNext: kotlin.Boolean
@@ -1186,9 +1186,9 @@ public abstract class ShortIterator : kotlin.Iterator<kotlin.Short> {
} }
internal final class ShortProgressionIterator : kotlin.ShortIterator { internal final class ShortProgressionIterator : kotlin.ShortIterator {
/*primary*/ public constructor ShortProgressionIterator(/*0*/ start: kotlin.Short, /*1*/ end: kotlin.Short, /*2*/ increment: kotlin.Int) /*primary*/ public constructor ShortProgressionIterator(/*0*/ first: kotlin.Short, /*1*/ last: kotlin.Short, /*2*/ increment: kotlin.Int)
private final val finalElement: kotlin.Short private final val finalElement: kotlin.Int
private final fun <get-finalElement>(): kotlin.Short private final fun <get-finalElement>(): kotlin.Int
private final var hasNext: kotlin.Boolean private final var hasNext: kotlin.Boolean
private final fun <get-hasNext>(): kotlin.Boolean private final fun <get-hasNext>(): kotlin.Boolean
private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit private final fun <set-hasNext>(/*0*/ <set-?>: kotlin.Boolean): kotlin.Unit
@@ -18,22 +18,20 @@
package kotlin package kotlin
import kotlin.internal.getProgressionFinalElement
/** /**
* An iterator over a progression of values of type `Byte`. * An iterator over a progression of values of type `Byte`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class ByteProgressionIterator(start: Byte, end: Byte, val increment: Int) : ByteIterator() { internal class ByteProgressionIterator(first: Byte, last: Byte, val increment: Int) : ByteIterator() {
private var next = start.toInt() private var next = first.toInt()
private val finalElement: Byte = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toByte() private val finalElement = last.toInt()
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
override fun nextByte(): Byte { override fun nextByte(): Byte {
val value = next val value = next
if (value == finalElement.toInt()) { if (value == finalElement) {
hasNext = false hasNext = false
} }
else { else {
@@ -47,16 +45,16 @@ internal class ByteProgressionIterator(start: Byte, end: Byte, val increment: In
* An iterator over a progression of values of type `Char`. * An iterator over a progression of values of type `Char`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class CharProgressionIterator(start: Char, end: Char, val increment: Int) : CharIterator() { internal class CharProgressionIterator(first: Char, last: Char, val increment: Int) : CharIterator() {
private var next = start.toInt() private var next = first.toInt()
private val finalElement: Char = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toChar() private val finalElement = last.toInt()
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
override fun nextChar(): Char { override fun nextChar(): Char {
val value = next val value = next
if (value == finalElement.toInt()) { if (value == finalElement) {
hasNext = false hasNext = false
} }
else { else {
@@ -70,16 +68,16 @@ internal class CharProgressionIterator(start: Char, end: Char, val increment: In
* An iterator over a progression of values of type `Short`. * An iterator over a progression of values of type `Short`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class ShortProgressionIterator(start: Short, end: Short, val increment: Int) : ShortIterator() { internal class ShortProgressionIterator(first: Short, last: Short, val increment: Int) : ShortIterator() {
private var next = start.toInt() private var next = first.toInt()
private val finalElement: Short = getProgressionFinalElement(start.toInt(), end.toInt(), increment).toShort() private val finalElement = last.toInt()
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
override fun nextShort(): Short { override fun nextShort(): Short {
val value = next val value = next
if (value == finalElement.toInt()) { if (value == finalElement) {
hasNext = false hasNext = false
} }
else { else {
@@ -93,10 +91,10 @@ internal class ShortProgressionIterator(start: Short, end: Short, val increment:
* An iterator over a progression of values of type `Int`. * An iterator over a progression of values of type `Int`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class IntProgressionIterator(start: Int, end: Int, val increment: Int) : IntIterator() { internal class IntProgressionIterator(first: Int, last: Int, val increment: Int) : IntIterator() {
private var next = start private var next = first
private val finalElement: Int = getProgressionFinalElement(start, end, increment) private val finalElement = last
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
@@ -116,10 +114,10 @@ internal class IntProgressionIterator(start: Int, end: Int, val increment: Int)
* An iterator over a progression of values of type `Long`. * An iterator over a progression of values of type `Long`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class LongProgressionIterator(start: Long, end: Long, val increment: Long) : LongIterator() { internal class LongProgressionIterator(first: Long, last: Long, val increment: Long) : LongIterator() {
private var next = start private var next = first
private val finalElement: Long = getProgressionFinalElement(start, end, increment) private val finalElement = last
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
+7 -5
View File
@@ -18,6 +18,8 @@
package kotlin package kotlin
import kotlin.internal.getProgressionLastElement
@Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING) @Deprecated("Use IntProgression instead.", ReplaceWith("IntProgression"), level = DeprecationLevel.WARNING)
/** /**
* A progression of values of type `Byte`. * A progression of values of type `Byte`.
@@ -41,7 +43,7 @@ public open class ByteProgression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: Byte = kotlin.internal.getProgressionFinalElement(start.toInt(), endInclusive.toInt(), increment).toByte() public val last: Byte = getProgressionLastElement(start.toInt(), endInclusive.toInt(), increment).toByte()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: Byte get() = first public override val start: Byte get() = first
@@ -99,7 +101,7 @@ public open class CharProgression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: Char = kotlin.internal.getProgressionFinalElement(start.toInt(), endInclusive.toInt(), increment).toChar() public val last: Char = getProgressionLastElement(start.toInt(), endInclusive.toInt(), increment).toChar()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: Char get() = first public override val start: Char get() = first
@@ -158,7 +160,7 @@ public open class ShortProgression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: Short = kotlin.internal.getProgressionFinalElement(start.toInt(), endInclusive.toInt(), increment).toShort() public val last: Short = getProgressionLastElement(start.toInt(), endInclusive.toInt(), increment).toShort()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: Short get() = first public override val start: Short get() = first
@@ -216,7 +218,7 @@ public open class IntProgression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: Int = kotlin.internal.getProgressionFinalElement(start.toInt(), endInclusive.toInt(), increment).toInt() public val last: Int = getProgressionLastElement(start.toInt(), endInclusive.toInt(), increment).toInt()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: Int get() = first public override val start: Int get() = first
@@ -274,7 +276,7 @@ public open class LongProgression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: Long = kotlin.internal.getProgressionFinalElement(start.toLong(), endInclusive.toLong(), increment).toLong() public val last: Long = getProgressionLastElement(start.toLong(), endInclusive.toLong(), increment).toLong()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: Long get() = first public override val start: Long get() = first
@@ -37,31 +37,8 @@ private fun differenceModulo(a: Long, b: Long, c: Long): Long {
} }
/**
* Calculates the final element of a bounded arithmetic progression, i.e. the last element of the progression which is in the range
* from [start] to [end] in case of a positive [increment], or from [end] to [start] in case of a negative
* increment.
*
* No validation on passed parameters is performed. The given parameters should satisfy the condition: either
* `increment > 0` and `start >= end`, or `increment < 0` and`start >= end`.
* @param start first element of the progression
* @param end ending bound for the progression
* @param increment increment, or difference of successive elements in the progression
* @return the final element of the progression
* @suppress
*/
@Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.") @Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.")
public fun getProgressionFinalElement(start: Int, end: Int, increment: Int): Int { public fun getProgressionFinalElement(start: Int, end: Int, increment: Int): Int = getProgressionLastElement(start, end, increment)
if (increment > 0) {
return end - differenceModulo(end, start, increment)
}
else if (increment < 0) {
return end + differenceModulo(start, end, -increment)
}
else {
throw IllegalArgumentException("Increment is zero.")
}
}
/** /**
* Calculates the final element of a bounded arithmetic progression, i.e. the last element of the progression which is in the range * Calculates the final element of a bounded arithmetic progression, i.e. the last element of the progression which is in the range
@@ -76,8 +53,34 @@ public fun getProgressionFinalElement(start: Int, end: Int, increment: Int): Int
* @return the final element of the progression * @return the final element of the progression
* @suppress * @suppress
*/ */
@Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.") internal fun getProgressionLastElement(start: Int, end: Int, increment: Int): Int {
public fun getProgressionFinalElement(start: Long, end: Long, increment: Long): Long { if (increment > 0) {
return end - differenceModulo(end, start, increment)
}
else if (increment < 0) {
return end + differenceModulo(start, end, -increment)
}
else {
throw IllegalArgumentException("Increment is zero.")
}
}
@Deprecated("This function supports the compiler infrastructure and is not intended to be used directly from user code. It may become internal soon.")
public fun getProgressionFinalElement(start: Long, end: Long, increment: Long): Long = getProgressionLastElement(start, end, increment)
/**
* Calculates the final element of a bounded arithmetic progression, i.e. the last element of the progression which is in the range
* from [start] to [end] in case of a positive [increment], or from [end] to [start] in case of a negative
* increment.
*
* No validation on passed parameters is performed. The given parameters should satisfy the condition: either
* `increment > 0` and `start >= end`, or `increment < 0` and`start >= end`.
* @param start first element of the progression
* @param end ending bound for the progression
* @param increment increment, or difference of successive elements in the progression
* @return the final element of the progression
* @suppress
*/
internal fun getProgressionLastElement(start: Long, end: Long, increment: Long): Long {
if (increment > 0) { if (increment > 0) {
return end - differenceModulo(end, start, increment) return end - differenceModulo(end, start, increment)
} }
@@ -35,16 +35,16 @@ fun integerProgressionIterator(kind: ProgressionKind): String {
* An iterator over a progression of values of type `$t`. * An iterator over a progression of values of type `$t`.
* @property increment the number by which the value is incremented on each step. * @property increment the number by which the value is incremented on each step.
*/ */
internal class ${t}ProgressionIterator(start: $t, end: $t, val increment: $incrementType) : ${t}Iterator() { internal class ${t}ProgressionIterator(first: $t, last: $t, val increment: $incrementType) : ${t}Iterator() {
private var next = start$toInt private var next = first$toInt
private val finalElement: $t = getProgressionFinalElement(start$toInt, end$toInt, increment)$toType private val finalElement = last$toInt
private var hasNext: Boolean = if (increment > 0) start <= end else start >= end private var hasNext: Boolean = if (increment > 0) first <= last else first >= last
override fun hasNext(): Boolean = hasNext override fun hasNext(): Boolean = hasNext
override fun next$t(): $t { override fun next$t(): $t {
val value = next val value = next
if (value == finalElement$toInt) { if (value == finalElement) {
hasNext = false hasNext = false
} }
else { else {
@@ -77,8 +77,6 @@ internal class ${t}ProgressionIterator(start: $t, val end: $t, val increment: $t
class GenerateProgressionIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) { class GenerateProgressionIterators(out: PrintWriter) : BuiltInsSourceGenerator(out) {
override fun generateBody() { override fun generateBody() {
out.println("import kotlin.internal.getProgressionFinalElement")
out.println()
for (kind in ProgressionKind.values()) { for (kind in ProgressionKind.values()) {
if (kind != FLOAT && kind != DOUBLE) { if (kind != FLOAT && kind != DOUBLE) {
out.println(integerProgressionIterator(kind)) out.println(integerProgressionIterator(kind))
@@ -74,7 +74,7 @@ public open class $progression
/** /**
* The last element in the progression. * The last element in the progression.
*/ */
public val last: $t = kotlin.internal.getProgressionFinalElement(start.to$incrementType(), endInclusive.to$incrementType(), increment).to$t() public val last: $t = getProgressionLastElement(start.to$incrementType(), endInclusive.to$incrementType(), increment).to$t()
@Deprecated("Use first instead.", ReplaceWith("first")) @Deprecated("Use first instead.", ReplaceWith("first"))
public override val start: $t get() = first public override val start: $t get() = first
@@ -182,6 +182,8 @@ public open class $progression(
} }
override fun generateBody() { override fun generateBody() {
out.println("import kotlin.internal.getProgressionLastElement")
out.println()
for (kind in ProgressionKind.values) { for (kind in ProgressionKind.values) {
if (kind == FLOAT || kind == DOUBLE) if (kind == FLOAT || kind == DOUBLE)
continue continue