Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| index 0eec3369c4bd7521af836fcbc003d1b304c08464..42be430ac72def4688530903b5433c402f83ea53 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart |
| @@ -1625,15 +1625,10 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| }"""); |
| } |
| - /// Returns a map from OutputUnit to a hash of its content. The hash uniquely |
| - /// identifies the code of the output-unit. It does not include |
| - /// boilerplate JS code, like the sourcemap directives or the hash |
| - /// itself. |
| - Map<OutputUnit, String> emitDeferredOutputUnits(Program program) { |
| - if (!program.isSplit) return const {}; |
| - |
| + Map<OutputUnit, jsAst.Expression> buildDescriptorsForOutputUnits( |
| + Program program) { |
| Map<OutputUnit, jsAst.Expression> outputs = |
| - new Map<OutputUnit, jsAst.Expression>(); |
| + new Map<OutputUnit, jsAst.Expression>(); |
|
karlklose
2015/05/22 07:27:49
Undo change here an din l. 1640.
herhut
2015/05/22 07:57:20
Done.
|
| for (Fragment fragment in program.deferredFragments) { |
| OutputUnit outputUnit = fragment.outputUnit; |
| @@ -1642,7 +1637,7 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| if (descriptors != null && descriptors.isNotEmpty) { |
| Iterable<LibraryElement> libraries = |
| - task.outputLibraryLists[outputUnit]; |
| + task.outputLibraryLists[outputUnit]; |
| if (libraries == null) libraries = []; |
| // TODO(johnniwinther): Avoid creating [CodeBuffer]s. |
| @@ -1656,7 +1651,7 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| } |
| } |
| - return emitDeferredCode(program, outputs); |
| + return outputs; |
| } |
| int emitProgram(ProgramBuilder programBuilder) { |
| @@ -1665,13 +1660,17 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| assembleProgram(program); |
| + // Construct the ASTs for all deferred output units. |
| + Map<OutputUnit, jsAst.Program> deferredParts = |
| + buildOutputAstForDeferredCode(program); |
| + |
| // Emit deferred units first, so we have their hashes. |
| // Map from OutputUnit to a hash of its content. The hash uniquely |
| // identifies the code of the output-unit. It does not include |
| // boilerplate JS code, like the sourcemap directives or the hash |
| // itself. |
| Map<OutputUnit, String> deferredLoadHashes = |
| - emitDeferredOutputUnits(program); |
| + emitDeferredOutputUnits(deferredParts); |
| emitMainOutputUnit(program, deferredLoadHashes); |
| if (backend.requiresPreamble && |
| @@ -1791,38 +1790,19 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| return new jsAst.Block(parts); |
| } |
| - /// Emits code for all output units except the main. |
| - /// Returns a mapping from outputUnit to a hash of the corresponding hunk that |
| - /// can be used for calling the initializer. |
| - Map<OutputUnit, String> emitDeferredCode( |
| - Program program, |
| - Map<OutputUnit, jsAst.Expression> deferredAsts) { |
| + Map <OutputUnit, jsAst.Program> buildOutputAstForDeferredCode( |
| + Program program) { |
| + if (!program.isSplit) return const {}; |
|
karlklose
2015/05/22 07:27:49
Add type arguments to map literal.
herhut
2015/05/22 07:57:20
Done.
|
| - Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); |
| + Map<OutputUnit, jsAst.Program> result = |
| + new Map<OutputUnit, jsAst.Program>(); |
| + |
| + Map<OutputUnit, jsAst.Expression> deferredAsts = |
| + buildDescriptorsForOutputUnits(program); |
| for (Fragment fragment in program.deferredFragments) { |
| OutputUnit outputUnit = fragment.outputUnit; |
| - |
| jsAst.Expression libraryDescriptor = deferredAsts[outputUnit]; |
| - |
| - List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| - Hasher hasher = new Hasher(); |
| - outputListeners.add(hasher); |
| - |
| - LineColumnCollector lineColumnCollector; |
| - if (generateSourceMap) { |
| - lineColumnCollector = new LineColumnCollector(); |
| - outputListeners.add(lineColumnCollector); |
| - } |
| - |
| - String partPrefix = |
| - backend.deferredPartFileName(outputUnit.name, addExtension: false); |
| - CodeOutput output = new StreamCodeOutput( |
| - compiler.outputProvider(partPrefix, 'part.js'), |
| - outputListeners); |
| - |
| - outputBuffers[outputUnit] = output; |
| - |
| List<jsAst.Statement> body = <jsAst.Statement>[]; |
| // No renaming in the top-level function to save the locals for the |
| @@ -1837,9 +1817,9 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| ..add(js.statement('var $setupProgramName = ' |
| '$globalsHolder.$setupProgramName;')) |
| ..add(js.statement('var ${namer.isolateName} = ' |
| - '${globalsHolder}.${namer.isolateName};')); |
| + '${globalsHolder}.${namer.isolateName};')); |
|
karlklose
2015/05/22 07:27:49
Undo changes here and in l. 1822.
herhut
2015/05/22 07:57:20
Done.
|
| String typesAccess = |
| - generateEmbeddedGlobalAccessString(embeddedNames.TYPES); |
| + generateEmbeddedGlobalAccessString(embeddedNames.TYPES); |
| if (libraryDescriptor != null) { |
| // The argument to reflectionDataParser is assigned to a temporary |
| // 'dart' so that 'dart.' will appear as the prefix to dart methods |
| @@ -1869,14 +1849,49 @@ function(originalDescriptor, name, holder, isStatic, globalFunctionsAccess) { |
| List<jsAst.Statement> statements = <jsAst.Statement>[]; |
| - statements..add(buildGeneratedBy()) |
| + statements |
| + ..add(buildGeneratedBy()) |
| ..add(js.statement('${deferredInitializers}.current = ' |
| - """function (${globalsHolder}) { |
| - # |
| - } |
| + """function (${globalsHolder}) { |
| + # |
| + } |
| """, [body])); |
| - output.addBuffer(jsAst.prettyPrint(new jsAst.Program(statements), |
| + result[outputUnit] = new jsAst.Program(statements); |
| + } |
| + |
| + return result; |
| + } |
| + |
| + /// Returns a map from OutputUnit to a hash of its content. The hash uniquely |
| + /// identifies the code of the output-unit. It does not include |
| + /// boilerplate JS code, like the sourcemap directives or the hash |
| + /// itself. |
| + Map<OutputUnit, String> emitDeferredOutputUnits( |
| + Map<OutputUnit, jsAst.Program> outputAsts) { |
| + |
| + Map<OutputUnit, String> hunkHashes = new Map<OutputUnit, String>(); |
| + |
| + for (OutputUnit outputUnit in outputAsts.keys) { |
| + List<CodeOutputListener> outputListeners = <CodeOutputListener>[]; |
| + Hasher hasher = new Hasher(); |
| + outputListeners.add(hasher); |
| + |
| + LineColumnCollector lineColumnCollector; |
| + if (generateSourceMap) { |
| + lineColumnCollector = new LineColumnCollector(); |
| + outputListeners.add(lineColumnCollector); |
| + } |
| + |
| + String partPrefix = |
| + backend.deferredPartFileName(outputUnit.name, addExtension: false); |
| + CodeOutput output = new StreamCodeOutput( |
| + compiler.outputProvider(partPrefix, 'part.js'), |
| + outputListeners); |
| + |
| + outputBuffers[outputUnit] = output; |
| + |
| + output.addBuffer(jsAst.prettyPrint(outputAsts[outputUnit], |
| compiler, |
| monitor: compiler.dumpInfoTask)); |