Store scope for body resolution in ScriptDescriptor

This commit is contained in:
Andrey Breslav
2014-03-27 17:46:50 +04:00
parent 3e957031b9
commit 5ef329b713
10 changed files with 21 additions and 28 deletions
@@ -131,7 +131,6 @@ public class ReplInterpreter {
}
private static void prepareForTheNextReplLine(@NotNull TopDownAnalysisContext c) {
c.getScriptScopes().clear();
c.getScripts().clear();
}
@@ -29,7 +29,6 @@ import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager;
@@ -56,8 +55,6 @@ public interface BodiesResolveContext extends GlobalContext {
Function<JetDeclaration, JetScope> getDeclaringScopes();
@Mutable
Map<JetScript, ScriptDescriptor> getScripts();
@Mutable
Map<JetScript, WritableScope> getScriptScopes();
DataFlowInfo getOuterDataFlowInfo();
@NotNull
@@ -46,7 +46,6 @@ public class CachedBodiesResolveContext implements BodiesResolveContext {
private final Map<JetNamedFunction, SimpleFunctionDescriptor> functions;
private final Function<JetDeclaration, JetScope> declaringScopes;
private final Map<JetScript, ScriptDescriptor> scripts;
private final Map<JetScript, WritableScope> scriptScopes;
private final DataFlowInfo outerDataFlowInfo;
private @NotNull TopDownAnalysisParameters topDownAnalysisParameters;
@@ -58,7 +57,6 @@ public class CachedBodiesResolveContext implements BodiesResolveContext {
functions = Collections.unmodifiableMap(context.getFunctions());
declaringScopes = context.getDeclaringScopes();
scripts = Collections.unmodifiableMap(context.getScripts());
scriptScopes = Collections.unmodifiableMap(context.getScriptScopes());
outerDataFlowInfo = context.getOuterDataFlowInfo();
topDownAnalysisParameters = context.getTopDownAnalysisParameters();
@@ -106,11 +104,6 @@ public class CachedBodiesResolveContext implements BodiesResolveContext {
return scripts;
}
@Override
public Map<JetScript, WritableScope> getScriptScopes() {
return scriptScopes;
}
@Override
public DataFlowInfo getOuterDataFlowInfo() {
return outerDataFlowInfo;
@@ -80,7 +80,7 @@ public class ImportsResolver {
}
// SCRIPT: process script import directives
for (JetScript script : c.getScripts().keySet()) {
WritableScope scriptScope = c.getScriptScopes().get(script);
WritableScope scriptScope = ((ScriptDescriptorImpl) c.getScripts().get(script)).getScopeForBodyResolution();
processImportsInFile(lookupMode, scriptScope, script.getImportDirectives(), true);
}
}
@@ -69,7 +69,7 @@ public class ScriptBodyResolver {
for (Map.Entry<JetScript, ScriptDescriptor> e : c.getScripts().entrySet()) {
JetScript declaration = e.getKey();
ScriptDescriptorImpl descriptor = (ScriptDescriptorImpl) e.getValue();
WritableScope scope = c.getScriptScopes().get(declaration);
WritableScope scope = descriptor.getScopeForBodyResolution();
// TODO: lock in resolveScriptDeclarations
scope.changeLockLevel(WritableScope.LockLevel.READING);
@@ -107,12 +107,12 @@ public class ScriptHeaderResolver {
FqName nameForScript = ScriptNameUtil.classNameForScript((JetFile) script.getContainingFile());
Name className = nameForScript.shortName();
ScriptDescriptor scriptDescriptor = new ScriptDescriptorImpl(ns, priority, outerScope, className);
ScriptDescriptorImpl scriptDescriptor = new ScriptDescriptorImpl(ns, priority, outerScope, className);
WritableScopeImpl scriptScope = new WritableScopeImpl(outerScope, scriptDescriptor, RedeclarationHandler.DO_NOTHING, "script");
scriptScope.changeLockLevel(WritableScope.LockLevel.BOTH);
scriptDescriptor.setScopeForBodyResolution(scriptScope);
c.getScriptScopes().put(script, scriptScope);
c.getScripts().put(script, scriptDescriptor);
trace.record(BindingContext.SCRIPT, script, scriptDescriptor);
@@ -129,7 +129,7 @@ public class ScriptHeaderResolver {
for (Map.Entry<JetScript, ScriptDescriptor> e : c.getScripts().entrySet()) {
JetScript declaration = e.getKey();
ScriptDescriptorImpl descriptor = (ScriptDescriptorImpl) e.getValue();
WritableScope scope = c.getScriptScopes().get(declaration);
WritableScope scope = descriptor.getScopeForBodyResolution();
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
@@ -58,7 +58,6 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
public final Map<JetDeclarationContainer, JetScope> normalScope = Maps.newHashMap();
private final Map<JetScript, ScriptDescriptor> scripts = Maps.newLinkedHashMap();
private final Map<JetScript, WritableScope> scriptScopes = Maps.newHashMap();
private StringBuilder debugOutput;
@@ -148,12 +147,6 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
return scripts;
}
@Override
@NotNull
public Map<JetScript, WritableScope> getScriptScopes() {
return scriptScopes;
}
public Map<JetParameter, PropertyDescriptor> getPrimaryConstructorParameterProperties() {
return primaryConstructorParameterProperties;
}
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.descriptors.impl.ScriptCodeDescriptor;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
public interface ScriptDescriptor extends Annotated, DeclarationDescriptor, DeclarationDescriptorNonRoot {
String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
@@ -35,4 +36,7 @@ public interface ScriptDescriptor extends Annotated, DeclarationDescriptor, Decl
@NotNull
ClassDescriptor getClassDescriptor();
@NotNull
JetScope getScopeForBodyResolution();
}
@@ -52,6 +52,7 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
private final ClassDescriptorImpl classDescriptor;
private final WritableScopeImpl classScope;
private WritableScope scopeForBodyResolution;
public ScriptDescriptorImpl(
@NotNull DeclarationDescriptor containingDeclaration,
@@ -175,4 +176,15 @@ public class ScriptDescriptorImpl extends DeclarationDescriptorNonRootImpl imple
public ClassDescriptor getClassDescriptor() {
return classDescriptor;
}
@Override
@NotNull
public WritableScope getScopeForBodyResolution() {
return scopeForBodyResolution;
}
public void setScopeForBodyResolution(@NotNull WritableScope scopeForBodyResolution) {
assert this.scopeForBodyResolution == null : "Scope for body resolution already set for " + this;
this.scopeForBodyResolution = scopeForBodyResolution;
}
}
@@ -482,11 +482,6 @@ public class ResolveElementCache {
return Collections.emptyMap();
}
@Override
public Map<JetScript, WritableScope> getScriptScopes() {
return Collections.emptyMap();
}
@Override
public DataFlowInfo getOuterDataFlowInfo() {
return DataFlowInfo.EMPTY;