OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.js_emitter.full_emitter; | 5 library dart2js.js_emitter.full_emitter; |
6 | 6 |
7 import 'dart:collection' show HashMap; | 7 import 'dart:collection' show HashMap; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; | 10 import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames; |
11 import 'package:js_runtime/shared/embedded_names.dart' | 11 import 'package:js_runtime/shared/embedded_names.dart' |
12 show JsBuiltin, JsGetName; | 12 show JsBuiltin, JsGetName; |
13 | 13 |
14 import '../../../compiler_new.dart'; | 14 import '../../../compiler_new.dart'; |
15 import '../../common.dart'; | 15 import '../../common.dart'; |
16 import '../../compiler.dart' show Compiler; | 16 import '../../compiler.dart' show Compiler; |
17 import '../../constants/values.dart'; | 17 import '../../constants/values.dart'; |
18 import '../../common_elements.dart' show CommonElements, ElementEnvironment; | 18 import '../../common_elements.dart' show CommonElements, ElementEnvironment; |
19 import '../../elements/resolution_types.dart' show ResolutionDartType; | |
20 import '../../deferred_load.dart' show OutputUnit; | 19 import '../../deferred_load.dart' show OutputUnit; |
21 import '../../elements/elements.dart' show LibraryElement, TypedefElement; | |
22 import '../../elements/entities.dart'; | 20 import '../../elements/entities.dart'; |
23 import '../../elements/entity_utils.dart' as utils; | 21 import '../../elements/entity_utils.dart' as utils; |
| 22 import '../../elements/types.dart'; |
24 import '../../elements/names.dart'; | 23 import '../../elements/names.dart'; |
25 import '../../hash/sha1.dart' show Hasher; | 24 import '../../hash/sha1.dart' show Hasher; |
26 import '../../io/code_output.dart'; | 25 import '../../io/code_output.dart'; |
27 import '../../io/location_provider.dart' show LocationCollector; | 26 import '../../io/location_provider.dart' show LocationCollector; |
28 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 27 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
29 import '../../js/js.dart' as jsAst; | 28 import '../../js/js.dart' as jsAst; |
30 import '../../js/js.dart' show js; | 29 import '../../js/js.dart' show js; |
31 import '../../js_backend/js_backend.dart' | 30 import '../../js_backend/js_backend.dart' |
32 show | 31 show |
33 ConstantEmitter, | 32 ConstantEmitter, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 83 |
85 class Emitter extends js_emitter.EmitterBase { | 84 class Emitter extends js_emitter.EmitterBase { |
86 final Compiler compiler; | 85 final Compiler compiler; |
87 final CodeEmitterTask task; | 86 final CodeEmitterTask task; |
88 final ClosedWorld _closedWorld; | 87 final ClosedWorld _closedWorld; |
89 | 88 |
90 // The following fields will be set to copies of the program-builder's | 89 // The following fields will be set to copies of the program-builder's |
91 // collector. | 90 // collector. |
92 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists; | 91 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists; |
93 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists; | 92 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists; |
94 List<TypedefElement> typedefsNeededForReflection; | 93 List<TypedefEntity> typedefsNeededForReflection; |
95 | 94 |
96 final ContainerBuilder containerBuilder = new ContainerBuilder(); | 95 final ContainerBuilder containerBuilder = new ContainerBuilder(); |
97 final ClassEmitter classEmitter; | 96 final ClassEmitter classEmitter; |
98 final NsmEmitter nsmEmitter; | 97 final NsmEmitter nsmEmitter; |
99 final InterceptorEmitter interceptorEmitter; | 98 final InterceptorEmitter interceptorEmitter; |
100 final Sorter _sorter; | 99 final Sorter _sorter; |
101 | 100 |
102 // TODO(johnniwinther): Wrap these fields in a caching strategy. | 101 // TODO(johnniwinther): Wrap these fields in a caching strategy. |
103 final List<jsAst.Statement> cachedEmittedConstantsAst = <jsAst.Statement>[]; | 102 final List<jsAst.Statement> cachedEmittedConstantsAst = <jsAst.Statement>[]; |
104 | 103 |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 } else if (selector.isSetter) { | 505 } else if (selector.isSetter) { |
507 return _getReflectionSetterName(selector.memberName, mangledName); | 506 return _getReflectionSetterName(selector.memberName, mangledName); |
508 } else { | 507 } else { |
509 return _getReflectionFunctionName( | 508 return _getReflectionFunctionName( |
510 selector.memberName, selector.callStructure); | 509 selector.memberName, selector.callStructure); |
511 } | 510 } |
512 } | 511 } |
513 return null; | 512 return null; |
514 } | 513 } |
515 | 514 |
516 /// Returns the "reflection name" of a [TypedefElement], if needed. | 515 /// Returns the "reflection name" of a [TypedefEntity], if needed. |
517 /// | 516 /// |
518 /// The reflection name of typedef 'F' is 'F'. | 517 /// The reflection name of typedef 'F' is 'F'. |
519 /// | 518 /// |
520 /// This is used by js_mirrors.dart. | 519 /// This is used by js_mirrors.dart. |
521 String getReflectionTypedefName( | 520 String getReflectionTypedefName( |
522 TypedefElement typedef, jsAst.Name mangledName) { | 521 TypedefEntity typedef, jsAst.Name mangledName) { |
523 String name = typedef.name; | 522 String name = typedef.name; |
524 if (backend.mirrorsData.shouldRetainName(name)) { | 523 if (backend.mirrorsData.shouldRetainName(name)) { |
525 // TODO(ahe): Enable the next line when I can tell the difference between | 524 // TODO(ahe): Enable the next line when I can tell the difference between |
526 // an instance method and a global. They may have the same mangled name. | 525 // an instance method and a global. They may have the same mangled name. |
527 // if (recordedMangledNames.contains(mangledName)) return null; | 526 // if (recordedMangledNames.contains(mangledName)) return null; |
528 recordedMangledNames.add(mangledName); | 527 recordedMangledNames.add(mangledName); |
529 return typedef.name; | 528 return typedef.name; |
530 } | 529 } |
531 return null; | 530 return null; |
532 } | 531 } |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); | 1149 cspPrecompiledConstructorNamesFor(outputUnit).add(js('#', constructorName)); |
1151 } | 1150 } |
1152 | 1151 |
1153 void assembleTypedefs(Program program) { | 1152 void assembleTypedefs(Program program) { |
1154 Fragment mainFragment = program.mainFragment; | 1153 Fragment mainFragment = program.mainFragment; |
1155 OutputUnit mainOutputUnit = mainFragment.outputUnit; | 1154 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
1156 | 1155 |
1157 // Emit all required typedef declarations into the main output unit. | 1156 // Emit all required typedef declarations into the main output unit. |
1158 // TODO(karlklose): unify required classes and typedefs to declarations | 1157 // TODO(karlklose): unify required classes and typedefs to declarations |
1159 // and have builders for each kind. | 1158 // and have builders for each kind. |
1160 for (TypedefElement typedef in typedefsNeededForReflection) { | 1159 for (TypedefEntity typedef in typedefsNeededForReflection) { |
1161 LibraryElement library = typedef.library; | 1160 LibraryEntity library = typedef.library; |
1162 // TODO(karlklose): add a TypedefBuilder and move this code there. | 1161 // TODO(karlklose): add a TypedefBuilder and move this code there. |
1163 ResolutionDartType type = typedef.alias; | 1162 FunctionType type = _elementEnvironment.getFunctionTypeOfTypedef(typedef); |
1164 // TODO(zarah): reify type variables once reflection on type arguments of | 1163 // TODO(zarah): reify type variables once reflection on type arguments of |
1165 // typedefs is supported. | 1164 // typedefs is supported. |
1166 jsAst.Expression typeIndex = | 1165 jsAst.Expression typeIndex = |
1167 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); | 1166 task.metadataCollector.reifyType(type, ignoreTypeVariables: true); |
1168 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); | 1167 ClassBuilder builder = new ClassBuilder.forStatics(typedef, namer); |
1169 builder.addPropertyByName( | 1168 builder.addPropertyByName( |
1170 embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex); | 1169 embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, typeIndex); |
1171 builder.addPropertyByName( | 1170 builder.addPropertyByName( |
1172 embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, js.boolean(true)); | 1171 embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, js.boolean(true)); |
1173 | 1172 |
(...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1963 // data. | 1962 // data. |
1964 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1963 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
1965 "needed for a given deferred library import."; | 1964 "needed for a given deferred library import."; |
1966 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1965 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
1967 compiler.outputProvider( | 1966 compiler.outputProvider( |
1968 compiler.options.deferredMapUri.path, '', OutputType.info) | 1967 compiler.options.deferredMapUri.path, '', OutputType.info) |
1969 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1968 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
1970 ..close(); | 1969 ..close(); |
1971 } | 1970 } |
1972 } | 1971 } |
OLD | NEW |