Delete JvmPrimitiveType.getAsmType()
Create PrimitiveTypesUtil in frontend.java for this and other utilities
This commit is contained in:
@@ -47,6 +47,7 @@ import static org.jetbrains.asm4.Opcodes.*;
|
|||||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||||
|
|
||||||
public class AsmUtil {
|
public class AsmUtil {
|
||||||
private static final Set<ClassDescriptor> PRIMITIVE_NUMBER_CLASSES = Sets.newHashSet(
|
private static final Set<ClassDescriptor> PRIMITIVE_NUMBER_CLASSES = Sets.newHashSet(
|
||||||
@@ -81,14 +82,15 @@ public class AsmUtil {
|
|||||||
private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath";
|
private static final String STUB_EXCEPTION_MESSAGE = "Stubs are for compiler only, do not add them to runtime classpath";
|
||||||
|
|
||||||
private static final ImmutableMap<Integer, JvmPrimitiveType> primitiveTypeByAsmSort;
|
private static final ImmutableMap<Integer, JvmPrimitiveType> primitiveTypeByAsmSort;
|
||||||
private static final ImmutableMap<Type, JvmPrimitiveType> primitiveTypeByBoxedType;
|
private static final ImmutableMap<Type, Type> primitiveTypeByBoxedType;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
ImmutableMap.Builder<Integer, JvmPrimitiveType> typeBySortBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<Integer, JvmPrimitiveType> typeBySortBuilder = ImmutableMap.builder();
|
||||||
ImmutableMap.Builder<Type, JvmPrimitiveType> typeByWrapperBuilder = ImmutableMap.builder();
|
ImmutableMap.Builder<Type, Type> typeByWrapperBuilder = ImmutableMap.builder();
|
||||||
for (JvmPrimitiveType type : JvmPrimitiveType.values()) {
|
for (JvmPrimitiveType primitiveType : JvmPrimitiveType.values()) {
|
||||||
typeBySortBuilder.put(type.getAsmType().getSort(), type);
|
Type asmType = asmTypeForPrimitive(primitiveType);
|
||||||
typeByWrapperBuilder.put(type.getWrapper().getAsmType(), type);
|
typeBySortBuilder.put(asmType.getSort(), primitiveType);
|
||||||
|
typeByWrapperBuilder.put(primitiveType.getWrapper().getAsmType(), asmType);
|
||||||
}
|
}
|
||||||
primitiveTypeByAsmSort = typeBySortBuilder.build();
|
primitiveTypeByAsmSort = typeBySortBuilder.build();
|
||||||
primitiveTypeByBoxedType = typeByWrapperBuilder.build();
|
primitiveTypeByBoxedType = typeByWrapperBuilder.build();
|
||||||
@@ -104,14 +106,12 @@ public class AsmUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Type unboxType(@NotNull Type type) {
|
public static Type unboxType(@NotNull Type boxedType) {
|
||||||
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByBoxedType.get(type);
|
Type primitiveType = primitiveTypeByBoxedType.get(boxedType);
|
||||||
if (jvmPrimitiveType != null) {
|
if (primitiveType == null) {
|
||||||
return jvmPrimitiveType.getAsmType();
|
throw new UnsupportedOperationException("Unboxing: " + boxedType);
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
|
||||||
}
|
}
|
||||||
|
return primitiveType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isIntPrimitive(Type type) {
|
public static boolean isIntPrimitive(Type type) {
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||||
|
|
||||||
public class ArrayIterator implements IntrinsicMethod {
|
public class ArrayIterator implements IntrinsicMethod {
|
||||||
@Override
|
@Override
|
||||||
@@ -66,7 +67,7 @@ public class ArrayIterator implements IntrinsicMethod {
|
|||||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||||
if (containingDeclaration.equals(arrayClass)) {
|
if (containingDeclaration.equals(arrayClass)) {
|
||||||
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
||||||
String methodSignature = "([" + jvmPrimitiveType.getAsmType() + ")" + iteratorDesc;
|
String methodSignature = "([" + asmTypeForPrimitive(jvmPrimitiveType) + ")" + iteratorDesc;
|
||||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||||
return StackValue.onStack(Type.getType(iteratorDesc));
|
return StackValue.onStack(Type.getType(iteratorDesc));
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -33,6 +33,8 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||||
|
|
||||||
public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
||||||
private static KotlinToJavaTypesMap instance = null;
|
private static KotlinToJavaTypesMap instance = null;
|
||||||
|
|
||||||
@@ -56,7 +58,7 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
|||||||
FqName builtInsFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
FqName builtInsFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
||||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||||
Type asmType = jvmPrimitiveType.getAsmType();
|
Type asmType = asmTypeForPrimitive(jvmPrimitiveType);
|
||||||
FqName fqName = builtInsFqName.child(primitiveType.getTypeName());
|
FqName fqName = builtInsFqName.child(primitiveType.getTypeName());
|
||||||
|
|
||||||
register(fqName, asmType);
|
register(fqName, asmType);
|
||||||
|
|||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.jet.lang.resolve.java.mapping;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||||
|
|
||||||
|
import static org.jetbrains.asm4.Type.*;
|
||||||
|
|
||||||
|
public class PrimitiveTypesUtil {
|
||||||
|
private PrimitiveTypesUtil() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Type asmTypeForPrimitive(@NotNull JvmPrimitiveType jvmPrimitiveType) {
|
||||||
|
switch (jvmPrimitiveType) {
|
||||||
|
case BOOLEAN: return BOOLEAN_TYPE;
|
||||||
|
case CHAR: return CHAR_TYPE;
|
||||||
|
case BYTE: return BYTE_TYPE;
|
||||||
|
case SHORT: return SHORT_TYPE;
|
||||||
|
case INT: return INT_TYPE;
|
||||||
|
case FLOAT: return FLOAT_TYPE;
|
||||||
|
case LONG: return LONG_TYPE;
|
||||||
|
case DOUBLE: return DOUBLE_TYPE;
|
||||||
|
default: throw new IllegalStateException("Unknown primitive type: " + jvmPrimitiveType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-16
@@ -16,30 +16,27 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.java;
|
package org.jetbrains.jet.lang.resolve.java;
|
||||||
|
|
||||||
import org.jetbrains.asm4.Type;
|
|
||||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||||
|
|
||||||
public enum JvmPrimitiveType {
|
public enum JvmPrimitiveType {
|
||||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean", Type.BOOLEAN_TYPE),
|
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean"),
|
||||||
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character", Type.CHAR_TYPE),
|
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character"),
|
||||||
BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte", Type.BYTE_TYPE),
|
BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte"),
|
||||||
SHORT(PrimitiveType.SHORT, "short", "java.lang.Short", Type.SHORT_TYPE),
|
SHORT(PrimitiveType.SHORT, "short", "java.lang.Short"),
|
||||||
INT(PrimitiveType.INT, "int", "java.lang.Integer", Type.INT_TYPE),
|
INT(PrimitiveType.INT, "int", "java.lang.Integer"),
|
||||||
FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float", Type.FLOAT_TYPE),
|
FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float"),
|
||||||
LONG(PrimitiveType.LONG, "long", "java.lang.Long", Type.LONG_TYPE),
|
LONG(PrimitiveType.LONG, "long", "java.lang.Long"),
|
||||||
DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double", Type.DOUBLE_TYPE),
|
DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double"),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final PrimitiveType primitiveType;
|
private final PrimitiveType primitiveType;
|
||||||
private final String name;
|
private final String name;
|
||||||
private final JvmClassName wrapper;
|
private final JvmClassName wrapper;
|
||||||
private final Type asmType;
|
|
||||||
|
|
||||||
private JvmPrimitiveType(PrimitiveType primitiveType, String name, String wrapperClassName, Type asmType) {
|
private JvmPrimitiveType(PrimitiveType primitiveType, String name, String wrapperClassName) {
|
||||||
this.primitiveType = primitiveType;
|
this.primitiveType = primitiveType;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.wrapper = JvmClassName.byFqNameWithoutInnerClasses(wrapperClassName);
|
this.wrapper = JvmClassName.byFqNameWithoutInnerClasses(wrapperClassName);
|
||||||
this.asmType = asmType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PrimitiveType getPrimitiveType() {
|
public PrimitiveType getPrimitiveType() {
|
||||||
@@ -53,8 +50,4 @@ public enum JvmPrimitiveType {
|
|||||||
public JvmClassName getWrapper() {
|
public JvmClassName getWrapper() {
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getAsmType() {
|
|
||||||
return asmType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user