Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/resolution/members.dart b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| index 2ffddf4b9f5deee84e13f3f2d0ae03fd5b093235..153ed6cdc7d8d5177824e8630cc3613b2ab2dc7d 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/resolution/members.dart |
| @@ -259,8 +259,11 @@ class ResolverTask extends CompilerTask { |
| return measure(() { |
| if (Elements.isErroneousElement(element)) return null; |
| - for (MetadataAnnotation metadata in element.metadata) { |
| - metadata.ensureResolved(compiler); |
| + processMetadata([result]) { |
| + for (MetadataAnnotation metadata in element.metadata) { |
| + metadata.ensureResolved(compiler); |
| + } |
| + return result; |
| } |
| ElementKind kind = element.kind; |
| @@ -268,18 +271,19 @@ class ResolverTask extends CompilerTask { |
| identical(kind, ElementKind.FUNCTION) || |
| identical(kind, ElementKind.GETTER) || |
| identical(kind, ElementKind.SETTER)) { |
| - return resolveMethodElement(element); |
| + return processMetadata(resolveMethodElement(element)); |
| } |
| - if (identical(kind, ElementKind.FIELD)) return resolveField(element); |
| - |
| + if (identical(kind, ElementKind.FIELD)) { |
| + return processMetadata(resolveField(element)); |
| + } |
| if (element.isClass) { |
| ClassElement cls = element; |
| cls.ensureResolved(compiler); |
| - return null; |
| + return processMetadata(); |
| } else if (element.isTypedef) { |
| TypedefElement typdef = element; |
| - return resolveTypedef(typdef); |
| + return processMetadata(resolveTypedef(typdef)); |
| } |
| compiler.unimplemented(element, "resolve($element)"); |
| @@ -546,11 +550,16 @@ class ResolverTask extends CompilerTask { |
| }); |
| } |
| + /// Creates a [ResolverVisitor] for resolving an AST in context of [element]. |
| + /// If [useEnclosingScope] is `true` then the initial scope of the visitor |
| + /// does not include inner scope of [element]. |
| + /// |
| /// This method should only be used by this library (or tests of |
| /// this library). |
| - ResolverVisitor visitorFor(Element element) { |
| + ResolverVisitor visitorFor(Element element, {bool useEnclosingScope: false}) { |
| return new ResolverVisitor(compiler, element, |
| - new ResolutionRegistry(compiler, element)); |
| + new ResolutionRegistry(compiler, element), |
| + useEnclosingScope: useEnclosingScope); |
| } |
| TreeElements resolveField(VariableElementX element) { |
| @@ -1175,12 +1184,14 @@ class ResolverTask extends CompilerTask { |
| ResolutionRegistry registry = new ResolutionRegistry(compiler, element); |
| return compiler.withCurrentElement(element, () { |
| return measure(() { |
| + assert(element.resolutionState == STATE_NOT_STARTED); |
| + element.resolutionState = STATE_STARTED; |
| Typedef node = |
| compiler.parser.measure(() => element.parseNode(compiler)); |
| TypedefResolverVisitor visitor = |
| new TypedefResolverVisitor(compiler, element, registry); |
| visitor.visit(node); |
| - |
| + element.resolutionState = STATE_DONE; |
| return registry.mapping; |
| }); |
| }); |
| @@ -1193,14 +1204,12 @@ class ResolverTask extends CompilerTask { |
| annotation.resolutionState = STATE_STARTED; |
| Node node = annotation.parseNode(compiler); |
| - // TODO(johnniwinther): Find the right analyzable element to hold the |
| - // [TreeElements] for the annotation. |
| Element annotatedElement = annotation.annotatedElement; |
| - Element context = annotatedElement.enclosingElement; |
| - if (context == null) { |
| - context = annotatedElement; |
| - } |
| - ResolverVisitor visitor = visitorFor(context); |
| + AnalyzableElement context = annotatedElement.analyzableElement; |
| + assert(invariant(node, context != null, |
| + message: "No context found for metadata annotation " |
| + "on $annotatedElement.")); |
| + ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true); |
| ResolutionRegistry registry = visitor.registry; |
| node.accept(visitor); |
| // TODO(johnniwinther): Avoid passing the [TreeElements] to |
| @@ -1208,8 +1217,8 @@ class ResolverTask extends CompilerTask { |
| annotation.value = |
| constantCompiler.compileMetadata(annotation, node, registry.mapping); |
| // TODO(johnniwinther): Register the relation between the annotation |
| - // and the annotated element instead. This will allow the backed to |
| - // retrieve the backend constant and only registered metadata on the |
| + // and the annotated element instead. This will allow the backend to |
| + // retrieve the backend constant and only register metadata on the |
| // elements for which it is needed. (Issue 17732). |
| registry.registerMetadataConstant(annotation.value); |
| annotation.resolutionState = STATE_DONE; |
| @@ -1785,8 +1794,8 @@ class TypeResolver { |
| } |
| } else if (element.isTypedef) { |
| TypedefElement typdef = element; |
| - // TODO(ahe): Should be [ensureResolved]. |
| - compiler.resolveTypedef(typdef); |
| + typdef.ensureResolved(compiler); |
|
karlklose
2014/05/27 07:52:46
Add a TODO that resolution should imply that the t
Johnni Winther
2014/05/27 08:43:32
Done.
|
| + element.computeType(compiler); |
| var arguments = new LinkBuilder<DartType>(); |
| bool hasTypeArgumentMismatch = resolveTypeArguments( |
| visitor, node, typdef.typeVariables, arguments); |
| @@ -2002,7 +2011,8 @@ class ResolverVisitor extends MappingVisitor<Element> { |
| ResolverVisitor(Compiler compiler, |
| Element element, |
| - ResolutionRegistry registry) |
| + ResolutionRegistry registry, |
| + {bool useEnclosingScope: false}) |
| : this.enclosingElement = element, |
| // When the element is a field, we are actually resolving its |
| // initial value, which should not have access to instance |
| @@ -2012,7 +2022,8 @@ class ResolverVisitor extends MappingVisitor<Element> { |
| this.currentClass = element.isMember ? element.enclosingClass |
| : null, |
| this.statementScope = new StatementScope(), |
| - scope = element.buildScope(), |
| + scope = useEnclosingScope |
| + ? Scope.buildEnclosingScope(element) : element.buildScope(), |
| // The type annotations on a typedef do not imply type checks. |
| // TODO(karlklose): clean this up (dartbug.com/8870). |
| inCheckContext = compiler.enableTypeAssertions && |
| @@ -3925,7 +3936,7 @@ class TypedefCyclicVisitor extends DartTypeVisitor { |
| * types. |
| */ |
| class ClassResolverVisitor extends TypeDefinitionVisitor { |
| - ClassElement get element => enclosingElement; |
| + BaseClassElementX get element => enclosingElement; |
| ClassResolverVisitor(Compiler compiler, |
| ClassElement classElement, |
| @@ -4656,14 +4667,14 @@ Element lookupInScope(Compiler compiler, Node node, |
| return Elements.unwrap(scope.lookup(name), compiler, node); |
| } |
| -TreeElements _ensureTreeElements(AnalyzableElement element) { |
| +TreeElements _ensureTreeElements(AnalyzableElementX element) { |
| if (element._treeElements == null) { |
| element._treeElements = new TreeElementMapping(element); |
| } |
| return element._treeElements; |
| } |
| -abstract class AnalyzableElement implements Element { |
| +abstract class AnalyzableElementX implements AnalyzableElement { |
| TreeElements _treeElements; |
| bool get hasTreeElements => _treeElements != null; |