| 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 fletchc_incremental; | 5 library fletchc_incremental; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| 11 import 'dart:developer' show | 11 import 'dart:developer' show |
| 12 UserTag; | 12 UserTag; |
| 13 | 13 |
| 14 import 'package:compiler/src/apiimpl.dart' show | 14 import 'package:compiler/src/apiimpl.dart' show |
| 15 Compiler; | 15 CompilerImpl; |
| 16 | 16 |
| 17 import 'package:compiler/compiler_new.dart' show | 17 import 'package:compiler/compiler_new.dart' show |
| 18 CompilerDiagnostics, | 18 CompilerDiagnostics, |
| 19 CompilerInput, | 19 CompilerInput, |
| 20 CompilerOutput, | 20 CompilerOutput, |
| 21 Diagnostic; | 21 Diagnostic; |
| 22 | 22 |
| 23 import 'package:compiler/src/elements/elements.dart' show | 23 import 'package:compiler/src/elements/elements.dart' show |
| 24 ClassElement, | 24 ClassElement, |
| 25 ConstructorElement, | 25 ConstructorElement, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 | 141 |
| 142 FletchCompilerImplementation get compiler => _compiler; | 142 FletchCompilerImplementation get compiler => _compiler; |
| 143 | 143 |
| 144 /// Perform a full compile of [script]. This will reset the incremental | 144 /// Perform a full compile of [script]. This will reset the incremental |
| 145 /// compiler. | 145 /// compiler. |
| 146 /// | 146 /// |
| 147 /// Notice: a full compile means not incremental. The part of the program | 147 /// Notice: a full compile means not incremental. The part of the program |
| 148 /// that is compiled is determined by tree shaking. | 148 /// that is compiled is determined by tree shaking. |
| 149 Future<bool> compile(Uri script) { | 149 Future<bool> compile(Uri script) { |
| 150 _compiler = null; | 150 _compiler = null; |
| 151 return _reuseCompiler(null).then((Compiler compiler) { | 151 return _reuseCompiler(null).then((CompilerImpl compiler) { |
| 152 _compiler = compiler; | 152 _compiler = compiler; |
| 153 return compiler.run(script); | 153 return compiler.run(script); |
| 154 }); | 154 }); |
| 155 } | 155 } |
| 156 | 156 |
| 157 /// Perform a full analysis of [script]. This will reset the incremental | 157 /// Perform a full analysis of [script]. This will reset the incremental |
| 158 /// compiler. | 158 /// compiler. |
| 159 /// | 159 /// |
| 160 /// Notice: a full analysis is analogous to a full compile, that is, full | 160 /// Notice: a full analysis is analogous to a full compile, that is, full |
| 161 /// analysis not incremental. The part of the program that is analyzed is | 161 /// analysis not incremental. The part of the program that is analyzed is |
| 162 /// determined by tree shaking. | 162 /// determined by tree shaking. |
| 163 Future<int> analyze(Uri script) { | 163 Future<int> analyze(Uri script) { |
| 164 _compiler = null; | 164 _compiler = null; |
| 165 int initialErrorCount = _context.errorCount; | 165 int initialErrorCount = _context.errorCount; |
| 166 int initialProblemCount = _context.problemCount; | 166 int initialProblemCount = _context.problemCount; |
| 167 return _reuseCompiler(null, analyzeOnly: true).then((Compiler compiler) { | 167 return _reuseCompiler(null, analyzeOnly: true).then( |
| 168 (CompilerImpl compiler) { |
| 168 // Don't try to reuse the compiler object. | 169 // Don't try to reuse the compiler object. |
| 169 return compiler.run(script).then((_) { | 170 return compiler.run(script).then((_) { |
| 170 return _context.problemCount == initialProblemCount | 171 return _context.problemCount == initialProblemCount |
| 171 ? 0 | 172 ? 0 |
| 172 : _context.errorCount == initialErrorCount | 173 : _context.errorCount == initialErrorCount |
| 173 ? exit_codes.ANALYSIS_HAD_NON_ERROR_PROBLEMS | 174 ? exit_codes.ANALYSIS_HAD_NON_ERROR_PROBLEMS |
| 174 : exit_codes.ANALYSIS_HAD_ERRORS; | 175 : exit_codes.ANALYSIS_HAD_ERRORS; |
| 175 }); | 176 }); |
| 176 }); | 177 }); |
| 177 } | 178 } |
| 178 | 179 |
| 179 Future<Compiler> _reuseCompiler( | 180 Future<CompilerImpl> _reuseCompiler( |
| 180 Future<bool> reuseLibrary(LibraryElement library), | 181 Future<bool> reuseLibrary(LibraryElement library), |
| 181 {bool analyzeOnly: false}) { | 182 {bool analyzeOnly: false}) { |
| 182 List<String> options = this.options == null | 183 List<String> options = this.options == null |
| 183 ? <String> [] : new List<String>.from(this.options); | 184 ? <String> [] : new List<String>.from(this.options); |
| 184 options.addAll(INCREMENTAL_OPTIONS); | 185 options.addAll(INCREMENTAL_OPTIONS); |
| 185 if (analyzeOnly) { | 186 if (analyzeOnly) { |
| 186 options.add("--analyze-only"); | 187 options.add("--analyze-only"); |
| 187 } | 188 } |
| 188 return reuseCompiler( | 189 return reuseCompiler( |
| 189 cachedCompiler: _compiler, | 190 cachedCompiler: _compiler, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 Uri updatedFile = updatedFiles[uri]; | 227 Uri updatedFile = updatedFiles[uri]; |
| 227 return inputProvider.readFromUri(updatedFile == null ? uri : updatedFile); | 228 return inputProvider.readFromUri(updatedFile == null ? uri : updatedFile); |
| 228 } | 229 } |
| 229 LibraryUpdater updater = new LibraryUpdater( | 230 LibraryUpdater updater = new LibraryUpdater( |
| 230 _compiler, | 231 _compiler, |
| 231 mappingInputProvider, | 232 mappingInputProvider, |
| 232 logTime, | 233 logTime, |
| 233 logVerbose, | 234 logVerbose, |
| 234 _context); | 235 _context); |
| 235 _context.registerUriWithUpdates(updatedFiles.keys); | 236 _context.registerUriWithUpdates(updatedFiles.keys); |
| 236 return _reuseCompiler(updater.reuseLibrary).then((Compiler compiler) async { | 237 return _reuseCompiler(updater.reuseLibrary).then( |
| 238 (CompilerImpl compiler) async { |
| 237 _compiler = compiler; | 239 _compiler = compiler; |
| 238 FletchDelta delta = await updater.computeUpdateFletch(currentSystem); | 240 FletchDelta delta = await updater.computeUpdateFletch(currentSystem); |
| 239 _checkCompilationFailed(); | 241 _checkCompilationFailed(); |
| 240 return delta; | 242 return delta; |
| 241 }); | 243 }); |
| 242 } | 244 } |
| 243 | 245 |
| 244 FletchDelta computeInitialDelta() { | 246 FletchDelta computeInitialDelta() { |
| 245 FletchBackend backend = _compiler.backend; | 247 FletchBackend backend = _compiler.backend; |
| 246 return backend.computeDelta(); | 248 return backend.computeDelta(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 327 |
| 326 case "production": | 328 case "production": |
| 327 return IncrementalMode.production; | 329 return IncrementalMode.production; |
| 328 | 330 |
| 329 case "experimental": | 331 case "experimental": |
| 330 return IncrementalMode.experimental; | 332 return IncrementalMode.experimental; |
| 331 | 333 |
| 332 } | 334 } |
| 333 return null; | 335 return null; |
| 334 } | 336 } |
| OLD | NEW |