Tracing in descriptor resolver refactored

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