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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user