change for 9 array classes
This commit is contained in:
@@ -301,6 +301,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
private abstract class ForLoopGenerator {
|
||||
protected JetForExpression expression;
|
||||
protected Type loopRangeType;
|
||||
protected JetType expressionType;
|
||||
protected VariableDescriptor parameterDescriptor;
|
||||
|
||||
public ForLoopGenerator(JetForExpression expression, Type loopRangeType) {
|
||||
@@ -308,6 +309,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
this.loopRangeType = loopRangeType;
|
||||
final JetParameter loopParameter = expression.getLoopParameter();
|
||||
this.parameterDescriptor = bindingContext.get(BindingContext.VALUE_PARAMETER, loopParameter);
|
||||
expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange());
|
||||
}
|
||||
|
||||
public void invoke() {
|
||||
@@ -364,7 +366,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
protected void generatePrologue() {
|
||||
myLengthVar = myMap.enterTemp();
|
||||
gen(expression.getLoopRange(), loopRangeType);
|
||||
derefArray(bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange()));
|
||||
v.arraylength();
|
||||
v.store(myLengthVar, Type.INT_TYPE);
|
||||
myIndexVar = myMap.enterTemp();
|
||||
@@ -373,15 +374,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
protected void generateCondition(Type asmParamType, Label end) {
|
||||
Type arrayElParamType = state.getStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor()) ? JetTypeMapper.boxType(asmParamType): asmParamType;
|
||||
|
||||
v.load(myIndexVar, Type.INT_TYPE);
|
||||
v.load(myLengthVar, Type.INT_TYPE);
|
||||
v.ificmpge(end);
|
||||
|
||||
gen(expression.getLoopRange(), loopRangeType); // array
|
||||
derefArray(bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getLoopRange()));
|
||||
v.load(myIndexVar, Type.INT_TYPE);
|
||||
v.aload(asmParamType);
|
||||
StackValue.onStack(asmParamType).put(asmParamType, v);
|
||||
v.aload(arrayElParamType);
|
||||
StackValue.onStack(arrayElParamType).put(asmParamType, v);
|
||||
v.store(lookupLocal(parameterDescriptor), asmParamType);
|
||||
}
|
||||
|
||||
@@ -1626,10 +1628,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
//noinspection ConstantConditions
|
||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
type = typeMapper.mapType(expressionType, OwnerKind.IMPLEMENTATION);
|
||||
if (state.getStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor())) {
|
||||
if (type.getSort() == Type.ARRAY) {
|
||||
generateNewArray(expression, expressionType);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ClassDescriptor classDecl = (ClassDescriptor) constructorDescriptor.getContainingDeclaration();
|
||||
|
||||
receiver.put(receiver.type, v);
|
||||
@@ -1692,43 +1693,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
gen(args.get(0).getArgumentExpression(), Type.INT_TYPE);
|
||||
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/arrays/JetArray", "newArray", "(ILjet/typeinfo/TypeInfo;)Ljet/arrays/JetArray;");
|
||||
}
|
||||
else {
|
||||
elementType = arrayType.getArguments().get(0).getType();
|
||||
JetStandardLibrary standardLibrary = state.getStandardLibrary();
|
||||
if (elementType.equals(standardLibrary.getIntType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newIntArray", "(I)Ljet/arrays/JetIntArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getLongType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newLongArray", "(I)Ljet/arrays/JetLongArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getShortType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newShortArray", "(I)Ljet/arrays/JetShortArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getByteType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newByteArray", "(I)Ljet/arrays/JetByteArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getCharType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newCharArray", "(I)Ljet/arrays/JetCharArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getFloatType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newFloatArray", "(I)Ljet/arrays/JetFloatArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getDoubleType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newDoubleArray", "(I)Ljet/arrays/JetDoubleArray;");
|
||||
}
|
||||
else if (elementType.equals(standardLibrary.getBooleanType())) {
|
||||
v.invokestatic("jet/arrays/JetArray", "newBoolArray", "(I)Ljet/arrays/JetBoolArray;");
|
||||
if(state.getStandardLibrary().getArray().equals(arrayType.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = typeMapper.getGenericsElementType(arrayType);
|
||||
if(elementType != null) {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/typeinfo/TypeInfo", "newArray", "(ILjet/typeinfo/TypeInfo;)[Ljava/lang/Object;");
|
||||
}
|
||||
else {
|
||||
generateTypeInfo(elementType);
|
||||
v.invokestatic("jet/arrays/JetArray", "newGenericArray", "(ILjet/typeinfo/TypeInfo;)Ljet/arrays/JetGenericArray;");
|
||||
v.newarray(JetTypeMapper.boxType(typeMapper.mapType(arrayType.getArguments().get(0).getType())));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Type type = typeMapper.mapType(arrayType, OwnerKind.IMPLEMENTATION);
|
||||
v.newarray(type.getElementType());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1737,11 +1715,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
JetType type = bindingContext.get(BindingContext.EXPRESSION_TYPE, array);
|
||||
final Type arrayType = type == null ? Type.VOID_TYPE : typeMapper.mapType(type);
|
||||
gen(array, arrayType);
|
||||
derefArray(type);
|
||||
generateArrayIndex(expression);
|
||||
if (state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
return StackValue.arrayElement(typeMapper.mapType(elementType), typeMapper.isGenericsArray(type));
|
||||
if (arrayType.getSort() == Type.ARRAY) {
|
||||
if(state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
Type notBoxed = typeMapper.mapType(elementType);
|
||||
Type boxed = JetTypeMapper.boxType(notBoxed);
|
||||
return StackValue.arrayElement(notBoxed, true);
|
||||
}
|
||||
else {
|
||||
return StackValue.arrayElement(arrayType.getElementType(), false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PsiElement declaration = BindingContextUtils.resolveToDeclarationPsiElement(bindingContext, expression);
|
||||
@@ -1764,7 +1748,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
}
|
||||
|
||||
public void derefArray(JetType type) {
|
||||
public void _derefArray(JetType type) {
|
||||
if (state.getStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
|
||||
JetType elementType = type.getArguments().get(0).getType();
|
||||
JetStandardLibrary standardLibrary = state.getStandardLibrary();
|
||||
|
||||
@@ -40,15 +40,15 @@ public class JetTypeMapper {
|
||||
public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number");
|
||||
public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder");
|
||||
|
||||
public static final Type ARRAY_INT_TYPE = Type.getObjectType("jet/arrays/JetIntArray");
|
||||
public static final Type ARRAY_LONG_TYPE = Type.getObjectType("jet/arrays/JetLongArray");
|
||||
public static final Type ARRAY_SHORT_TYPE = Type.getObjectType("jet/arrays/JetShortArray");
|
||||
public static final Type ARRAY_BYTE_TYPE = Type.getObjectType("jet/arrays/JetByteArray");
|
||||
public static final Type ARRAY_CHAR_TYPE = Type.getObjectType("jet/arrays/JetCharArray");
|
||||
public static final Type ARRAY_FLOAT_TYPE = Type.getObjectType("jet/arrays/JetFloatArray");
|
||||
public static final Type ARRAY_DOUBLE_TYPE = Type.getObjectType("jet/arrays/JetDoubleArray");
|
||||
public static final Type ARRAY_BOOL_TYPE = Type.getObjectType("jet/arrays/JetBoolArray");
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getObjectType("jet/arrays/JetGenericArray");
|
||||
public static final Type ARRAY_INT_TYPE = Type.getType(int[].class);
|
||||
public static final Type ARRAY_LONG_TYPE = Type.getType(long[].class);
|
||||
public static final Type ARRAY_SHORT_TYPE = Type.getType(short[].class);
|
||||
public static final Type ARRAY_BYTE_TYPE = Type.getType(byte[].class);
|
||||
public static final Type ARRAY_CHAR_TYPE = Type.getType(char[].class);
|
||||
public static final Type ARRAY_FLOAT_TYPE = Type.getType(float[].class);
|
||||
public static final Type ARRAY_DOUBLE_TYPE = Type.getType(double[].class);
|
||||
public static final Type ARRAY_BOOL_TYPE = Type.getType(boolean[].class);
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final BindingContext bindingContext;
|
||||
@@ -56,7 +56,6 @@ public class JetTypeMapper {
|
||||
private final Map<String, Integer> anonymousSubclassesCount = new HashMap<String, Integer>();
|
||||
|
||||
private final HashMap<JetType,String> knowTypes = new HashMap<JetType, String>();
|
||||
private final HashMap<JetType,String> knowArrayTypes = new HashMap<JetType, String>();
|
||||
|
||||
public JetTypeMapper(JetStandardLibrary standardLibrary, BindingContext bindingContext) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
@@ -383,41 +382,41 @@ public class JetTypeMapper {
|
||||
return Type.getType(String.class);
|
||||
}
|
||||
|
||||
if(jetType.equals(standardLibrary.getByteArrayType())){
|
||||
return ARRAY_BYTE_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getShortArrayType())){
|
||||
return ARRAY_SHORT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getIntArrayType())){
|
||||
return ARRAY_INT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getLongArrayType())){
|
||||
return ARRAY_LONG_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getFloatArrayType())){
|
||||
return ARRAY_FLOAT_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getDoubleArrayType())){
|
||||
return ARRAY_DOUBLE_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getCharArrayType())){
|
||||
return ARRAY_CHAR_TYPE;
|
||||
}
|
||||
if(jetType.equals(standardLibrary.getBooleanArrayType())){
|
||||
return ARRAY_BOOL_TYPE;
|
||||
}
|
||||
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (standardLibrary.getArray().equals(descriptor)) {
|
||||
if (jetType.getArguments().size() != 1) {
|
||||
throw new UnsupportedOperationException("arrays must have one type argument");
|
||||
}
|
||||
JetType memberType = jetType.getArguments().get(0).getType();
|
||||
|
||||
if (memberType.equals(standardLibrary.getIntType())) {
|
||||
return ARRAY_INT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getLongType())) {
|
||||
return ARRAY_LONG_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getShortType())) {
|
||||
return ARRAY_SHORT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getByteType())) {
|
||||
return ARRAY_BYTE_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getCharType())) {
|
||||
return ARRAY_CHAR_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getFloatType())) {
|
||||
return ARRAY_FLOAT_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getDoubleType())) {
|
||||
return ARRAY_DOUBLE_TYPE;
|
||||
}
|
||||
if (memberType.equals(standardLibrary.getBooleanType())) {
|
||||
return ARRAY_BOOL_TYPE;
|
||||
}
|
||||
if(!isGenericsArray(jetType))
|
||||
return ARRAY_GENERIC_TYPE;
|
||||
return Type.getType("[" + boxType(mapType(memberType, kind)).getDescriptor());
|
||||
else
|
||||
return TYPE_OBJECT;
|
||||
return ARRAY_GENERIC_TYPE;
|
||||
}
|
||||
if (JetStandardClasses.getAny().equals(descriptor)) {
|
||||
return Type.getType(Object.class);
|
||||
@@ -704,20 +703,17 @@ public class JetTypeMapper {
|
||||
knowTypes.put(standardLibrary.getTuple0Type(),"TUPLE0_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getNullableTuple0Type(),"NULLABLE_TUPLE0_TYPE_INFO");
|
||||
|
||||
knowArrayTypes.put(standardLibrary.getIntType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getLongType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getShortType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getByteType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getCharType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getFloatType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getDoubleType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowArrayTypes.put(standardLibrary.getBooleanType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getIntArrayType(), "INT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getLongArrayType(), "LONG_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getShortArrayType(),"SHORT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getByteArrayType(),"BYTE_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getCharArrayType(),"CHAR_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getFloatArrayType(),"FLOAT_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getDoubleArrayType(),"DOUBLE_ARRAY_TYPE_INFO");
|
||||
knowTypes.put(standardLibrary.getBooleanArrayType(),"BOOLEAN_ARRAY_TYPE_INFO");
|
||||
}
|
||||
|
||||
public String isKnownTypeInfo(JetType jetType) {
|
||||
if(standardLibrary.getArray().equals(jetType.getConstructor().getDeclarationDescriptor()))
|
||||
return knowArrayTypes.get(jetType.getArguments().get(0).getType());
|
||||
|
||||
return knowTypes.get(jetType);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ public abstract class StackValue {
|
||||
return new Invert(stackValue);
|
||||
}
|
||||
|
||||
public static StackValue arrayElement(Type type, boolean genericsArray) {
|
||||
return new ArrayElement(type, genericsArray);
|
||||
public static StackValue arrayElement(Type type, boolean unbox) {
|
||||
return new ArrayElement(type, unbox);
|
||||
}
|
||||
|
||||
public static StackValue collectionElement(Type type, CallableMethod getter, CallableMethod setter) {
|
||||
@@ -424,32 +424,23 @@ public abstract class StackValue {
|
||||
}
|
||||
|
||||
private static class ArrayElement extends StackValue {
|
||||
private boolean genericsArray;
|
||||
private Type boxed;
|
||||
|
||||
public ArrayElement(Type type, boolean genericsArray) {
|
||||
public ArrayElement(Type type, boolean unbox) {
|
||||
super(type);
|
||||
this.genericsArray = genericsArray;
|
||||
this.boxed = unbox ? JetTypeMapper.boxType(type) : type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(Type type, InstructionAdapter v) {
|
||||
if(genericsArray) {
|
||||
v.invokevirtual("jet/arrays/JetArray", "get", "(I)Ljava/lang/Object;");
|
||||
}
|
||||
else {
|
||||
v.aload(this.type); // assumes array and index are on the stack
|
||||
}
|
||||
coerce(type, v);
|
||||
v.aload(boxed); // assumes array and index are on the stack
|
||||
onStack(boxed).coerce(type, v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void store(InstructionAdapter v) {
|
||||
if(genericsArray) {
|
||||
v.invokevirtual("jet/arrays/JetArray", "set", "(ILjava/lang/Object;)V");
|
||||
}
|
||||
else {
|
||||
v.astore(type); // assumes array and index are on the stack
|
||||
}
|
||||
onStack(type).coerce(boxed, v);
|
||||
v.astore(boxed);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,32 +18,7 @@ public class ArraySize implements IntrinsicMethod {
|
||||
@Override
|
||||
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
|
||||
receiver.put(JetTypeMapper.TYPE_OBJECT, v);
|
||||
if(receiver.type.equals(JetTypeMapper.TYPE_OBJECT)) {
|
||||
v.visitTypeInsn(Opcodes.CHECKCAST, "jet/arrays/JetArray");
|
||||
v.invokevirtual("jet/arrays/JetArray", "getSize", "()I");
|
||||
}
|
||||
else {
|
||||
if(receiver.type.equals(JetTypeMapper.ARRAY_BYTE_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[B");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_SHORT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[S");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_INT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[I");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_LONG_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[J");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_FLOAT_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[F");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_DOUBLE_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[D");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_CHAR_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[C");
|
||||
else if(receiver.type.equals(JetTypeMapper.ARRAY_BOOL_TYPE))
|
||||
v.getfield(receiver.type.getInternalName(), "array", "[Z");
|
||||
else
|
||||
v.getfield("jet/arrays/JetGenericArray", "array", "[Ljava/lang/Object;");
|
||||
|
||||
v.arraylength();
|
||||
}
|
||||
v.arraylength();
|
||||
|
||||
return StackValue.onStack(Type.INT_TYPE);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class IntrinsicMethods {
|
||||
private static final IntrinsicMethod DEC = new Increment(-1);
|
||||
|
||||
private static final List<String> PRIMITIVE_NUMBER_TYPES = ImmutableList.of("Boolean", "Byte", "Char", "Short", "Int", "Float", "Long", "Double");
|
||||
public static final ArraySize ARRAY_SIZE = new ArraySize();
|
||||
|
||||
private final Project myProject;
|
||||
private final JetStandardLibrary myStdLib;
|
||||
@@ -41,7 +42,6 @@ public class IntrinsicMethods {
|
||||
for (String method : primitiveCastMethods) {
|
||||
declareIntrinsicProperty("Number", method, NUMBER_CAST);
|
||||
}
|
||||
declareIntrinsicProperty("Array", "size", new ArraySize());
|
||||
|
||||
for (String type : PRIMITIVE_NUMBER_TYPES) {
|
||||
declareIntrinsicFunction(type, "minus", 0, UNARY_MINUS);
|
||||
@@ -73,6 +73,20 @@ public class IntrinsicMethods {
|
||||
|
||||
declareIntrinsicStringMethods();
|
||||
declareIntrinsicProperty("String", "length", new StringLength());
|
||||
|
||||
declareArrayMethods();
|
||||
}
|
||||
|
||||
private void declareArrayMethods() {
|
||||
declareIntrinsicProperty("Array", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ByteArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("ShortArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("IntArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("LongArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("FloatArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("DoubleArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("CharArray", "size", ARRAY_SIZE);
|
||||
declareIntrinsicProperty("BooleanArray", "size", ARRAY_SIZE);
|
||||
}
|
||||
|
||||
private void declareIntrinsicStringMethods() {
|
||||
|
||||
+16
-1
@@ -114,7 +114,14 @@ public class JavaTypeTransformer {
|
||||
|
||||
@Override
|
||||
public JetType visitArrayType(PsiArrayType arrayType) {
|
||||
JetType type = transformToType(arrayType.getComponentType());
|
||||
PsiType componentType = arrayType.getComponentType();
|
||||
if(componentType instanceof PsiPrimitiveType) {
|
||||
JetType jetType = getPrimitiveTypesMap().get("[" + componentType.getCanonicalText());
|
||||
if(jetType != null)
|
||||
return TypeUtils.makeNullable(jetType);
|
||||
}
|
||||
|
||||
JetType type = transformToType(componentType);
|
||||
return TypeUtils.makeNullable(standardLibrary.getArrayType(type));
|
||||
}
|
||||
|
||||
@@ -136,6 +143,14 @@ public class JavaTypeTransformer {
|
||||
primitiveTypesMap.put("float", standardLibrary.getFloatType());
|
||||
primitiveTypesMap.put("double", standardLibrary.getDoubleType());
|
||||
primitiveTypesMap.put("boolean", standardLibrary.getBooleanType());
|
||||
primitiveTypesMap.put("[byte", standardLibrary.getByteArrayType());
|
||||
primitiveTypesMap.put("[short", standardLibrary.getShortArrayType());
|
||||
primitiveTypesMap.put("[char", standardLibrary.getCharArrayType());
|
||||
primitiveTypesMap.put("[int", standardLibrary.getIntArrayType());
|
||||
primitiveTypesMap.put("[long", standardLibrary.getLongArrayType());
|
||||
primitiveTypesMap.put("[float", standardLibrary.getFloatArrayType());
|
||||
primitiveTypesMap.put("[double", standardLibrary.getDoubleArrayType());
|
||||
primitiveTypesMap.put("[boolean", standardLibrary.getBooleanArrayType());
|
||||
primitiveTypesMap.put("void", JetStandardClasses.getUnitType());
|
||||
primitiveTypesMap.put("java.lang.Byte", TypeUtils.makeNullable(standardLibrary.getByteType()));
|
||||
primitiveTypesMap.put("java.lang.Short", TypeUtils.makeNullable(standardLibrary.getShortType()));
|
||||
|
||||
@@ -56,6 +56,62 @@ class Array<T>(val size : Int) {
|
||||
fun iterator() : Iterator<T>
|
||||
}
|
||||
|
||||
class ByteArray(val size : Int) {
|
||||
fun get(index : Int) : Byte
|
||||
fun set(index : Int, value : Byte) : Unit
|
||||
|
||||
fun iterator() : Iterator<Byte>
|
||||
}
|
||||
|
||||
class ShortArray(val size : Int) {
|
||||
fun get(index : Int) : Short
|
||||
fun set(index : Int, value : Short) : Unit
|
||||
|
||||
fun iterator() : Iterator<Short>
|
||||
}
|
||||
|
||||
class IntArray(val size : Int) {
|
||||
fun get(index : Int) : Int
|
||||
fun set(index : Int, value : Int) : Unit
|
||||
|
||||
fun iterator() : Iterator<Int>
|
||||
}
|
||||
|
||||
class LongArray(val size : Int) {
|
||||
fun get(index : Int) : Long
|
||||
fun set(index : Int, value : Long) : Unit
|
||||
|
||||
fun iterator() : Iterator<Long>
|
||||
}
|
||||
|
||||
class FloatArray(val size : Int) {
|
||||
fun get(index : Int) : Float
|
||||
fun set(index : Int, value : Float) : Unit
|
||||
|
||||
fun iterator() : Iterator<Float>
|
||||
}
|
||||
|
||||
class DoubleArray(val size : Int) {
|
||||
fun get(index : Int) : Double
|
||||
fun set(index : Int, value : Double) : Unit
|
||||
|
||||
fun iterator() : Iterator<Double>
|
||||
}
|
||||
|
||||
class CharArray(val size : Int) {
|
||||
fun get(index : Int) : Char
|
||||
fun set(index : Int, value : Char) : Unit
|
||||
|
||||
fun iterator() : Iterator<Char>
|
||||
}
|
||||
|
||||
class BooleanArray(val size : Int) {
|
||||
fun get(index : Int) : Boolean
|
||||
fun set(index : Int, value : Boolean) : Unit
|
||||
|
||||
fun iterator() : Iterator<Boolean>
|
||||
}
|
||||
|
||||
trait Comparable<in T> {
|
||||
fun compareTo(other : T) : Int
|
||||
}
|
||||
|
||||
@@ -82,6 +82,24 @@ public class JetStandardLibrary {
|
||||
private final JetType nullableBooleanType;
|
||||
private final JetType nullableTuple0Type;
|
||||
|
||||
private final ClassDescriptor byteArrayClass;
|
||||
private final ClassDescriptor charArrayClass;
|
||||
private final ClassDescriptor shortArrayClass;
|
||||
private final ClassDescriptor intArrayClass;
|
||||
private final ClassDescriptor longArrayClass;
|
||||
private final ClassDescriptor floatArrayClass;
|
||||
private final ClassDescriptor doubleArrayClass;
|
||||
private final ClassDescriptor booleanArrayClass;
|
||||
|
||||
private final JetType byteArrayType;
|
||||
private final JetType charArrayType;
|
||||
private final JetType shortArrayType;
|
||||
private final JetType intArrayType;
|
||||
private final JetType longArrayType;
|
||||
private final JetType floatArrayType;
|
||||
private final JetType doubleArrayType;
|
||||
private final JetType booleanArrayType;
|
||||
|
||||
public JetType getTuple0Type() {
|
||||
return tuple0Type;
|
||||
}
|
||||
@@ -136,6 +154,24 @@ public class JetStandardLibrary {
|
||||
this.stringType = new JetTypeImpl(getString());
|
||||
this.tuple0Type = new JetTypeImpl(JetStandardClasses.getTuple(0));
|
||||
|
||||
this.byteArrayClass = (ClassDescriptor) libraryScope.getClassifier("ByteArray");
|
||||
this.charArrayClass = (ClassDescriptor) libraryScope.getClassifier("CharArray");
|
||||
this.shortArrayClass = (ClassDescriptor) libraryScope.getClassifier("ShortArray");
|
||||
this.intArrayClass = (ClassDescriptor) libraryScope.getClassifier("IntArray");
|
||||
this.longArrayClass = (ClassDescriptor) libraryScope.getClassifier("LongArray");
|
||||
this.floatArrayClass = (ClassDescriptor) libraryScope.getClassifier("FloatArray");
|
||||
this.doubleArrayClass = (ClassDescriptor) libraryScope.getClassifier("DoubleArray");
|
||||
this.booleanArrayClass = (ClassDescriptor) libraryScope.getClassifier("BooleanArray");
|
||||
|
||||
this.byteArrayType = new JetTypeImpl(byteArrayClass);
|
||||
this.charArrayType = new JetTypeImpl(charArrayClass);
|
||||
this.shortArrayType = new JetTypeImpl(shortArrayClass);
|
||||
this.intArrayType = new JetTypeImpl(intArrayClass);
|
||||
this.longArrayType = new JetTypeImpl(longArrayClass);
|
||||
this.floatArrayType = new JetTypeImpl(floatArrayClass);
|
||||
this.doubleArrayType = new JetTypeImpl(doubleArrayClass);
|
||||
this.booleanArrayType = new JetTypeImpl(booleanArrayClass);
|
||||
|
||||
this.nullableByteType = TypeUtils.makeNullable(byteType);
|
||||
this.nullableCharType = TypeUtils.makeNullable(charType);
|
||||
this.nullableShortType = TypeUtils.makeNullable(shortType);
|
||||
@@ -343,4 +379,68 @@ public class JetStandardLibrary {
|
||||
public JetType getNullableTuple0Type() {
|
||||
return nullableTuple0Type;
|
||||
}
|
||||
|
||||
public JetType getBooleanArrayType() {
|
||||
return booleanArrayType;
|
||||
}
|
||||
|
||||
public JetType getByteArrayType() {
|
||||
return byteArrayType;
|
||||
}
|
||||
|
||||
public JetType getCharArrayType() {
|
||||
return charArrayType;
|
||||
}
|
||||
|
||||
public JetType getShortArrayType() {
|
||||
return shortArrayType;
|
||||
}
|
||||
|
||||
public JetType getIntArrayType() {
|
||||
return intArrayType;
|
||||
}
|
||||
|
||||
public JetType getLongArrayType() {
|
||||
return longArrayType;
|
||||
}
|
||||
|
||||
public JetType getFloatArrayType() {
|
||||
return floatArrayType;
|
||||
}
|
||||
|
||||
public JetType getDoubleArrayType() {
|
||||
return doubleArrayType;
|
||||
}
|
||||
|
||||
public ClassDescriptor getByteArrayClass() {
|
||||
return byteArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getCharArrayClass() {
|
||||
return charArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getShortArrayClass() {
|
||||
return shortArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getIntArrayClass() {
|
||||
return intArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getLongArrayClass() {
|
||||
return longArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getFloatArrayClass() {
|
||||
return floatArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getDoubleArrayClass() {
|
||||
return doubleArrayClass;
|
||||
}
|
||||
|
||||
public ClassDescriptor getBooleanArrayClass() {
|
||||
return booleanArrayClass;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user