Tracing in descriptor resolver refactored
This commit is contained in:
@@ -30,7 +30,10 @@ public class ClassDescriptorResolver {
|
|||||||
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
ClassDescriptorImpl classDescriptor = new ClassDescriptorImpl(
|
||||||
scope.getContainingDeclaration(),
|
scope.getContainingDeclaration(),
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
|
||||||
classElement.getName());
|
safeName(classElement.getName()));
|
||||||
|
|
||||||
|
trace.recordDeclarationResolution(classElement, classDescriptor);
|
||||||
|
|
||||||
WritableScope parameterScope = semanticServices.createWritableScope(scope, classDescriptor);
|
WritableScope parameterScope = semanticServices.createWritableScope(scope, classDescriptor);
|
||||||
|
|
||||||
// This call has side-effects on the parameterScope (fills it in)
|
// This call has side-effects on the parameterScope (fills it in)
|
||||||
@@ -77,7 +80,7 @@ public class ClassDescriptorResolver {
|
|||||||
descriptor,
|
descriptor,
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(classElement.getModifierList()),
|
||||||
!open,
|
!open,
|
||||||
classElement.getName(),
|
safeName(classElement.getName()),
|
||||||
typeParameters,
|
typeParameters,
|
||||||
supertypes);
|
supertypes);
|
||||||
descriptor.setTypeConstructor(
|
descriptor.setTypeConstructor(
|
||||||
@@ -198,7 +201,6 @@ public class ClassDescriptorResolver {
|
|||||||
semanticServices.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
|
semanticServices.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = valueParameter.getName();
|
|
||||||
JetType type;
|
JetType type;
|
||||||
if (typeReference == null) {
|
if (typeReference == null) {
|
||||||
semanticServices.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
|
semanticServices.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
|
||||||
@@ -210,7 +212,7 @@ public class ClassDescriptorResolver {
|
|||||||
functionDescriptor,
|
functionDescriptor,
|
||||||
i,
|
i,
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(valueParameter.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(valueParameter.getModifierList()),
|
||||||
name == null ? "<no name provided>" : name,
|
safeName(valueParameter.getName()),
|
||||||
valueParameter.isMutable() ? type : null,
|
valueParameter.isMutable() ? type : null,
|
||||||
type,
|
type,
|
||||||
valueParameter.getDefaultValue() != null,
|
valueParameter.getDefaultValue() != null,
|
||||||
@@ -244,7 +246,7 @@ public class ClassDescriptorResolver {
|
|||||||
containingDescriptor,
|
containingDescriptor,
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(typeParameter.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(typeParameter.getModifierList()),
|
||||||
typeParameter.getVariance(),
|
typeParameter.getVariance(),
|
||||||
typeParameter.getName(),
|
safeName(typeParameter.getName()),
|
||||||
Collections.singleton(bound),
|
Collections.singleton(bound),
|
||||||
bound
|
bound
|
||||||
);
|
);
|
||||||
@@ -259,16 +261,17 @@ public class ClassDescriptorResolver {
|
|||||||
}
|
}
|
||||||
Collection<JetType> result = new ArrayList<JetType>();
|
Collection<JetType> result = new ArrayList<JetType>();
|
||||||
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
for (JetDelegationSpecifier delegationSpecifier : delegationSpecifiers) {
|
||||||
result.add(resolveType(extensibleScope, delegationSpecifier));
|
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
|
||||||
|
if (typeReference != null) {
|
||||||
|
result.add(typeResolver.resolveType(extensibleScope, typeReference));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.add(ErrorType.createErrorType("No type reference"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetType resolveType(JetScope scope, JetDelegationSpecifier delegationSpecifier) {
|
|
||||||
JetTypeReference typeReference = delegationSpecifier.getTypeReference(); // TODO : make it not null
|
|
||||||
return typeResolver.resolveType(scope, typeReference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PropertyDescriptor resolveValueParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter) {
|
public PropertyDescriptor resolveValueParameterDescriptor(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope scope, @NotNull JetParameter parameter) {
|
||||||
JetType type = getParameterType(scope, parameter);
|
JetType type = getParameterType(scope, parameter);
|
||||||
@@ -292,7 +295,7 @@ public class ClassDescriptorResolver {
|
|||||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptorImpl(
|
PropertyDescriptor propertyDescriptor = new PropertyDescriptorImpl(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(parameter.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(parameter.getModifierList()),
|
||||||
parameter.getName(),
|
safeName(parameter.getName()),
|
||||||
parameter.isMutable() ? null : type,
|
parameter.isMutable() ? null : type,
|
||||||
type);
|
type);
|
||||||
trace.recordDeclarationResolution(parameter, propertyDescriptor);
|
trace.recordDeclarationResolution(parameter, propertyDescriptor);
|
||||||
@@ -320,7 +323,7 @@ public class ClassDescriptorResolver {
|
|||||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||||
containingDeclaration,
|
containingDeclaration,
|
||||||
AttributeResolver.INSTANCE.resolveAttributes(property.getModifierList()),
|
AttributeResolver.INSTANCE.resolveAttributes(property.getModifierList()),
|
||||||
property.getName(),
|
safeName(property.getName()),
|
||||||
property.isVar() ? type : null,
|
property.isVar() ? type : null,
|
||||||
type);
|
type);
|
||||||
trace.recordDeclarationResolution(property, propertyDescriptor);
|
trace.recordDeclarationResolution(property, propertyDescriptor);
|
||||||
@@ -389,4 +392,9 @@ public class ClassDescriptorResolver {
|
|||||||
trace.recordDeclarationResolution(parameter, propertyDescriptor);
|
trace.recordDeclarationResolution(parameter, propertyDescriptor);
|
||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static String safeName(String name) {
|
||||||
|
return name == null ? "<no name provided>" : name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,13 @@ public class TopDownAnalyzer {
|
|||||||
private final JetSemanticServices semanticServices;
|
private final JetSemanticServices semanticServices;
|
||||||
private final ClassDescriptorResolver classDescriptorResolver;
|
private final ClassDescriptorResolver classDescriptorResolver;
|
||||||
private final BindingTrace trace;
|
private final BindingTrace trace;
|
||||||
|
private final JetTypeInferrer typeInferrer;
|
||||||
|
|
||||||
public TopDownAnalyzer(JetSemanticServices semanticServices, @NotNull BindingTrace bindingTrace) {
|
public TopDownAnalyzer(JetSemanticServices semanticServices, @NotNull BindingTrace bindingTrace) {
|
||||||
this.semanticServices = semanticServices;
|
this.semanticServices = semanticServices;
|
||||||
this.classDescriptorResolver = new ClassDescriptorResolver(semanticServices, bindingTrace);
|
this.classDescriptorResolver = new ClassDescriptorResolver(semanticServices, bindingTrace);
|
||||||
this.trace = bindingTrace;
|
this.trace = bindingTrace;
|
||||||
|
this.typeInferrer = semanticServices.getTypeInferrer(trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(@NotNull JetScope outerScope, @NotNull JetDeclaration declaration) {
|
public void process(@NotNull JetScope outerScope, @NotNull JetDeclaration declaration) {
|
||||||
@@ -58,6 +60,9 @@ public class TopDownAnalyzer {
|
|||||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||||
|
|
||||||
String name = namespace.getName();
|
String name = namespace.getName();
|
||||||
|
if (name == null) {
|
||||||
|
name = "<no name provided>";
|
||||||
|
}
|
||||||
NamespaceDescriptor namespaceDescriptor = declaringScope.getDeclaredNamespace(name);
|
NamespaceDescriptor namespaceDescriptor = declaringScope.getDeclaredNamespace(name);
|
||||||
if (namespaceDescriptor == null) {
|
if (namespaceDescriptor == null) {
|
||||||
namespaceDescriptor = new NamespaceDescriptor(
|
namespaceDescriptor = new NamespaceDescriptor(
|
||||||
@@ -78,9 +83,11 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
if (importDirective.isAllUnder()) {
|
if (importDirective.isAllUnder()) {
|
||||||
JetExpression importedReference = importDirective.getImportedReference();
|
JetExpression importedReference = importDirective.getImportedReference();
|
||||||
JetType type = semanticServices.getTypeInferrer(trace).getType(namespaceScope, importedReference, false);
|
if (importedReference != null) {
|
||||||
if (type != null) {
|
JetType type = typeInferrer.getType(namespaceScope, importedReference, false);
|
||||||
namespaceScope.importScope(type.getMemberScope());
|
if (type != null) {
|
||||||
|
namespaceScope.importScope(type.getMemberScope());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -110,7 +117,6 @@ public class TopDownAnalyzer {
|
|||||||
declaringScope.addClassDescriptor(mutableClassDescriptor);
|
declaringScope.addClassDescriptor(mutableClassDescriptor);
|
||||||
|
|
||||||
classes.put(klass, mutableClassDescriptor);
|
classes.put(klass, mutableClassDescriptor);
|
||||||
trace.recordDeclarationResolution(klass, mutableClassDescriptor);
|
|
||||||
declaringScopes.put(klass, declaringScope);
|
declaringScopes.put(klass, declaringScope);
|
||||||
|
|
||||||
return mutableClassDescriptor.getUnsubstitutedMemberScope();
|
return mutableClassDescriptor.getUnsubstitutedMemberScope();
|
||||||
@@ -218,7 +224,6 @@ public class TopDownAnalyzer {
|
|||||||
FunctionDescriptor descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope.getContainingDeclaration(), declaringScope, function);
|
FunctionDescriptor descriptor = classDescriptorResolver.resolveFunctionDescriptor(declaringScope.getContainingDeclaration(), declaringScope, function);
|
||||||
declaringScope.addFunctionDescriptor(descriptor);
|
declaringScope.addFunctionDescriptor(descriptor);
|
||||||
functions.put(function, descriptor);
|
functions.put(function, descriptor);
|
||||||
trace.recordDeclarationResolution(function, descriptor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processProperty(WritableScope declaringScope, JetProperty property) {
|
private void processProperty(WritableScope declaringScope, JetProperty property) {
|
||||||
@@ -258,7 +263,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void resolveExpression(@NotNull JetScope scope, JetExpression expression, boolean preferBlock) {
|
private void resolveExpression(@NotNull JetScope scope, JetExpression expression, boolean preferBlock) {
|
||||||
semanticServices.getTypeInferrer(trace).getType(scope, expression, preferBlock);
|
typeInferrer.getType(scope, expression, preferBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -644,7 +644,7 @@ public class JetTypeInferrer {
|
|||||||
JetTypeReference typeReference = loopParameter.getTypeReference();
|
JetTypeReference typeReference = loopParameter.getTypeReference();
|
||||||
PropertyDescriptor propertyDescriptor;
|
PropertyDescriptor propertyDescriptor;
|
||||||
if (typeReference != null) {
|
if (typeReference != null) {
|
||||||
propertyDescriptor = semanticServices.getClassDescriptorResolver(trace).resolveValueParameterDescriptor(scope.getContainingDeclaration(), scope, loopParameter);
|
propertyDescriptor = classDescriptorResolver.resolveValueParameterDescriptor(scope.getContainingDeclaration(), scope, loopParameter);
|
||||||
JetType actualParameterType = propertyDescriptor.getOutType();
|
JetType actualParameterType = propertyDescriptor.getOutType();
|
||||||
if (expectedParameterType != null &&
|
if (expectedParameterType != null &&
|
||||||
!semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
|
!semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
|
||||||
@@ -655,7 +655,7 @@ public class JetTypeInferrer {
|
|||||||
if (expectedParameterType == null) {
|
if (expectedParameterType == null) {
|
||||||
expectedParameterType = ErrorType.createErrorType("Error");
|
expectedParameterType = ErrorType.createErrorType("Error");
|
||||||
}
|
}
|
||||||
propertyDescriptor = semanticServices.getClassDescriptorResolver(trace).resolveValueParameterDescriptor(scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
propertyDescriptor = classDescriptorResolver.resolveValueParameterDescriptor(scope.getContainingDeclaration(), loopParameter, expectedParameterType);
|
||||||
}
|
}
|
||||||
loopScope.addPropertyDescriptor(propertyDescriptor);
|
loopScope.addPropertyDescriptor(propertyDescriptor);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class NamespaceDescriptor extends DeclarationDescriptorImpl {
|
|||||||
|
|
||||||
private JetScope memberScope;
|
private JetScope memberScope;
|
||||||
|
|
||||||
public NamespaceDescriptor(@Nullable DeclarationDescriptor containingDeclaration, List<Attribute> attributes, String name) {
|
public NamespaceDescriptor(@Nullable DeclarationDescriptor containingDeclaration, @NotNull List<Attribute> attributes, @NotNull String name) {
|
||||||
super(containingDeclaration, attributes, name);
|
super(containingDeclaration, attributes, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user