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.lang.resolve.DescriptorUtils.*;
|
||||
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 {
|
||||
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 ImmutableMap<Integer, JvmPrimitiveType> primitiveTypeByAsmSort;
|
||||
private static final ImmutableMap<Type, JvmPrimitiveType> primitiveTypeByBoxedType;
|
||||
private static final ImmutableMap<Type, Type> primitiveTypeByBoxedType;
|
||||
|
||||
static {
|
||||
ImmutableMap.Builder<Integer, JvmPrimitiveType> typeBySortBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<Type, JvmPrimitiveType> typeByWrapperBuilder = ImmutableMap.builder();
|
||||
for (JvmPrimitiveType type : JvmPrimitiveType.values()) {
|
||||
typeBySortBuilder.put(type.getAsmType().getSort(), type);
|
||||
typeByWrapperBuilder.put(type.getWrapper().getAsmType(), type);
|
||||
ImmutableMap.Builder<Type, Type> typeByWrapperBuilder = ImmutableMap.builder();
|
||||
for (JvmPrimitiveType primitiveType : JvmPrimitiveType.values()) {
|
||||
Type asmType = asmTypeForPrimitive(primitiveType);
|
||||
typeBySortBuilder.put(asmType.getSort(), primitiveType);
|
||||
typeByWrapperBuilder.put(primitiveType.getWrapper().getAsmType(), asmType);
|
||||
}
|
||||
primitiveTypeByAsmSort = typeBySortBuilder.build();
|
||||
primitiveTypeByBoxedType = typeByWrapperBuilder.build();
|
||||
@@ -104,14 +106,12 @@ public class AsmUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Type unboxType(@NotNull Type type) {
|
||||
JvmPrimitiveType jvmPrimitiveType = primitiveTypeByBoxedType.get(type);
|
||||
if (jvmPrimitiveType != null) {
|
||||
return jvmPrimitiveType.getAsmType();
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Unboxing: " + type);
|
||||
public static Type unboxType(@NotNull Type boxedType) {
|
||||
Type primitiveType = primitiveTypeByBoxedType.get(boxedType);
|
||||
if (primitiveType == null) {
|
||||
throw new UnsupportedOperationException("Unboxing: " + boxedType);
|
||||
}
|
||||
return primitiveType;
|
||||
}
|
||||
|
||||
public static boolean isIntPrimitive(Type type) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||
|
||||
public class ArrayIterator implements IntrinsicMethod {
|
||||
@Override
|
||||
@@ -66,7 +67,7 @@ public class ArrayIterator implements IntrinsicMethod {
|
||||
ClassDescriptor arrayClass = KotlinBuiltIns.getInstance().getPrimitiveArrayClassDescriptor(primitiveType);
|
||||
if (containingDeclaration.equals(arrayClass)) {
|
||||
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);
|
||||
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.Map;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||
|
||||
public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
||||
private static KotlinToJavaTypesMap instance = null;
|
||||
|
||||
@@ -56,7 +58,7 @@ public class KotlinToJavaTypesMap extends JavaToKotlinClassMapBuilder {
|
||||
FqName builtInsFqName = KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
|
||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
|
||||
Type asmType = jvmPrimitiveType.getAsmType();
|
||||
Type asmType = asmTypeForPrimitive(jvmPrimitiveType);
|
||||
FqName fqName = builtInsFqName.child(primitiveType.getTypeName());
|
||||
|
||||
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;
|
||||
|
||||
import org.jetbrains.asm4.Type;
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||
|
||||
public enum JvmPrimitiveType {
|
||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean", Type.BOOLEAN_TYPE),
|
||||
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character", Type.CHAR_TYPE),
|
||||
BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte", Type.BYTE_TYPE),
|
||||
SHORT(PrimitiveType.SHORT, "short", "java.lang.Short", Type.SHORT_TYPE),
|
||||
INT(PrimitiveType.INT, "int", "java.lang.Integer", Type.INT_TYPE),
|
||||
FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float", Type.FLOAT_TYPE),
|
||||
LONG(PrimitiveType.LONG, "long", "java.lang.Long", Type.LONG_TYPE),
|
||||
DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double", Type.DOUBLE_TYPE),
|
||||
BOOLEAN(PrimitiveType.BOOLEAN, "boolean", "java.lang.Boolean"),
|
||||
CHAR(PrimitiveType.CHAR, "char", "java.lang.Character"),
|
||||
BYTE(PrimitiveType.BYTE, "byte", "java.lang.Byte"),
|
||||
SHORT(PrimitiveType.SHORT, "short", "java.lang.Short"),
|
||||
INT(PrimitiveType.INT, "int", "java.lang.Integer"),
|
||||
FLOAT(PrimitiveType.FLOAT, "float", "java.lang.Float"),
|
||||
LONG(PrimitiveType.LONG, "long", "java.lang.Long"),
|
||||
DOUBLE(PrimitiveType.DOUBLE, "double", "java.lang.Double"),
|
||||
;
|
||||
|
||||
private final PrimitiveType primitiveType;
|
||||
private final String name;
|
||||
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.name = name;
|
||||
this.wrapper = JvmClassName.byFqNameWithoutInnerClasses(wrapperClassName);
|
||||
this.asmType = asmType;
|
||||
}
|
||||
|
||||
public PrimitiveType getPrimitiveType() {
|
||||
@@ -53,8 +50,4 @@ public enum JvmPrimitiveType {
|
||||
public JvmClassName getWrapper() {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public Type getAsmType() {
|
||||
return asmType;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user