| OLD | NEW |
| 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 library dart2js.mirrors_used; | 5 library dart2js.mirrors_used; |
| 6 | 6 |
| 7 import 'common/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
| 8 import 'common.dart'; | 8 import 'common.dart'; |
| 9 import 'compile_time_constants.dart' show ConstantCompiler; | 9 import 'compile_time_constants.dart' show ConstantCompiler; |
| 10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
| 11 import 'constants/expressions.dart'; | 11 import 'constants/expressions.dart'; |
| 12 import 'constants/values.dart' | 12 import 'constants/values.dart' |
| 13 show | 13 show |
| 14 ConstantValue, | 14 ConstantValue, |
| 15 ConstructedConstantValue, | 15 ConstructedConstantValue, |
| 16 ListConstantValue, | 16 ListConstantValue, |
| 17 StringConstantValue, | 17 StringConstantValue, |
| 18 TypeConstantValue; | 18 TypeConstantValue; |
| 19 import 'dart_types.dart' show DartType, InterfaceType; | 19 import 'dart_types.dart' show DartType, InterfaceType; |
| 20 import 'elements/elements.dart' | 20 import 'elements/elements.dart' |
| 21 show | 21 show |
| 22 ClassElement, | 22 ClassElement, |
| 23 Element, | 23 Element, |
| 24 FieldElement, |
| 24 ImportElement, | 25 ImportElement, |
| 25 LibraryElement, | 26 LibraryElement, |
| 26 MetadataAnnotation, | 27 MetadataAnnotation, |
| 27 ScopeContainerElement, | 28 ScopeContainerElement; |
| 28 VariableElement; | |
| 29 import 'resolution/tree_elements.dart' show TreeElements; | 29 import 'resolution/tree_elements.dart' show TreeElements; |
| 30 import 'tree/tree.dart' show NamedArgument, NewExpression, Node; | 30 import 'tree/tree.dart' show NamedArgument, NewExpression, Node; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Compiler task that analyzes MirrorsUsed annotations. | 33 * Compiler task that analyzes MirrorsUsed annotations. |
| 34 * | 34 * |
| 35 * When importing 'dart:mirrors', it is possible to annotate the import with | 35 * When importing 'dart:mirrors', it is possible to annotate the import with |
| 36 * MirrorsUsed annotation. This is a way to declare what elements will be | 36 * MirrorsUsed annotation. This is a way to declare what elements will be |
| 37 * reflected on at runtime. Such elements, even they would normally be | 37 * reflected on at runtime. Such elements, even they would normally be |
| 38 * discarded by the implicit tree-shaking algorithm must be preserved in the | 38 * discarded by the implicit tree-shaking algorithm must be preserved in the |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 metaTargets = b.metaTargets; | 307 metaTargets = b.metaTargets; |
| 308 } else if (metaTargets != wildcard && b.metaTargets != null) { | 308 } else if (metaTargets != wildcard && b.metaTargets != null) { |
| 309 metaTargets.addAll(b.metaTargets); | 309 metaTargets.addAll(b.metaTargets); |
| 310 } | 310 } |
| 311 return new MirrorUsage(symbols, targets, metaTargets, null); | 311 return new MirrorUsage(symbols, targets, metaTargets, null); |
| 312 } | 312 } |
| 313 | 313 |
| 314 /// Convert a [constant] to an instance of [MirrorUsage] using information | 314 /// Convert a [constant] to an instance of [MirrorUsage] using information |
| 315 /// that was resolved during [MirrorUsageAnalyzerTask.validate]. | 315 /// that was resolved during [MirrorUsageAnalyzerTask.validate]. |
| 316 MirrorUsage buildUsage(ConstructedConstantValue constant) { | 316 MirrorUsage buildUsage(ConstructedConstantValue constant) { |
| 317 Map<Element, ConstantValue> fields = constant.fields; | 317 Map<FieldElement, ConstantValue> fields = constant.fields; |
| 318 ClassElement cls = compiler.commonElements.mirrorsUsedClass; | 318 ClassElement cls = compiler.commonElements.mirrorsUsedClass; |
| 319 VariableElement symbolsField = cls.lookupLocalMember('symbols'); | 319 FieldElement symbolsField = cls.lookupLocalMember('symbols'); |
| 320 VariableElement targetsField = cls.lookupLocalMember('targets'); | 320 FieldElement targetsField = cls.lookupLocalMember('targets'); |
| 321 VariableElement metaTargetsField = cls.lookupLocalMember('metaTargets'); | 321 FieldElement metaTargetsField = cls.lookupLocalMember('metaTargets'); |
| 322 VariableElement overrideField = cls.lookupLocalMember('override'); | 322 FieldElement overrideField = cls.lookupLocalMember('override'); |
| 323 | 323 |
| 324 return new MirrorUsage( | 324 return new MirrorUsage( |
| 325 cachedStrings[fields[symbolsField]], | 325 cachedStrings[fields[symbolsField]], |
| 326 cachedElements[fields[targetsField]], | 326 cachedElements[fields[targetsField]], |
| 327 cachedElements[fields[metaTargetsField]], | 327 cachedElements[fields[metaTargetsField]], |
| 328 cachedElements[fields[overrideField]]); | 328 cachedElements[fields[overrideField]]); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 /// Used to represent a resolved MirrorsUsed constant. | 332 /// Used to represent a resolved MirrorsUsed constant. |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 // @MirrorsUsed(targets: fisk) | 564 // @MirrorsUsed(targets: fisk) |
| 565 // ^^^^ | 565 // ^^^^ |
| 566 // | 566 // |
| 567 // Instead of saying 'fisk' should pretty print the problematic constant | 567 // Instead of saying 'fisk' should pretty print the problematic constant |
| 568 // value. | 568 // value. |
| 569 return spannable; | 569 return spannable; |
| 570 } | 570 } |
| 571 return node; | 571 return node; |
| 572 } | 572 } |
| 573 } | 573 } |
| OLD | NEW |