Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: JetBrains/kotlin
base: 49178e6cff
...
head fork: JetBrains/kotlin
compare: a95cc798a2
  • 6 commits
  • 38 files changed
  • 0 commit comments
  • 1 contributor
Showing with 542 additions and 254 deletions.
  1. +2 −1  compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java
  2. +15 −5 compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
  3. +1 −1  compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
  4. +68 −46 compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
  5. +2 −1  compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java
  6. +3 −4 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java
  7. +76 −127 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
  8. +103 −0 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java
  9. +0 −6 compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java
  10. +0 −11 compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java
  11. +1 −2  compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java
  12. +1 −2  compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
  13. +7 −14 compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java
  14. +1 −2  compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacadeForEverything.java
  15. +2 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java
  16. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java
  17. +4 −0 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableMemberDescriptor.java
  18. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
  19. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java
  20. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java
  21. +2 −11 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java
  22. +30 −0 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRoot.java
  23. +51 −0 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRootImpl.java
  24. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/FunctionDescriptorImpl.java
  25. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/MemberDescriptor.java
  26. +9 −2 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ModuleDescriptor.java
  27. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/PropertyAccessorDescriptor.java
  28. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ScriptDescriptor.java
  29. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/TypeParameterDescriptorImpl.java
  30. +1 −1  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/VariableDescriptorImpl.java
  31. +4 −2 compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java
  32. +45 −0 compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibraryNames.java
  33. +15 −0 compiler/frontend/src/org/jetbrains/jet/lang/types/lang/PrimitiveType.java
  34. +86 −0 compiler/frontend/src/org/jetbrains/jet/lang/types/ref/ClassName.java
  35. +2 −0  compiler/frontend/src/org/jetbrains/jet/lang/types/ref/JetTypeName.java
  36. +1 −1  idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java
  37. +0 −2  injector-generator/src/org/jetbrains/jet/di/AllInjectorsGenerator.java
  38. +1 −3 js/js.translator/src/org/jetbrains/k2js/analyze/AnalyzerFacadeForJS.java
