remove JetStandardLibrary dependency from jvm backend
This commit is contained in:
@@ -21,6 +21,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
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 @@ public abstract class ClassBodyCodegen {
|
||||
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);
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
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 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -2494,7 +2501,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
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");
|
||||
@@ -2573,13 +2580,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
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);
|
||||
|
||||
@@ -72,7 +72,7 @@ public class GenerationState {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.BindingContext;
|
||||
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,18 +67,13 @@ public class JetTypeMapper {
|
||||
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;
|
||||
private ClassBuilderMode classBuilderMode;
|
||||
|
||||
|
||||
@Inject
|
||||
public void setStandardLibrary(JetStandardLibrary standardLibrary) {
|
||||
this.standardLibrary = standardLibrary;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setBindingContext(BindingContext bindingContext) {
|
||||
this.bindingContext = bindingContext;
|
||||
@@ -111,7 +110,39 @@ public class JetTypeMapper {
|
||||
return closureAnnotator;
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -370,7 +401,16 @@ public class JetTypeMapper {
|
||||
|
||||
@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);
|
||||
@@ -415,7 +455,9 @@ public class JetTypeMapper {
|
||||
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");
|
||||
}
|
||||
@@ -451,7 +493,7 @@ public class JetTypeMapper {
|
||||
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");
|
||||
}
|
||||
@@ -549,8 +591,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
@@ -976,28 +1017,27 @@ public class JetTypeMapper {
|
||||
return result;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,11 +1050,13 @@ public class JetTypeMapper {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
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 @@ public class PropertyCodegen {
|
||||
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);
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
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 class ArrayIterator implements IntrinsicMethod {
|
||||
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());
|
||||
|
||||
@@ -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.codegen.JetTypeMapper;
|
||||
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 @@ import javax.annotation.PreDestroy;
|
||||
/* 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 @@ public class InjectorForJetTypeMapper {
|
||||
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 class InjectorForJetTypeMapper {
|
||||
this.jetTypeMapper.setClassBuilderMode(classBuilderMode);
|
||||
this.jetTypeMapper.setClosureAnnotator(closureAnnotator);
|
||||
this.jetTypeMapper.setCompilerSpecialMode(compilerSpecialMode);
|
||||
this.jetTypeMapper.setStandardLibrary(jetStandardLibrary);
|
||||
|
||||
closureAnnotator.setBindingContext(bindingContext);
|
||||
closureAnnotator.setFiles(listOfJetFile);
|
||||
|
||||
@@ -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.intrinsics.IntrinsicMethods;
|
||||
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 @@ import javax.annotation.PreDestroy;
|
||||
/* 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 @@ public class InjectorForJvmCodegen {
|
||||
private ClosureAnnotator closureAnnotator;
|
||||
|
||||
public InjectorForJvmCodegen(
|
||||
@NotNull JetStandardLibrary jetStandardLibrary,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull List<JetFile> listOfJetFile,
|
||||
@NotNull Project project,
|
||||
@@ -74,7 +70,6 @@ public class InjectorForJvmCodegen {
|
||||
@NotNull GenerationState generationState,
|
||||
@NotNull ClassBuilderFactory classBuilderFactory
|
||||
) {
|
||||
this.jetStandardLibrary = jetStandardLibrary;
|
||||
this.bindingContext = bindingContext;
|
||||
this.listOfJetFile = listOfJetFile;
|
||||
this.project = project;
|
||||
@@ -94,7 +89,6 @@ public class 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);
|
||||
@@ -126,10 +120,6 @@ public class InjectorForJvmCodegen {
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public JetStandardLibrary getJetStandardLibrary() {
|
||||
return this.jetStandardLibrary;
|
||||
}
|
||||
|
||||
public GenerationState getGenerationState() {
|
||||
return this.generationState;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
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 class ReplInterpreter {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
+1
-2
@@ -34,7 +34,6 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
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 enum AnalyzerFacadeForJVM implements AnalyzerFacade {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -28,31 +28,29 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
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
|
||||
@@ -65,11 +63,6 @@ public class AnalyzeExhaust {
|
||||
return bindingContext;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetStandardLibrary getStandardLibrary() {
|
||||
return standardLibrary;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Throwable getError() {
|
||||
return error;
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
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 class AnalyzerFacadeForEverything {
|
||||
|
||||
try {
|
||||
injector.getBodyResolver().resolveBodies(bodiesResolveContext);
|
||||
return AnalyzeExhaust.success(traceContext.getBindingContext(), JetStandardLibrary.getInstance());
|
||||
return AnalyzeExhaust.success(traceContext.getBindingContext());
|
||||
} finally {
|
||||
injector.destroy();
|
||||
}
|
||||
|
||||
@@ -502,11 +502,13 @@ public class JetStandardLibrary {
|
||||
return volatileType;
|
||||
}
|
||||
|
||||
public final boolean isVolatile(PropertyDescriptor descriptor) {
|
||||
public static boolean isVolatile(PropertyDescriptor descriptor) {
|
||||
List<AnnotationDescriptor> annotations = descriptor.getOriginal().getAnnotations();
|
||||
if (annotations != null) {
|
||||
for(AnnotationDescriptor d: annotations) {
|
||||
if (d.getType().equals(getVolatileType())) { return true; }
|
||||
if (JetStandardLibraryNames.VOLATILE.is(d.getType())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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.types.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ref.ClassName;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*/
|
||||
public class JetStandardLibraryNames {
|
||||
|
||||
@NotNull
|
||||
private static ClassName classIn(@NotNull String name, int typeParameterCount) {
|
||||
return new ClassName(
|
||||
JetStandardClasses.STANDARD_CLASSES_FQNAME.child(Name.identifier(name)),
|
||||
typeParameterCount);
|
||||
}
|
||||
|
||||
public static final ClassName ARRAY = classIn("Array", 1);
|
||||
public static final ClassName VOLATILE = classIn("volatile", 0);
|
||||
public static final ClassName INT = PrimitiveType.INT.getClassName();
|
||||
public static final ClassName COMPARABLE = classIn("Comparable", 1);
|
||||
public static final ClassName NOTHING = classIn("Nothing", 0);
|
||||
public static final ClassName STRING = classIn("String", 0);
|
||||
public static final ClassName CHAR_SEQUENCE = classIn("CharSequence", 0);
|
||||
public static final ClassName NUMBER = classIn("Number", 0);
|
||||
public static final ClassName THROWABLE = classIn("Throwable", 0);
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.types.lang;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ref.ClassName;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -36,10 +37,14 @@ public enum PrimitiveType {
|
||||
|
||||
private final Name typeName;
|
||||
private final Name arrayTypeName;
|
||||
private final ClassName className;
|
||||
private final ClassName arrayClassName;
|
||||
|
||||
private PrimitiveType(String typeName) {
|
||||
this.typeName = Name.identifier(typeName);
|
||||
this.arrayTypeName = Name.identifier(typeName + "Array");
|
||||
this.className = new ClassName(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(this.typeName), 0);
|
||||
this.arrayClassName = new ClassName(JetStandardClasses.STANDARD_CLASSES_FQNAME.child(this.arrayTypeName), 0);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -51,4 +56,14 @@ public enum PrimitiveType {
|
||||
public Name getArrayTypeName() {
|
||||
return arrayTypeName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassName getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassName getArrayClassName() {
|
||||
return arrayClassName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.types.ref;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*
|
||||
* @see JetTypeName
|
||||
*/
|
||||
public final class ClassName {
|
||||
|
||||
@NotNull
|
||||
private final FqName fqName;
|
||||
private final int typeParameterCount;
|
||||
|
||||
public ClassName(@NotNull FqName fqName, int typeParameterCount) {
|
||||
this.fqName = fqName;
|
||||
this.typeParameterCount = typeParameterCount;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FqName getFqName() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
public int getTypeParameterCount() {
|
||||
return typeParameterCount;
|
||||
}
|
||||
|
||||
|
||||
public boolean is(@NotNull ClassDescriptor clazz) {
|
||||
return DescriptorUtils.getFQName(clazz).equalsTo(fqName);
|
||||
}
|
||||
|
||||
public boolean is(@NotNull JetType type) {
|
||||
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
|
||||
return classifier instanceof ClassDescriptor && is((ClassDescriptor) classifier);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return fqName + "<" + typeParameterCount + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ClassName className = (ClassName) o;
|
||||
|
||||
if (typeParameterCount != className.typeParameterCount) return false;
|
||||
if (!fqName.equals(className.fqName)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = fqName.hashCode();
|
||||
result = 31 * result + typeParameterCount;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
*
|
||||
* @see ClassName
|
||||
*/
|
||||
public class JetTypeName {
|
||||
// generic types one day
|
||||
|
||||
@@ -163,7 +163,7 @@ public class JetPositionManager implements PositionManager {
|
||||
final AnalyzeExhaust analyzeExhaust = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||
analyzeExhaust.throwIfError();
|
||||
JetTypeMapper typeMapper = new InjectorForJetTypeMapper(
|
||||
analyzeExhaust.getStandardLibrary(), analyzeExhaust.getBindingContext(), Collections.singletonList(file)).getJetTypeMapper();
|
||||
analyzeExhaust.getBindingContext(), Collections.singletonList(file)).getJetTypeMapper();
|
||||
myTypeMappers.put(file, typeMapper);
|
||||
return typeMapper;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,6 @@ public class AllInjectorsGenerator {
|
||||
|
||||
private static void generateInjectorForJvmCodegen() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
generator.addPublicParameter(JetStandardLibrary.class);
|
||||
generator.addParameter(BindingContext.class);
|
||||
generator.addParameter(DiType.listOf(JetFile.class));
|
||||
generator.addParameter(Project.class);
|
||||
@@ -184,7 +183,6 @@ public class AllInjectorsGenerator {
|
||||
|
||||
private static void generateInjectorForJetTypeMapper() throws IOException {
|
||||
DependencyInjectorGenerator generator = new DependencyInjectorGenerator(false);
|
||||
generator.addParameter(JetStandardLibrary.class);
|
||||
generator.addParameter(BindingContext.class);
|
||||
generator.addParameter(DiType.listOf(JetFile.class));
|
||||
generator.addPublicField(JetTypeMapper.class);
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.analyzer.AnalyzerFacadeForEverything;
|
||||
import org.jetbrains.jet.di.InjectorForBodyResolve;
|
||||
import org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJs;
|
||||
import org.jetbrains.jet.lang.DefaultModuleConfiguration;
|
||||
import org.jetbrains.jet.lang.ModuleConfiguration;
|
||||
@@ -38,7 +37,6 @@ import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -100,7 +98,7 @@ public final class AnalyzerFacadeForJS {
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user