| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Command line tool to run the checker on a Dart program. | 5 /// Command line tool to run the checker on a Dart program. |
| 6 library dev_compiler.src.compiler; | 6 library dev_compiler.src.compiler; |
| 7 | 7 |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:math' as math; | 10 import 'dart:math' as math; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 String _runtimeOutputDir; | 77 String _runtimeOutputDir; |
| 78 | 78 |
| 79 /// Already compiled sources, so we don't compile them again. | 79 /// Already compiled sources, so we don't compile them again. |
| 80 final _compiled = new HashSet<LibraryElement>(); | 80 final _compiled = new HashSet<LibraryElement>(); |
| 81 | 81 |
| 82 bool _failure = false; | 82 bool _failure = false; |
| 83 bool get failure => _failure; | 83 bool get failure => _failure; |
| 84 | 84 |
| 85 BatchCompiler(AnalysisContext context, CompilerOptions options, | 85 BatchCompiler(AnalysisContext context, CompilerOptions options, |
| 86 {AnalysisErrorListener reporter}) | 86 {AnalysisErrorListener reporter}) |
| 87 : super(context, options, reporter) { | 87 : super( |
| 88 context, |
| 89 options, |
| 90 new ErrorCollector( |
| 91 reporter ?? AnalysisErrorListener.NULL_LISTENER)) { |
| 88 _inputBaseDir = options.inputBaseDir; | 92 _inputBaseDir = options.inputBaseDir; |
| 89 if (outputDir != null) { | 93 if (outputDir != null) { |
| 90 _jsGen = new JSGenerator(this); | 94 _jsGen = new JSGenerator(this); |
| 91 _runtimeOutputDir = path.join(outputDir, 'dev_compiler', 'runtime'); | 95 _runtimeOutputDir = path.join(outputDir, 'dev_compiler', 'runtime'); |
| 92 } | 96 } |
| 93 _dartCore = context.typeProvider.objectType.element.library; | 97 _dartCore = context.typeProvider.objectType.element.library; |
| 94 } | 98 } |
| 95 | 99 |
| 100 ErrorCollector get reporter => checker.reporter; |
| 101 |
| 96 void reset() { | 102 void reset() { |
| 97 _compiled.clear(); | 103 _compiled.clear(); |
| 98 } | 104 } |
| 99 | 105 |
| 100 /// Compiles every file in [options.inputs]. | 106 /// Compiles every file in [options.inputs]. |
| 101 /// Returns true on successful compile. | 107 /// Returns true on successful compile. |
| 102 bool run() { | 108 bool run() { |
| 103 var clock = new Stopwatch()..start(); | 109 var clock = new Stopwatch()..start(); |
| 104 options.inputs.forEach(compileFromUriString); | 110 options.inputs.forEach(compileFromUriString); |
| 105 clock.stop(); | 111 clock.stop(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 120 var source = context.sourceFactory.forUri(Uri.encodeFull('$uri')); | 126 var source = context.sourceFactory.forUri(Uri.encodeFull('$uri')); |
| 121 if (source == null) { | 127 if (source == null) { |
| 122 throw new ArgumentError.value('$uri', 'uri', 'could not find source for'); | 128 throw new ArgumentError.value('$uri', 'uri', 'could not find source for'); |
| 123 } | 129 } |
| 124 compileSource(source); | 130 compileSource(source); |
| 125 } | 131 } |
| 126 | 132 |
| 127 void compileSource(Source source) { | 133 void compileSource(Source source) { |
| 128 if (AnalysisEngine.isHtmlFileName(source.uri.path)) { | 134 if (AnalysisEngine.isHtmlFileName(source.uri.path)) { |
| 129 _compileHtml(source); | 135 _compileHtml(source); |
| 130 return; | 136 } else { |
| 137 _compileLibrary(context.computeLibraryElement(source)); |
| 131 } | 138 } |
| 132 compileLibrary(context.computeLibraryElement(source)); | 139 reporter.flush(); |
| 133 } | 140 } |
| 134 | 141 |
| 135 void compileLibrary(LibraryElement library) { | 142 void _compileLibrary(LibraryElement library) { |
| 136 if (!_compiled.add(library)) return; | 143 if (!_compiled.add(library)) return; |
| 137 | 144 |
| 138 if (!options.checkSdk && library.source.uri.scheme == 'dart') { | 145 if (!options.checkSdk && library.source.uri.scheme == 'dart') { |
| 139 if (_jsGen != null) _copyDartRuntime(); | 146 if (_jsGen != null) _copyDartRuntime(); |
| 140 return; | 147 return; |
| 141 } | 148 } |
| 142 | 149 |
| 143 // TODO(jmesserly): in incremental mode, we can skip the transitive | 150 // TODO(jmesserly): in incremental mode, we can skip the transitive |
| 144 // compile of imports/exports. | 151 // compile of imports/exports. |
| 145 compileLibrary(_dartCore); // implicit dart:core dependency | 152 _compileLibrary(_dartCore); // implicit dart:core dependency |
| 146 library.importedLibraries.forEach(compileLibrary); | 153 library.importedLibraries.forEach(_compileLibrary); |
| 147 library.exportedLibraries.forEach(compileLibrary); | 154 library.exportedLibraries.forEach(_compileLibrary); |
| 148 | 155 |
| 149 var unitElements = [library.definingCompilationUnit]..addAll(library.parts); | 156 var unitElements = [library.definingCompilationUnit]..addAll(library.parts); |
| 150 var units = <CompilationUnit>[]; | 157 var units = <CompilationUnit>[]; |
| 151 | 158 |
| 152 bool failureInLib = false; | 159 bool failureInLib = false; |
| 153 for (var element in unitElements) { | 160 for (var element in unitElements) { |
| 154 var unit = context.resolveCompilationUnit(element.source, library); | 161 var unit = context.resolveCompilationUnit(element.source, library); |
| 155 units.add(unit); | 162 units.add(unit); |
| 156 failureInLib = logErrors(element.source) || failureInLib; | 163 failureInLib = logErrors(element.source) || failureInLib; |
| 157 checker.visitCompilationUnit(unit); | 164 checker.visitCompilationUnit(unit); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 209 } |
| 203 } | 210 } |
| 204 scriptSource = new DartScript(source, fragments); | 211 scriptSource = new DartScript(source, fragments); |
| 205 } | 212 } |
| 206 } else if (AnalysisEngine.isDartFileName(srcAttr)) { | 213 } else if (AnalysisEngine.isDartFileName(srcAttr)) { |
| 207 scriptSource = context.sourceFactory.resolveUri(source, srcAttr); | 214 scriptSource = context.sourceFactory.resolveUri(source, srcAttr); |
| 208 } | 215 } |
| 209 | 216 |
| 210 if (scriptSource != null) { | 217 if (scriptSource != null) { |
| 211 var lib = context.computeLibraryElement(scriptSource); | 218 var lib = context.computeLibraryElement(scriptSource); |
| 212 compileLibrary(lib); | 219 _compileLibrary(lib); |
| 213 script.replaceWith(_linkLibraries(lib, loadedLibs, from: htmlOutDir)); | 220 script.replaceWith(_linkLibraries(lib, loadedLibs, from: htmlOutDir)); |
| 214 } | 221 } |
| 215 } | 222 } |
| 216 | 223 |
| 217 new File(getOutputPath(source.uri)).openSync(mode: FileMode.WRITE) | 224 new File(getOutputPath(source.uri)).openSync(mode: FileMode.WRITE) |
| 218 ..writeStringSync(document.outerHtml) | 225 ..writeStringSync(document.outerHtml) |
| 219 ..writeStringSync('\n') | 226 ..writeStringSync('\n') |
| 220 ..closeSync(); | 227 ..closeSync(); |
| 221 } | 228 } |
| 222 | 229 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 abstract class AbstractCompiler { | 272 abstract class AbstractCompiler { |
| 266 final CompilerOptions options; | 273 final CompilerOptions options; |
| 267 final AnalysisContext context; | 274 final AnalysisContext context; |
| 268 final CodeChecker checker; | 275 final CodeChecker checker; |
| 269 | 276 |
| 270 AbstractCompiler(AnalysisContext context, CompilerOptions options, | 277 AbstractCompiler(AnalysisContext context, CompilerOptions options, |
| 271 [AnalysisErrorListener reporter]) | 278 [AnalysisErrorListener reporter]) |
| 272 : context = context, | 279 : context = context, |
| 273 options = options, | 280 options = options, |
| 274 checker = createChecker(context.typeProvider, options.strongOptions, | 281 checker = createChecker(context.typeProvider, options.strongOptions, |
| 275 reporter == null ? AnalysisErrorListener.NULL_LISTENER : reporter) { | 282 reporter ?? AnalysisErrorListener.NULL_LISTENER) { |
| 276 enableDevCompilerInference(context, options.strongOptions); | 283 enableDevCompilerInference(context, options.strongOptions); |
| 277 } | 284 } |
| 278 | 285 |
| 279 static CodeChecker createChecker(TypeProvider typeProvider, | 286 static CodeChecker createChecker(TypeProvider typeProvider, |
| 280 StrongModeOptions options, AnalysisErrorListener reporter) { | 287 StrongModeOptions options, AnalysisErrorListener reporter) { |
| 281 return new CodeChecker( | 288 return new CodeChecker( |
| 282 new RestrictedRules(typeProvider, options: options), reporter, options); | 289 new RestrictedRules(typeProvider, options: options), reporter, options); |
| 283 } | 290 } |
| 284 | 291 |
| 285 String get outputDir => options.codegenOptions.outputDir; | 292 String get outputDir => options.codegenOptions.outputDir; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 '_rtti.js', | 446 '_rtti.js', |
| 440 '_classes.js', | 447 '_classes.js', |
| 441 '_operations.js', | 448 '_operations.js', |
| 442 'dart_runtime.js', | 449 'dart_runtime.js', |
| 443 ]; | 450 ]; |
| 444 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); | 451 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); |
| 445 return files; | 452 return files; |
| 446 }(); | 453 }(); |
| 447 | 454 |
| 448 final _log = new Logger('dev_compiler.src.compiler'); | 455 final _log = new Logger('dev_compiler.src.compiler'); |
| OLD | NEW |