| 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 part of dart2js.js_emitter; | 5 part of dart2js.js_emitter; |
| 6 | 6 |
| 7 | 7 |
| 8 class OldEmitter implements Emitter { | 8 class OldEmitter implements Emitter { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 final CodeEmitterTask task; | 10 final CodeEmitterTask task; |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 invariant(classElement, builder.functionType == null); | 747 invariant(classElement, builder.functionType == null); |
| 748 invariant(classElement, builder.fieldMetadata == null); | 748 invariant(classElement, builder.fieldMetadata == null); |
| 749 properties.properties.addAll(builder.properties); | 749 properties.properties.addAll(builder.properties); |
| 750 } else { | 750 } else { |
| 751 classEmitter.generateClass( | 751 classEmitter.generateClass( |
| 752 classElement, properties, additionalProperties[classElement]); | 752 classElement, properties, additionalProperties[classElement]); |
| 753 } | 753 } |
| 754 }); | 754 }); |
| 755 } | 755 } |
| 756 | 756 |
| 757 void emitStaticFunctions(List<Element> staticFunctions) { | 757 void emitStaticFunctions(Iterable<Method> staticFunctions) { |
| 758 for (Element element in staticFunctions) { | 758 // We need to filter out null-elements for the interceptors. |
| 759 Iterable<Element> elements = staticFunctions |
| 760 .where((Method method) => method.element != null) |
| 761 .map((Method method) => method.element); |
| 762 |
| 763 for (Element element in elements) { |
| 759 ClassBuilder builder = new ClassBuilder(element, namer); | 764 ClassBuilder builder = new ClassBuilder(element, namer); |
| 760 containerBuilder.addMember(element, builder); | 765 containerBuilder.addMember(element, builder); |
| 761 getElementDescriptor(element).properties.addAll(builder.properties); | 766 getElementDescriptor(element).properties.addAll(builder.properties); |
| 762 } | 767 } |
| 763 } | 768 } |
| 764 | 769 |
| 765 void emitStaticNonFinalFieldInitializations(CodeOutput output, | 770 void emitStaticNonFinalFieldInitializations(CodeOutput output, |
| 766 OutputUnit outputUnit) { | 771 OutputUnit outputUnit) { |
| 767 void emitInitialization(Element element, jsAst.Expression initialValue) { | 772 void emitInitialization(Element element, jsAst.Expression initialValue) { |
| 768 jsAst.Expression init = | 773 jsAst.Expression init = |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 | 874 |
| 870 // Sorting by the long name clusters constants with the same constructor | 875 // Sorting by the long name clusters constants with the same constructor |
| 871 // which compresses a tiny bit better. | 876 // which compresses a tiny bit better. |
| 872 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); | 877 int r = namer.constantLongName(a).compareTo(namer.constantLongName(b)); |
| 873 if (r != 0) return r; | 878 if (r != 0) return r; |
| 874 // Resolve collisions in the long name by using the constant name (i.e. JS | 879 // Resolve collisions in the long name by using the constant name (i.e. JS |
| 875 // name) which is unique. | 880 // name) which is unique. |
| 876 return namer.constantName(a).compareTo(namer.constantName(b)); | 881 return namer.constantName(a).compareTo(namer.constantName(b)); |
| 877 } | 882 } |
| 878 | 883 |
| 879 void emitCompileTimeConstants(CodeOutput output, OutputUnit outputUnit) { | 884 void emitCompileTimeConstants(CodeOutput output, |
| 880 List<ConstantValue> constants = outputConstantLists[outputUnit]; | 885 List<Constant> constants, |
| 881 if (constants == null) return; | 886 {bool isMainFragment}) { |
| 887 assert(isMainFragment != null); |
| 888 |
| 889 if (constants.isEmpty) return; |
| 882 CodeOutput constantOutput = output; | 890 CodeOutput constantOutput = output; |
| 883 if (compiler.hasIncrementalSupport && outputUnit.isMainOutput) { | 891 if (compiler.hasIncrementalSupport && isMainFragment) { |
| 884 constantOutput = cachedEmittedConstantsBuffer; | 892 constantOutput = cachedEmittedConstantsBuffer; |
| 885 } | 893 } |
| 886 for (ConstantValue constant in constants) { | 894 for (Constant constant in constants) { |
| 887 if (compiler.hasIncrementalSupport && outputUnit.isMainOutput) { | 895 ConstantValue constantValue = constant.value; |
| 888 if (cachedEmittedConstants.contains(constant)) continue; | 896 if (compiler.hasIncrementalSupport && isMainFragment) { |
| 889 cachedEmittedConstants.add(constant); | 897 if (cachedEmittedConstants.contains(constantValue)) continue; |
| 898 cachedEmittedConstants.add(constantValue); |
| 890 } | 899 } |
| 891 jsAst.Expression init = buildConstantInitializer(constant); | 900 jsAst.Expression init = buildConstantInitializer(constantValue); |
| 892 constantOutput.addBuffer(jsAst.prettyPrint(init, compiler, | 901 constantOutput.addBuffer(jsAst.prettyPrint(init, compiler, |
| 893 monitor: compiler.dumpInfoTask)); | 902 monitor: compiler.dumpInfoTask)); |
| 894 constantOutput.add('$N'); | 903 constantOutput.add('$N'); |
| 895 } | 904 } |
| 896 if (compiler.hasIncrementalSupport && outputUnit.isMainOutput) { | 905 if (compiler.hasIncrementalSupport && isMainFragment) { |
| 897 output.addBuffer(constantOutput); | 906 output.addBuffer(constantOutput); |
| 898 } | 907 } |
| 899 } | 908 } |
| 900 | 909 |
| 901 jsAst.Expression buildConstantInitializer(ConstantValue constant) { | 910 jsAst.Expression buildConstantInitializer(ConstantValue constant) { |
| 902 String name = namer.constantName(constant); | 911 String name = namer.constantName(constant); |
| 903 return js('#.# = #', | 912 return js('#.# = #', |
| 904 [namer.globalObjectForConstant(constant), name, | 913 [namer.globalObjectForConstant(constant), name, |
| 905 constantInitializerExpression(constant)]); | 914 constantInitializerExpression(constant)]); |
| 906 } | 915 } |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 } | 1277 } |
| 1269 } | 1278 } |
| 1270 | 1279 |
| 1271 void emitTypedefs() { | 1280 void emitTypedefs() { |
| 1272 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | 1281 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; |
| 1273 | 1282 |
| 1274 // Emit all required typedef declarations into the main output unit. | 1283 // Emit all required typedef declarations into the main output unit. |
| 1275 // TODO(karlklose): unify required classes and typedefs to declarations | 1284 // TODO(karlklose): unify required classes and typedefs to declarations |
| 1276 // and have builders for each kind. | 1285 // and have builders for each kind. |
| 1277 for (TypedefElement typedef in typedefsNeededForReflection) { | 1286 for (TypedefElement typedef in typedefsNeededForReflection) { |
| 1278 OutputUnit mainUnit = compiler.deferredLoadTask.mainOutputUnit; | |
| 1279 LibraryElement library = typedef.library; | 1287 LibraryElement library = typedef.library; |
| 1280 // TODO(karlklose): add a TypedefBuilder and move this code there. | 1288 // TODO(karlklose): add a TypedefBuilder and move this code there. |
| 1281 DartType type = typedef.alias; | 1289 DartType type = typedef.alias; |
| 1282 int typeIndex = metadataEmitter.reifyType(type); | 1290 int typeIndex = metadataEmitter.reifyType(type); |
| 1283 ClassBuilder builder = new ClassBuilder(typedef, namer); | 1291 ClassBuilder builder = new ClassBuilder(typedef, namer); |
| 1284 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, | 1292 builder.addProperty(embeddedNames.TYPEDEF_TYPE_PROPERTY_NAME, |
| 1285 js.number(typeIndex)); | 1293 js.number(typeIndex)); |
| 1286 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, | 1294 builder.addProperty(embeddedNames.TYPEDEF_PREDICATE_PROPERTY_NAME, |
| 1287 js.boolean(true)); | 1295 js.boolean(true)); |
| 1288 | 1296 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1362 compiler.reportInfo( | 1370 compiler.reportInfo( |
| 1363 element, MessageKind.GENERIC, {'text': 'Pending statics.'})); | 1371 element, MessageKind.GENERIC, {'text': 'Pending statics.'})); |
| 1364 } | 1372 } |
| 1365 | 1373 |
| 1366 if (pendingStatics != null && !pendingStatics.isEmpty) { | 1374 if (pendingStatics != null && !pendingStatics.isEmpty) { |
| 1367 compiler.internalError(pendingStatics.first, | 1375 compiler.internalError(pendingStatics.first, |
| 1368 'Pending statics (see above).'); | 1376 'Pending statics (see above).'); |
| 1369 } | 1377 } |
| 1370 } | 1378 } |
| 1371 | 1379 |
| 1372 void emitMainOutputUnit(Map<OutputUnit, String> deferredLoadHashes, | 1380 void emitLibrary(Library library) { |
| 1381 emitStaticFunctions(library.statics); |
| 1382 |
| 1383 Iterable<ClassElement> classes = |
| 1384 library.classes.map((Class cls) => cls.element); |
| 1385 for (ClassElement element in classes) { |
| 1386 generateClass(element, getElementDescriptor(element)); |
| 1387 } |
| 1388 |
| 1389 LibraryElement libraryElement = library.element; |
| 1390 ClassBuilder builder = getElementDescriptor(libraryElement); |
| 1391 classEmitter.emitFields(library.element, builder, emitStatics: true); |
| 1392 } |
| 1393 |
| 1394 void emitMainOutputUnit(Program program, |
| 1395 Map<OutputUnit, String> deferredLoadHashes, |
| 1373 CodeBuffer nativeBuffer) { | 1396 CodeBuffer nativeBuffer) { |
| 1397 Fragment mainFragment = program.fragments.first; |
| 1398 OutputUnit mainOutputUnit = mainFragment.outputUnit; |
| 1399 |
| 1374 LineColumnCollector lineColumnCollector; | 1400 LineColumnCollector lineColumnCollector; |
| 1375 List<CodeOutputListener> codeOutputListeners; | 1401 List<CodeOutputListener> codeOutputListeners; |
| 1376 if (generateSourceMap) { | 1402 if (generateSourceMap) { |
| 1377 lineColumnCollector = new LineColumnCollector(); | 1403 lineColumnCollector = new LineColumnCollector(); |
| 1378 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; | 1404 codeOutputListeners = <CodeOutputListener>[lineColumnCollector]; |
| 1379 } | 1405 } |
| 1380 | 1406 |
| 1381 OutputUnit mainOutputUnit = compiler.deferredLoadTask.mainOutputUnit; | |
| 1382 CodeOutput mainOutput = | 1407 CodeOutput mainOutput = |
| 1383 new StreamCodeOutput(compiler.outputProvider('', 'js'), | 1408 new StreamCodeOutput(compiler.outputProvider('', 'js'), |
| 1384 codeOutputListeners); | 1409 codeOutputListeners); |
| 1385 outputBuffers[mainOutputUnit] = mainOutput; | 1410 outputBuffers[mainOutputUnit] = mainOutput; |
| 1386 | 1411 |
| 1387 bool isProgramSplit = compiler.deferredLoadTask.isProgramSplit; | 1412 bool isProgramSplit = program.isSplit; |
| 1388 | 1413 |
| 1389 mainOutput.add(buildGeneratedBy()); | 1414 mainOutput.add(buildGeneratedBy()); |
| 1390 addComment(HOOKS_API_USAGE, mainOutput); | 1415 addComment(HOOKS_API_USAGE, mainOutput); |
| 1391 | 1416 |
| 1392 if (isProgramSplit) { | 1417 if (isProgramSplit) { |
| 1393 /// For deferred loading we communicate the initializers via this global | 1418 /// For deferred loading we communicate the initializers via this global |
| 1394 /// variable. The deferred hunks will add their initialization to this. | 1419 /// variable. The deferred hunks will add their initialization to this. |
| 1395 /// The semicolon is important in minified mode, without it the | 1420 /// The semicolon is important in minified mode, without it the |
| 1396 /// following parenthesis looks like a call to the object literal. | 1421 /// following parenthesis looks like a call to the object literal. |
| 1397 mainOutput.add( | 1422 mainOutput.add( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 if (isProgramSplit) { | 1482 if (isProgramSplit) { |
| 1458 mainOutput.add( | 1483 mainOutput.add( |
| 1459 '${globalsHolder}.${namer.isolateName}$_=$_${namer.isolateName}$N' | 1484 '${globalsHolder}.${namer.isolateName}$_=$_${namer.isolateName}$N' |
| 1460 '${globalsHolder}.$initName$_=${_}$initName$N' | 1485 '${globalsHolder}.$initName$_=${_}$initName$N' |
| 1461 '${globalsHolder}.$parseReflectionDataName$_=$_' | 1486 '${globalsHolder}.$parseReflectionDataName$_=$_' |
| 1462 '$parseReflectionDataName$N'); | 1487 '$parseReflectionDataName$N'); |
| 1463 } | 1488 } |
| 1464 mainOutput.add('init()$N$n'); | 1489 mainOutput.add('init()$N$n'); |
| 1465 mainOutput.add('$isolateProperties$_=$_$isolatePropertiesName$N'); | 1490 mainOutput.add('$isolateProperties$_=$_$isolatePropertiesName$N'); |
| 1466 | 1491 |
| 1467 emitStaticFunctions(task.outputStaticLists[mainOutputUnit]); | 1492 mainFragment.libraries.forEach(emitLibrary); |
| 1468 | |
| 1469 List<ClassElement> classes = task.outputClassLists[mainOutputUnit]; | |
| 1470 if (classes != null) { | |
| 1471 for (ClassElement element in classes) { | |
| 1472 generateClass(element, getElementDescriptor(element)); | |
| 1473 } | |
| 1474 } | |
| 1475 | 1493 |
| 1476 Iterable<LibraryElement> libraries = | 1494 Iterable<LibraryElement> libraries = |
| 1477 task.outputLibraryLists[mainOutputUnit]; | 1495 task.outputLibraryLists[mainOutputUnit]; |
| 1478 if (libraries == null) libraries = []; | 1496 if (libraries == null) libraries = []; |
| 1479 emitLibraries(libraries); | |
| 1480 emitTypedefs(); | 1497 emitTypedefs(); |
| 1481 emitMangledNames(mainOutput); | 1498 emitMangledNames(mainOutput); |
| 1482 | 1499 |
| 1483 checkEverythingEmitted(elementDescriptors.keys); | 1500 checkEverythingEmitted(elementDescriptors.keys); |
| 1484 | 1501 |
| 1485 CodeBuffer libraryBuffer = new CodeBuffer(); | 1502 CodeBuffer libraryBuffer = new CodeBuffer(); |
| 1486 for (LibraryElement library in Elements.sortedByPosition(libraries)) { | 1503 for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| 1487 writeLibraryDescriptors(libraryBuffer, library); | 1504 writeLibraryDescriptors(libraryBuffer, library); |
| 1488 elementDescriptors.remove(library); | 1505 elementDescriptors.remove(library); |
| 1489 } | 1506 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1507 interceptorEmitter.emitOneShotInterceptors(mainOutput); | 1524 interceptorEmitter.emitOneShotInterceptors(mainOutput); |
| 1508 | 1525 |
| 1509 if (task.outputContainsConstantList) { | 1526 if (task.outputContainsConstantList) { |
| 1510 emitMakeConstantList(mainOutput); | 1527 emitMakeConstantList(mainOutput); |
| 1511 } | 1528 } |
| 1512 | 1529 |
| 1513 // Constants in checked mode call into RTI code to set type information | 1530 // Constants in checked mode call into RTI code to set type information |
| 1514 // which may need getInterceptor (and one-shot interceptor) methods, so | 1531 // which may need getInterceptor (and one-shot interceptor) methods, so |
| 1515 // we have to make sure that [emitGetInterceptorMethods] and | 1532 // we have to make sure that [emitGetInterceptorMethods] and |
| 1516 // [emitOneShotInterceptors] have been called. | 1533 // [emitOneShotInterceptors] have been called. |
| 1517 emitCompileTimeConstants(mainOutput, mainOutputUnit); | 1534 emitCompileTimeConstants( |
| 1535 mainOutput, mainFragment.constants, isMainFragment: true); |
| 1518 | 1536 |
| 1519 emitDeferredBoilerPlate(mainOutput, deferredLoadHashes); | 1537 emitDeferredBoilerPlate(mainOutput, deferredLoadHashes); |
| 1520 | 1538 |
| 1521 if (compiler.deferredMapUri != null) { | 1539 if (compiler.deferredMapUri != null) { |
| 1522 outputDeferredMap(); | 1540 outputDeferredMap(); |
| 1523 } | 1541 } |
| 1524 | 1542 |
| 1525 // Static field initializations require the classes and compile-time | 1543 // Static field initializations require the classes and compile-time |
| 1526 // constants to be set up. | 1544 // constants to be set up. |
| 1527 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit); | 1545 emitStaticNonFinalFieldInitializations(mainOutput, mainOutputUnit); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1726 holder[name] = method; | 1744 holder[name] = method; |
| 1727 } | 1745 } |
| 1728 if (isStatic) globalFunctionsAccess[name] = method; | 1746 if (isStatic) globalFunctionsAccess[name] = method; |
| 1729 }"""); | 1747 }"""); |
| 1730 } | 1748 } |
| 1731 | 1749 |
| 1732 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely | 1750 /// Returns a map from OutputUnit to a hash of its content. The hash uniquely |
| 1733 /// identifies the code of the output-unit. It does not include | 1751 /// identifies the code of the output-unit. It does not include |
| 1734 /// boilerplate JS code, like the sourcemap directives or the hash | 1752 /// boilerplate JS code, like the sourcemap directives or the hash |
| 1735 /// itself. | 1753 /// itself. |
| 1736 Map<OutputUnit, String> emitDeferredOutputUnits() { | 1754 Map<OutputUnit, String> emitDeferredOutputUnits(Program program) { |
| 1737 if (!compiler.deferredLoadTask.isProgramSplit) return const {}; | 1755 if (!program.isSplit) return const {}; |
| 1738 | 1756 |
| 1739 Map<OutputUnit, CodeBuffer> outputBuffers = | 1757 Map<OutputUnit, CodeBuffer> outputBuffers = |
| 1740 new Map<OutputUnit, CodeBuffer>(); | 1758 new Map<OutputUnit, CodeBuffer>(); |
| 1741 | 1759 |
| 1742 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) { | 1760 for (Fragment fragment in program.deferredFragments) { |
| 1743 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) continue; | 1761 OutputUnit outputUnit = fragment.outputUnit; |
| 1744 | 1762 |
| 1745 List<Element> functions = task.outputStaticLists[outputUnit]; | |
| 1746 if (functions != null) { | |
| 1747 emitStaticFunctions(functions); | |
| 1748 } | |
| 1749 | 1763 |
| 1750 List<ClassElement> classes = task.outputClassLists[outputUnit]; | 1764 fragment.libraries.forEach(emitLibrary); |
| 1751 if (classes != null) { | |
| 1752 for (ClassElement element in classes) { | |
| 1753 generateClass(element, getElementDescriptor(element)); | |
| 1754 } | |
| 1755 } | |
| 1756 | 1765 |
| 1757 if (elementDescriptors.isNotEmpty) { | 1766 if (elementDescriptors.isNotEmpty) { |
| 1758 Iterable<LibraryElement> libraries = | 1767 Iterable<LibraryElement> libraries = |
| 1759 task.outputLibraryLists[outputUnit]; | 1768 task.outputLibraryLists[outputUnit]; |
| 1760 if (libraries == null) libraries = []; | 1769 if (libraries == null) libraries = []; |
| 1761 emitLibraries(libraries); | |
| 1762 | 1770 |
| 1763 // TODO(johnniwinther): Avoid creating [CodeBuffer]s. | 1771 // TODO(johnniwinther): Avoid creating [CodeBuffer]s. |
| 1764 CodeBuffer buffer = new CodeBuffer(); | 1772 CodeBuffer buffer = new CodeBuffer(); |
| 1765 outputBuffers[outputUnit] = buffer; | 1773 outputBuffers[outputUnit] = buffer; |
| 1766 for (LibraryElement library in Elements.sortedByPosition(libraries)) { | 1774 for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| 1767 writeLibraryDescriptors(buffer, library); | 1775 writeLibraryDescriptors(buffer, library); |
| 1768 elementDescriptors.remove(library); | 1776 elementDescriptors.remove(library); |
| 1769 } | 1777 } |
| 1770 } | 1778 } |
| 1771 } | 1779 } |
| 1772 | 1780 |
| 1773 return emitDeferredCode(outputBuffers); | 1781 return emitDeferredCode(program, outputBuffers); |
| 1774 } | 1782 } |
| 1775 | 1783 |
| 1776 CodeBuffer buildNativesBuffer() { | 1784 CodeBuffer buildNativesBuffer() { |
| 1777 // Emit native classes on [nativeBuffer]. | 1785 // Emit native classes on [nativeBuffer]. |
| 1778 // TODO(johnniwinther): Avoid creating a [CodeBuffer]. | 1786 // TODO(johnniwinther): Avoid creating a [CodeBuffer]. |
| 1779 final CodeBuffer nativeBuffer = new CodeBuffer(); | 1787 final CodeBuffer nativeBuffer = new CodeBuffer(); |
| 1780 | 1788 |
| 1781 if (nativeClasses.isEmpty) return nativeBuffer; | 1789 if (nativeClasses.isEmpty) return nativeBuffer; |
| 1782 | 1790 |
| 1783 | 1791 |
| 1784 addComment('Native classes', nativeBuffer); | 1792 addComment('Native classes', nativeBuffer); |
| 1785 | 1793 |
| 1786 nativeEmitter.generateNativeClasses(nativeClasses, additionalProperties); | 1794 nativeEmitter.generateNativeClasses(nativeClasses, additionalProperties); |
| 1787 | 1795 |
| 1788 nativeEmitter.finishGenerateNativeClasses(); | 1796 nativeEmitter.finishGenerateNativeClasses(); |
| 1789 nativeEmitter.assembleCode(nativeBuffer); | 1797 nativeEmitter.assembleCode(nativeBuffer); |
| 1790 | 1798 |
| 1791 return nativeBuffer; | 1799 return nativeBuffer; |
| 1792 } | 1800 } |
| 1793 | 1801 |
| 1794 int emitProgram(Program program) { | 1802 int emitProgram(Program program) { |
| 1795 // Shorten the code by using [namer.currentIsolate] as temporary. | 1803 // Shorten the code by using [namer.currentIsolate] as temporary. |
| 1796 isolateProperties = namer.currentIsolate; | 1804 isolateProperties = namer.currentIsolate; |
| 1797 | 1805 |
| 1798 // Emit deferred units first, so we have their hashes. | 1806 // Emit deferred units first, so we have their hashes. |
| 1799 // Map from OutputUnit to a hash of its content. The hash uniquely | 1807 // Map from OutputUnit to a hash of its content. The hash uniquely |
| 1800 // identifies the code of the output-unit. It does not include | 1808 // identifies the code of the output-unit. It does not include |
| 1801 // boilerplate JS code, like the sourcemap directives or the hash | 1809 // boilerplate JS code, like the sourcemap directives or the hash |
| 1802 // itself. | 1810 // itself. |
| 1803 Map<OutputUnit, String> deferredLoadHashes = emitDeferredOutputUnits(); | 1811 Map<OutputUnit, String> deferredLoadHashes = |
| 1812 emitDeferredOutputUnits(program); |
| 1804 CodeBuffer nativeBuffer = buildNativesBuffer(); | 1813 CodeBuffer nativeBuffer = buildNativesBuffer(); |
| 1805 emitMainOutputUnit(deferredLoadHashes, nativeBuffer); | 1814 emitMainOutputUnit(program, deferredLoadHashes, nativeBuffer); |
| 1806 | 1815 |
| 1807 if (backend.requiresPreamble && | 1816 if (backend.requiresPreamble && |
| 1808 !backend.htmlLibraryIsLoaded) { | 1817 !backend.htmlLibraryIsLoaded) { |
| 1809 compiler.reportHint(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); | 1818 compiler.reportHint(NO_LOCATION_SPANNABLE, MessageKind.PREAMBLE); |
| 1810 } | 1819 } |
| 1811 // Return the total program size. | 1820 // Return the total program size. |
| 1812 return outputBuffers.values.fold(0, (a, b) => a + b.length); | 1821 return outputBuffers.values.fold(0, (a, b) => a + b.length); |
| 1813 } | 1822 } |
| 1814 | 1823 |
| 1815 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { | 1824 String generateSourceMapTag(Uri sourceMapUri, Uri fileUri) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 | 1927 |
| 1919 emitMapping(embeddedNames.DEFERRED_LIBRARY_URIS, deferredLibraryUris); | 1928 emitMapping(embeddedNames.DEFERRED_LIBRARY_URIS, deferredLibraryUris); |
| 1920 emitMapping(embeddedNames.DEFERRED_LIBRARY_HASHES, | 1929 emitMapping(embeddedNames.DEFERRED_LIBRARY_HASHES, |
| 1921 deferredLibraryHashes); | 1930 deferredLibraryHashes); |
| 1922 } | 1931 } |
| 1923 | 1932 |
| 1924 /// Emits code for all output units except the main. | 1933 /// Emits code for all output units except the main. |
| 1925 /// Returns a mapping from outputUnit to a hash of the corresponding hunk that | 1934 /// Returns a mapping from outputUnit to a hash of the corresponding hunk that |
| 1926 /// can be used for calling the initializer. | 1935 /// can be used for calling the initializer. |
| 1927 Map<OutputUnit, String> emitDeferredCode( | 1936 Map<OutputUnit, String> emitDeferredCode( |
| 1937 Program program, |
| 1928 Map<OutputUnit, CodeBuffer> deferredBuffers) { | 1938 Map<OutputUnit, CodeBuffer> deferredBuffers) { |
| 1929 | 1939 |
| 1930 Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); | 1940 Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); |
| 1931 | 1941 |
| 1932 for (OutputUnit outputUnit in compiler.deferredLoadTask.allOutputUnits) { | 1942 for (Fragment fragment in program.deferredFragments) { |
| 1933 if (outputUnit == compiler.deferredLoadTask.mainOutputUnit) continue; | 1943 OutputUnit outputUnit = fragment.outputUnit; |
| 1934 | 1944 |
| 1935 CodeOutput libraryDescriptorBuffer = deferredBuffers[outputUnit]; | 1945 CodeOutput libraryDescriptorBuffer = deferredBuffers[outputUnit]; |
| 1936 | 1946 |
| 1937 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; | 1947 List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| 1938 Hasher hasher = new Hasher(); | 1948 Hasher hasher = new Hasher(); |
| 1939 outputListeners.add(hasher); | 1949 outputListeners.add(hasher); |
| 1940 | 1950 |
| 1941 LineColumnCollector lineColumnCollector; | 1951 LineColumnCollector lineColumnCollector; |
| 1942 if (generateSourceMap) { | 1952 if (generateSourceMap) { |
| 1943 lineColumnCollector = new LineColumnCollector(); | 1953 lineColumnCollector = new LineColumnCollector(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 // provided as second argument). | 1997 // provided as second argument). |
| 1988 // We need to do this, because we use the same variable for setting up | 1998 // We need to do this, because we use the same variable for setting up |
| 1989 // the isolate-properties and for storing the current isolate. During | 1999 // the isolate-properties and for storing the current isolate. During |
| 1990 // the setup (the code above this lines) we must set the variable to | 2000 // the setup (the code above this lines) we must set the variable to |
| 1991 // the isolate-properties. | 2001 // the isolate-properties. |
| 1992 // After we have done the setup it must point to the current Isolate. | 2002 // After we have done the setup it must point to the current Isolate. |
| 1993 // Otherwise all methods/functions accessing isolate variables will | 2003 // Otherwise all methods/functions accessing isolate variables will |
| 1994 // access the wrong object. | 2004 // access the wrong object. |
| 1995 output.add("${namer.currentIsolate}$_=${_}arguments[1]$N"); | 2005 output.add("${namer.currentIsolate}$_=${_}arguments[1]$N"); |
| 1996 | 2006 |
| 1997 emitCompileTimeConstants(output, outputUnit); | 2007 emitCompileTimeConstants( |
| 2008 output, fragment.constants, isMainFragment: false); |
| 1998 emitStaticNonFinalFieldInitializations(output, outputUnit); | 2009 emitStaticNonFinalFieldInitializations(output, outputUnit); |
| 1999 output.add('}$N'); | 2010 output.add('}$N'); |
| 2000 | 2011 |
| 2001 if (compiler.useContentSecurityPolicy) { | 2012 if (compiler.useContentSecurityPolicy) { |
| 2002 jsAst.FunctionDeclaration precompiledFunctionAst = | 2013 jsAst.FunctionDeclaration precompiledFunctionAst = |
| 2003 buildCspPrecompiledFunctionFor(outputUnit); | 2014 buildCspPrecompiledFunctionFor(outputUnit); |
| 2004 | 2015 |
| 2005 output.addBuffer( | 2016 output.addBuffer( |
| 2006 jsAst.prettyPrint( | 2017 jsAst.prettyPrint( |
| 2007 precompiledFunctionAst, compiler, | 2018 precompiledFunctionAst, compiler, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2093 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2104 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2094 if (element.isInstanceMember) { | 2105 if (element.isInstanceMember) { |
| 2095 cachedClassBuilders.remove(element.enclosingClass); | 2106 cachedClassBuilders.remove(element.enclosingClass); |
| 2096 | 2107 |
| 2097 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2108 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2098 | 2109 |
| 2099 } | 2110 } |
| 2100 } | 2111 } |
| 2101 } | 2112 } |
| 2102 } | 2113 } |
| OLD | NEW |