Delete obsolete JVM intrinsics for ranges/progressions

All Range and Progression classes are now fully written in Kotlin and thus do
not need any intrinsics to operate
This commit is contained in:
Alexander Udalov
2014-02-25 23:00:16 +04:00
parent 11cc7f46f4
commit 6dca53347f
5 changed files with 6 additions and 170 deletions
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitiveNumberClassDescriptor;
import static org.jetbrains.jet.lang.types.lang.KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME;
public class RangeCodegenUtil {
private static final ImmutableMap<FqName, PrimitiveType> RANGE_TO_ELEMENT_TYPE;
@@ -41,8 +42,10 @@ public class RangeCodegenUtil {
ImmutableMap.Builder<FqName, PrimitiveType> rangeBuilder = ImmutableMap.builder();
ImmutableMap.Builder<FqName, PrimitiveType> progressionBuilder = ImmutableMap.builder();
for (PrimitiveType primitiveType : PrimitiveType.values()) {
rangeBuilder.put(getRangeClassFqName(primitiveType), primitiveType);
progressionBuilder.put(getProgressionClassFqName(primitiveType), primitiveType);
FqName rangeClassFqName = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(primitiveType.getTypeName() + "Range"));
FqName progressionClassFqName = BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(primitiveType.getTypeName() + "Progression"));
rangeBuilder.put(rangeClassFqName, primitiveType);
progressionBuilder.put(progressionClassFqName, primitiveType);
}
RANGE_TO_ELEMENT_TYPE = rangeBuilder.build();
PROGRESSION_TO_ELEMENT_TYPE = progressionBuilder.build();
@@ -121,16 +124,6 @@ public class RangeCodegenUtil {
return false;
}
@NotNull
public static FqName getRangeClassFqName(@NotNull PrimitiveType type) {
return KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(type.getTypeName() + "Range"));
}
@NotNull
public static FqName getProgressionClassFqName(@NotNull PrimitiveType type) {
return KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(type.getTypeName() + "Progression"));
}
public static class BinaryCall {
public final JetExpression left;
public final JetExpression op;
@@ -19,17 +19,12 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.codegen.RangeCodegenUtil;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.resolve.CompileTimeConstantUtils;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import javax.annotation.PostConstruct;
@@ -131,36 +126,10 @@ public class IntrinsicMethods {
declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength());
declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength());
registerStaticField(getFqNameSafe(KotlinBuiltIns.getInstance().getUnit()), Name.identifier("VALUE"));
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
FqName rangeClassFqName = RangeCodegenUtil.getRangeClassFqName(type);
FqName progressionClassFqName = RangeCodegenUtil.getProgressionClassFqName(type);
registerStaticField(rangeClassFqName, Name.identifier("EMPTY"));
registerRangeOrProgressionProperty(rangeClassFqName, Name.identifier("start"));
registerRangeOrProgressionProperty(rangeClassFqName, Name.identifier("end"));
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("start"));
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("end"));
registerRangeOrProgressionProperty(progressionClassFqName, Name.identifier("increment"));
}
declareArrayMethods();
}
private void registerStaticField(@NotNull FqName classFqName, @NotNull Name propertyName) {
FqNameUnsafe classObjectFqName = classFqName.toUnsafe().child(SpecialNames.getClassObjectName(classFqName.shortName()));
intrinsicsMap.registerIntrinsic(classObjectFqName, propertyName, -1, new StaticField(classFqName, propertyName));
}
private void registerRangeOrProgressionProperty(@NotNull FqName ownerClass, @NotNull Name propertyName) {
intrinsicsMap.registerIntrinsic(ownerClass, propertyName, -1, new PropertyOfProgressionOrRange(ownerClass, propertyName));
}
private void declareArrayMethods() {
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
declareArrayMethodsForPrimitive(jvmPrimitiveType);
}
@@ -29,8 +29,6 @@ import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Map;
class IntrinsicsMap {
private static final class Key {
@NotNull
private final FqNameUnsafe owner;
@@ -79,18 +77,11 @@ class IntrinsicsMap {
private final Map<Key, IntrinsicMethod> intrinsicsMap = Maps.newHashMap();
/**
* @param valueParameterCount -1 for property
*/
public void registerIntrinsic(@NotNull FqNameUnsafe owner, @NotNull Name name, int valueParameterCount, @NotNull IntrinsicMethod impl) {
intrinsicsMap.put(new Key(owner, name, valueParameterCount), impl);
}
/**
* @param valueParameterCount -1 for property
*/
public void registerIntrinsic(@NotNull FqName owner, @NotNull Name name, int valueParameterCount, @NotNull IntrinsicMethod impl) {
registerIntrinsic(owner.toUnsafe(), name, valueParameterCount, impl);
intrinsicsMap.put(new Key(owner.toUnsafe(), name, valueParameterCount), impl);
}
@@ -1,62 +0,0 @@
/*
* 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.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.PropertyCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
public class PropertyOfProgressionOrRange extends IntrinsicMethod {
private final FqName ownerClass;
private final Name propertyName;
public PropertyOfProgressionOrRange(@NotNull FqName ownerClass, @NotNull Name propertyName) {
this.ownerClass = ownerClass;
this.propertyName = propertyName;
}
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
List<JetExpression> arguments,
StackValue receiver
) {
String ownerInternalName = JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName();
Type boxedType = boxType(returnType);
String getterName = PropertyCodegen.getterName(propertyName);
receiver.put(receiver.type, v);
v.invokevirtual(ownerInternalName, getterName, "()" + boxedType.getDescriptor());
return boxedType;
}
}
@@ -1,55 +0,0 @@
/*
* 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.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.Type;
import org.jetbrains.asm4.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.List;
public class StaticField extends IntrinsicMethod {
private final FqName ownerClass;
private final Name propertyName;
public StaticField(FqName ownerClass, Name propertyName) {
this.ownerClass = ownerClass;
this.propertyName = propertyName;
}
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
@Nullable PsiElement element,
@Nullable List<JetExpression> arguments,
StackValue receiver
) {
v.getstatic(JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName(), propertyName.asString(), returnType.getDescriptor());
return returnType;
}
}