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_incremental; | 5 library dart2js_incremental; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 EventSink, | 8 EventSink, |
9 Future; | 9 Future; |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 {Logger logTime, | 117 {Logger logTime, |
118 Logger logVerbose}) { | 118 Logger logVerbose}) { |
119 if (logTime == null) { | 119 if (logTime == null) { |
120 logTime = (_) {}; | 120 logTime = (_) {}; |
121 } | 121 } |
122 if (logVerbose == null) { | 122 if (logVerbose == null) { |
123 logVerbose = (_) {}; | 123 logVerbose = (_) {}; |
124 } | 124 } |
125 Future mappingInputProvider(Uri uri) { | 125 Future mappingInputProvider(Uri uri) { |
126 Uri updatedFile = updatedFiles[uri]; | 126 Uri updatedFile = updatedFiles[uri]; |
127 return inputProvider(updatedFile == null ? uri : updatedFile); | 127 return inputProvider.readFromUri(updatedFile == null ? uri : updatedFile); |
128 } | 128 } |
129 LibraryUpdater updater = new LibraryUpdater( | 129 LibraryUpdater updater = new LibraryUpdater( |
130 _compiler, | 130 _compiler, |
131 mappingInputProvider, | 131 mappingInputProvider, |
132 logTime, | 132 logTime, |
133 logVerbose, | 133 logVerbose, |
134 _context); | 134 _context); |
135 _context.registerUriWithUpdates(updatedFiles.keys); | 135 _context.registerUriWithUpdates(updatedFiles.keys); |
136 Future<CompilerImpl> future = _reuseCompiler(updater.reuseLibrary); | 136 Future<CompilerImpl> future = _reuseCompiler(updater.reuseLibrary); |
137 return future.then((Compiler compiler) { | 137 return future.then((CompilerImpl compiler) { |
138 _compiler = compiler; | 138 _compiler = compiler; |
139 if (compiler.compilationFailed) { | 139 if (compiler.compilationFailed) { |
140 return null; | 140 return null; |
141 } else { | 141 } else { |
142 String update = updater.computeUpdateJs(); | 142 String update = updater.computeUpdateJs(); |
143 _updates.add(update); | 143 _updates.add(update); |
144 return update; | 144 return update; |
145 } | 145 } |
146 }); | 146 }); |
147 } | 147 } |
148 | 148 |
149 String allUpdates() { | 149 String allUpdates() { |
150 jsAst.Node updates = jsAst.js.escapedString(_updates.join("")); | 150 jsAst.Node updates = jsAst.js.escapedString(_updates.join("")); |
151 | 151 |
152 JavaScriptBackend backend = _compiler.backend; | 152 JavaScriptBackend backend = _compiler.backend; |
153 | 153 |
154 jsAst.FunctionDeclaration mainRunner = jsAst.js.statement(r""" | 154 jsAst.FunctionDeclaration mainRunner = jsAst.js.statement(r""" |
155 function dartMainRunner(main, args) { | 155 function dartMainRunner(main, args) { |
156 #helper.patch(#updates + "\n//# sourceURL=initial_patch.js\n"); | 156 #helper.patch(#updates + "\n//# sourceURL=initial_patch.js\n"); |
157 return main(args); | 157 return main(args); |
158 }""", {'updates': updates, 'helper': backend.namer.accessIncrementalHelper}); | 158 }""", {'updates': updates, 'helper': backend.namer.accessIncrementalHelper}); |
159 | 159 |
160 jsAst.Printer printer = new jsAst.Printer(_compiler, null); | 160 return jsAst.prettyPrint(mainRunner, _compiler).getText(); |
161 printer.blockOutWithoutBraces(mainRunner); | |
162 return printer.outBuffer.getText(); | |
163 } | 161 } |
164 } | 162 } |
165 | 163 |
166 class IncrementalCompilationFailed { | 164 class IncrementalCompilationFailed { |
167 final String reason; | 165 final String reason; |
168 | 166 |
169 const IncrementalCompilationFailed(this.reason); | 167 const IncrementalCompilationFailed(this.reason); |
170 | 168 |
171 String toString() => "Can't incrementally compile program.\n\n$reason"; | 169 String toString() => "Can't incrementally compile program.\n\n$reason"; |
172 } | 170 } |
OLD | NEW |