View
3  compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java
@@ -21,6 +21,7 @@
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
+import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -109,7 +110,7 @@ private void generatePrimaryConstructorProperties(PropertyCodegen propertyCodege
if (!propertyDescriptor.isVar()) {
modifiers |= Opcodes.ACC_FINAL;
}
- if (state.getInjector().getJetStandardLibrary().isVolatile(propertyDescriptor)) {
+ if (JetStandardLibrary.isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE;
}
Type type = state.getInjector().getJetTypeMapper().mapType(propertyDescriptor.getType(), MapTypeMode.VALUE);
View
20 compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java
@@ -42,6 +42,7 @@
import org.jetbrains.jet.lang.resolve.scopes.receivers.ScriptReceiver;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
+import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames;
import org.jetbrains.jet.lexer.JetTokens;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
@@ -517,7 +518,13 @@ protected void generatePrologue() {
}
protected void generateCondition(Type asmParamType, Label end) {
- Type arrayElParamType = state.getInjector().getJetStandardLibrary().getArray().equals(expressionType.getConstructor().getDeclarationDescriptor()) ? boxType(asmParamType): asmParamType;
+ Type arrayElParamType;
+ if (JetStandardLibraryNames.ARRAY.is(expressionType)) {
+ arrayElParamType = boxType(asmParamType);
+ }
+ else {
+ arrayElParamType = asmParamType;
+ }
v.load(myIndexVar, Type.INT_TYPE);
v.load(myArrayVar, TYPE_OBJECT);
@@ -1015,7 +1022,10 @@ public StackValue visitSimpleNameExpression(JetSimpleNameExpression expression,
// descriptor = ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
//}
- final IntrinsicMethod intrinsic = state.getInjector().getIntrinsics().getIntrinsic(descriptor);
+ IntrinsicMethod intrinsic = null;
+ if (descriptor instanceof CallableMemberDescriptor) {
+ intrinsic = state.getInjector().getIntrinsics().getIntrinsic((CallableMemberDescriptor) descriptor);
+ }
if (intrinsic != null) {
final Type expectedType = expressionType(expression);
return intrinsic.generate(this, v, expectedType, expression, Collections.<JetExpression>emptyList(), receiver, state);
@@ -2491,7 +2501,7 @@ public void generateNewArray(JetCallExpression expression, JetType arrayType) {
args.add(va.getArgumentExpression());
args.addAll(expression.getFunctionLiteralArguments());
- boolean isArray = state.getInjector().getJetStandardLibrary().getArray().equals(arrayType.getConstructor().getDeclarationDescriptor());
+ boolean isArray = JetStandardLibraryNames.ARRAY.is(arrayType);
if (isArray) {
// if (args.size() != 2 && !arrayType.getArguments().get(0).getType().isNullable()) {
// throw new CompilationException("array constructor of non-nullable type requires two arguments");
@@ -2570,13 +2580,13 @@ public StackValue visitArrayAccessExpression(JetArrayAccessExpression expression
final List<JetExpression> indices = expression.getIndexExpressions();
FunctionDescriptor operationDescriptor = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
assert operationDescriptor != null;
- if (arrayType.getSort() == Type.ARRAY && indices.size() == 1 && operationDescriptor.getValueParameters().get(0).getType().equals(state.getInjector().getJetStandardLibrary().getIntType())) {
+ if (arrayType.getSort() == Type.ARRAY && indices.size() == 1 && JetStandardLibraryNames.INT.is(operationDescriptor.getValueParameters().get(0).getType())) {
gen(array, arrayType);
for (JetExpression index : indices) {
gen(index, Type.INT_TYPE);
}
assert type != null;
- if (state.getInjector().getJetStandardLibrary().getArray().equals(type.getConstructor().getDeclarationDescriptor())) {
+ if (JetStandardLibraryNames.ARRAY.is(type)) {
JetType elementType = type.getArguments().get(0).getType();
Type notBoxed = asmType(elementType);
return StackValue.arrayElement(notBoxed, true);
View
2  compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
@@ -72,7 +72,7 @@ public GenerationState(Project project, ClassBuilderFactory builderFactory, Prog
this.files = files;
this.classBuilderMode = builderFactory.getClassBuilderMode();
this.injector = new InjectorForJvmCodegen(
- analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(),
+ analyzeExhaust.getBindingContext(),
this.files, project, compilerSpecialMode, builderFactory.getClassBuilderMode(), this, builderFactory);
}
View
114 compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
@@ -16,6 +16,7 @@
package org.jetbrains.jet.codegen;
+import com.google.common.collect.Maps;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -29,12 +30,15 @@
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.*;
+import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
+import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
+import org.jetbrains.jet.lang.types.ref.ClassName;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
@@ -63,7 +67,7 @@
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
public static final Type TUPLE0_TYPE = Type.getObjectType("jet/Tuple0");
- private JetStandardLibrary standardLibrary;
+ private JetStandardLibrary standardLibrary1;
public BindingContext bindingContext;
private ClosureAnnotator closureAnnotator;
private CompilerSpecialMode compilerSpecialMode;
@@ -71,11 +75,6 @@
@Inject
- public void setStandardLibrary(JetStandardLibrary standardLibrary) {
- this.standardLibrary = standardLibrary;
- }
-
- @Inject
public void setBindingContext(BindingContext bindingContext) {
this.bindingContext = bindingContext;
}
@@ -98,7 +97,6 @@ public void setClassBuilderMode(ClassBuilderMode classBuilderMode) {
@PostConstruct
public void init() {
initKnownTypes();
- initKnownTypeNames();
}
@@ -112,8 +110,39 @@ public ClosureAnnotator getClosureAnnotator() {
return closureAnnotator;
}
- private final HashMap<JetType,String> knowTypeNames = new HashMap<JetType, String>();
- private final HashMap<JetType,Type> knowTypes = new HashMap<JetType, Type>();
+ private static final class KnownTypeKey {
+ @NotNull
+ private final FqNameUnsafe className;
+ private final boolean nullable;
+
+ private KnownTypeKey(@NotNull FqNameUnsafe className, boolean nullable) {
+ this.className = className;
+ this.nullable = nullable;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ KnownTypeKey that = (KnownTypeKey) o;
+
+ if (nullable != that.nullable) return false;
+ if (!className.equals(that.className)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = className.hashCode();
+ result = 31 * result + (nullable ? 1 : 0);
+ return result;
+ }
+ }
+
+ private final HashMap<KnownTypeKey, Type> knowTypes = Maps.newHashMap();
+
public static final Type TYPE_ITERATOR = Type.getObjectType("jet/Iterator");
public static final Type TYPE_INT_RANGE = Type.getObjectType("jet/IntRange");
@@ -372,7 +401,16 @@ public Type mapType(@NotNull final JetType jetType, @NotNull MapTypeMode kind) {
@NotNull
public Type mapType(JetType jetType, @Nullable BothSignatureWriter signatureVisitor, @NotNull MapTypeMode kind) {
- Type known = knowTypes.get(jetType);
+ Type known = null;
+ ClassifierDescriptor classifier = jetType.getConstructor().getDeclarationDescriptor();
+
+ if (compilerSpecialMode != CompilerSpecialMode.BUILTINS) {
+ if (classifier instanceof ClassDescriptor) {
+ KnownTypeKey key = new KnownTypeKey(DescriptorUtils.getFQName(classifier), jetType.isNullable());
+ known = knowTypes.get(key);
+ }
+ }
+
if (known != null) {
if (kind == MapTypeMode.VALUE) {
return mapKnownAsmType(jetType, known, signatureVisitor, false);
@@ -417,7 +455,9 @@ else if (kind == MapTypeMode.IMPL) {
return asmType;
}
- if (standardLibrary.getArray().equals(descriptor)) {
+ if (descriptor instanceof ClassDescriptor
+ && JetStandardLibraryNames.ARRAY.is((ClassDescriptor) descriptor)
+ && compilerSpecialMode != CompilerSpecialMode.BUILTINS) {
if (jetType.getArguments().size() != 1) {
throw new UnsupportedOperationException("arrays must have one type argument");
}
@@ -453,7 +493,7 @@ else if (kind == MapTypeMode.IMPL) {
Type asmType;
boolean forceReal;
- if (standardLibrary.getComparable().equals(descriptor)) {
+ if (JetStandardLibraryNames.COMPARABLE.is((ClassDescriptor) descriptor) && compilerSpecialMode != CompilerSpecialMode.BUILTINS) {
if (jetType.getArguments().size() != 1) {
throw new UnsupportedOperationException("Comparable must have one type argument");
}
@@ -551,8 +591,7 @@ public static Type boxType(Type asmType) {
}
public CallableMethod mapToCallableMethod(FunctionDescriptor functionDescriptor, boolean superCall, OwnerKind kind) {
- if (functionDescriptor == null)
- return null;
+ if (functionDescriptor == null) { return null; }
final DeclarationDescriptor functionParent = functionDescriptor.getOriginal().getContainingDeclaration();
@@ -978,46 +1017,27 @@ else if (p.getVisibility() == Visibilities.INTERNAL) {
return result;
}
- private void initKnownTypeNames() {
- knowTypeNames.put(JetStandardClasses.getAnyType(), "ANY_TYPE_INFO");
- knowTypeNames.put(JetStandardClasses.getNullableAnyType(), "NULLABLE_ANY_TYPE_INFO");
-
- for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
- PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
- knowTypeNames.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.name() + "_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), "NULLABLE_" + jvmPrimitiveType.name() + "_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.name() + "_ARRAY_TYPE_INFO");
- }
-
- knowTypeNames.put(standardLibrary.getStringType(),"STRING_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getNullableStringType(),"NULLABLE_STRING_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getTuple0Type(),"TUPLE0_TYPE_INFO");
- knowTypeNames.put(standardLibrary.getNullableTuple0Type(),"NULLABLE_TUPLE0_TYPE_INFO");
+ private void registerKnownType(@NotNull ClassName className, @NotNull Type nonNullType, @NotNull Type nullableType) {
+ knowTypes.put(new KnownTypeKey(className.getFqName().toUnsafe(), true), nullableType);
+ knowTypes.put(new KnownTypeKey(className.getFqName().toUnsafe(), false), nonNullType);
}
private void initKnownTypes() {
- knowTypes.put(JetStandardClasses.getNothingType(), TYPE_NOTHING);
- knowTypes.put(JetStandardClasses.getNullableNothingType(), TYPE_NOTHING);
-
+ registerKnownType(JetStandardLibraryNames.NOTHING, TYPE_NOTHING, TYPE_NOTHING);
+
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
- knowTypes.put(standardLibrary.getPrimitiveJetType(primitiveType), jvmPrimitiveType.getAsmType());
- knowTypes.put(standardLibrary.getNullablePrimitiveJetType(primitiveType), jvmPrimitiveType.getWrapper().getAsmType());
+ registerKnownType(primitiveType.getClassName(), jvmPrimitiveType.getAsmType(), jvmPrimitiveType.getWrapper().getAsmType());
}
- knowTypes.put(standardLibrary.getNumberType(),JL_NUMBER_TYPE);
- knowTypes.put(standardLibrary.getStringType(),JL_STRING_TYPE);
- knowTypes.put(standardLibrary.getNullableStringType(),JL_STRING_TYPE);
- knowTypes.put(standardLibrary.getCharSequenceType(),JL_CHAR_SEQUENCE_TYPE);
- knowTypes.put(standardLibrary.getNullableCharSequenceType(),JL_CHAR_SEQUENCE_TYPE);
- knowTypes.put(standardLibrary.getThrowableType(), TYPE_THROWABLE);
- knowTypes.put(standardLibrary.getNullableThrowableType(), TYPE_THROWABLE);
+ registerKnownType(JetStandardLibraryNames.NUMBER, JL_NUMBER_TYPE, JL_NUMBER_TYPE);
+ registerKnownType(JetStandardLibraryNames.STRING, JL_STRING_TYPE, JL_STRING_TYPE);
+ registerKnownType(JetStandardLibraryNames.CHAR_SEQUENCE, JL_CHAR_SEQUENCE_TYPE, JL_CHAR_SEQUENCE_TYPE);
+ registerKnownType(JetStandardLibraryNames.THROWABLE, TYPE_THROWABLE, TYPE_THROWABLE);
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
- knowTypes.put(standardLibrary.getPrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType());
- knowTypes.put(standardLibrary.getNullablePrimitiveArrayJetType(primitiveType), jvmPrimitiveType.getAsmArrayType());
+ registerKnownType(primitiveType.getArrayClassName(), jvmPrimitiveType.getAsmArrayType(), jvmPrimitiveType.getAsmArrayType());
}
}
@@ -1030,11 +1050,13 @@ private boolean isForceReal(JvmClassName className) {
public boolean isGenericsArray(JetType type) {
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
- if (declarationDescriptor instanceof TypeParameterDescriptor)
+ if (declarationDescriptor instanceof TypeParameterDescriptor) {
return true;
+ }
- if (standardLibrary.getArray().equals(declarationDescriptor))
+ if (JetStandardLibraryNames.ARRAY.is(type)) {
return isGenericsArray(type.getArguments().get(0).getType());
+ }
return false;
}
View
3  compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java
@@ -30,6 +30,7 @@
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import org.jetbrains.jet.lang.resolve.name.Name;
+import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
@@ -99,7 +100,7 @@ private void generateBackingField(JetProperty p, PropertyDescriptor propertyDesc
if (!propertyDescriptor.isVar()) {
modifiers |= Opcodes.ACC_FINAL;
}
- if (state.getInjector().getJetStandardLibrary().isVolatile(propertyDescriptor)) {
+ if (JetStandardLibrary.isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE;
}
Type type = state.getInjector().getJetTypeMapper().mapType(propertyDescriptor.getType(), MapTypeMode.VALUE);
View
7 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayIterator.java
@@ -30,6 +30,7 @@
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
+import org.jetbrains.jet.lang.types.lang.JetStandardLibraryNames;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
@@ -46,16 +47,14 @@ public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, @Not
JetCallExpression call = (JetCallExpression) element;
FunctionDescriptor funDescriptor = (FunctionDescriptor) codegen.getBindingContext().get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) call.getCalleeExpression());
ClassDescriptor containingDeclaration = (ClassDescriptor) funDescriptor.getContainingDeclaration().getOriginal();
- JetStandardLibrary standardLibrary = codegen.getState().getInjector().getJetStandardLibrary();
- if (containingDeclaration.equals(standardLibrary.getArray())) {
+ if (JetStandardLibraryNames.ARRAY.is(containingDeclaration)) {
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljet/Iterator;");
return StackValue.onStack(JetTypeMapper.TYPE_ITERATOR);
}
else {
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
- ClassDescriptor arrayClass = standardLibrary.getPrimitiveArrayClassDescriptor(primitiveType);
- if (containingDeclaration.equals(arrayClass)) {
+ if (primitiveType.getArrayClassName().is(containingDeclaration)) {
String methodSignature = "([" + jvmPrimitiveType.getJvmLetter() + ")" + jvmPrimitiveType.getIterator().getDescriptor();
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
return StackValue.onStack(jvmPrimitiveType.getIterator().getAsmType());
View
203 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethods.java
@@ -18,24 +18,20 @@
import com.google.common.collect.ImmutableList;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.psi.JavaPsiFacade;
-import com.intellij.psi.PsiClass;
-import com.intellij.psi.PsiMethod;
-import com.intellij.psi.search.DelegatingGlobalSearchScope;
-import com.intellij.psi.search.ProjectScope;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
+import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
+import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
import org.jetbrains.jet.lang.resolve.name.Name;
-import org.jetbrains.jet.lang.resolve.scopes.DescriptorPredicate;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
-import org.jetbrains.jet.plugin.JetFileType;
import org.objectweb.asm.Opcodes;
import javax.annotation.PostConstruct;
@@ -71,10 +67,9 @@
public static final String KOTLIN_JAVA_CLASS_PROPERTY = "kotlin.javaClass.property";
private Project myProject;
- private JetStandardLibrary myStdLib;
- private final Map<DeclarationDescriptor, IntrinsicMethod> myMethods = new HashMap<DeclarationDescriptor, IntrinsicMethod>();
private final Map<String, IntrinsicMethod> namedMethods = new HashMap<String, IntrinsicMethod>();
private static final IntrinsicMethod ARRAY_ITERATOR = new ArrayIterator();
+ private final IntrinsicsMap intrinsicsMap = new IntrinsicsMap();
@Inject
@@ -82,11 +77,6 @@ public void setMyProject(Project myProject) {
this.myProject = myProject;
}
- @Inject
- public void setMyStdLib(JetStandardLibrary myStdLib) {
- this.myStdLib = myStdLib;
- }
-
@PostConstruct
public void init() {
namedMethods.put(KOTLIN_JAVA_CLASS_FUNCTION, new JavaClassFunction());
@@ -95,21 +85,21 @@ public void init() {
ImmutableList<Name> primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList();
for (Name method : primitiveCastMethods) {
- declareIntrinsicFunction(Name.identifier("Number"), method, 0, NUMBER_CAST, true);
+ declareIntrinsicFunction(Name.identifier("Number"), method, 0, NUMBER_CAST);
for (Name type : PRIMITIVE_NUMBER_TYPES) {
- declareIntrinsicFunction(type, method, 0, NUMBER_CAST, true);
+ declareIntrinsicFunction(type, method, 0, NUMBER_CAST);
}
}
for (Name type : PRIMITIVE_NUMBER_TYPES) {
- declareIntrinsicFunction(type, Name.identifier("plus"), 0, UNARY_PLUS, false);
- declareIntrinsicFunction(type, Name.identifier("minus"), 0, UNARY_MINUS, false);
- declareIntrinsicFunction(type, Name.identifier("inv"), 0, INV, false);
- declareIntrinsicFunction(type, Name.identifier("rangeTo"), 1, UP_TO, false);
- declareIntrinsicFunction(type, Name.identifier("upto"), 1, UP_TO, false);
- declareIntrinsicFunction(type, Name.identifier("downto"), 1, DOWN_TO, false);
- declareIntrinsicFunction(type, Name.identifier("inc"), 0, INC, false);
- declareIntrinsicFunction(type, Name.identifier("dec"), 0, DEC, false);
+ declareIntrinsicFunction(type, Name.identifier("plus"), 0, UNARY_PLUS);
+ declareIntrinsicFunction(type, Name.identifier("minus"), 0, UNARY_MINUS);
+ declareIntrinsicFunction(type, Name.identifier("inv"), 0, INV);
+ declareIntrinsicFunction(type, Name.identifier("rangeTo"), 1, UP_TO);
+ declareIntrinsicFunction(type, Name.identifier("upto"), 1, UP_TO);
+ declareIntrinsicFunction(type, Name.identifier("downto"), 1, DOWN_TO);
+ declareIntrinsicFunction(type, Name.identifier("inc"), 0, INC);
+ declareIntrinsicFunction(type, Name.identifier("dec"), 0, DEC);
}
declareBinaryOp(Name.identifier("plus"), Opcodes.IADD);
@@ -124,36 +114,36 @@ public void init() {
declareBinaryOp(Name.identifier("or"), Opcodes.IOR);
declareBinaryOp(Name.identifier("xor"), Opcodes.IXOR);
- declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("not"), 0, new Not(), true);
-
- declareIntrinsicFunction(Name.identifier("String"), Name.identifier("plus"), 1, new Concat(), true);
- declareIntrinsicFunction(Name.identifier("CharSequence"), Name.identifier("get"), 1, new StringGetChar(), true);
- declareIntrinsicFunction(Name.identifier("String"), Name.identifier("get"), 1, new StringGetChar(), true);
-
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("toString")), 0, new ToString());
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("equals")), 1, EQUALS);
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("identityEquals")), 1, IDENTITY_EQUALS);
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("plus")), 1, STRING_PLUS);
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("arrayOfNulls")), 1, new NewArray());
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("sure")), 0, new Sure());
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("synchronized")), 2, new StupidSync());
- declareOverload(myStdLib.getLibraryScope().getFunctions(Name.identifier("iterator")), 0, new IteratorIterator());
-
- declareIntrinsicFunction(Name.identifier("ByteIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("ShortIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("IntIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("LongIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("CharIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("BooleanIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("FloatIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
- declareIntrinsicFunction(Name.identifier("DoubleIterator"), Name.identifier("next"), 0, ITERATOR_NEXT, false);
+ declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("not"), 0, new Not());
+
+ declareIntrinsicFunction(Name.identifier("String"), Name.identifier("plus"), 1, new Concat());
+ declareIntrinsicFunction(Name.identifier("CharSequence"), Name.identifier("get"), 1, new StringGetChar());
+ declareIntrinsicFunction(Name.identifier("String"), Name.identifier("get"), 1, new StringGetChar());
+
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("toString"), 0, new ToString());
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("equals"), 1, EQUALS);
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("identityEquals"), 1, IDENTITY_EQUALS);
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("plus"), 1, STRING_PLUS);
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("arrayOfNulls"), 1, new NewArray());
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("sure"), 0, new Sure());
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("synchronized"), 2, new StupidSync());
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME, Name.identifier("iterator"), 0, new IteratorIterator());
+
+
+ declareIntrinsicFunction(Name.identifier("ByteIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("ShortIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("IntIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("LongIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("CharIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("BooleanIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("FloatIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
+ declareIntrinsicFunction(Name.identifier("DoubleIterator"), Name.identifier("next"), 0, ITERATOR_NEXT);
for (Name type : PRIMITIVE_TYPES) {
- declareIntrinsicFunction(type, Name.identifier("compareTo"), 1, new CompareTo(), false);
+ declareIntrinsicFunction(type, Name.identifier("compareTo"), 1, new CompareTo());
}
// declareIntrinsicFunction("Any", "equals", 1, new Equals());
//
- declareIntrinsicStringMethods();
declareIntrinsicProperty(Name.identifier("CharSequence"), Name.identifier("length"), new StringLength());
declareIntrinsicProperty(Name.identifier("String"), Name.identifier("length"), new StringLength());
@@ -168,91 +158,37 @@ private void declareArrayMethods() {
declareIntrinsicProperty(Name.identifier("Array"), Name.identifier("size"), ARRAY_SIZE);
declareIntrinsicProperty(Name.identifier("Array"), Name.identifier("indices"), ARRAY_INDICES);
- declareIntrinsicFunction(Name.identifier("Array"), Name.identifier("set"), 2, ARRAY_SET, true);
- declareIntrinsicFunction(Name.identifier("Array"), Name.identifier("get"), 1, ARRAY_GET, true);
- declareIterator(myStdLib.getArray());
+ declareIntrinsicFunction(Name.identifier("Array"), Name.identifier("set"), 2, ARRAY_SET);
+ declareIntrinsicFunction(Name.identifier("Array"), Name.identifier("get"), 1, ARRAY_GET);
+ declareIterator(Name.identifier("Array"));
}
private void declareArrayMethodsForPrimitive(JvmPrimitiveType jvmPrimitiveType) {
PrimitiveType primitiveType = jvmPrimitiveType.getPrimitiveType();
declareIntrinsicProperty(primitiveType.getArrayTypeName(), Name.identifier("size"), ARRAY_SIZE);
declareIntrinsicProperty(primitiveType.getArrayTypeName(), Name.identifier("indices"), ARRAY_INDICES);
- declareIntrinsicFunction(primitiveType.getArrayTypeName(), Name.identifier("set"), 2, ARRAY_SET, true);
- declareIntrinsicFunction(primitiveType.getArrayTypeName(), Name.identifier("get"), 1, ARRAY_GET, true);
- declareIterator(myStdLib.getPrimitiveArrayClassDescriptor(primitiveType));
+ declareIntrinsicFunction(primitiveType.getArrayTypeName(), Name.identifier("set"), 2, ARRAY_SET);
+ declareIntrinsicFunction(primitiveType.getArrayTypeName(), Name.identifier("get"), 1, ARRAY_GET);
+ declareIterator(primitiveType.getArrayTypeName());
}
- private void declareIterator(ClassDescriptor classDescriptor) {
- declareOverload(classDescriptor.getDefaultType().getMemberScope().getFunctions(Name.identifier("iterator")), 0, ARRAY_ITERATOR);
- }
-
- private void declareIntrinsicStringMethods() {
- final ClassDescriptor stringClass = myStdLib.getString();
- final Collection<DeclarationDescriptor> stringMembers = stringClass.getMemberScope(Collections.<TypeProjection>emptyList()).getAllDescriptors(DescriptorPredicate.all());
- final PsiClass stringPsiClass = JavaPsiFacade.getInstance(myProject).findClass(
- "java.lang.String",
- new DelegatingGlobalSearchScope(ProjectScope.getLibrariesScope(myProject)) {
- @Override
- public boolean contains(VirtualFile file) {
- return myBaseScope.contains(file) && file.getFileType() != JetFileType.INSTANCE;
- }
- }
- );
- for (DeclarationDescriptor stringMember : stringMembers) {
- if (stringMember instanceof SimpleFunctionDescriptor) {
- final SimpleFunctionDescriptor stringMethod = (SimpleFunctionDescriptor) stringMember;
- final PsiMethod[] methods = stringPsiClass != null?
- stringPsiClass.findMethodsByName(stringMember.getName().getName(), false) : new PsiMethod[]{};
- for (PsiMethod method : methods) {
- if (method.getParameterList().getParametersCount() == stringMethod.getValueParameters().size()) {
- myMethods.put(stringMethod, new PsiMethodCall(stringMethod));
- }
- }
- }
- }
+ private void declareIterator(@NotNull Name arrayClassName) {
+ declareIntrinsicFunction(arrayClassName, Name.identifier("iterator"), 0, ARRAY_ITERATOR);
}
private void declareBinaryOp(Name methodName, int opcode) {
BinaryOp op = new BinaryOp(opcode);
for (Name type : PRIMITIVE_TYPES) {
- declareIntrinsicFunction(type, methodName, 1, op, false);
+ declareIntrinsicFunction(type, methodName, 1, op);
}
}
private void declareIntrinsicProperty(Name className, Name methodName, IntrinsicMethod implementation) {
- final JetScope numberScope = getClassMemberScope(className);
- Collection<VariableDescriptor> properties = numberScope.getProperties(methodName);
- assert properties.size() == 1;
- final VariableDescriptor property = properties.iterator().next();
- myMethods.put(property.getOriginal(), implementation);
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(className), methodName, -1, implementation);
}
- private void declareIntrinsicFunction(Name className, Name functionName, int arity, IntrinsicMethod implementation, boolean original) {
- JetScope memberScope = getClassMemberScope(className);
- final Collection<FunctionDescriptor> group = memberScope.getFunctions(functionName);
- for (FunctionDescriptor descriptor : group) {
- if (className.equals(descriptor.getContainingDeclaration().getName()) && descriptor.getValueParameters().size() == arity) {
- myMethods.put(original ? descriptor.getOriginal() : descriptor, implementation);
- }
- }
- }
-
- private void declareOverload(Collection<FunctionDescriptor> group, int arity, IntrinsicMethod implementation) {
- for (FunctionDescriptor descriptor : group) {
- if (descriptor.getValueParameters().size() == arity) {
- myMethods.put(descriptor.getOriginal(), implementation);
- }
- }
- }
-
- private JetScope getClassMemberScope(Name className) {
- final ClassDescriptor descriptor = (ClassDescriptor) myStdLib.getLibraryScope().getClassifier(className);
- final List<TypeParameterDescriptor> typeParameterDescriptors = descriptor.getTypeConstructor().getParameters();
- List<TypeProjection> typeParameters = new ArrayList<TypeProjection>();
- for (TypeParameterDescriptor typeParameterDescriptor : typeParameterDescriptors) {
- typeParameters.add(new TypeProjection(JetStandardClasses.getAnyType()));
- }
- return descriptor.getMemberScope(typeParameters);
+ private void declareIntrinsicFunction(Name className, Name functionName, int arity, IntrinsicMethod implementation) {
+ intrinsicsMap.registerIntrinsic(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(className), functionName, arity, implementation);
}
public IntrinsicMethod isIntrinsicMethod(DeclarationDescriptor descriptor) {
@@ -269,17 +205,30 @@ public IntrinsicMethod isIntrinsicMethod(DeclarationDescriptor descriptor) {
return null;
}
- public IntrinsicMethod getIntrinsic(DeclarationDescriptor descriptor) {
- IntrinsicMethod intrinsicMethod = myMethods.get(descriptor.getOriginal());
- if (intrinsicMethod == null) {
- List<AnnotationDescriptor> annotations = descriptor.getAnnotations();
- if (annotations != null) {
- for (AnnotationDescriptor annotation : annotations) {
- if("Intrinsic".equals(annotation.getType().getConstructor().getDeclarationDescriptor().getName().getName())) {
- String value = (String) annotation.getValueArguments().get(0).getValue();
- intrinsicMethod = namedMethods.get(value);
- if (intrinsicMethod != null) { break; }
- }
+ @Nullable
+ public IntrinsicMethod getIntrinsic(@NotNull CallableMemberDescriptor descriptor) {
+ IntrinsicMethod intrinsicMethod = intrinsicsMap.getIntrinsic(descriptor);
+ if (intrinsicMethod != null) {
+ return intrinsicMethod;
+ }
+
+ if (descriptor instanceof SimpleFunctionDescriptor) {
+ SimpleFunctionDescriptor functionDescriptor = (SimpleFunctionDescriptor) descriptor;
+ if (!functionDescriptor.getReceiverParameter().exists()) {
+ FqNameUnsafe ownerFqName = DescriptorUtils.getFQName(descriptor.getContainingDeclaration());
+ if (ownerFqName.equalsTo("jet.String")) {
+ return new PsiMethodCall(functionDescriptor);
+ }
+ }
+ }
+
+ List<AnnotationDescriptor> annotations = descriptor.getAnnotations();
+ if (annotations != null) {
+ for (AnnotationDescriptor annotation : annotations) {
+ if("Intrinsic".equals(annotation.getType().getConstructor().getDeclarationDescriptor().getName().getName())) {
+ String value = (String) annotation.getValueArguments().get(0).getValue();
+ intrinsicMethod = namedMethods.get(value);
+ if (intrinsicMethod != null) { break; }
}
}
}
View
103 compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicsMap.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2010-2012 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.google.common.collect.Maps;
+import com.sun.javaws.jnl.PropertyDesc;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
+import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
+import org.jetbrains.jet.lang.resolve.DescriptorUtils;
+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 java.util.Map;
+
+/**
+ * @author Stepan Koltsov
+ */
+class IntrinsicsMap {
+
+
+ private static final class Key {
+ @NotNull
+ private final FqNameUnsafe owner;
+ @NotNull
+ private final Name name;
+ private final int valueParameterCount;
+
+ private Key(@NotNull FqNameUnsafe owner, @NotNull Name name, int valueParameterCount) {
+ this.owner = owner;
+ this.name = name;
+ this.valueParameterCount = valueParameterCount;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Key key = (Key) o;
+
+ if (valueParameterCount != key.valueParameterCount) return false;
+ if (!name.equals(key.name)) return false;
+ if (!owner.equals(key.owner)) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = owner.hashCode();
+ result = 31 * result + name.hashCode();
+ result = 31 * result + valueParameterCount;
+ return result;
+ }
+ }
+
+ private int valueParameterCountForKey(@NotNull CallableMemberDescriptor member) {
+ if (member instanceof PropertyDescriptor) {
+ return -1;
+ }
+ else {
+ return member.getValueParameters().size();
+ }
+ }
+
+ private Map<Key, IntrinsicMethod> intrinsicsMap = Maps.newHashMap();
+
+
+ /**
+ * @param valueParameterCount -1 for property
+ */
+ public void registerIntrinsic(@NotNull FqName owner, @NotNull Name name, int valueParameterCount, @NotNull IntrinsicMethod impl) {
+ intrinsicsMap.put(new Key(owner.toUnsafe(), name, valueParameterCount), impl);
+ }
+
+
+ @Nullable
+ public IntrinsicMethod getIntrinsic(@NotNull CallableMemberDescriptor descriptor) {
+ Key key = new Key(
+ DescriptorUtils.getFQName(descriptor.getContainingDeclaration()),
+ descriptor.getName(),
+ valueParameterCountForKey(descriptor));
+ return intrinsicsMap.get(key);
+ }
+
+}
View
6 compiler/backend/src/org/jetbrains/jet/di/InjectorForJetTypeMapper.java
@@ -17,7 +17,6 @@
package org.jetbrains.jet.di;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -25,7 +24,6 @@
import org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode;
import org.jetbrains.jet.codegen.ClassBuilderMode;
import org.jetbrains.jet.codegen.ClosureAnnotator;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -35,7 +33,6 @@
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForJetTypeMapper {
- private final JetStandardLibrary jetStandardLibrary;
private final BindingContext bindingContext;
private final List<JetFile> listOfJetFile;
private JetTypeMapper jetTypeMapper;
@@ -44,11 +41,9 @@
private ClosureAnnotator closureAnnotator;
public InjectorForJetTypeMapper(
- @NotNull JetStandardLibrary jetStandardLibrary,
@NotNull BindingContext bindingContext,
@NotNull List<JetFile> listOfJetFile
) {
- this.jetStandardLibrary = jetStandardLibrary;
this.bindingContext = bindingContext;
this.listOfJetFile = listOfJetFile;
this.jetTypeMapper = new JetTypeMapper();
@@ -60,7 +55,6 @@ public InjectorForJetTypeMapper(
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
this.jetTypeMapper.setClosureAnnotator(closureAnnotator);
this.jetTypeMapper.setCompilerSpecialMode(compilerSpecialMode);
- this.jetTypeMapper.setStandardLibrary(jetStandardLibrary);
closureAnnotator.setBindingContext(bindingContext);
closureAnnotator.setFiles(listOfJetFile);
View
11 compiler/backend/src/org/jetbrains/jet/di/InjectorForJvmCodegen.java
@@ -17,7 +17,6 @@
package org.jetbrains.jet.di;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -33,7 +32,6 @@
import org.jetbrains.jet.codegen.ClassFileFactory;
import org.jetbrains.jet.codegen.MemberCodegen;
import org.jetbrains.jet.codegen.ClosureAnnotator;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.lang.resolve.BindingContext;
import java.util.List;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -48,7 +46,6 @@
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
public class InjectorForJvmCodegen {
- private final JetStandardLibrary jetStandardLibrary;
private final BindingContext bindingContext;
private final List<JetFile> listOfJetFile;
private final Project project;
@@ -65,7 +62,6 @@
private ClosureAnnotator closureAnnotator;
public InjectorForJvmCodegen(
- @NotNull JetStandardLibrary jetStandardLibrary,
@NotNull BindingContext bindingContext,
@NotNull List<JetFile> listOfJetFile,
@NotNull Project project,
@@ -74,7 +70,6 @@ public InjectorForJvmCodegen(
@NotNull GenerationState generationState,
@NotNull ClassBuilderFactory classBuilderFactory
) {
- this.jetStandardLibrary = jetStandardLibrary;
this.bindingContext = bindingContext;
this.listOfJetFile = listOfJetFile;
this.project = project;
@@ -94,7 +89,6 @@ public InjectorForJvmCodegen(
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
this.jetTypeMapper.setClosureAnnotator(closureAnnotator);
this.jetTypeMapper.setCompilerSpecialMode(compilerSpecialMode);
- this.jetTypeMapper.setStandardLibrary(jetStandardLibrary);
this.classCodegen.setJetTypeMapper(jetTypeMapper);
this.classCodegen.setState(generationState);
@@ -107,7 +101,6 @@ public InjectorForJvmCodegen(
this.scriptCodegen.setState(generationState);
this.intrinsics.setMyProject(project);
- this.intrinsics.setMyStdLib(jetStandardLibrary);
this.classFileFactory.setBuilderFactory(classBuilderFactory);
this.classFileFactory.setState(generationState);
@@ -127,10 +120,6 @@ public InjectorForJvmCodegen(
public void destroy() {
}
- public JetStandardLibrary getJetStandardLibrary() {
- return this.jetStandardLibrary;
- }
-
public GenerationState getGenerationState() {
return this.generationState;
}
View
3  compiler/cli/src/org/jetbrains/jet/cli/jvm/repl/ReplInterpreter.java
@@ -57,7 +57,6 @@
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import org.jetbrains.jet.plugin.JetLanguage;
import org.jetbrains.jet.utils.ExceptionUtils;
import org.jetbrains.jet.utils.Progress;
@@ -212,7 +211,7 @@ public void log(String message) {
}
GenerationState generationState = new GenerationState(jetCoreEnvironment.getProject(), ClassBuilderFactories.binaries(false), backendProgress,
- AnalyzeExhaust.success(trace.getBindingContext(), JetStandardLibrary.getInstance()), Collections.singletonList(psiFile),
+ AnalyzeExhaust.success(trace.getBindingContext()), Collections.singletonList(psiFile),
jetCoreEnvironment.getCompilerDependencies().getCompilerSpecialMode());
generationState.compileScript(psiFile.getScript(), scriptClassName, earierScripts, CompilationErrorHandler.THROW_EXCEPTION);
View
3  compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
@@ -34,7 +34,6 @@
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
import org.jetbrains.jet.lang.resolve.name.Name;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.Collection;
import java.util.Collections;
@@ -133,7 +132,7 @@ public static AnalyzeExhaust analyzeFilesWithJavaIntegration(
BodiesResolveContext bodiesResolveContext = storeContextForBodiesResolve ?
new CachedBodiesResolveContext(injector.getTopDownAnalysisContext()) :
null;
- return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), JetStandardLibrary.getInstance(), bodiesResolveContext);
+ return AnalyzeExhaust.success(bindingTraceContext.getBindingContext(), bodiesResolveContext);
} finally {
injector.destroy();
}
View
21 compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java
@@ -28,31 +28,29 @@
public class AnalyzeExhaust {
@NotNull
private final BindingContext bindingContext;
- private final JetStandardLibrary standardLibrary;
private final Throwable error;
@Nullable
private final BodiesResolveContext bodiesResolveContext;
private AnalyzeExhaust(@NotNull BindingContext bindingContext,
- @Nullable JetStandardLibrary standardLibrary, @Nullable BodiesResolveContext bodiesResolveContext, @Nullable Throwable error) {
+ @Nullable BodiesResolveContext bodiesResolveContext, @Nullable Throwable error) {
this.bindingContext = bindingContext;
- this.standardLibrary = standardLibrary;
this.error = error;
this.bodiesResolveContext = bodiesResolveContext;
}
- public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @NotNull JetStandardLibrary standardLibrary) {
- return new AnalyzeExhaust(bindingContext, standardLibrary, null, null);
+ public static AnalyzeExhaust success(@NotNull BindingContext bindingContext) {
+ return new AnalyzeExhaust(bindingContext, null, null);
}
- public static AnalyzeExhaust success(@NotNull BindingContext bindingContext, @NotNull JetStandardLibrary standardLibrary,
- BodiesResolveContext bodiesResolveContext) {
- return new AnalyzeExhaust(bindingContext, standardLibrary, bodiesResolveContext, null);
+ public static AnalyzeExhaust success(@NotNull BindingContext bindingContext,
+ BodiesResolveContext bodiesResolveContext) {
+ return new AnalyzeExhaust(bindingContext, bodiesResolveContext, null);
}
public static AnalyzeExhaust error(@NotNull BindingContext bindingContext, @NotNull Throwable error) {
- return new AnalyzeExhaust(bindingContext, null, null, error);
+ return new AnalyzeExhaust(bindingContext, null, error);
}
@Nullable
@@ -66,11 +64,6 @@ public BindingContext getBindingContext() {
}
@NotNull
- public JetStandardLibrary getStandardLibrary() {
- return standardLibrary;
- }
-
- @NotNull
public Throwable getError() {
return error;
}
View
3  compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzerFacadeForEverything.java
@@ -26,7 +26,6 @@
import org.jetbrains.jet.lang.resolve.BodiesResolveContext;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters;
-import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.List;
@@ -51,7 +50,7 @@ public static AnalyzeExhaust analyzeBodiesInFilesWithJavaIntegration(
try {
injector.getBodyResolver().resolveBodies(bodiesResolveContext);
- return AnalyzeExhaust.success(traceContext.getBindingContext(), JetStandardLibrary.getInstance());
+ return AnalyzeExhaust.success(traceContext.getBindingContext());
} finally {
injector.destroy();
}
View
3  ...iler/frontend/src/org/jetbrains/jet/lang/descriptors/AbstractNamespaceDescriptorImpl.java
@@ -27,7 +27,7 @@
/**
* @author abreslav
*/
-public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorImpl implements NamespaceDescriptor {
+public abstract class AbstractNamespaceDescriptorImpl extends DeclarationDescriptorNonRootImpl implements NamespaceDescriptor {
private NamespaceType namespaceType;
public AbstractNamespaceDescriptorImpl(
@@ -44,6 +44,7 @@ public AbstractNamespaceDescriptorImpl(
}
@Override
+ @NotNull
public NamespaceDescriptorParent getContainingDeclaration() {
return (NamespaceDescriptorParent) super.getContainingDeclaration();
}
View
2  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableDescriptor.java
@@ -28,7 +28,7 @@
/**
* @author abreslav
*/
-public interface CallableDescriptor extends DeclarationDescriptorWithVisibility {
+public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot {
@NotNull
ReceiverDescriptor getReceiverParameter();
View
4 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/CallableMemberDescriptor.java
@@ -28,6 +28,10 @@
@Override
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
+ @NotNull
+ @Override
+ CallableMemberDescriptor getOriginal();
+
void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden);
enum Kind {
View
2  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassDescriptorImpl.java
@@ -32,7 +32,7 @@
/**
* @author abreslav
*/
-public class ClassDescriptorImpl extends DeclarationDescriptorImpl implements ClassDescriptorFromSource {
+public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implements ClassDescriptorFromSource {
private TypeConstructor typeConstructor;
private JetScope memberDeclarations;
View
2  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassOrNamespaceDescriptor.java
@@ -19,5 +19,5 @@
/**
* @author Stepan Koltsov
*/
-public interface ClassOrNamespaceDescriptor extends DeclarationDescriptor {
+public interface ClassOrNamespaceDescriptor extends DeclarationDescriptorNonRoot {
}
View
2  compiler/frontend/src/org/jetbrains/jet/lang/descriptors/ClassifierDescriptor.java
@@ -24,7 +24,7 @@
/**
* @author abreslav
*/
-public interface ClassifierDescriptor extends DeclarationDescriptor {
+public interface ClassifierDescriptor extends DeclarationDescriptorNonRoot {
@NotNull
TypeConstructor getTypeConstructor();
View
13 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorImpl.java
@@ -17,7 +17,6 @@
package org.jetbrains.jet.lang.descriptors;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotatedImpl;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -26,19 +25,16 @@
import java.util.List;
/**
- * @author abreslav
+ * @author Stepan Koltsov
*/
public abstract class DeclarationDescriptorImpl extends AnnotatedImpl implements Named, DeclarationDescriptor {
@NotNull
private final Name name;
- private final DeclarationDescriptor containingDeclaration;
- public DeclarationDescriptorImpl(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull Name name) {
+ public DeclarationDescriptorImpl(@NotNull List<AnnotationDescriptor> annotations, @NotNull Name name) {
super(annotations);
-
this.name = name;
- this.containingDeclaration = containingDeclaration;
}
@NotNull
@@ -54,11 +50,6 @@ public DeclarationDescriptor getOriginal() {
}
@Override
- public DeclarationDescriptor getContainingDeclaration() {
- return containingDeclaration;
- }
-
- @Override
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
accept(visitor, null);
}
View
30 compiler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRoot.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010-2012 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.descriptors;
+
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Stepan Koltsov
+ */
+public interface DeclarationDescriptorNonRoot extends DeclarationDescriptor {
+
+ @Override
+ @NotNull
+ DeclarationDescriptor getContainingDeclaration();
+
+}
View
51 ...ler/frontend/src/org/jetbrains/jet/lang/descriptors/DeclarationDescriptorNonRootImpl.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2010-2012 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.descriptors;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
+import org.jetbrains.jet.lang.resolve.name.Name;
+
+import java.util.List;
+
+/**
+ * @author abreslav
+ */
+public abstract class DeclarationDescriptorNonRootImpl
+ extends DeclarationDescriptorImpl
+ implements DeclarationDescriptorNonRoot {
+
+ @NotNull
+ private final DeclarationDescriptor containingDeclaration;
+
+ public DeclarationDescriptorNonRootImpl(
+ @NotNull DeclarationDescriptor containingDeclaration,
+ @NotNull List<AnnotationDescriptor> annotations,
+ @NotNull Name name) {
+ super(annotations, name);
+
+ this.containingDeclaration = containingDeclaration;
+ }
+