From 04ab3e15196cae260c2417eb9f6e7a4e0125a294 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 6 Dec 2017 16:11:22 +0300 Subject: [PATCH] Use ForInSimpleProgressionLoopGenerator for most of the loop intrinsics --- .../codegen/range/ArrayIndicesRangeValue.kt | 6 +- .../range/CharSequenceIndicesRangeValue.kt | 4 +- .../range/CollectionIndicesRangeValue.kt | 4 +- .../range/DownToProgressionRangeValue.kt | 4 +- .../PrimitiveNumberRangeLiteralRangeValue.kt | 28 ++++-- .../range/PrimitiveNumberUntilRangeValue.kt | 4 +- ...bstractForInExclusiveRangeLoopGenerator.kt | 45 --------- .../AbstractForInRangeLoopGenerator.kt | 2 +- ...tForInRangeWithGivenBoundsLoopGenerator.kt | 35 ------- .../ForInArrayIndicesRangeLoopGenerator.kt | 31 ------ ...InCharSequenceIndicesRangeLoopGenerator.kt | 32 ------ ...orInCollectionIndicesRangeLoopGenerator.kt | 31 ------ .../ForInDownToProgressionLoopGenerator.kt | 37 ------- .../ForInOptimizedIndicesLoopGenerator.kt | 48 --------- .../forLoop/ForInRangeLiteralLoopGenerator.kt | 42 -------- .../ForInSimpleProgressionLoopGenerator.kt | 98 +++++++++++++++++++ .../ForInUntilConstantRangeLoopGenerator.kt | 38 ------- .../forLoop/ForInUntilRangeLoopGenerator.kt | 39 -------- 18 files changed, 132 insertions(+), 396 deletions(-) delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/AbstractForInExclusiveRangeLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/AbstractForInRangeWithGivenBoundsLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInArrayIndicesRangeLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCharSequenceIndicesRangeLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCollectionIndicesRangeLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInDownToProgressionLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInOptimizedIndicesLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInRangeLiteralLoopGenerator.kt create mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilConstantRangeLoopGenerator.kt delete mode 100644 compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilRangeLoopGenerator.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/ArrayIndicesRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/ArrayIndicesRangeValue.kt index a35b45bcc78..9164d00d611 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/ArrayIndicesRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/ArrayIndicesRangeValue.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.codegen.range import org.jetbrains.kotlin.codegen.ExpressionCodegen import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.codegen.generateCallReceiver -import org.jetbrains.kotlin.codegen.range.forLoop.ForInArrayIndicesRangeLoopGenerator +import org.jetbrains.kotlin.codegen.range.forLoop.ForInSimpleProgressionLoopGenerator import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.org.objectweb.asm.Type class ArrayIndicesRangeValue(rangeCall: ResolvedCall): PrimitiveNumberRangeIntrinsicRangeValue(rangeCall) { + private val expectedReceiverType: KotlinType = ExpressionCodegen.getExpectedReceiverType(rangeCall) override fun getBoundedValue(codegen: ExpressionCodegen) = @@ -42,6 +43,5 @@ class ArrayIndicesRangeValue(rangeCall: ResolvedCall): P ) override fun createForLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression) = - ForInArrayIndicesRangeLoopGenerator(codegen, forExpression, rangeCall) - + ForInSimpleProgressionLoopGenerator.fromBoundedValueWithStep1(codegen, forExpression, getBoundedValue(codegen)) } \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/CharSequenceIndicesRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/CharSequenceIndicesRangeValue.kt index 25bcbcc88e4..f8c52731537 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/CharSequenceIndicesRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/CharSequenceIndicesRangeValue.kt @@ -19,7 +19,7 @@ package org.jetbrains.kotlin.codegen.range import org.jetbrains.kotlin.codegen.ExpressionCodegen import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.codegen.generateCallReceiver -import org.jetbrains.kotlin.codegen.range.forLoop.ForInCharSequenceIndicesRangeLoopGenerator +import org.jetbrains.kotlin.codegen.range.forLoop.ForInSimpleProgressionLoopGenerator import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -42,5 +42,5 @@ class CharSequenceIndicesRangeValue(rangeCall: ResolvedCall ): PrimitiveNumberRangeIntrinsicRangeValue(rangeCall) { + override fun getBoundedValue(codegen: ExpressionCodegen) = SimpleBoundedValue(codegen, rangeCall) override fun createForLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression): ForLoopGenerator = getConstRangeForInRangeLiteralGenerator(codegen, forExpression) ?: - ForInRangeLiteralLoopGenerator(codegen, forExpression, rangeCall) + ForInSimpleProgressionLoopGenerator.fromBoundedValueWithStep1(codegen, forExpression, getBoundedValue(codegen)) private fun getConstRangeForInRangeLiteralGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression): ForLoopGenerator? { val rhsExpression = rangeCall.valueArgumentsByIndex?.run { get(0).arguments[0].getArgumentExpression() } ?: return null @@ -45,8 +51,18 @@ class PrimitiveNumberRangeLiteralRangeValue( is IntValue -> constValue.value + 1 else -> return null } + // Watch out for integer overflow - if (untilValue == Int.MIN_VALUE) return null - return ForInUntilConstantRangeLoopGenerator(codegen, forExpression, rangeCall, untilValue) + return if (untilValue == Int.MIN_VALUE) + null + else + ForInSimpleProgressionLoopGenerator( + codegen, forExpression, + startValue = codegen.generateCallReceiver(rangeCall), + isStartInclusive = true, + endValue = StackValue.integerConstant(untilValue, asmElementType), + isEndInclusive = false, + step = 1 + ) } } \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberUntilRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberUntilRangeValue.kt index ef44ba1f0e9..bd39fe61ba6 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberUntilRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberUntilRangeValue.kt @@ -17,7 +17,7 @@ package org.jetbrains.kotlin.codegen.range import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.range.forLoop.ForInUntilRangeLoopGenerator +import org.jetbrains.kotlin.codegen.range.forLoop.ForInSimpleProgressionLoopGenerator import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall @@ -27,5 +27,5 @@ class PrimitiveNumberUntilRangeValue(rangeCall: ResolvedCall -) : ForInOptimizedIndicesLoopGenerator(codegen, forExpression, loopRangeCall) { - override fun getReceiverSizeAsInt() { - v.arraylength() - } -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCharSequenceIndicesRangeLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCharSequenceIndicesRangeLoopGenerator.kt deleted file mode 100644 index 6a94c9f085c..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCharSequenceIndicesRangeLoopGenerator.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall - -class ForInCharSequenceIndicesRangeLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : ForInOptimizedIndicesLoopGenerator(codegen, forExpression, loopRangeCall) { - - override fun getReceiverSizeAsInt() { - v.invokeinterface("java/lang/CharSequence", "length", "()I") - } -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCollectionIndicesRangeLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCollectionIndicesRangeLoopGenerator.kt deleted file mode 100644 index 21783d2d4ad..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInCollectionIndicesRangeLoopGenerator.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall - -class ForInCollectionIndicesRangeLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : ForInOptimizedIndicesLoopGenerator(codegen, forExpression, loopRangeCall) { - override fun getReceiverSizeAsInt() { - v.invokeinterface("java/util/Collection", "size", "()I") - } -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInDownToProgressionLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInDownToProgressionLoopGenerator.kt deleted file mode 100644 index 204f46e724e..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInDownToProgressionLoopGenerator.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.StackValue -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue - -class ForInDownToProgressionLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : AbstractForInRangeWithGivenBoundsLoopGenerator(codegen, forExpression, -1) { - private val from: ReceiverValue = loopRangeCall.extensionReceiver!! - private val to: KtExpression = ExpressionCodegen.getSingleArgumentExpression(loopRangeCall)!! - - override fun generateFrom(): StackValue = codegen.generateReceiverValue(from, false) - - override fun generateTo(): StackValue = codegen.gen(to) -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInOptimizedIndicesLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInOptimizedIndicesLoopGenerator.kt deleted file mode 100644 index cbd7b01e363..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInOptimizedIndicesLoopGenerator.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.StackValue -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.org.objectweb.asm.Type - -abstract class ForInOptimizedIndicesLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : AbstractForInExclusiveRangeLoopGenerator(codegen, forExpression) { - protected val receiverValue: ReceiverValue = loopRangeCall.extensionReceiver!! - protected val expectedReceiverType: KotlinType = ExpressionCodegen.getExpectedReceiverType(loopRangeCall) - - override fun generateFrom(): StackValue = - StackValue.constant(0, asmElementType) - - override fun generateTo(): StackValue = - StackValue.operation(Type.INT_TYPE) { v -> - codegen.generateReceiverValue(receiverValue, false).put(codegen.asmType(expectedReceiverType), v) - getReceiverSizeAsInt() - } - - /** - * `(receiver -> size:I)` - */ - protected abstract fun getReceiverSizeAsInt() -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInRangeLiteralLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInRangeLiteralLoopGenerator.kt deleted file mode 100644 index 7622436d4f1..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInRangeLiteralLoopGenerator.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.StackValue -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue - -class ForInRangeLiteralLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : AbstractForInRangeWithGivenBoundsLoopGenerator(codegen, forExpression) { - private val from: ReceiverValue = loopRangeCall.dispatchReceiver!! - private val to: KtExpression = ExpressionCodegen.getSingleArgumentExpression(loopRangeCall)!! - - override fun generateFrom(): StackValue = codegen.generateReceiverValue(from, false) - - override fun generateTo(): StackValue = codegen.gen(to) - - override fun storeRangeStartAndEnd() { - loopParameter().store(generateFrom(), v) - StackValue.local(endVar, asmElementType).store(generateTo(), v) - } -} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt new file mode 100644 index 00000000000..9779875a25c --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInSimpleProgressionLoopGenerator.kt @@ -0,0 +1,98 @@ +/* + * Copyright 2010-2017 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.kotlin.codegen.range.forLoop + +import org.jetbrains.kotlin.codegen.ExpressionCodegen +import org.jetbrains.kotlin.codegen.StackValue +import org.jetbrains.kotlin.codegen.range.SimpleBoundedValue +import org.jetbrains.kotlin.psi.KtForExpression +import org.jetbrains.org.objectweb.asm.Label +import org.jetbrains.org.objectweb.asm.Type + +class ForInSimpleProgressionLoopGenerator( + codegen: ExpressionCodegen, + forExpression: KtForExpression, + private val startValue: StackValue, + private val isStartInclusive: Boolean, + private val endValue: StackValue, + private val isEndInclusive: Boolean, + step: Int +) : AbstractForInRangeLoopGenerator(codegen, forExpression, step) { + + constructor( + codegen: ExpressionCodegen, + forExpression: KtForExpression, + boundedValue: SimpleBoundedValue, + step: Int + ) : this( + codegen, forExpression, + startValue = if (step == 1) boundedValue.lowBound else boundedValue.highBound, + isStartInclusive = if (step == 1) boundedValue.isLowInclusive else boundedValue.isHighInclusive, + endValue = if (step == 1) boundedValue.highBound else boundedValue.lowBound, + isEndInclusive = if (step == 1) boundedValue.isHighInclusive else boundedValue.isLowInclusive, + step = step + ) + + companion object { + fun fromBoundedValueWithStep1(codegen: ExpressionCodegen, forExpression: KtForExpression, boundedValue: SimpleBoundedValue) = + ForInSimpleProgressionLoopGenerator(codegen, forExpression, boundedValue, 1) + + fun fromBoundedValueWithStepMinus1(codegen: ExpressionCodegen, forExpression: KtForExpression, boundedValue: SimpleBoundedValue) = + ForInSimpleProgressionLoopGenerator(codegen, forExpression, boundedValue, -1) + } + + override fun storeRangeStartAndEnd() { + loopParameter().store(startValue, v) + // Skip 1st element if start is not inclusive. + if (!isStartInclusive) incrementLoopVariable() + + StackValue.local(endVar, asmElementType).store(endValue, v) + } + + override fun checkEmptyLoop(loopExit: Label) { + // No check required if end is non-inclusive: loop is generated with pre-condition. + if (isEndInclusive) { + super.checkEmptyLoop(loopExit) + } + } + + override fun checkPreCondition(loopExit: Label) { + // Generate pre-condition loop if end is not inclusive. + if (!isEndInclusive) { + loopParameter().put(asmElementType, v) + v.load(endVar, asmElementType) + if (asmElementType.sort == Type.LONG) { + v.lcmp() + v.ifge(loopExit) + } + else { + v.ificmpge(loopExit) + } + } + } + + override fun checkPostConditionAndIncrement(loopExit: Label) { + // Generate post-condition loop if end is inclusive. + // Otherwise, just increment the loop variable. + if (isEndInclusive) { + super.checkPostConditionAndIncrement(loopExit) + } + else { + incrementLoopVariable() + } + } +} \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilConstantRangeLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilConstantRangeLoopGenerator.kt deleted file mode 100644 index 23872324fee..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilConstantRangeLoopGenerator.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.StackValue -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue - -class ForInUntilConstantRangeLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*>, - private val untilValue: Int -) : AbstractForInExclusiveRangeLoopGenerator(codegen, forExpression) { - private val from: ReceiverValue = loopRangeCall.dispatchReceiver!! - - override fun generateFrom(): StackValue = - codegen.generateReceiverValue(from, false) - - override fun generateTo(): StackValue = - StackValue.integerConstant(untilValue, asmElementType) -} \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilRangeLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilRangeLoopGenerator.kt deleted file mode 100644 index 0224e91e7fa..00000000000 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/forLoop/ForInUntilRangeLoopGenerator.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2017 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.kotlin.codegen.range.forLoop - -import org.jetbrains.kotlin.codegen.ExpressionCodegen -import org.jetbrains.kotlin.codegen.StackValue -import org.jetbrains.kotlin.psi.KtExpression -import org.jetbrains.kotlin.psi.KtForExpression -import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue - -class ForInUntilRangeLoopGenerator( - codegen: ExpressionCodegen, - forExpression: KtForExpression, - loopRangeCall: ResolvedCall<*> -) : AbstractForInExclusiveRangeLoopGenerator(codegen, forExpression) { - private val from: ReceiverValue = loopRangeCall.extensionReceiver!! - private val to: KtExpression = ExpressionCodegen.getSingleArgumentExpression(loopRangeCall)!! - - override fun generateFrom(): StackValue = - codegen.generateReceiverValue(from, false) - - override fun generateTo(): StackValue = - codegen.gen(to) -}