Permalink
Browse files

Merged similar intrinsic methods.

  • Loading branch information...
1 parent 5ccbce6 commit aa74bb6611a38c6fa4f2cb0e27c39a45b677ff71 Evgeny Gerashchenko committed Mar 19, 2013
View
19 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
@@ -147,15 +147,10 @@ public void init() {
declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength());
declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength());
- Name unitName = KotlinBuiltIns.getInstance().getUnit().getName();
- intrinsicsMap.registerIntrinsic(
- getClassObjectFqName(unitName),
- Name.identifier("VALUE"), -1, new UnitValue());
+ registerStaticField(getFQName(KotlinBuiltIns.getInstance().getUnit()).toSafe(), Name.identifier("VALUE"));
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
- intrinsicsMap.registerIntrinsic(
- getClassObjectFqName(type.getRangeTypeName()),
- Name.identifier("EMPTY"), -1, new EmptyRange(type));
+ registerStaticField(type.getRangeClassName(), Name.identifier("EMPTY"));
}
for (PrimitiveType type : PrimitiveType.NUMBER_TYPES) {
@@ -170,13 +165,13 @@ public void init() {
declareArrayMethods();
}
- private void registerRangeOrProgressionProperty(@NotNull FqName ownerClass, @NotNull Name propertyName) {
- intrinsicsMap.registerIntrinsic(ownerClass, propertyName, -1, new PropertyOfProgressionOrRange(ownerClass, propertyName));
+ private void registerStaticField(@NotNull FqName classFqName, @NotNull Name propertyName) {
+ FqNameUnsafe classObjectFqName = classFqName.toUnsafe().child(getClassObjectName(classFqName.shortName()));
+ intrinsicsMap.registerIntrinsic(classObjectFqName, propertyName, -1, new StaticField(classFqName, propertyName));
}
- @NotNull
- private static FqNameUnsafe getClassObjectFqName(@NotNull Name builtinClassName) {
- return KotlinBuiltIns.getInstance().getBuiltInsPackageFqName().child(builtinClassName).toUnsafe().child(getClassObjectName(builtinClassName));
+ private void registerRangeOrProgressionProperty(@NotNull FqName ownerClass, @NotNull Name propertyName) {
+ intrinsicsMap.registerIntrinsic(ownerClass, propertyName, -1, new PropertyOfProgressionOrRange(ownerClass, propertyName));
}
private void declareArrayMethods() {
View
17 ...ns/jet/codegen/intrinsics/EmptyRange.java → ...s/jet/codegen/intrinsics/StaticField.java
@@ -26,15 +26,19 @@
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
-import org.jetbrains.jet.lang.types.lang.PrimitiveType;
+import org.jetbrains.jet.lang.resolve.name.FqName;
+import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.List;
-public class EmptyRange implements IntrinsicMethod {
- private final PrimitiveType elementType;
+public class StaticField implements IntrinsicMethod {
+ private final FqName ownerClass;
+ private final Name propertyName;
- public EmptyRange(PrimitiveType elementType) {
- this.elementType = elementType;
+
+ public StaticField(FqName ownerClass, Name propertyName) {
+ this.ownerClass = ownerClass;
+ this.propertyName = propertyName;
}
@Override
@@ -47,8 +51,7 @@ public StackValue generate(
StackValue receiver,
@NotNull GenerationState state
) {
- JvmClassName name = JvmClassName.byFqNameWithoutInnerClasses(elementType.getRangeClassName().getFqName());
- v.getstatic(name.toString(), "EMPTY", "L" + name + ";");
+ v.getstatic(JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName(), propertyName.getName(), expectedType.getDescriptor());
return StackValue.onStack(expectedType);
}
}
View
48 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnitValue.java
@@ -1,48 +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.codegen.state.GenerationState;
-import org.jetbrains.jet.lang.psi.JetExpression;
-
-import java.util.List;
-
-import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_UNIT_TYPE;
-
-public class UnitValue implements IntrinsicMethod {
-
- @Override
- public StackValue generate(
- ExpressionCodegen codegen,
- InstructionAdapter v,
- @NotNull Type expectedType,
- @Nullable PsiElement element,
- @Nullable List<JetExpression> arguments,
- StackValue receiver,
- @NotNull GenerationState state
- ) {
- v.getstatic(JET_UNIT_TYPE.getInternalName(), "VALUE", JET_UNIT_TYPE.getDescriptor());
- return StackValue.onStack(expectedType);
- }
-}

0 comments on commit aa74bb6

Please sign in to comment.