| 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 15 matching lines...) Expand all Loading... |
| 26 FieldElement, | 26 FieldElement, |
| 27 FunctionElement, | 27 FunctionElement, |
| 28 FunctionSignature, | 28 FunctionSignature, |
| 29 LibraryElement, | 29 LibraryElement, |
| 30 MethodElement, | 30 MethodElement, |
| 31 TypedefElement, | 31 TypedefElement, |
| 32 VariableElement; | 32 VariableElement; |
| 33 import '../../elements/entities.dart'; | 33 import '../../elements/entities.dart'; |
| 34 import '../../hash/sha1.dart' show Hasher; | 34 import '../../hash/sha1.dart' show Hasher; |
| 35 import '../../io/code_output.dart'; | 35 import '../../io/code_output.dart'; |
| 36 import '../../io/line_column_provider.dart' show LineColumnCollector; | 36 import '../../io/location_provider.dart' show LocationCollector; |
| 37 import '../../io/source_map_builder.dart' show SourceMapBuilder; | 37 import '../../io/source_map_builder.dart' show SourceMapBuilder; |
| 38 import '../../js/js.dart' as jsAst; | 38 import '../../js/js.dart' as jsAst; |
| 39 import '../../js/js.dart' show js; | 39 import '../../js/js.dart' show js; |
| 40 import '../../js_backend/backend_helpers.dart' show BackendHelpers; | 40 import '../../js_backend/backend_helpers.dart' show BackendHelpers; |
| 41 import '../../js_backend/js_backend.dart' | 41 import '../../js_backend/js_backend.dart' |
| 42 show | 42 show |
| 43 ConstantEmitter, | 43 ConstantEmitter, |
| 44 JavaScriptBackend, | 44 JavaScriptBackend, |
| 45 JavaScriptConstantCompiler, | 45 JavaScriptConstantCompiler, |
| 46 Namer, | 46 Namer, |
| (...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 buildConvertGlobalObjectToFastObjects(), | 1516 buildConvertGlobalObjectToFastObjects(), |
| 1517 "debugFastObjects": buildDebugFastObjectCode(), | 1517 "debugFastObjects": buildDebugFastObjectCode(), |
| 1518 "init": buildInitFunction(program.outputContainsConstantList), | 1518 "init": buildInitFunction(program.outputContainsConstantList), |
| 1519 "main": buildMain(mainFragment.invokeMain) | 1519 "main": buildMain(mainFragment.invokeMain) |
| 1520 })); | 1520 })); |
| 1521 | 1521 |
| 1522 return new jsAst.Program(statements); | 1522 return new jsAst.Program(statements); |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 void emitMainOutputUnit(OutputUnit mainOutputUnit, jsAst.Program program) { | 1525 void emitMainOutputUnit(OutputUnit mainOutputUnit, jsAst.Program program) { |
| 1526 LineColumnCollector lineColumnCollector; | 1526 LocationCollector locationCollector; |
| 1527 List<CodeOutputListener> codeOutputListeners; | 1527 List<CodeOutputListener> codeOutputListeners; |
| 1528 if (generateSourceMap) { | 1528 if (generateSourceMap) { |
| 1529 lineColumnCollector = new LineColumnCollector(); | 1529 locationCollector = new LocationCollector(); |
| 1530 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | 1530 codeOutputListeners = <CodeOutputListener>[locationCollector]; |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 CodeOutput mainOutput = new StreamCodeOutput( | 1533 CodeOutput mainOutput = new StreamCodeOutput( |
| 1534 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); | 1534 compiler.outputProvider('', 'js', OutputType.js), codeOutputListeners); |
| 1535 outputBuffers[mainOutputUnit] = mainOutput; | 1535 outputBuffers[mainOutputUnit] = mainOutput; |
| 1536 | 1536 |
| 1537 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler, | 1537 mainOutput.addBuffer(jsAst.createCodeBuffer(program, compiler, |
| 1538 monitor: compiler.dumpInfoTask)); | 1538 monitor: compiler.dumpInfoTask)); |
| 1539 | 1539 |
| 1540 if (compiler.options.deferredMapUri != null) { | 1540 if (compiler.options.deferredMapUri != null) { |
| 1541 outputDeferredMap(); | 1541 outputDeferredMap(); |
| 1542 } | 1542 } |
| 1543 | 1543 |
| 1544 if (generateSourceMap) { | 1544 if (generateSourceMap) { |
| 1545 mainOutput.add(SourceMapBuilder.generateSourceMapTag( | 1545 mainOutput.add(SourceMapBuilder.generateSourceMapTag( |
| 1546 compiler.options.sourceMapUri, compiler.options.outputUri)); | 1546 compiler.options.sourceMapUri, compiler.options.outputUri)); |
| 1547 } | 1547 } |
| 1548 | 1548 |
| 1549 mainOutput.close(); | 1549 mainOutput.close(); |
| 1550 | 1550 |
| 1551 if (generateSourceMap) { | 1551 if (generateSourceMap) { |
| 1552 SourceMapBuilder.outputSourceMap( | 1552 SourceMapBuilder.outputSourceMap( |
| 1553 mainOutput, | 1553 mainOutput, |
| 1554 lineColumnCollector, | 1554 locationCollector, |
| 1555 '', | 1555 '', |
| 1556 compiler.options.sourceMapUri, | 1556 compiler.options.sourceMapUri, |
| 1557 compiler.options.outputUri, | 1557 compiler.options.outputUri, |
| 1558 compiler.outputProvider); | 1558 compiler.outputProvider); |
| 1559 } | 1559 } |
| 1560 } | 1560 } |
| 1561 | 1561 |
| 1562 Map<OutputUnit, jsAst.Expression> buildDescriptorsForOutputUnits( | 1562 Map<OutputUnit, jsAst.Expression> buildDescriptorsForOutputUnits( |
| 1563 Program program) { | 1563 Program program) { |
| 1564 Map<OutputUnit, jsAst.Expression> outputs = | 1564 Map<OutputUnit, jsAst.Expression> outputs = |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 /// itself. | 1847 /// itself. |
| 1848 Map<OutputUnit, String> emitDeferredOutputUnits( | 1848 Map<OutputUnit, String> emitDeferredOutputUnits( |
| 1849 Map<OutputUnit, jsAst.Program> outputAsts) { | 1849 Map<OutputUnit, jsAst.Program> outputAsts) { |
| 1850 Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); | 1850 Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); |
| 1851 | 1851 |
| 1852 for (OutputUnit outputUnit in outputAsts.keys) { | 1852 for (OutputUnit outputUnit in outputAsts.keys) { |
| 1853 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; | 1853 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| 1854 Hasher hasher = new Hasher(); | 1854 Hasher hasher = new Hasher(); |
| 1855 outputListeners.add(hasher); | 1855 outputListeners.add(hasher); |
| 1856 | 1856 |
| 1857 LineColumnCollector lineColumnCollector; | 1857 LocationCollector locationCollector; |
| 1858 if (generateSourceMap) { | 1858 if (generateSourceMap) { |
| 1859 lineColumnCollector = new LineColumnCollector(); | 1859 locationCollector = new LocationCollector(); |
| 1860 outputListeners.add(lineColumnCollector); | 1860 outputListeners.add(locationCollector); |
| 1861 } | 1861 } |
| 1862 | 1862 |
| 1863 String partPrefix = | 1863 String partPrefix = |
| 1864 backend.deferredPartFileName(outputUnit.name, addExtension: false); | 1864 backend.deferredPartFileName(outputUnit.name, addExtension: false); |
| 1865 CodeOutput output = new StreamCodeOutput( | 1865 CodeOutput output = new StreamCodeOutput( |
| 1866 compiler.outputProvider(partPrefix, 'part.js', OutputType.jsPart), | 1866 compiler.outputProvider(partPrefix, 'part.js', OutputType.jsPart), |
| 1867 outputListeners); | 1867 outputListeners); |
| 1868 | 1868 |
| 1869 outputBuffers[outputUnit] = output; | 1869 outputBuffers[outputUnit] = output; |
| 1870 | 1870 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1897 if (outputUri != null) { | 1897 if (outputUri != null) { |
| 1898 String partFileName = partName + ".js"; | 1898 String partFileName = partName + ".js"; |
| 1899 List<String> partSegments = outputUri.pathSegments.toList(); | 1899 List<String> partSegments = outputUri.pathSegments.toList(); |
| 1900 partSegments[partSegments.length - 1] = partFileName; | 1900 partSegments[partSegments.length - 1] = partFileName; |
| 1901 partUri = | 1901 partUri = |
| 1902 compiler.options.outputUri.replace(pathSegments: partSegments); | 1902 compiler.options.outputUri.replace(pathSegments: partSegments); |
| 1903 } | 1903 } |
| 1904 | 1904 |
| 1905 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri)); | 1905 output.add(SourceMapBuilder.generateSourceMapTag(mapUri, partUri)); |
| 1906 output.close(); | 1906 output.close(); |
| 1907 SourceMapBuilder.outputSourceMap(output, lineColumnCollector, partName, | 1907 SourceMapBuilder.outputSourceMap(output, locationCollector, partName, |
| 1908 mapUri, partUri, compiler.outputProvider); | 1908 mapUri, partUri, compiler.outputProvider); |
| 1909 } else { | 1909 } else { |
| 1910 output.close(); | 1910 output.close(); |
| 1911 } | 1911 } |
| 1912 | 1912 |
| 1913 hunkHashes[outputUnit] = hash; | 1913 hunkHashes[outputUnit] = hash; |
| 1914 } | 1914 } |
| 1915 return hunkHashes; | 1915 return hunkHashes; |
| 1916 } | 1916 } |
| 1917 | 1917 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1928 // data. | 1928 // data. |
| 1929 mapping["_comment"] = "This mapping shows which compiled `.js` files are " | 1929 mapping["_comment"] = "This mapping shows which compiled `.js` files are " |
| 1930 "needed for a given deferred library import."; | 1930 "needed for a given deferred library import."; |
| 1931 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); | 1931 mapping.addAll(compiler.deferredLoadTask.computeDeferredMap()); |
| 1932 compiler.outputProvider( | 1932 compiler.outputProvider( |
| 1933 compiler.options.deferredMapUri.path, '', OutputType.info) | 1933 compiler.options.deferredMapUri.path, '', OutputType.info) |
| 1934 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) | 1934 ..add(const JsonEncoder.withIndent(" ").convert(mapping)) |
| 1935 ..close(); | 1935 ..close(); |
| 1936 } | 1936 } |
| 1937 } | 1937 } |
| OLD | NEW |