| 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; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 import '../../js/js.dart' as jsAst; | 37 import '../../js/js.dart' as jsAst; |
| 38 import '../../js/js.dart' show js; | 38 import '../../js/js.dart' show js; |
| 39 import '../../js_backend/js_backend.dart' | 39 import '../../js_backend/js_backend.dart' |
| 40 show | 40 show |
| 41 ConstantEmitter, | 41 ConstantEmitter, |
| 42 JavaScriptBackend, | 42 JavaScriptBackend, |
| 43 JavaScriptConstantCompiler, | 43 JavaScriptConstantCompiler, |
| 44 Namer, | 44 Namer, |
| 45 SetterName, | 45 SetterName, |
| 46 TypeVariableCodegenAnalysis; | 46 TypeVariableCodegenAnalysis; |
| 47 import '../../js_backend/native_data.dart'; |
| 47 import '../../universe/call_structure.dart' show CallStructure; | 48 import '../../universe/call_structure.dart' show CallStructure; |
| 48 import '../../universe/selector.dart' show Selector; | 49 import '../../universe/selector.dart' show Selector; |
| 49 import '../../universe/world_builder.dart' show CodegenWorldBuilder; | 50 import '../../universe/world_builder.dart' show CodegenWorldBuilder; |
| 50 import '../../util/uri_extras.dart' show relativize; | 51 import '../../util/uri_extras.dart' show relativize; |
| 51 import '../../world.dart' show ClosedWorld; | 52 import '../../world.dart' show ClosedWorld; |
| 52 import '../constant_ordering.dart' show deepCompareConstants; | 53 import '../constant_ordering.dart' show deepCompareConstants; |
| 53 import '../headers.dart'; | 54 import '../headers.dart'; |
| 54 import '../js_emitter.dart' hide Emitter, EmitterFactory; | 55 import '../js_emitter.dart' hide Emitter, EmitterFactory; |
| 55 import '../js_emitter.dart' as js_emitter show Emitter, EmitterFactory; | 56 import '../js_emitter.dart' as js_emitter show Emitter, EmitterFactory; |
| 56 import '../model.dart'; | 57 import '../model.dart'; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 Emitter createEmitter( | 87 Emitter createEmitter( |
| 87 CodeEmitterTask task, Namer namer, ClosedWorld closedWorld) { | 88 CodeEmitterTask task, Namer namer, ClosedWorld closedWorld) { |
| 88 return new Emitter(task.compiler, namer, closedWorld, generateSourceMap, | 89 return new Emitter(task.compiler, namer, closedWorld, generateSourceMap, |
| 89 task, task.sorter); | 90 task, task.sorter); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 | 93 |
| 93 class Emitter implements js_emitter.Emitter { | 94 class Emitter implements js_emitter.Emitter { |
| 94 final Compiler compiler; | 95 final Compiler compiler; |
| 95 final CodeEmitterTask task; | 96 final CodeEmitterTask task; |
| 97 final ClosedWorld _closedWorld; |
| 96 | 98 |
| 97 // The following fields will be set to copies of the program-builder's | 99 // The following fields will be set to copies of the program-builder's |
| 98 // collector. | 100 // collector. |
| 99 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists; | 101 Map<OutputUnit, List<FieldEntity>> outputStaticNonFinalFieldLists; |
| 100 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists; | 102 Map<OutputUnit, Set<LibraryEntity>> outputLibraryLists; |
| 101 List<TypedefElement> typedefsNeededForReflection; | 103 List<TypedefElement> typedefsNeededForReflection; |
| 102 | 104 |
| 103 final ContainerBuilder containerBuilder = new ContainerBuilder(); | 105 final ContainerBuilder containerBuilder = new ContainerBuilder(); |
| 104 final ClassEmitter classEmitter; | 106 final ClassEmitter classEmitter; |
| 105 final NsmEmitter nsmEmitter; | 107 final NsmEmitter nsmEmitter; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 * | 166 * |
| 165 * See [getElementDescriptor]. | 167 * See [getElementDescriptor]. |
| 166 */ | 168 */ |
| 167 // TODO(ahe): Generate statics with their class, and store only libraries in | 169 // TODO(ahe): Generate statics with their class, and store only libraries in |
| 168 // this map. | 170 // this map. |
| 169 final Map<Fragment, Map<Element, ClassBuilder>> elementDescriptors = | 171 final Map<Fragment, Map<Element, ClassBuilder>> elementDescriptors = |
| 170 new Map<Fragment, Map<Element, ClassBuilder>>(); | 172 new Map<Fragment, Map<Element, ClassBuilder>>(); |
| 171 | 173 |
| 172 final bool generateSourceMap; | 174 final bool generateSourceMap; |
| 173 | 175 |
| 174 Emitter(Compiler compiler, Namer namer, ClosedWorld closedWorld, | 176 Emitter(this.compiler, this.namer, this._closedWorld, this.generateSourceMap, |
| 175 this.generateSourceMap, this.task, this._sorter) | 177 this.task, this._sorter) |
| 176 : this.compiler = compiler, | 178 : classEmitter = new ClassEmitter(_closedWorld), |
| 177 this.namer = namer, | 179 interceptorEmitter = new InterceptorEmitter(_closedWorld), |
| 178 classEmitter = new ClassEmitter(closedWorld), | 180 nsmEmitter = new NsmEmitter(_closedWorld) { |
| 179 interceptorEmitter = new InterceptorEmitter(closedWorld), | |
| 180 nsmEmitter = new NsmEmitter(closedWorld) { | |
| 181 constantEmitter = new ConstantEmitter( | 181 constantEmitter = new ConstantEmitter( |
| 182 compiler, namer, this.constantReference, constantListGenerator); | 182 compiler, namer, this.constantReference, constantListGenerator); |
| 183 containerBuilder.emitter = this; | 183 containerBuilder.emitter = this; |
| 184 classEmitter.emitter = this; | 184 classEmitter.emitter = this; |
| 185 nsmEmitter.emitter = this; | 185 nsmEmitter.emitter = this; |
| 186 interceptorEmitter.emitter = this; | 186 interceptorEmitter.emitter = this; |
| 187 } | 187 } |
| 188 | 188 |
| 189 DiagnosticReporter get reporter => compiler.reporter; | 189 DiagnosticReporter get reporter => compiler.reporter; |
| 190 | 190 |
| 191 NativeData get _nativeData => _closedWorld.nativeData; |
| 192 |
| 191 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) { | 193 List<jsAst.Node> cspPrecompiledFunctionFor(OutputUnit outputUnit) { |
| 192 return _cspPrecompiledFunctions.putIfAbsent( | 194 return _cspPrecompiledFunctions.putIfAbsent( |
| 193 outputUnit, () => new List<jsAst.Node>()); | 195 outputUnit, () => new List<jsAst.Node>()); |
| 194 } | 196 } |
| 195 | 197 |
| 196 List<jsAst.Expression> cspPrecompiledConstructorNamesFor( | 198 List<jsAst.Expression> cspPrecompiledConstructorNamesFor( |
| 197 OutputUnit outputUnit) { | 199 OutputUnit outputUnit) { |
| 198 return _cspPrecompiledConstructorNames.putIfAbsent( | 200 return _cspPrecompiledConstructorNames.putIfAbsent( |
| 199 outputUnit, () => new List<jsAst.Expression>()); | 201 outputUnit, () => new List<jsAst.Expression>()); |
| 200 } | 202 } |
| (...skipping 1440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1641 if (backend.backendUsage.requiresPreamble && !backend.htmlLibraryIsLoaded) { | 1643 if (backend.backendUsage.requiresPreamble && !backend.htmlLibraryIsLoaded) { |
| 1642 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); | 1644 reporter.reportHintMessage(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
| 1643 } | 1645 } |
| 1644 // Return the total program size. | 1646 // Return the total program size. |
| 1645 return outputBuffers.values.fold(0, (a, b) => a + b.length); | 1647 return outputBuffers.values.fold(0, (a, b) => a + b.length); |
| 1646 } | 1648 } |
| 1647 | 1649 |
| 1648 ClassBuilder getStaticMethodDescriptor( | 1650 ClassBuilder getStaticMethodDescriptor( |
| 1649 MethodElement element, Fragment fragment) { | 1651 MethodElement element, Fragment fragment) { |
| 1650 Element owner = element.library; | 1652 Element owner = element.library; |
| 1651 if (!backend.nativeData.isNativeMember(element)) { | 1653 if (!_nativeData.isNativeMember(element)) { |
| 1652 // For static (not top level) elements, record their code in a buffer | 1654 // For static (not top level) elements, record their code in a buffer |
| 1653 // specific to the class. For now, not supported for native classes and | 1655 // specific to the class. For now, not supported for native classes and |
| 1654 // native elements. | 1656 // native elements. |
| 1655 ClassElement cls = element.enclosingClass; | 1657 ClassElement cls = element.enclosingClass; |
| 1656 if (compiler.codegenWorldBuilder.directlyInstantiatedClasses | 1658 if (compiler.codegenWorldBuilder.directlyInstantiatedClasses |
| 1657 .contains(cls) && | 1659 .contains(cls) && |
| 1658 !backend.nativeData.isNativeClass(cls) && | 1660 !_nativeData.isNativeClass(cls) && |
| 1659 compiler.deferredLoadTask.outputUnitForElement(element) == | 1661 compiler.deferredLoadTask.outputUnitForElement(element) == |
| 1660 compiler.deferredLoadTask.outputUnitForElement(cls)) { | 1662 compiler.deferredLoadTask.outputUnitForElement(cls)) { |
| 1661 owner = cls; | 1663 owner = cls; |
| 1662 } | 1664 } |
| 1663 } | 1665 } |
| 1664 return _getElementDescriptor(element, owner, fragment); | 1666 return _getElementDescriptor(element, owner, fragment); |
| 1665 } | 1667 } |
| 1666 | 1668 |
| 1667 ClassBuilder getLibraryDescriptor(LibraryElement element, Fragment fragment) { | 1669 ClassBuilder getLibraryDescriptor(LibraryElement element, Fragment fragment) { |
| 1668 return _getElementDescriptor(element, element, fragment); | 1670 return _getElementDescriptor(element, element, fragment); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 // data. | 1930 // data. |
| 1929 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1931 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 1930 "needed for a given deferred library import."; | 1932 "needed for a given deferred library import."; |
| 1931 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1933 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 1932 compiler.outputProvider( | 1934 compiler.outputProvider( |
| 1933 compiler.options.deferredMapUri.path, '', OutputType.info) | 1935 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 1934 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1936 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 1935 ..close(); | 1937 ..close(); |
| 1936 } | 1938 } |
| 1937 } | 1939 } |
| OLD | NEW |