Intrinsics for 'reversed': downTo
#KT-21323 In Progress
This commit is contained in:
+6
-1
@@ -24,7 +24,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtForExpression
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
|
||||
class DownToProgressionRangeValue(rangeCall: ResolvedCall<out CallableDescriptor>): PrimitiveNumberRangeIntrinsicRangeValue(rangeCall) {
|
||||
class DownToProgressionRangeValue(rangeCall: ResolvedCall<out CallableDescriptor>) :
|
||||
PrimitiveNumberRangeIntrinsicRangeValue(rangeCall), ReversableRangeValue {
|
||||
|
||||
override fun getBoundedValue(codegen: ExpressionCodegen) =
|
||||
SimpleBoundedValue(
|
||||
codegen, rangeCall,
|
||||
@@ -34,4 +36,7 @@ class DownToProgressionRangeValue(rangeCall: ResolvedCall<out CallableDescriptor
|
||||
|
||||
override fun createForLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression) =
|
||||
ForInSimpleProgressionLoopGenerator.fromBoundedValueWithStepMinus1(codegen, forExpression, getBoundedValue(codegen))
|
||||
|
||||
override fun createForInReversedLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression) =
|
||||
ForInSimpleProgressionLoopGenerator.fromBoundedValueWithStep1(codegen, forExpression, getBoundedValue(codegen))
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// WITH_RUNTIME
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var sum = 0
|
||||
for (i in (4 downTo 1).reversed()) {
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
assertEquals(1234, sum)
|
||||
|
||||
var sumL = 0L
|
||||
for (i in (4L downTo 1L).reversed()) {
|
||||
sumL = sumL * 10 + i
|
||||
}
|
||||
assertEquals(1234L, sumL)
|
||||
|
||||
var sumC = 0
|
||||
for (i in ('4' downTo '1').reversed()) {
|
||||
sumC = sumC * 10 + i.toInt() - '0'.toInt()
|
||||
}
|
||||
assertEquals(1234, sumC)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_RUNTIME
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(): String {
|
||||
var sum = 0
|
||||
for (i in (4 downTo 1).reversed()) {
|
||||
sum = sum * 10 + i
|
||||
}
|
||||
assertEquals(1234, sum)
|
||||
|
||||
var sumL = 0L
|
||||
for (i in (4L downTo 1L).reversed()) {
|
||||
sumL = sumL * 10 + i
|
||||
}
|
||||
assertEquals(1234L, sumL)
|
||||
|
||||
var sumC = 0
|
||||
for (i in ('4' downTo '1').reversed()) {
|
||||
sumC = sumC * 10 + i.toInt() - '0'.toInt()
|
||||
}
|
||||
assertEquals(1234, sumC)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// 0 reversed
|
||||
+6
@@ -15259,6 +15259,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedDownTo.kt")
|
||||
public void testForInReversedDownTo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedDownTo.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedEmptyRange.kt")
|
||||
public void testForInReversedEmptyRange() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedEmptyRange.kt");
|
||||
|
||||
@@ -15259,6 +15259,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedDownTo.kt")
|
||||
public void testForInReversedDownTo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedDownTo.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedEmptyRange.kt")
|
||||
public void testForInReversedEmptyRange() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedEmptyRange.kt");
|
||||
|
||||
@@ -1426,6 +1426,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedDownTo.kt")
|
||||
public void testForInReversedDownTo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInReversed/forInReversedDownTo.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedEmptyRangeLiteral.kt")
|
||||
public void testForInReversedEmptyRangeLiteral() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInReversed/forInReversedEmptyRangeLiteral.kt");
|
||||
|
||||
@@ -15259,6 +15259,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedDownTo.kt")
|
||||
public void testForInReversedDownTo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedDownTo.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedEmptyRange.kt")
|
||||
public void testForInReversedEmptyRange() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedEmptyRange.kt");
|
||||
|
||||
@@ -16675,6 +16675,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedDownTo.kt")
|
||||
public void testForInReversedDownTo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedDownTo.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("forInReversedEmptyRange.kt")
|
||||
public void testForInReversedEmptyRange() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/ranges/forInReversed/forInReversedEmptyRange.kt");
|
||||
|
||||
Reference in New Issue
Block a user