KT-5044 code cleanup, test added

This commit is contained in:
Vsevolod
2016-10-11 21:14:57 +03:00
committed by Dmitry Petrov
parent bd6f83b9b7
commit e788ef408f
4 changed files with 44 additions and 12 deletions
@@ -3470,13 +3470,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
* Translates x in a..b to a <= x && x <= b
* and x !in a..b to a > x || x > b for any primitive type
*/
private void generateInPrimitiveRange(StackValue leftValue, KtBinaryExpression rangeExpression, boolean isInverted) {
Type rangeType = leftValue.type;
private void generateInPrimitiveRange(StackValue argument, KtBinaryExpression rangeExpression, boolean isInverted) {
Type rangeType = argument.type;
int localVarIndex = myFrameMap.enterTemp(rangeType);
// Load left bound
gen(rangeExpression.getLeft(), rangeType);
// Load x into local variable to avoid StackValue#put side-effects
leftValue.put(rangeType, v);
argument.put(rangeType, v);
v.store(localVarIndex, rangeType);
v.load(localVarIndex, rangeType);
@@ -217,15 +217,6 @@ public class RangeCodegenUtil {
return false;
}
private static boolean isBuiltInRangeTo(@NotNull CallableDescriptor descriptor) {
if (!isTopLevelInPackage(descriptor, "rangeTo", "kotlin.ranges")) {
return false;
}
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
return extensionReceiver != null;
}
/*
* Checks whether for expression 'x in a..b' a..b is primitive integral range
* with same type as x.
@@ -256,6 +247,15 @@ public class RangeCodegenUtil {
return false;
}
private static boolean isBuiltInRangeTo(@NotNull CallableDescriptor descriptor) {
if (!isTopLevelInPackage(descriptor, "rangeTo", "kotlin.ranges")) {
return false;
}
ReceiverParameterDescriptor extensionReceiver = descriptor.getExtensionReceiverParameter();
return extensionReceiver != null;
}
private static boolean isTopLevelInPackage(@NotNull CallableDescriptor descriptor, @NotNull String name, @NotNull String packageName) {
if (!name.equals(descriptor.getName().asString())) return false;