提交 0a7c7bbc 编写于 作者: A Andrey Breslav

The stages of TopDownAnalyzer now only talk to each other through TopDownAnalysisContext

上级 5587b027
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION; import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION;
...@@ -18,22 +14,12 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION; ...@@ -18,22 +14,12 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.ANNOTATION;
* @author abreslav * @author abreslav
*/ */
public class DeclarationResolver { public class DeclarationResolver {
private final BindingTrace trace;
private final AnnotationResolver annotationResolver; private final AnnotationResolver annotationResolver;
private final ClassDescriptorResolver classDescriptorResolver;
private final TopDownAnalysisContext context; private final TopDownAnalysisContext context;
private final Map<JetNamedFunction, FunctionDescriptorImpl> functions = Maps.newLinkedHashMap(); public DeclarationResolver(TopDownAnalysisContext context) {
private final Map<JetDeclaration, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
public DeclarationResolver(JetSemanticServices semanticServices, BindingTrace trace, TopDownAnalysisContext context) {
this.trace = trace;
this.context = context; this.context = context;
this.annotationResolver = new AnnotationResolver(semanticServices, trace); this.annotationResolver = new AnnotationResolver(context.getSemanticServices(), context.getTrace());
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
} }
public void process() { public void process() {
...@@ -63,7 +49,7 @@ public class DeclarationResolver { ...@@ -63,7 +49,7 @@ public class DeclarationResolver {
if (modifierList != null) { if (modifierList != null) {
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries(); List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
for (JetAnnotationEntry annotationEntry : annotationEntries) { for (JetAnnotationEntry annotationEntry : annotationEntries) {
AnnotationDescriptor annotationDescriptor = trace.get(ANNOTATION, annotationEntry); AnnotationDescriptor annotationDescriptor = context.getTrace().get(ANNOTATION, annotationEntry);
if (annotationDescriptor != null) { if (annotationDescriptor != null) {
annotationResolver.resolveAnnotationStub(mutableClassDescriptor.getScopeForSupertypeResolution(), annotationEntry, annotationDescriptor); annotationResolver.resolveAnnotationStub(mutableClassDescriptor.getScopeForSupertypeResolution(), annotationEntry, annotationDescriptor);
} }
...@@ -105,30 +91,30 @@ public class DeclarationResolver { ...@@ -105,30 +91,30 @@ public class DeclarationResolver {
declaration.accept(new JetVisitorVoid() { declaration.accept(new JetVisitorVoid() {
@Override @Override
public void visitNamedFunction(JetNamedFunction function) { public void visitNamedFunction(JetNamedFunction function) {
FunctionDescriptorImpl functionDescriptor = classDescriptorResolver.resolveFunctionDescriptor(namespaceLike, scope, function); FunctionDescriptorImpl functionDescriptor = context.getClassDescriptorResolver().resolveFunctionDescriptor(namespaceLike, scope, function);
namespaceLike.addFunctionDescriptor(functionDescriptor); namespaceLike.addFunctionDescriptor(functionDescriptor);
functions.put(function, functionDescriptor); context.getFunctions().put(function, functionDescriptor);
declaringScopes.put(function, scope); context.getDeclaringScopes().put(function, scope);
} }
@Override @Override
public void visitProperty(JetProperty property) { public void visitProperty(JetProperty property) {
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePropertyDescriptor(namespaceLike, scope, property); PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolvePropertyDescriptor(namespaceLike, scope, property);
namespaceLike.addPropertyDescriptor(propertyDescriptor); namespaceLike.addPropertyDescriptor(propertyDescriptor);
properties.put(property, propertyDescriptor); context.getProperties().put(property, propertyDescriptor);
declaringScopes.put(property, scope); context.getDeclaringScopes().put(property, scope);
} }
@Override @Override
public void visitObjectDeclaration(JetObjectDeclaration declaration) { public void visitObjectDeclaration(JetObjectDeclaration declaration) {
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration)); PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, declaration, context.getObjects().get(declaration));
namespaceLike.addPropertyDescriptor(propertyDescriptor); namespaceLike.addPropertyDescriptor(propertyDescriptor);
} }
@Override @Override
public void visitEnumEntry(JetEnumEntry enumEntry) { public void visitEnumEntry(JetEnumEntry enumEntry) {
if (enumEntry.getPrimaryConstructorParameterList() == null) { if (enumEntry.getPrimaryConstructorParameterList() == null) {
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, enumEntry, context.getClasses().get(enumEntry)); PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolveObjectDeclarationAsPropertyDescriptor(namespaceLike, enumEntry, context.getClasses().get(enumEntry));
MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor(); MutableClassDescriptor classObjectDescriptor = ((MutableClassDescriptor) namespaceLike).getClassObjectDescriptor();
assert classObjectDescriptor != null; assert classObjectDescriptor != null;
classObjectDescriptor.addPropertyDescriptor(propertyDescriptor); classObjectDescriptor.addPropertyDescriptor(propertyDescriptor);
...@@ -142,20 +128,20 @@ public class DeclarationResolver { ...@@ -142,20 +128,20 @@ public class DeclarationResolver {
if (!klass.hasPrimaryConstructor()) return; if (!klass.hasPrimaryConstructor()) return;
if (classDescriptor.getKind() == ClassKind.TRAIT) { if (classDescriptor.getKind() == ClassKind.TRAIT) {
trace.getErrorHandler().genericError(klass.getPrimaryConstructorParameterList().getNode(), "A trait may not have a constructor"); context.getTrace().getErrorHandler().genericError(klass.getPrimaryConstructorParameterList().getNode(), "A trait may not have a constructor");
} }
// TODO : not all the parameters are real properties // TODO : not all the parameters are real properties
JetScope memberScope = classDescriptor.getScopeForSupertypeResolution(); JetScope memberScope = classDescriptor.getScopeForSupertypeResolution();
ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass); ConstructorDescriptor constructorDescriptor = context.getClassDescriptorResolver().resolvePrimaryConstructorDescriptor(memberScope, classDescriptor, klass);
for (JetParameter parameter : klass.getPrimaryConstructorParameters()) { for (JetParameter parameter : klass.getPrimaryConstructorParameters()) {
PropertyDescriptor propertyDescriptor = classDescriptorResolver.resolvePrimaryConstructorParameterToAProperty( PropertyDescriptor propertyDescriptor = context.getClassDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
classDescriptor, classDescriptor,
memberScope, memberScope,
parameter parameter
); );
classDescriptor.addPropertyDescriptor(propertyDescriptor); classDescriptor.addPropertyDescriptor(propertyDescriptor);
primaryConstructorParameterProperties.add(propertyDescriptor); context.getPrimaryConstructorParameterProperties().add(propertyDescriptor);
} }
if (constructorDescriptor != null) { if (constructorDescriptor != null) {
classDescriptor.setPrimaryConstructor(constructorDescriptor); classDescriptor.setPrimaryConstructor(constructorDescriptor);
...@@ -164,34 +150,15 @@ public class DeclarationResolver { ...@@ -164,34 +150,15 @@ public class DeclarationResolver {
private void processSecondaryConstructor(MutableClassDescriptor classDescriptor, JetConstructor constructor) { private void processSecondaryConstructor(MutableClassDescriptor classDescriptor, JetConstructor constructor) {
if (classDescriptor.getKind() == ClassKind.TRAIT) { if (classDescriptor.getKind() == ClassKind.TRAIT) {
trace.getErrorHandler().genericError(constructor.getNameNode(), "A trait may not have a constructor"); context.getTrace().getErrorHandler().genericError(constructor.getNameNode(), "A trait may not have a constructor");
} }
ConstructorDescriptor constructorDescriptor = classDescriptorResolver.resolveSecondaryConstructorDescriptor( ConstructorDescriptor constructorDescriptor = context.getClassDescriptorResolver().resolveSecondaryConstructorDescriptor(
classDescriptor.getScopeForMemberResolution(), classDescriptor.getScopeForMemberResolution(),
classDescriptor, classDescriptor,
constructor); constructor);
classDescriptor.addConstructor(constructorDescriptor); classDescriptor.addConstructor(constructorDescriptor);
constructors.put(constructor, constructorDescriptor); context.getConstructors().put(constructor, constructorDescriptor);
declaringScopes.put(constructor, classDescriptor.getScopeForMemberLookup()); context.getDeclaringScopes().put(constructor, classDescriptor.getScopeForMemberLookup());
}
public Set<PropertyDescriptor> getPrimaryConstructorParameterProperties() {
return primaryConstructorParameterProperties;
}
public Map<JetDeclaration, ConstructorDescriptor> getConstructors() {
return constructors;
} }
public Map<JetProperty, PropertyDescriptor> getProperties() {
return properties;
}
public Map<JetDeclaration, JetScope> getDeclaringScopes() {
return declaringScopes;
}
public Map<JetNamedFunction, FunctionDescriptorImpl> getFunctions() {
return functions;
}
} }
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor; import com.google.common.collect.Sets;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.psi.JetClass; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetNamespace; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* @author abreslav * @author abreslav
*/ */
public class TopDownAnalysisContext { /*package*/ class TopDownAnalysisContext {
private final BindingTrace trace;
private final JetSemanticServices semanticServices;
private final ClassDescriptorResolver classDescriptorResolver;
private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap(); private final Map<JetClass, MutableClassDescriptor> classes = Maps.newLinkedHashMap();
private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap(); private final Map<JetObjectDeclaration, MutableClassDescriptor> objects = Maps.newLinkedHashMap();
protected final Map<JetNamespace, WritableScope> namespaceScopes = Maps.newHashMap(); protected final Map<JetNamespace, WritableScope> namespaceScopes = Maps.newHashMap();
protected final Map<JetNamespace, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap(); protected final Map<JetNamespace, NamespaceDescriptorImpl> namespaceDescriptors = Maps.newHashMap();
private final Map<JetNamedFunction, FunctionDescriptorImpl> functions = Maps.newLinkedHashMap();
private final Map<JetDeclaration, ConstructorDescriptor> constructors = Maps.newLinkedHashMap();
private final Map<JetProperty, PropertyDescriptor> properties = Maps.newLinkedHashMap();
private final Set<PropertyDescriptor> primaryConstructorParameterProperties = Sets.newHashSet();
private final Map<JetDeclaration, JetScope> declaringScopes = Maps.newHashMap();
public TopDownAnalysisContext(JetSemanticServices semanticServices, BindingTrace trace) {
this.trace = trace;
this.semanticServices = semanticServices;
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
}
public BindingTrace getTrace() {
return trace;
}
public JetSemanticServices getSemanticServices() {
return semanticServices;
}
public ClassDescriptorResolver getClassDescriptorResolver() {
return classDescriptorResolver;
}
public Map<JetClass, MutableClassDescriptor> getClasses() { public Map<JetClass, MutableClassDescriptor> getClasses() {
return classes; return classes;
} }
...@@ -35,5 +63,24 @@ public class TopDownAnalysisContext { ...@@ -35,5 +63,24 @@ public class TopDownAnalysisContext {
return namespaceDescriptors; return namespaceDescriptors;
} }
public Set<PropertyDescriptor> getPrimaryConstructorParameterProperties() {
return primaryConstructorParameterProperties;
}
public Map<JetDeclaration, ConstructorDescriptor> getConstructors() {
return constructors;
}
public Map<JetProperty, PropertyDescriptor> getProperties() {
return properties;
}
public Map<JetDeclaration, JetScope> getDeclaringScopes() {
return declaringScopes;
}
public Map<JetNamedFunction, FunctionDescriptorImpl> getFunctions() {
return functions;
}
} }
...@@ -60,26 +60,22 @@ public class TopDownAnalyzer { ...@@ -60,26 +60,22 @@ public class TopDownAnalyzer {
@NotNull JetSemanticServices semanticServices, @NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) { @NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) {
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace); TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace);
TopDownAnalysisContext context = typeHierarchyResolver.process(outerScope, owner, declarations); new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
new DeclarationResolver(context).process();
DeclarationResolver declarationResolver = new DeclarationResolver(semanticServices, trace, context); new BodyResolver(context).resolveBehaviorDeclarationBodies();
declarationResolver.process();
new BodyResolver(semanticServices, trace, context, declarationResolver).resolveBehaviorDeclarationBodies();
} }
public static void processStandardLibraryNamespace( public static void processStandardLibraryNamespace(
@NotNull JetSemanticServices semanticServices, @NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace, @NotNull BindingTrace trace,
@NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) { @NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) {
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace); TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace);
TopDownAnalysisContext context = typeHierarchyResolver.processStandardLibraryNamespace(outerScope, standardLibraryNamespace, namespace); context.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope());
context.getNamespaceDescriptors().put(namespace, standardLibraryNamespace);
DeclarationResolver declarationResolver = new DeclarationResolver(semanticServices, trace, context); new TypeHierarchyResolver(context).process(outerScope, standardLibraryNamespace, namespace.getDeclarations());
declarationResolver.process(); new DeclarationResolver(context).process();
BodyResolver bodyResolver = new BodyResolver(context) {
BodyResolver bodyResolver = new BodyResolver(semanticServices, trace, context, declarationResolver) {
@Override @Override
protected void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor, @Nullable ClassDescriptor classDescriptor) { protected void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor, @Nullable ClassDescriptor classDescriptor) {
} }
......
package org.jetbrains.jet.lang.resolve; package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
...@@ -19,43 +18,24 @@ import java.util.Map; ...@@ -19,43 +18,24 @@ import java.util.Map;
* @author abreslav * @author abreslav
*/ */
public class TypeHierarchyResolver { public class TypeHierarchyResolver {
private final TopDownAnalysisContext context;
private final BindingTrace trace; public TypeHierarchyResolver(TopDownAnalysisContext context) {
private final JetSemanticServices semanticServices; this.context = context;
private final ClassDescriptorResolver classDescriptorResolver;
public TypeHierarchyResolver(JetSemanticServices semanticServices, BindingTrace trace) {
this.trace = trace;
this.semanticServices = semanticServices;
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
}
public TopDownAnalysisContext process(@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) {
TopDownAnalysisContext context = new TopDownAnalysisContext();
return doProcess(outerScope, owner, declarations, context);
}
public TopDownAnalysisContext processStandardLibraryNamespace(@NotNull JetScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) {
TopDownAnalysisContext context = new TopDownAnalysisContext();
context.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope());
context.getNamespaceDescriptors().put(namespace, standardLibraryNamespace);
return doProcess(outerScope, standardLibraryNamespace, namespace.getDeclarations(), context);
} }
private TopDownAnalysisContext doProcess(JetScope outerScope, NamespaceLike owner, List<JetDeclaration> declarations, TopDownAnalysisContext context) { public void process(@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) {
collectNamespacesAndClassifiers(outerScope, owner, declarations, context); // namespaceScopes, classes collectNamespacesAndClassifiers(outerScope, owner, declarations); // namespaceScopes, classes
createTypeConstructors(context); // create type constructors for classes and generic parameters createTypeConstructors(); // create type constructors for classes and generic parameters
resolveTypesInClassHeaders(context); // Generic bounds and types in supertype lists (no expressions or constructor resolution) resolveTypesInClassHeaders(); // Generic bounds and types in supertype lists (no expressions or constructor resolution)
checkTypesInClassHeaders(context); // Generic bounds and supertype lists checkTypesInClassHeaders(); // Generic bounds and supertype lists
return context;
} }
private void collectNamespacesAndClassifiers( private void collectNamespacesAndClassifiers(
@NotNull final JetScope outerScope, @NotNull final JetScope outerScope,
@NotNull final NamespaceLike owner, @NotNull final NamespaceLike owner,
@NotNull Collection<JetDeclaration> declarations, @NotNull Collection<JetDeclaration> declarations) {
@NotNull final TopDownAnalysisContext context) {
for (JetDeclaration declaration : declarations) { for (JetDeclaration declaration : declarations) {
declaration.accept(new JetVisitorVoid() { declaration.accept(new JetVisitorVoid() {
@Override @Override
...@@ -72,26 +52,26 @@ public class TypeHierarchyResolver { ...@@ -72,26 +52,26 @@ public class TypeHierarchyResolver {
Collections.<AnnotationDescriptor>emptyList(), // TODO Collections.<AnnotationDescriptor>emptyList(), // TODO
name name
); );
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler()).setDebugName("Namespace member scope")); namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, context.getTrace().getErrorHandler()).setDebugName("Namespace member scope"));
owner.addNamespace(namespaceDescriptor); owner.addNamespace(namespaceDescriptor);
trace.record(BindingContext.NAMESPACE, namespace, namespaceDescriptor); context.getTrace().record(BindingContext.NAMESPACE, namespace, namespaceDescriptor);
} }
context.getNamespaceDescriptors().put(namespace, namespaceDescriptor); context.getNamespaceDescriptors().put(namespace, namespaceDescriptor);
WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), trace.getErrorHandler()); WriteThroughScope namespaceScope = new WriteThroughScope(outerScope, namespaceDescriptor.getMemberScope(), context.getTrace().getErrorHandler());
context.getNamespaceScopes().put(namespace, namespaceScope); context.getNamespaceScopes().put(namespace, namespaceScope);
processImports(namespace, namespaceScope, outerScope); processImports(namespace, namespaceScope, outerScope);
collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations(), context); collectNamespacesAndClassifiers(namespaceScope, namespaceDescriptor, namespace.getDeclarations());
} }
@Override @Override
public void visitClass(JetClass klass) { public void visitClass(JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner, outerScope, getClassKind(klass)); MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, getClassKind(klass));
if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) { if (klass.hasModifier(JetTokens.ENUM_KEYWORD)) {
MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(trace, mutableClassDescriptor, outerScope, ClassKind.OBJECT); MutableClassDescriptor classObjectDescriptor = new MutableClassDescriptor(context.getTrace(), mutableClassDescriptor, outerScope, ClassKind.OBJECT);
classObjectDescriptor.setName("class-object-for-" + klass.getName()); classObjectDescriptor.setName("class-object-for-" + klass.getName());
classObjectDescriptor.setModality(Modality.FINAL); classObjectDescriptor.setModality(Modality.FINAL);
classObjectDescriptor.createTypeConstructor(); classObjectDescriptor.createTypeConstructor();
...@@ -122,7 +102,7 @@ public class TypeHierarchyResolver { ...@@ -122,7 +102,7 @@ public class TypeHierarchyResolver {
context.getClasses().put(enumEntry, classDescriptor); context.getClasses().put(enumEntry, classDescriptor);
} }
else { else {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, classObjectDescriptor, outerScope, ClassKind.CLASS); // TODO : Special kind for enum entry classes? MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), classObjectDescriptor, outerScope, ClassKind.CLASS); // TODO : Special kind for enum entry classes?
visitClassOrObject( visitClassOrObject(
enumEntry, enumEntry,
(Map) context.getClasses(), (Map) context.getClasses(),
...@@ -134,7 +114,7 @@ public class TypeHierarchyResolver { ...@@ -134,7 +114,7 @@ public class TypeHierarchyResolver {
} }
private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner) { private MutableClassDescriptor createClassDescriptorForObject(@NotNull JetClassOrObject declaration, @NotNull NamespaceLike owner) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, owner, outerScope, ClassKind.OBJECT) { MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(context.getTrace(), owner, outerScope, ClassKind.OBJECT) {
@Override @Override
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) { public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptor classObjectDescriptor) {
return ClassObjectStatus.NOT_ALLOWED; return ClassObjectStatus.NOT_ALLOWED;
...@@ -142,7 +122,7 @@ public class TypeHierarchyResolver { ...@@ -142,7 +122,7 @@ public class TypeHierarchyResolver {
}; };
visitClassOrObject(declaration, (Map) context.getObjects(), owner, outerScope, mutableClassDescriptor); visitClassOrObject(declaration, (Map) context.getObjects(), owner, outerScope, mutableClassDescriptor);
createPrimaryConstructor(mutableClassDescriptor); createPrimaryConstructor(mutableClassDescriptor);
trace.record(BindingContext.CLASS, declaration, mutableClassDescriptor); context.getTrace().record(BindingContext.CLASS, declaration, mutableClassDescriptor);
return mutableClassDescriptor; return mutableClassDescriptor;
} }
...@@ -161,12 +141,12 @@ public class TypeHierarchyResolver { ...@@ -161,12 +141,12 @@ public class TypeHierarchyResolver {
// declaringScopes.put((JetDeclaration) declaration, outerScope); // declaringScopes.put((JetDeclaration) declaration, outerScope);
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution(); JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
collectNamespacesAndClassifiers(classScope, mutableClassDescriptor, declaration.getDeclarations(), context); collectNamespacesAndClassifiers(classScope, mutableClassDescriptor, declaration.getDeclarations());
} }
@Override @Override
public void visitTypedef(JetTypedef typedef) { public void visitTypedef(JetTypedef typedef) {
trace.getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]"); context.getTrace().getErrorHandler().genericError(typedef.getNode(), "Unsupported [TopDownAnalyzer]");
} }
@Override @Override
...@@ -176,10 +156,10 @@ public class TypeHierarchyResolver { ...@@ -176,10 +156,10 @@ public class TypeHierarchyResolver {
NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner)); NamespaceLike.ClassObjectStatus status = owner.setClassObjectDescriptor(createClassDescriptorForObject(objectDeclaration, owner));
switch (status) { switch (status) {
case DUPLICATE: case DUPLICATE:
trace.getErrorHandler().genericError(classObject.getNode(), "Only one class object is allowed per class"); context.getTrace().getErrorHandler().genericError(classObject.getNode(), "Only one class object is allowed per class");
break; break;
case NOT_ALLOWED: case NOT_ALLOWED:
trace.getErrorHandler().genericError(classObject.getNode(), "A class object is not allowed here"); context.getTrace().getErrorHandler().genericError(classObject.getNode(), "A class object is not allowed here");
break; break;
} }
} }
...@@ -200,13 +180,13 @@ public class TypeHierarchyResolver { ...@@ -200,13 +180,13 @@ public class TypeHierarchyResolver {
List<JetImportDirective> importDirectives = namespace.getImportDirectives(); List<JetImportDirective> importDirectives = namespace.getImportDirectives();
for (JetImportDirective importDirective : importDirectives) { for (JetImportDirective importDirective : importDirectives) {
if (importDirective.isAbsoluteInRootNamespace()) { if (importDirective.isAbsoluteInRootNamespace()) {
trace.getErrorHandler().genericError(namespace.getNode(), "Unsupported by TDA"); // TODO context.getTrace().getErrorHandler().genericError(namespace.getNode(), "Unsupported by TDA"); // TODO
continue; continue;
} }
if (importDirective.isAllUnder()) { if (importDirective.isAllUnder()) {
JetExpression importedReference = importDirective.getImportedReference(); JetExpression importedReference = importDirective.getImportedReference();
if (importedReference != null) { if (importedReference != null) {
JetTypeInferrer.Services typeInferrerServices = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION); JetTypeInferrer.Services typeInferrerServices = context.getSemanticServices().getTypeInferrerServices(context.getTrace(), JetFlowInformationProvider.THROW_EXCEPTION);
JetType type = typeInferrerServices.getTypeWithNamespaces(namespaceScope, importedReference); JetType type = typeInferrerServices.getTypeWithNamespaces(namespaceScope, importedReference);
if (type != null) { if (type != null) {
namespaceScope.importScope(type.getMemberScope()); namespaceScope.importScope(type.getMemberScope());
...@@ -220,7 +200,7 @@ public class TypeHierarchyResolver { ...@@ -220,7 +200,7 @@ public class TypeHierarchyResolver {
JetExpression importedReference = importDirective.getImportedReference(); JetExpression importedReference = importDirective.getImportedReference();
if (importedReference instanceof JetDotQualifiedExpression) { if (importedReference instanceof JetDotQualifiedExpression) {
JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference; JetDotQualifiedExpression reference = (JetDotQualifiedExpression) importedReference;
JetType type = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression()); JetType type = context.getSemanticServices().getTypeInferrerServices(context.getTrace(), JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, reference.getReceiverExpression());
JetExpression selectorExpression = reference.getSelectorExpression(); JetExpression selectorExpression = reference.getSelectorExpression();
if (selectorExpression != null) { if (selectorExpression != null) {
referenceExpression = (JetSimpleNameExpression) selectorExpression; referenceExpression = (JetSimpleNameExpression) selectorExpression;
...@@ -241,7 +221,7 @@ public class TypeHierarchyResolver { ...@@ -241,7 +221,7 @@ public class TypeHierarchyResolver {
} }
if (classifierDescriptor != null) { if (classifierDescriptor != null) {
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor); context.getTrace().record(BindingContext.REFERENCE_TARGET, referenceExpression, classifierDescriptor);
String aliasName = importDirective.getAliasName(); String aliasName = importDirective.getAliasName();
String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName(); String importedClassifierName = aliasName != null ? aliasName : classifierDescriptor.getName();
...@@ -251,11 +231,11 @@ public class TypeHierarchyResolver { ...@@ -251,11 +231,11 @@ public class TypeHierarchyResolver {
} }
} }
private void createTypeConstructors(TopDownAnalysisContext context) { private void createTypeConstructors() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
classDescriptorResolver.resolveMutableClassDescriptor(jetClass, descriptor); context.getClassDescriptorResolver().resolveMutableClassDescriptor(jetClass, descriptor);
descriptor.createTypeConstructor(); descriptor.createTypeConstructor();
} }
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) { for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
...@@ -265,30 +245,30 @@ public class TypeHierarchyResolver { ...@@ -265,30 +245,30 @@ public class TypeHierarchyResolver {
} }
} }
private void resolveTypesInClassHeaders(TopDownAnalysisContext context) { private void resolveTypesInClassHeaders() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
classDescriptorResolver.resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters()); context.getClassDescriptorResolver().resolveGenericBounds(jetClass, descriptor.getScopeForSupertypeResolution(), descriptor.getTypeConstructor().getParameters());
classDescriptorResolver.resolveSupertypes(jetClass, descriptor); context.getClassDescriptorResolver().resolveSupertypes(jetClass, descriptor);
} }
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) { for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
JetClassOrObject jetClass = entry.getKey(); JetClassOrObject jetClass = entry.getKey();
MutableClassDescriptor descriptor = entry.getValue(); MutableClassDescriptor descriptor = entry.getValue();
classDescriptorResolver.resolveSupertypes(jetClass, descriptor); context.getClassDescriptorResolver().resolveSupertypes(jetClass, descriptor);
} }
} }
private void checkTypesInClassHeaders(TopDownAnalysisContext context) { private void checkTypesInClassHeaders() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) { for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey(); JetClass jetClass = entry.getKey();
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) { for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
JetTypeReference typeReference = delegationSpecifier.getTypeReference(); JetTypeReference typeReference = delegationSpecifier.getTypeReference();
if (typeReference != null) { if (typeReference != null) {
JetType type = trace.getBindingContext().get(BindingContext.TYPE, typeReference); JetType type = context.getTrace().getBindingContext().get(BindingContext.TYPE, typeReference);
if (type != null) { if (type != null) {
classDescriptorResolver.checkBounds(typeReference, type); context.getClassDescriptorResolver().checkBounds(typeReference, type);
} }
} }
} }
...@@ -296,9 +276,9 @@ public class TypeHierarchyResolver { ...@@ -296,9 +276,9 @@ public class TypeHierarchyResolver {
for (JetTypeParameter jetTypeParameter : jetClass.getTypeParameters()) { for (JetTypeParameter jetTypeParameter : jetClass.getTypeParameters()) {
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound(); JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
if (extendsBound != null) { if (extendsBound != null) {
JetType type = trace.getBindingContext().get(BindingContext.TYPE, extendsBound); JetType type = context.getTrace().getBindingContext().get(BindingContext.TYPE, extendsBound);
if (type != null) { if (type != null) {
classDescriptorResolver.checkBounds(extendsBound, type); context.getClassDescriptorResolver().checkBounds(extendsBound, type);
} }
} }
} }
...@@ -306,9 +286,9 @@ public class TypeHierarchyResolver { ...@@ -306,9 +286,9 @@ public class TypeHierarchyResolver {
for (JetTypeConstraint constraint : jetClass.getTypeConstaints()) { for (JetTypeConstraint constraint : jetClass.getTypeConstaints()) {
JetTypeReference extendsBound = constraint.getBoundTypeReference(); JetTypeReference extendsBound = constraint.getBoundTypeReference();
if (extendsBound != null) { if (extendsBound != null) {
JetType type = trace.getBindingContext().get(BindingContext.TYPE, extendsBound); JetType type = context.getTrace().getBindingContext().get(BindingContext.TYPE, extendsBound);
if (type != null) { if (type != null) {
classDescriptorResolver.checkBounds(extendsBound, type); context.getClassDescriptorResolver().checkBounds(extendsBound, type);
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册