| 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..07360511356f75984dda6a0a810ca557bdff24be 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;
|
| @@ -1766,6 +1775,8 @@ class TypeResolver {
|
| type = checkNoTypeArguments(element.computeType(compiler));
|
| } else if (element.isClass) {
|
| ClassElement cls = element;
|
| + // TODO(johnniwinther): [_ensureClassWillBeResolved] should imply
|
| + // [computeType].
|
| compiler.resolver._ensureClassWillBeResolved(cls);
|
| element.computeType(compiler);
|
| var arguments = new LinkBuilder<DartType>();
|
| @@ -1785,8 +1796,9 @@ class TypeResolver {
|
| }
|
| } else if (element.isTypedef) {
|
| TypedefElement typdef = element;
|
| - // TODO(ahe): Should be [ensureResolved].
|
| - compiler.resolveTypedef(typdef);
|
| + // TODO(johnniwinther): [ensureResolved] should imply [computeType].
|
| + typdef.ensureResolved(compiler);
|
| + element.computeType(compiler);
|
| var arguments = new LinkBuilder<DartType>();
|
| bool hasTypeArgumentMismatch = resolveTypeArguments(
|
| visitor, node, typdef.typeVariables, arguments);
|
| @@ -2002,7 +2014,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 +2025,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 +3939,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 +4670,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;
|
|
|