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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 if (!_compiled.add(library)) return; | 145 if (!_compiled.add(library)) return; |
146 | 146 |
147 if (!options.checkSdk && library.source.uri.scheme == 'dart') { | 147 if (!options.checkSdk && library.source.uri.scheme == 'dart') { |
148 if (_jsGen != null) _copyDartRuntime(); | 148 if (_jsGen != null) _copyDartRuntime(); |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 // TODO(jmesserly): in incremental mode, we can skip the transitive | 152 // TODO(jmesserly): in incremental mode, we can skip the transitive |
153 // compile of imports/exports. | 153 // compile of imports/exports. |
154 _compileLibrary(_dartCore); // implicit dart:core dependency | 154 _compileLibrary(_dartCore); // implicit dart:core dependency |
155 library.importedLibraries.forEach(_compileLibrary); | 155 for (var import in library.imports) _compileLibrary(import.importedLibrary); |
156 library.exportedLibraries.forEach(_compileLibrary); | 156 for (var export in library.exports) _compileLibrary(export.exportedLibrary); |
157 | 157 |
158 var unitElements = [library.definingCompilationUnit]..addAll(library.parts); | 158 var unitElements = [library.definingCompilationUnit]..addAll(library.parts); |
159 var units = <CompilationUnit>[]; | 159 var units = <CompilationUnit>[]; |
160 | 160 |
161 bool failureInLib = false; | 161 bool failureInLib = false; |
162 for (var element in unitElements) { | 162 for (var element in unitElements) { |
163 var unit = context.resolveCompilationUnit(element.source, library); | 163 var unit = context.resolveCompilationUnit(element.source, library); |
164 units.add(unit); | 164 units.add(unit); |
165 failureInLib = logErrors(element.source) || failureInLib; | 165 failureInLib = logErrors(element.source) || failureInLib; |
166 checker.visitCompilationUnit(unit); | 166 checker.visitCompilationUnit(unit); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 } else { | 258 } else { |
259 var file = path.join(outputDir, getModulePath(uri)); | 259 var file = path.join(outputDir, getModulePath(uri)); |
260 df.append(html_codegen.libraryInclude(path.relative(file, from: from))); | 260 df.append(html_codegen.libraryInclude(path.relative(file, from: from))); |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 df.append(html_codegen.invokeMain(getModuleName(mainLib.source.uri))); | 264 df.append(html_codegen.invokeMain(getModuleName(mainLib.source.uri))); |
265 return df; | 265 return df; |
266 } | 266 } |
267 | 267 |
268 void _collectLibraries(LibraryElement lib, LinkedHashSet<Uri> loaded) { | 268 void _collectLibraries(LibraryElement lib, LinkedHashSet<Uri> loaded) { |
Jennifer Messerly
2015/09/15 00:32:59
our own ordered hash set was not effective because
| |
269 var uri = lib.source.uri; | 269 var uri = lib.source.uri; |
270 if (!loaded.add(uri)) return; | 270 if (!loaded.add(uri)) return; |
271 _collectLibraries(_dartCore, loaded); | 271 _collectLibraries(_dartCore, loaded); |
272 for (var l in lib.importedLibraries) _collectLibraries(l, loaded); | 272 |
273 for (var l in lib.exportedLibraries) _collectLibraries(l, loaded); | 273 for (var l in lib.imports) _collectLibraries(l.importedLibrary, loaded); |
274 for (var l in lib.exports) _collectLibraries(l.exportedLibrary, loaded); | |
274 // Move the item to the end of the list. | 275 // Move the item to the end of the list. |
275 loaded.remove(uri); | 276 loaded.remove(uri); |
276 loaded.add(uri); | 277 loaded.add(uri); |
277 } | 278 } |
278 } | 279 } |
279 | 280 |
280 abstract class AbstractCompiler { | 281 abstract class AbstractCompiler { |
281 final CompilerOptions options; | 282 final CompilerOptions options; |
282 final AnalysisContext context; | 283 final AnalysisContext context; |
283 final CodeChecker checker; | 284 final CodeChecker checker; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 '_rtti.js', | 455 '_rtti.js', |
455 '_classes.js', | 456 '_classes.js', |
456 '_operations.js', | 457 '_operations.js', |
457 'dart_runtime.js', | 458 'dart_runtime.js', |
458 ]; | 459 ]; |
459 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); | 460 files.addAll(corelibOrder.map((l) => l.replaceAll('.', '/') + '.js')); |
460 return files; | 461 return files; |
461 }(); | 462 }(); |
462 | 463 |
463 final _log = new Logger('dev_compiler.src.compiler'); | 464 final _log = new Logger('dev_compiler.src.compiler'); |
OLD | NEW |