| 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 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1122 MyClass.prototype = properties; | 1122 MyClass.prototype = properties; |
| 1123 new MyClass(); | 1123 new MyClass(); |
| 1124 #; | 1124 #; |
| 1125 return properties; | 1125 return properties; |
| 1126 }''', [debugCode]); | 1126 }''', [debugCode]); |
| 1127 | 1127 |
| 1128 output.addBuffer(jsAst.prettyPrint(convertToFastObject, compiler)); | 1128 output.addBuffer(jsAst.prettyPrint(convertToFastObject, compiler)); |
| 1129 output.add(N); | 1129 output.add(N); |
| 1130 } | 1130 } |
| 1131 | 1131 |
| 1132 void writeLibraryDescriptors(CodeOutput output, LibraryElement library) { | 1132 void writeLibraryDescriptor(CodeOutput output, LibraryElement library) { |
| 1133 var uri = ""; | 1133 var uri = ""; |
| 1134 if (!compiler.enableMinification || backend.mustPreserveUris) { | 1134 if (!compiler.enableMinification || backend.mustPreserveUris) { |
| 1135 uri = library.canonicalUri; | 1135 uri = library.canonicalUri; |
| 1136 if (uri.scheme == 'file' && compiler.outputUri != null) { | 1136 if (uri.scheme == 'file' && compiler.outputUri != null) { |
| 1137 uri = relativize(compiler.outputUri, library.canonicalUri, false); | 1137 uri = relativize(compiler.outputUri, library.canonicalUri, false); |
| 1138 } | 1138 } |
| 1139 } | 1139 } |
| 1140 ClassBuilder descriptor = elementDescriptors[library]; | 1140 ClassBuilder descriptor = elementDescriptors[library]; |
| 1141 if (descriptor == null) { | 1141 if (descriptor == null) { |
| 1142 // Nothing of the library was emitted. | 1142 // Nothing of the library was emitted. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1425 Iterable<LibraryElement> libraries = | 1425 Iterable<LibraryElement> libraries = |
| 1426 task.outputLibraryLists[mainOutputUnit]; | 1426 task.outputLibraryLists[mainOutputUnit]; |
| 1427 if (libraries == null) libraries = []; | 1427 if (libraries == null) libraries = []; |
| 1428 emitTypedefs(); | 1428 emitTypedefs(); |
| 1429 emitMangledNames(mainOutput); | 1429 emitMangledNames(mainOutput); |
| 1430 | 1430 |
| 1431 checkEverythingEmitted(elementDescriptors.keys); | 1431 checkEverythingEmitted(elementDescriptors.keys); |
| 1432 | 1432 |
| 1433 CodeBuffer libraryBuffer = new CodeBuffer(); | 1433 CodeBuffer libraryBuffer = new CodeBuffer(); |
| 1434 for (LibraryElement library in Elements.sortedByPosition(libraries)) { | 1434 for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| 1435 writeLibraryDescriptors(libraryBuffer, library); | 1435 writeLibraryDescriptor(libraryBuffer, library); |
| 1436 elementDescriptors.remove(library); | 1436 elementDescriptors.remove(library); |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 if (elementDescriptors.isNotEmpty) { |
| 1440 List<Element> remainingLibraries = elementDescriptors.keys |
| 1441 .where((Element e) => e is LibraryElement) |
| 1442 .toList(); |
| 1443 |
| 1444 // The remaining descriptors are only accessible through reflection. |
| 1445 // The program builder does not collect libraries that only |
| 1446 // contain typedefs that are used for reflection. |
| 1447 for (LibraryElement element in remainingLibraries) { |
| 1448 assert(element is LibraryElement || compiler.hasIncrementalSupport); |
| 1449 if (element is LibraryElement) { |
| 1450 writeLibraryDescriptor(libraryBuffer, element); |
| 1451 elementDescriptors.remove(element); |
| 1452 } |
| 1453 } |
| 1454 } |
| 1455 |
| 1439 bool needsNativeSupport = program.needsNativeSupport; | 1456 bool needsNativeSupport = program.needsNativeSupport; |
| 1440 mainOutput | 1457 mainOutput |
| 1441 ..addBuffer( | 1458 ..addBuffer( |
| 1442 jsAst.prettyPrint( | 1459 jsAst.prettyPrint( |
| 1443 getReflectionDataParser(this, backend, needsNativeSupport), | 1460 getReflectionDataParser(this, backend, needsNativeSupport), |
| 1444 compiler)) | 1461 compiler)) |
| 1445 ..add(n); | 1462 ..add(n); |
| 1446 | 1463 |
| 1447 // The argument to reflectionDataParser is assigned to a temporary 'dart' | 1464 // The argument to reflectionDataParser is assigned to a temporary 'dart' |
| 1448 // so that 'dart.' will appear as the prefix to dart methods in stack | 1465 // so that 'dart.' will appear as the prefix to dart methods in stack |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 | 1715 |
| 1699 if (elementDescriptors.isNotEmpty) { | 1716 if (elementDescriptors.isNotEmpty) { |
| 1700 Iterable<LibraryElement> libraries = | 1717 Iterable<LibraryElement> libraries = |
| 1701 task.outputLibraryLists[outputUnit]; | 1718 task.outputLibraryLists[outputUnit]; |
| 1702 if (libraries == null) libraries = []; | 1719 if (libraries == null) libraries = []; |
| 1703 | 1720 |
| 1704 // TODO(johnniwinther): Avoid creating [CodeBuffer]s. | 1721 // TODO(johnniwinther): Avoid creating [CodeBuffer]s. |
| 1705 CodeBuffer buffer = new CodeBuffer(); | 1722 CodeBuffer buffer = new CodeBuffer(); |
| 1706 outputBuffers[outputUnit] = buffer; | 1723 outputBuffers[outputUnit] = buffer; |
| 1707 for (LibraryElement library in Elements.sortedByPosition(libraries)) { | 1724 for (LibraryElement library in Elements.sortedByPosition(libraries)) { |
| 1708 writeLibraryDescriptors(buffer, library); | 1725 writeLibraryDescriptor(buffer, library); |
| 1709 elementDescriptors.remove(library); | 1726 elementDescriptors.remove(library); |
| 1710 } | 1727 } |
| 1711 } | 1728 } |
| 1712 } | 1729 } |
| 1713 | 1730 |
| 1714 return emitDeferredCode(program, outputBuffers); | 1731 return emitDeferredCode(program, outputBuffers); |
| 1715 } | 1732 } |
| 1716 | 1733 |
| 1717 int emitProgram(ProgramBuilder programBuilder) { | 1734 int emitProgram(ProgramBuilder programBuilder) { |
| 1718 Program program = programBuilder.buildProgram( | 1735 Program program = programBuilder.buildProgram( |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2021 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 2038 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 2022 if (element.isInstanceMember) { | 2039 if (element.isInstanceMember) { |
| 2023 cachedClassBuilders.remove(element.enclosingClass); | 2040 cachedClassBuilders.remove(element.enclosingClass); |
| 2024 | 2041 |
| 2025 nativeEmitter.cachedBuilders.remove(element.enclosingClass); | 2042 nativeEmitter.cachedBuilders.remove(element.enclosingClass); |
| 2026 | 2043 |
| 2027 } | 2044 } |
| 2028 } | 2045 } |
| 2029 } | 2046 } |
| 2030 } | 2047 } |
| OLD | NEW |