KT-925 step methods for integral ranges
This commit is contained in:
@@ -1046,11 +1046,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
isInterface = CodegenUtil.isInterface(containingDeclaration);
|
||||
}
|
||||
else {
|
||||
if(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.OBJECT)
|
||||
isInterface = false;
|
||||
if(containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor) containingDeclaration).getKind() == ClassKind.TRAIT)
|
||||
isInterface = true;
|
||||
else {
|
||||
JetClass jetClass = (JetClass) bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, containingDeclaration);
|
||||
isInterface = jetClass == null || jetClass.isTrait();
|
||||
isInterface = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2768,7 +2767,11 @@ If finally block is present, its last expression is the value of try expression.
|
||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, rangeExpression);
|
||||
assert jetType != null;
|
||||
final DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (isClass(descriptor, "IntRange")) {
|
||||
if (isClass(descriptor, "IntRange") ||
|
||||
isClass(descriptor, "CharRange") ||
|
||||
isClass(descriptor, "ByteRange") ||
|
||||
isClass(descriptor, "LongRange") ||
|
||||
isClass(descriptor, "ShortRange")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,6 +92,7 @@ public class IntrinsicMethods {
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("Array"), 1, new NewArray());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("sure"), 0, new Sure());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("synchronized"), 1, new StupidSync());
|
||||
declareOverload(myStdLib.getLibraryScope().getFunctions("iterator"), 0, new IteratorIterator());
|
||||
|
||||
declareIntrinsicFunction("ByteIterator", "next", 0, ITERATOR_NEXT);
|
||||
declareIntrinsicFunction("ShortIterator", "next", 0, ITERATOR_NEXT);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.jetbrains.jet.codegen.intrinsics;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||
import org.jetbrains.jet.codegen.StackValue;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.commons.InstructionAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class IteratorIterator implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, @Nullable PsiElement element, @Nullable List<JetExpression> arguments, StackValue receiver) {
|
||||
return receiver;
|
||||
}
|
||||
}
|
||||
@@ -19,19 +19,22 @@ public class RangeTo implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||
if(arguments.size()==1) {
|
||||
final Type leftType = receiver.type;
|
||||
final Type rightType = codegen.expressionType(arguments.get(0));
|
||||
receiver.put(Type.INT_TYPE, v);
|
||||
codegen.gen(arguments.get(0), Type.INT_TYPE);
|
||||
v.invokestatic("jet/IntRange", "rangeTo", "(II)Ljet/IntRange;");
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_INT_RANGE);
|
||||
codegen.gen(arguments.get(0), rightType);
|
||||
v.invokestatic("jet/runtime/Ranges", "rangeTo", "(" + receiver.type.getDescriptor() + leftType.getDescriptor() + ")" + expectedType.getDescriptor());
|
||||
return StackValue.onStack(expectedType);
|
||||
}
|
||||
else {
|
||||
JetBinaryExpression expression = (JetBinaryExpression) element;
|
||||
final Type leftType = codegen.expressionType(expression.getLeft());
|
||||
final Type rightType = codegen.expressionType(expression.getRight());
|
||||
if (JetTypeMapper.isIntPrimitive(leftType)) {
|
||||
codegen.gen(expression.getLeft(), Type.INT_TYPE);
|
||||
codegen.gen(expression.getRight(), Type.INT_TYPE);
|
||||
v.invokestatic(expectedType.getInternalName(), "rangeTo", "(" + leftType.getDescriptor() + leftType.getDescriptor() + ")" + expectedType.getDescriptor());
|
||||
return StackValue.onStack(JetTypeMapper.TYPE_INT_RANGE);
|
||||
codegen.gen(expression.getLeft(), leftType);
|
||||
codegen.gen(expression.getRight(), rightType);
|
||||
v.invokestatic("jet/runtime/Ranges", "rangeTo", "(" + leftType.getDescriptor() + rightType.getDescriptor() + ")" + expectedType.getDescriptor());
|
||||
return StackValue.onStack(expectedType);
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("ranges are only supported for int objects");
|
||||
|
||||
Reference in New Issue
Block a user