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

Side by Side Diff: pkg/compiler/lib/src/serialization/modelz.dart

Issue 2070493003: Revert "Remove Registry from registerMetadataConstant" and "Serialize metadata" (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « pkg/compiler/lib/src/serialization/keys.dart ('k') | pkg/compiler/lib/src/types/constants.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 /// Implementation of the element model used for deserialiation. 5 /// Implementation of the element model used for deserialiation.
6 /// 6 ///
7 /// These classes are created by [ElementDeserializer] triggered by the 7 /// These classes are created by [ElementDeserializer] triggered by the
8 /// [Deserializer]. 8 /// [Deserializer].
9 9
10 library dart2js.serialization.modelz; 10 library dart2js.serialization.modelz;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 @override 106 @override
107 bool get isStatic => false; 107 bool get isStatic => false;
108 108
109 @override 109 @override
110 bool get isSynthesized => false; 110 bool get isSynthesized => false;
111 111
112 @override 112 @override
113 bool get isTopLevel => false; 113 bool get isTopLevel => false;
114 114
115 // TODO(johnniwinther): Support metadata.
115 @override 116 @override
116 Iterable<MetadataAnnotation> get metadata => const <MetadataAnnotation>[]; 117 Iterable<MetadataAnnotation> get metadata => const <MetadataAnnotation>[];
117 118
118 @override 119 @override
119 Token get position => _unsupported('position'); 120 Token get position => _unsupported('position');
120 } 121 }
121 122
122 abstract class DeserializedElementZ extends ElementZ { 123 abstract class DeserializedElementZ extends ElementZ {
123 ObjectDecoder _decoder; 124 ObjectDecoder _decoder;
124 List<MetadataAnnotation> _metadata;
125 125
126 DeserializedElementZ(this._decoder); 126 DeserializedElementZ(this._decoder);
127 127
128 @override 128 @override
129 String get name => _decoder.getString(Key.NAME); 129 String get name => _decoder.getString(Key.NAME);
130 130
131 // TODO(johnniwinther): Should this be cached? 131 // TODO(johnniwinther): Should this be cached?
132 @override 132 @override
133 int get sourceOffset => _decoder.getInt(Key.OFFSET, isOptional: true); 133 int get sourceOffset => _decoder.getInt(Key.OFFSET, isOptional: true);
134 134
135 @override 135 @override
136 SourceSpan get sourcePosition { 136 SourceSpan get sourcePosition {
137 // TODO(johnniwinther): Should this be cached? 137 // TODO(johnniwinther): Should this be cached?
138 int offset = sourceOffset; 138 int offset = sourceOffset;
139 if (offset == null) return null; 139 if (offset == null) return null;
140 Uri uri = _decoder.getUri(Key.URI, isOptional: true); 140 Uri uri = _decoder.getUri(Key.URI, isOptional: true);
141 if (uri == null) { 141 if (uri == null) {
142 uri = compilationUnit.script.readableUri; 142 uri = compilationUnit.script.readableUri;
143 } 143 }
144 int length = _decoder.getInt(Key.LENGTH, isOptional: true); 144 int length = _decoder.getInt(Key.LENGTH, isOptional: true);
145 if (length == null) { 145 if (length == null) {
146 length = name.length; 146 length = name.length;
147 } 147 }
148 return new SourceSpan(uri, offset, offset + length); 148 return new SourceSpan(uri, offset, offset + length);
149 } 149 }
150
151 @override
152 Iterable<MetadataAnnotation> get metadata {
153 if (_metadata == null) {
154 _metadata = <MetadataAnnotation>[];
155 ListDecoder list = _decoder.getList(Key.METADATA, isOptional: true);
156 if (list != null) {
157 for (int index = 0; index < list.length; index++) {
158 ObjectDecoder object = list.getObject(index);
159 Element element = object.getElement(Key.ELEMENT);
160 Uri uri = object.getUri(Key.URI);
161 int offset = object.getInt(Key.OFFSET);
162 int length = object.getInt(Key.LENGTH);
163 ConstantExpression constant = object.getConstant(Key.CONSTANT);
164 _metadata.add(new MetadataAnnotationZ(
165 element, new SourceSpan(uri, offset, offset + length), constant));
166 }
167 }
168 }
169 return _metadata;
170 }
171 } 150 }
172 151
173 /// Deserializer for a collection of member elements serialized as a map from 152 /// Deserializer for a collection of member elements serialized as a map from
174 /// names to element declarations. 153 /// names to element declarations.
175 /// 154 ///
176 /// The serialized data contains the declared getters and setters but lookup 155 /// The serialized data contains the declared getters and setters but lookup
177 /// into the map returns an [AbstractFieldElement] for pairs of corresponding 156 /// into the map returns an [AbstractFieldElement] for pairs of corresponding
178 /// getters and setters. 157 /// getters and setters.
179 /// 158 ///
180 /// The underlying map encoding allows for lazy computation of the members upon 159 /// The underlying map encoding allows for lazy computation of the members upon
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 @override 939 @override
961 Link<DartType> get interfaces { 940 Link<DartType> get interfaces {
962 _ensureSuperHierarchy(); 941 _ensureSuperHierarchy();
963 return _interfaces; 942 return _interfaces;
964 } 943 }
965 944
966 @override 945 @override
967 bool get isProxy => _decoder.getBool(Key.IS_PROXY); 946 bool get isProxy => _decoder.getBool(Key.IS_PROXY);
968 947
969 @override 948 @override
970 bool get isInjected => _decoder.getBool(Key.IS_INJECTED);
971
972 @override
973 bool get isUnnamedMixinApplication => false; 949 bool get isUnnamedMixinApplication => false;
974 950
975 @override 951 @override
976 FunctionType get callType { 952 FunctionType get callType {
977 _ensureSuperHierarchy(); 953 _ensureSuperHierarchy();
978 // TODO(johnniwinther): Why can't this always be computed in ensureResolved? 954 // TODO(johnniwinther): Why can't this always be computed in ensureResolved?
979 return _callType; 955 return _callType;
980 } 956 }
981 } 957 }
982 958
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 abstract class MemberElementMixin 1473 abstract class MemberElementMixin
1498 implements DeserializedElementZ, MemberElement { 1474 implements DeserializedElementZ, MemberElement {
1499 @override 1475 @override
1500 MemberElement get memberContext => this; 1476 MemberElement get memberContext => this;
1501 1477
1502 @override 1478 @override
1503 Name get memberName => new Name(name, library); 1479 Name get memberName => new Name(name, library);
1504 1480
1505 @override 1481 @override
1506 List<FunctionElement> get nestedClosures => <FunctionElement>[]; 1482 List<FunctionElement> get nestedClosures => <FunctionElement>[];
1507
1508 @override
1509 bool get isInjected => _decoder.getBool(Key.IS_INJECTED);
1510 } 1483 }
1511 1484
1512 abstract class FieldElementZ extends DeserializedElementZ 1485 abstract class FieldElementZ extends DeserializedElementZ
1513 with 1486 with
1514 AnalyzableElementMixin, 1487 AnalyzableElementMixin,
1515 AstElementMixinZ, 1488 AstElementMixinZ,
1516 TypedElementMixin, 1489 TypedElementMixin,
1517 MemberElementMixin 1490 MemberElementMixin
1518 implements FieldElement { 1491 implements FieldElement {
1519 bool _isConst; 1492 bool _isConst;
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 } 2256 }
2284 2257
2285 @override 2258 @override
2286 ElementKind get kind => ElementKind.PREFIX; 2259 ElementKind get kind => ElementKind.PREFIX;
2287 2260
2288 @override 2261 @override
2289 Element lookupLocalMember(String memberName) { 2262 Element lookupLocalMember(String memberName) {
2290 return _unsupported('lookupLocalMember'); 2263 return _unsupported('lookupLocalMember');
2291 } 2264 }
2292 } 2265 }
2293
2294 class MetadataAnnotationZ implements MetadataAnnotation {
2295 final Element annotatedElement;
2296 final SourceSpan sourcePosition;
2297 final ConstantExpression constant;
2298
2299 MetadataAnnotationZ(
2300 this.annotatedElement, this.sourcePosition, this.constant);
2301
2302 @override
2303 MetadataAnnotation ensureResolved(Resolution resolution) {
2304 // Do nothing.
2305 }
2306
2307 @override
2308 Node get node => throw new UnsupportedError('${this}.node');
2309
2310 @override
2311 bool get hasNode => false;
2312
2313 String toString() => 'MetadataAnnotationZ(${constant.toDartText()})';
2314 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/serialization/keys.dart ('k') | pkg/compiler/lib/src/types/constants.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698