diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index abc14d2666c..73e6f058f3d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -40,6 +40,7 @@ import org.jetbrains.kotlin.codegen.coroutines.CoroutineCodegenUtilKt; import org.jetbrains.kotlin.codegen.coroutines.ResolvedCallWithRealDescriptor; import org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension; import org.jetbrains.kotlin.codegen.forLoop.AbstractForLoopGenerator; +import org.jetbrains.kotlin.codegen.forLoop.ForLoopGenerator; import org.jetbrains.kotlin.codegen.inline.*; import org.jetbrains.kotlin.codegen.intrinsics.*; import org.jetbrains.kotlin.codegen.pseudoInsns.PseudoInsnsKt; @@ -627,7 +628,7 @@ public class ExpressionCodegen extends KtVisitor impleme return context.getContextKind(); } - private void generateForLoop(AbstractForLoopGenerator generator) { + private void generateForLoop(ForLoopGenerator generator) { Label loopExit = new Label(); Label loopEntry = new Label(); Label continueLabel = new Label(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/AbstractForLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/AbstractForLoopGenerator.kt index 6a3391c2bc1..00c0970dfd7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/AbstractForLoopGenerator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/AbstractForLoopGenerator.kt @@ -30,8 +30,8 @@ import org.jetbrains.org.objectweb.asm.Type abstract class AbstractForLoopGenerator( protected val codegen: ExpressionCodegen, - val forExpression: KtForExpression -) { + override val forExpression: KtForExpression +) : ForLoopGenerator { protected val bindingContext = codegen.bindingContext protected val v = codegen.v!! @@ -52,7 +52,7 @@ abstract class AbstractForLoopGenerator( return nextCall.resultingDescriptor.returnType!! } - open fun beforeLoop() { + override fun beforeLoop() { val loopParameter = forExpression.loopParameter ?: return val multiParameter = loopParameter.destructuringDeclaration if (multiParameter != null) { @@ -75,11 +75,7 @@ abstract class AbstractForLoopGenerator( } } - abstract fun checkEmptyLoop(loopExit: Label) - - abstract fun checkPreCondition(loopExit: Label) - - fun beforeBody() { + override fun beforeBody() { assignToLoopParameter() v.mark(loopParameterStartLabel) @@ -118,7 +114,7 @@ abstract class AbstractForLoopGenerator( protected abstract fun checkPostConditionAndIncrement(loopExit: Label) - fun body() { + override fun body() { codegen.generateLoopBody(forExpression.body) } @@ -132,7 +128,7 @@ abstract class AbstractForLoopGenerator( return varIndex } - fun afterBody(loopExit: Label) { + override fun afterBody(loopExit: Label) { codegen.markStartLineNumber(forExpression) checkPostConditionAndIncrement(loopExit) @@ -140,7 +136,7 @@ abstract class AbstractForLoopGenerator( v.mark(bodyEnd) } - fun afterLoop() { + override fun afterLoop() { for (task in leaveVariableTasks.asReversed()) { task.run() } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForLoopGenerator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForLoopGenerator.kt new file mode 100644 index 00000000000..ab686c23f56 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/forLoop/ForLoopGenerator.kt @@ -0,0 +1,31 @@ +/* + * 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.forLoop + +import org.jetbrains.kotlin.psi.KtForExpression +import org.jetbrains.org.objectweb.asm.Label + +interface ForLoopGenerator { + val forExpression: KtForExpression + fun beforeLoop() + fun checkEmptyLoop(loopExit: Label) + fun checkPreCondition(loopExit: Label) + fun beforeBody() + fun body() + fun afterBody(loopExit: Label) + fun afterLoop() +} \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValue.kt index 99621f96040..3d71c7b6acf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/RangeValue.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.KtForExpression import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall interface RangeValue { - fun createForLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression): AbstractForLoopGenerator + fun createForLoopGenerator(codegen: ExpressionCodegen, forExpression: KtForExpression): ForLoopGenerator } class ArrayRangeValue : RangeValue {