Fix const range bounds generation

This commit is contained in:
Dmitry Petrov
2017-09-25 11:51:47 +03:00
parent e82544ffb0
commit 8f9ea3e08b
7 changed files with 77 additions and 3 deletions
@@ -179,6 +179,19 @@ public abstract class StackValue {
return type == Type.VOID_TYPE ? none() : new OnStack(type);
}
@NotNull
public static StackValue integerConstant(int value, @NotNull Type type) {
if (type == Type.LONG_TYPE) {
return constant(Long.valueOf(value), type);
}
else if (type == Type.BYTE_TYPE || type == Type.SHORT_TYPE || type == Type.INT_TYPE) {
return constant(Integer.valueOf(value), type);
}
else {
throw new AssertionError("Unexpected integer type: " + type);
}
}
@NotNull
public static StackValue constant(@Nullable Object value, @NotNull Type type) {
if (type == Type.BOOLEAN_TYPE) {
@@ -18,10 +18,8 @@ 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.constants.*
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
class ForInUntilConstantRangeLoopGenerator(
@@ -36,5 +34,5 @@ class ForInUntilConstantRangeLoopGenerator(
codegen.generateReceiverValue(from, false)
override fun generateTo(): StackValue =
StackValue.constant(untilValue, asmElementType)
StackValue.integerConstant(untilValue, asmElementType)
}