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