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

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

Issue 2060183002: Serialize metadata (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comment. 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.
116 @override 115 @override
117 Iterable<MetadataAnnotation> get metadata => const <MetadataAnnotation>[]; 116 Iterable<MetadataAnnotation> get metadata => const <MetadataAnnotation>[];
118 117
119 @override 118 @override
120 Token get position => _unsupported('position'); 119 Token get position => _unsupported('position');
121 } 120 }
122 121
123 abstract class DeserializedElementZ extends ElementZ { 122 abstract class DeserializedElementZ extends ElementZ {
124 ObjectDecoder _decoder; 123 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 }
150 } 171 }
151 172
152 /// Deserializer for a collection of member elements serialized as a map from 173 /// Deserializer for a collection of member elements serialized as a map from
153 /// names to element declarations. 174 /// names to element declarations.
154 /// 175 ///
155 /// The serialized data contains the declared getters and setters but lookup 176 /// The serialized data contains the declared getters and setters but lookup
156 /// into the map returns an [AbstractFieldElement] for pairs of corresponding 177 /// into the map returns an [AbstractFieldElement] for pairs of corresponding
157 /// getters and setters. 178 /// getters and setters.
158 /// 179 ///
159 /// The underlying map encoding allows for lazy computation of the members upon 180 /// The underlying map encoding allows for lazy computation of the members upon
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
939 @override 960 @override
940 Link<DartType> get interfaces { 961 Link<DartType> get interfaces {
941 _ensureSuperHierarchy(); 962 _ensureSuperHierarchy();
942 return _interfaces; 963 return _interfaces;
943 } 964 }
944 965
945 @override 966 @override
946 bool get isProxy => _decoder.getBool(Key.IS_PROXY); 967 bool get isProxy => _decoder.getBool(Key.IS_PROXY);
947 968
948 @override 969 @override
970 bool get isInjected => _decoder.getBool(Key.IS_INJECTED);
971
972 @override
949 bool get isUnnamedMixinApplication => false; 973 bool get isUnnamedMixinApplication => false;
950 974
951 @override 975 @override
952 FunctionType get callType { 976 FunctionType get callType {
953 _ensureSuperHierarchy(); 977 _ensureSuperHierarchy();
954 // TODO(johnniwinther): Why can't this always be computed in ensureResolved? 978 // TODO(johnniwinther): Why can't this always be computed in ensureResolved?
955 return _callType; 979 return _callType;
956 } 980 }
957 } 981 }
958 982
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 abstract class MemberElementMixin 1497 abstract class MemberElementMixin
1474 implements DeserializedElementZ, MemberElement { 1498 implements DeserializedElementZ, MemberElement {
1475 @override 1499 @override
1476 MemberElement get memberContext => this; 1500 MemberElement get memberContext => this;
1477 1501
1478 @override 1502 @override
1479 Name get memberName => new Name(name, library); 1503 Name get memberName => new Name(name, library);
1480 1504
1481 @override 1505 @override
1482 List<FunctionElement> get nestedClosures => <FunctionElement>[]; 1506 List<FunctionElement> get nestedClosures => <FunctionElement>[];
1507
1508 @override
1509 bool get isInjected => _decoder.getBool(Key.IS_INJECTED);
1483 } 1510 }
1484 1511
1485 abstract class FieldElementZ extends DeserializedElementZ 1512 abstract class FieldElementZ extends DeserializedElementZ
1486 with 1513 with
1487 AnalyzableElementMixin, 1514 AnalyzableElementMixin,
1488 AstElementMixinZ, 1515 AstElementMixinZ,
1489 TypedElementMixin, 1516 TypedElementMixin,
1490 MemberElementMixin 1517 MemberElementMixin
1491 implements FieldElement { 1518 implements FieldElement {
1492 bool _isConst; 1519 bool _isConst;
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2256 } 2283 }
2257 2284
2258 @override 2285 @override
2259 ElementKind get kind => ElementKind.PREFIX; 2286 ElementKind get kind => ElementKind.PREFIX;
2260 2287
2261 @override 2288 @override
2262 Element lookupLocalMember(String memberName) { 2289 Element lookupLocalMember(String memberName) {
2263 return _unsupported('lookupLocalMember'); 2290 return _unsupported('lookupLocalMember');
2264 } 2291 }
2265 } 2292 }
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