Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: pkg/compiler/lib/src/resolution/resolution.dart

Issue 1302333006: Support metadata on patches. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Remove partial renaming Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.resolution; 5 library dart2js.resolution;
6 6
7 import 'dart:collection' show Queue; 7 import 'dart:collection' show Queue;
8 8
9 import '../common/names.dart' show 9 import '../common/names.dart' show
10 Identifiers; 10 Identifiers;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return measure(() { 71 return measure(() {
72 if (Elements.isErroneous(element)) { 72 if (Elements.isErroneous(element)) {
73 // TODO(johnniwinther): Add a predicate for this. 73 // TODO(johnniwinther): Add a predicate for this.
74 assert(invariant(element, element is! ErroneousElement, 74 assert(invariant(element, element is! ErroneousElement,
75 message: "Element $element expected to have parse errors.")); 75 message: "Element $element expected to have parse errors."));
76 _ensureTreeElements(element); 76 _ensureTreeElements(element);
77 return const WorldImpact(); 77 return const WorldImpact();
78 } 78 }
79 79
80 WorldImpact processMetadata([WorldImpact result]) { 80 WorldImpact processMetadata([WorldImpact result]) {
81 for (MetadataAnnotation metadata in element.metadata) { 81 for (MetadataAnnotation metadata in element.implementation.metadata) {
82 metadata.ensureResolved(compiler); 82 metadata.ensureResolved(compiler);
83 } 83 }
84 return result; 84 return result;
85 } 85 }
86 86
87 ElementKind kind = element.kind; 87 ElementKind kind = element.kind;
88 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) || 88 if (identical(kind, ElementKind.GENERATIVE_CONSTRUCTOR) ||
89 identical(kind, ElementKind.FUNCTION) || 89 identical(kind, ElementKind.FUNCTION) ||
90 identical(kind, ElementKind.GETTER) || 90 identical(kind, ElementKind.GETTER) ||
91 identical(kind, ElementKind.SETTER)) { 91 identical(kind, ElementKind.SETTER)) {
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 // Stepwise assignment to ensure invariant. 587 // Stepwise assignment to ensure invariant.
588 element.supertypeLoadState = STATE_STARTED; 588 element.supertypeLoadState = STATE_STARTED;
589 element.supertypeLoadState = STATE_DONE; 589 element.supertypeLoadState = STATE_DONE;
590 element.resolutionState = STATE_DONE; 590 element.resolutionState = STATE_DONE;
591 // TODO(johnniwinther): Check matching type variables and 591 // TODO(johnniwinther): Check matching type variables and
592 // empty extends/implements clauses. 592 // empty extends/implements clauses.
593 } 593 }
594 } 594 }
595 595
596 void _postProcessClassElement(BaseClassElementX element) { 596 void _postProcessClassElement(BaseClassElementX element) {
597 for (MetadataAnnotation metadata in element.metadata) { 597 for (MetadataAnnotation metadata in element.implementation.metadata) {
598 metadata.ensureResolved(compiler); 598 metadata.ensureResolved(compiler);
599 ConstantValue value = 599 ConstantValue value =
600 compiler.constants.getConstantValue(metadata.constant); 600 compiler.constants.getConstantValue(metadata.constant);
601 if (!element.isProxy && value == compiler.proxyConstant) { 601 if (!element.isProxy && value == compiler.proxyConstant) {
602 element.isProxy = true; 602 element.isProxy = true;
603 } 603 }
604 } 604 }
605 605
606 // Force resolution of metadata on non-instance members since they may be 606 // Force resolution of metadata on non-instance members since they may be
607 // inspected by the backend while emitting. Metadata on instance members is 607 // inspected by the backend while emitting. Metadata on instance members is
608 // handled as a result of processing instantiated class members in the 608 // handled as a result of processing instantiated class members in the
609 // enqueuer. 609 // enqueuer.
610 // TODO(ahe): Avoid this eager resolution. 610 // TODO(ahe): Avoid this eager resolution.
611 element.forEachMember((_, Element member) { 611 element.forEachMember((_, Element member) {
612 if (!member.isInstanceMember) { 612 if (!member.isInstanceMember) {
613 compiler.withCurrentElement(member, () { 613 compiler.withCurrentElement(member, () {
614 for (MetadataAnnotation metadata in member.metadata) { 614 for (MetadataAnnotation metadata in member.implementation.metadata) {
615 metadata.ensureResolved(compiler); 615 metadata.ensureResolved(compiler);
616 } 616 }
617 }); 617 });
618 } 618 }
619 }); 619 });
620 620
621 computeClassMember(element, Identifiers.call); 621 computeClassMember(element, Identifiers.call);
622 } 622 }
623 623
624 void computeClassMembers(ClassElement element) { 624 void computeClassMembers(ClassElement element) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 assert(invariant(node, context != null, 989 assert(invariant(node, context != null,
990 message: "No context found for metadata annotation " 990 message: "No context found for metadata annotation "
991 "on $annotatedElement.")); 991 "on $annotatedElement."));
992 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true); 992 ResolverVisitor visitor = visitorFor(context, useEnclosingScope: true);
993 ResolutionRegistry registry = visitor.registry; 993 ResolutionRegistry registry = visitor.registry;
994 node.accept(visitor); 994 node.accept(visitor);
995 // TODO(johnniwinther): Avoid passing the [TreeElements] to 995 // TODO(johnniwinther): Avoid passing the [TreeElements] to
996 // [compileMetadata]. 996 // [compileMetadata].
997 annotation.constant = 997 annotation.constant =
998 constantCompiler.compileMetadata(annotation, node, registry.mapping); 998 constantCompiler.compileMetadata(annotation, node, registry.mapping);
999 constantCompiler.evaluate(annotation.constant);
999 // TODO(johnniwinther): Register the relation between the annotation 1000 // TODO(johnniwinther): Register the relation between the annotation
1000 // and the annotated element instead. This will allow the backend to 1001 // and the annotated element instead. This will allow the backend to
1001 // retrieve the backend constant and only register metadata on the 1002 // retrieve the backend constant and only register metadata on the
1002 // elements for which it is needed. (Issue 17732). 1003 // elements for which it is needed. (Issue 17732).
1003 registry.registerMetadataConstant(annotation, annotatedElement); 1004 registry.registerMetadataConstant(annotation, annotatedElement);
1004 annotation.resolutionState = STATE_DONE; 1005 annotation.resolutionState = STATE_DONE;
1005 })); 1006 }));
1006 } 1007 }
1007 1008
1008 error(Spannable node, MessageKind kind, [arguments = const {}]) { 1009 error(Spannable node, MessageKind kind, [arguments = const {}]) {
1009 compiler.reportError(node, kind, arguments); 1010 compiler.reportError(node, kind, arguments);
1010 } 1011 }
1011 1012
1012 Link<MetadataAnnotation> resolveMetadata(Element element, 1013 List<MetadataAnnotation> resolveMetadata(Element element,
1013 VariableDefinitions node) { 1014 VariableDefinitions node) {
1014 LinkBuilder<MetadataAnnotation> metadata = 1015 List<MetadataAnnotation> metadata = <MetadataAnnotation>[];
1015 new LinkBuilder<MetadataAnnotation>();
1016 for (Metadata annotation in node.metadata.nodes) { 1016 for (Metadata annotation in node.metadata.nodes) {
1017 ParameterMetadataAnnotation metadataAnnotation = 1017 ParameterMetadataAnnotation metadataAnnotation =
1018 new ParameterMetadataAnnotation(annotation); 1018 new ParameterMetadataAnnotation(annotation);
1019 metadataAnnotation.annotatedElement = element; 1019 metadataAnnotation.annotatedElement = element;
1020 metadata.addLast(metadataAnnotation.ensureResolved(compiler)); 1020 metadata.add(metadataAnnotation.ensureResolved(compiler));
1021 } 1021 }
1022 return metadata.toLink(); 1022 return metadata;
1023 } 1023 }
1024 } 1024 }
1025 1025
1026 TreeElements _ensureTreeElements(AnalyzableElementX element) { 1026 TreeElements _ensureTreeElements(AnalyzableElementX element) {
1027 if (element._treeElements == null) { 1027 if (element._treeElements == null) {
1028 element._treeElements = new TreeElementMapping(element); 1028 element._treeElements = new TreeElementMapping(element);
1029 } 1029 }
1030 return element._treeElements; 1030 return element._treeElements;
1031 } 1031 }
1032 1032
1033 abstract class AnalyzableElementX implements AnalyzableElement { 1033 abstract class AnalyzableElementX implements AnalyzableElement {
1034 TreeElements _treeElements; 1034 TreeElements _treeElements;
1035 1035
1036 bool get hasTreeElements => _treeElements != null; 1036 bool get hasTreeElements => _treeElements != null;
1037 1037
1038 TreeElements get treeElements { 1038 TreeElements get treeElements {
1039 assert(invariant(this, _treeElements !=null, 1039 assert(invariant(this, _treeElements !=null,
1040 message: "TreeElements have not been computed for $this.")); 1040 message: "TreeElements have not been computed for $this."));
1041 return _treeElements; 1041 return _treeElements;
1042 } 1042 }
1043 1043
1044 void reuseElement() { 1044 void reuseElement() {
1045 _treeElements = null; 1045 _treeElements = null;
1046 } 1046 }
1047 } 1047 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698