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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/metadata_collector.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart2js.js_emitter; 5 part of dart2js.js_emitter;
6 6
7 /// Represents an entry's position in one of the global metadata arrays. 7 /// Represents an entry's position in one of the global metadata arrays.
8 /// 8 ///
9 /// [_rc] is used to count the number of references of the token in the 9 /// [_rc] is used to count the number of references of the token in the
10 /// ast for a program. 10 /// ast for a program.
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 /// The metadata function returns the metadata associated with 154 /// The metadata function returns the metadata associated with
155 /// [element] in generated code. The metadata needs to be wrapped 155 /// [element] in generated code. The metadata needs to be wrapped
156 /// in a function as it refers to constants that may not have been 156 /// in a function as it refers to constants that may not have been
157 /// constructed yet. For example, a class is allowed to be 157 /// constructed yet. For example, a class is allowed to be
158 /// annotated with itself. The metadata function is used by 158 /// annotated with itself. The metadata function is used by
159 /// mirrors_patch to implement DeclarationMirror.metadata. 159 /// mirrors_patch to implement DeclarationMirror.metadata.
160 jsAst.Fun buildMetadataFunction(Element element) { 160 jsAst.Fun buildMetadataFunction(Element element) {
161 if (!_mustEmitMetadataFor(element)) return null; 161 if (!_mustEmitMetadataFor(element)) return null;
162 return _compiler.withCurrentElement(element, () { 162 return _compiler.withCurrentElement(element, () {
163 List<jsAst.Expression> metadata = <jsAst.Expression>[]; 163 List<jsAst.Expression> metadata = <jsAst.Expression>[];
164 Link link = element.metadata; 164 for (MetadataAnnotation annotation in element.metadata) {
165 // TODO(ahe): Why is metadata sometimes null? 165 ConstantValue constant =
166 if (link != null) { 166 _backend.constants.getConstantValueForMetadata(annotation);
167 for (; !link.isEmpty; link = link.tail) { 167 if (constant == null) {
168 MetadataAnnotation annotation = link.head; 168 _compiler.internalError(annotation, 'Annotation value is null.');
169 ConstantValue constant = 169 } else {
170 _backend.constants.getConstantValueForMetadata(annotation); 170 metadata.add(_emitter.constantReference(constant));
171 if (constant == null) {
172 _compiler.internalError(annotation, 'Annotation value is null.');
173 } else {
174 metadata.add(_emitter.constantReference(constant));
175 }
176 } 171 }
177 } 172 }
178 if (metadata.isEmpty) return null; 173 if (metadata.isEmpty) return null;
179 return js('function() { return # }', 174 return js('function() { return # }',
180 new jsAst.ArrayInitializer(metadata)); 175 new jsAst.ArrayInitializer(metadata));
181 }); 176 });
182 } 177 }
183 178
184 List<jsAst.DeferredNumber> reifyDefaultArguments(FunctionElement function) { 179 List<jsAst.DeferredNumber> reifyDefaultArguments(FunctionElement function) {
185 FunctionSignature signature = function.functionSignature; 180 FunctionSignature signature = function.functionSignature;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 result.finalize(_globalTypesCounter++); 277 result.finalize(_globalTypesCounter++);
283 } 278 }
284 return result; 279 return result;
285 }); 280 });
286 } 281 }
287 282
288 List<jsAst.DeferredNumber> computeMetadata(FunctionElement element) { 283 List<jsAst.DeferredNumber> computeMetadata(FunctionElement element) {
289 return _compiler.withCurrentElement(element, () { 284 return _compiler.withCurrentElement(element, () {
290 if (!_mustEmitMetadataFor(element)) return const <jsAst.DeferredNumber>[]; 285 if (!_mustEmitMetadataFor(element)) return const <jsAst.DeferredNumber>[];
291 List<jsAst.DeferredNumber> metadata = <jsAst.DeferredNumber>[]; 286 List<jsAst.DeferredNumber> metadata = <jsAst.DeferredNumber>[];
292 Link link = element.metadata; 287 for (MetadataAnnotation annotation in element.metadata) {
293 // TODO(ahe): Why is metadata sometimes null? 288 metadata.add(reifyMetadata(annotation));
294 if (link != null) {
295 for (; !link.isEmpty; link = link.tail) {
296 metadata.add(reifyMetadata(link.head));
297 }
298 } 289 }
299 return metadata; 290 return metadata;
300 }); 291 });
301 } 292 }
302 293
303 @override 294 @override
304 void finalizeTokens() { 295 void finalizeTokens() {
305 bool checkTokensInTypes(OutputUnit outputUnit, entries) { 296 bool checkTokensInTypes(OutputUnit outputUnit, entries) {
306 UnBoundDebugger debugger = new UnBoundDebugger(outputUnit); 297 UnBoundDebugger debugger = new UnBoundDebugger(outputUnit);
307 for (_BoundMetadataEntry entry in entries) { 298 for (_BoundMetadataEntry entry in entries) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 if (token is _ForwardingMetadataEntry && !token.isBound) { 359 if (token is _ForwardingMetadataEntry && !token.isBound) {
369 _foundUnboundToken = true; 360 _foundUnboundToken = true;
370 } 361 }
371 } 362 }
372 363
373 bool findUnboundPlaceholders(jsAst.Node node) { 364 bool findUnboundPlaceholders(jsAst.Node node) {
374 node.accept(this); 365 node.accept(this);
375 return _foundUnboundToken; 366 return _foundUnboundToken;
376 } 367 }
377 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698