TopDownAnalyzer is now a utility class

This commit is contained in:
Andrey Breslav
2011-09-09 18:01:11 +04:00
parent a8dc7599ef
commit dcc84a0e48
5 changed files with 20 additions and 57 deletions
@@ -77,10 +77,7 @@ public class AnalyzingUtils {
scope.importScope(new JavaPackageScope("", null, javaSemanticServices)); scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
scope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices)); scope.importScope(new JavaPackageScope("java.lang", null, javaSemanticServices));
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, bindingTraceContext); TopDownAnalyzer.process(semanticServices, bindingTraceContext, scope, new NamespaceLike.Adapter(owner) {
// topDownAnalyzer.process(scope, Collections.<JetDeclaration>singletonList(namespace));
// if (false)
topDownAnalyzer.process(scope, new NamespaceLike.Adapter(owner) {
@Override @Override
public NamespaceDescriptorImpl getNamespace(String name) { public NamespaceDescriptorImpl getNamespace(String name) {
@@ -13,16 +13,16 @@ import java.util.List;
* @author abreslav * @author abreslav
*/ */
public class TopDownAnalyzer { public class TopDownAnalyzer {
private final JetSemanticServices semanticServices;
private final BindingTrace trace;
public TopDownAnalyzer(JetSemanticServices semanticServices, @NotNull BindingTrace bindingTrace) { private TopDownAnalyzer() {}
this.semanticServices = semanticServices;
this.trace = bindingTrace;
}
public void processObject(@NotNull JetScope outerScope, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetObjectDeclaration object) { public static void processObject(
process(outerScope, new NamespaceLike.Adapter(containingDeclaration) { @NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace,
@NotNull JetScope outerScope,
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetObjectDeclaration object) {
process(semanticServices, trace, outerScope, new NamespaceLike.Adapter(containingDeclaration) {
@Override @Override
public NamespaceDescriptorImpl getNamespace(String name) { public NamespaceDescriptorImpl getNamespace(String name) {
@@ -56,7 +56,10 @@ public class TopDownAnalyzer {
}, Collections.<JetDeclaration>singletonList(object)); }, Collections.<JetDeclaration>singletonList(object));
} }
public void process(@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) { public static void process(
@NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace,
@NotNull JetScope outerScope, NamespaceLike owner, @NotNull List<JetDeclaration> declarations) {
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace); TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace);
typeHierarchyResolver.process(outerScope, owner, declarations); typeHierarchyResolver.process(outerScope, owner, declarations);
@@ -66,7 +69,10 @@ public class TopDownAnalyzer {
new BodyResolver(semanticServices, trace, typeHierarchyResolver, declarationResolver).resolveBehaviorDeclarationBodies(); new BodyResolver(semanticServices, trace, typeHierarchyResolver, declarationResolver).resolveBehaviorDeclarationBodies();
} }
public void processStandardLibraryNamespace(@NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) { public static void processStandardLibraryNamespace(
@NotNull JetSemanticServices semanticServices,
@NotNull BindingTrace trace,
@NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) {
TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace); TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace);
typeHierarchyResolver.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope()); typeHierarchyResolver.getNamespaceScopes().put(namespace, standardLibraryNamespace.getMemberScope());
typeHierarchyResolver.getNamespaceDescriptors().put(namespace, standardLibraryNamespace); typeHierarchyResolver.getNamespaceDescriptors().put(namespace, standardLibraryNamespace);
@@ -1,37 +0,0 @@
package org.jetbrains.jet.lang.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetNamespace;
import org.jetbrains.jet.lang.psi.JetProperty;
/**
* @author svtk
*/
//public class TopDownAnalyzerForStandardLibrary extends TopDownAnalyzer {
//
// public TopDownAnalyzerForStandardLibrary(JetSemanticServices semanticServices, @NotNull BindingTrace bindingTrace) {
// super(semanticServices, bindingTrace);
// }
//
// public void processStandardLibraryNamespace(@NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, @NotNull JetNamespace namespace) {
// namespaceScopes.put(namespace, standardLibraryNamespace.getMemberScope());
// namespaceDescriptors.put(namespace, standardLibraryNamespace);
// TypeHierarchyResolver typeHierarchyResolver = new TypeHierarchyResolver(semanticServices, trace);
// typeHierarchyResolver.process(outerScope, standardLibraryNamespace, namespace.getDeclarations());
//
// DeclarationResolver declarationResolver = new DeclarationResolver(semanticServices, trace, typeHierarchyResolver);
// declarationResolver.process();
//
// new BodyResolver(semanticServices, trace, typeHierarchyResolver, declarationResolver).resolveBehaviorDeclarationBodies();
// }
//
// @Override
// protected void checkProperty(JetProperty property, PropertyDescriptor propertyDescriptor, ClassDescriptor classDescriptor) {}
//
//
// @Override
// protected void checkFunction(JetNamedFunction function, FunctionDescriptor functionDescriptor, DeclarationDescriptor containingDescriptor) {}
//}
@@ -97,11 +97,10 @@ public class JetStandardLibrary {
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
BindingTraceContext bindingTraceContext = new BindingTraceContext(); BindingTraceContext bindingTraceContext = new BindingTraceContext();
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext);
WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, ErrorHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope"); WritableScopeImpl writableScope = new WritableScopeImpl(JetStandardClasses.STANDARD_CLASSES, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, ErrorHandler.THROW_EXCEPTION).setDebugName("Root bootstrap scope");
// this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); // this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
// bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations()); // bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations());
bootstrappingTDA.processStandardLibraryNamespace(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace()); TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace());
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
AnalyzingUtils.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingTraceContext.getBindingContext()); AnalyzingUtils.applyHandler(ErrorHandler.THROW_EXCEPTION, bindingTraceContext.getBindingContext());
@@ -867,8 +867,7 @@ public class JetTypeInferrer {
//noinspection unchecked //noinspection unchecked
traceAdapter.addHandler(slice, handler); traceAdapter.addHandler(slice, handler);
} }
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, traceAdapter); TopDownAnalyzer.processObject(semanticServices, traceAdapter, context.scope, context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
topDownAnalyzer.processObject(context.scope, context.scope.getContainingDeclaration(), expression.getObjectDeclaration());
return context.services.checkType(result[0], expression, context); return context.services.checkType(result[0], expression, context);
} }
@@ -2514,8 +2513,7 @@ public class JetTypeInferrer {
@Override @Override
public JetType visitObjectDeclaration(JetObjectDeclaration declaration, TypeInferenceContext context) { public JetType visitObjectDeclaration(JetObjectDeclaration declaration, TypeInferenceContext context) {
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, context.trace); TopDownAnalyzer.processObject(semanticServices, context.trace, scope, scope.getContainingDeclaration(), declaration);
topDownAnalyzer.processObject(scope, scope.getContainingDeclaration(), declaration);
ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration); ClassDescriptor classDescriptor = context.trace.getBindingContext().get(BindingContext.CLASS, declaration);
if (classDescriptor != null) { if (classDescriptor != null) {
PropertyDescriptor propertyDescriptor = context.classDescriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(scope.getContainingDeclaration(), declaration, classDescriptor); PropertyDescriptor propertyDescriptor = context.classDescriptorResolver.resolveObjectDeclarationAsPropertyDescriptor(scope.getContainingDeclaration(), declaration, classDescriptor);