| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.loader; | 5 library fasta.loader; |
| 6 | 6 |
| 7 import 'dart:async' show Future; | 7 import 'dart:async' show Future; |
| 8 | 8 |
| 9 import 'dart:collection' show Queue; | 9 import 'dart:collection' show Queue; |
| 10 | 10 |
| 11 import 'ast_kind.dart' show AstKind; | |
| 12 | |
| 13 import 'builder/builder.dart' show Builder, LibraryBuilder; | 11 import 'builder/builder.dart' show Builder, LibraryBuilder; |
| 14 | 12 |
| 15 import 'errors.dart' show InputError, firstSourceUri; | 13 import 'errors.dart' show InputError, firstSourceUri; |
| 16 | 14 |
| 17 import 'target_implementation.dart' show TargetImplementation; | 15 import 'target_implementation.dart' show TargetImplementation; |
| 18 | 16 |
| 19 import 'ticker.dart' show Ticker; | 17 import 'ticker.dart' show Ticker; |
| 20 | 18 |
| 21 abstract class Loader<L> { | 19 abstract class Loader<L> { |
| 22 final Map<Uri, LibraryBuilder> builders = <Uri, LibraryBuilder>{}; | 20 final Map<Uri, LibraryBuilder> builders = <Uri, LibraryBuilder>{}; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return builder; | 72 return builder; |
| 75 } | 73 } |
| 76 | 74 |
| 77 void ensureCoreLibrary() { | 75 void ensureCoreLibrary() { |
| 78 if (coreLibrary == null) { | 76 if (coreLibrary == null) { |
| 79 read(Uri.parse("dart:core")); | 77 read(Uri.parse("dart:core")); |
| 80 assert(coreLibrary != null); | 78 assert(coreLibrary != null); |
| 81 } | 79 } |
| 82 } | 80 } |
| 83 | 81 |
| 84 Future<Null> buildBodies(AstKind astKind) async { | 82 Future<Null> buildBodies() async { |
| 85 assert(coreLibrary != null); | 83 assert(coreLibrary != null); |
| 86 for (LibraryBuilder library in builders.values) { | 84 for (LibraryBuilder library in builders.values) { |
| 87 currentUriForCrashReporting = library.uri; | 85 currentUriForCrashReporting = library.uri; |
| 88 await buildBody(library, astKind); | 86 await buildBody(library); |
| 89 } | 87 } |
| 90 currentUriForCrashReporting = null; | 88 currentUriForCrashReporting = null; |
| 91 ticker.log((Duration elapsed, Duration sinceStart) { | 89 ticker.log((Duration elapsed, Duration sinceStart) { |
| 92 int libraryCount = builders.length; | 90 int libraryCount = builders.length; |
| 93 double ms = | 91 double ms = |
| 94 elapsed.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND; | 92 elapsed.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND; |
| 95 String message = "Built $libraryCount compilation units"; | 93 String message = "Built $libraryCount compilation units"; |
| 96 print(""" | 94 print(""" |
| 97 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is, | 95 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is, |
| 98 ${format(byteCount / ms, 3, 12)} bytes/ms, and | 96 ${format(byteCount / ms, 3, 12)} bytes/ms, and |
| (...skipping 20 matching lines...) Expand all Loading... |
| 119 print(""" | 117 print(""" |
| 120 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is, | 118 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is, |
| 121 ${format(byteCount / ms, 3, 12)} bytes/ms, and | 119 ${format(byteCount / ms, 3, 12)} bytes/ms, and |
| 122 ${format(ms / libraryCount, 3, 12)} ms/compilation unit."""); | 120 ${format(ms / libraryCount, 3, 12)} ms/compilation unit."""); |
| 123 }); | 121 }); |
| 124 } | 122 } |
| 125 | 123 |
| 126 Future<Null> buildOutline(covariant LibraryBuilder library); | 124 Future<Null> buildOutline(covariant LibraryBuilder library); |
| 127 | 125 |
| 128 /// Builds all the method bodies found in the given [library]. | 126 /// Builds all the method bodies found in the given [library]. |
| 129 /// | 127 Future<Null> buildBody(covariant LibraryBuilder library); |
| 130 /// [astKind] determines whether or not analyzer ASTs are used as an | |
| 131 /// intermediate data structure. | |
| 132 Future<Null> buildBody(covariant LibraryBuilder library, AstKind astKind); | |
| 133 | 128 |
| 134 List<InputError> collectCompileTimeErrors() { | 129 List<InputError> collectCompileTimeErrors() { |
| 135 List<InputError> errors = <InputError>[]; | 130 List<InputError> errors = <InputError>[]; |
| 136 for (LibraryBuilder library in builders.values) { | 131 for (LibraryBuilder library in builders.values) { |
| 137 if (library.loader == this) { | 132 if (library.loader == this) { |
| 138 errors.addAll(library.compileTimeErrors); | 133 errors.addAll(library.compileTimeErrors); |
| 139 } | 134 } |
| 140 } | 135 } |
| 141 return errors; | 136 return errors; |
| 142 } | 137 } |
| 143 | 138 |
| 144 Builder getCompileTimeError() => target.getCompileTimeError(this); | 139 Builder getCompileTimeError() => target.getCompileTimeError(this); |
| 145 | 140 |
| 146 Builder getNativeAnnotation() => target.getNativeAnnotation(this); | 141 Builder getNativeAnnotation() => target.getNativeAnnotation(this); |
| 147 } | 142 } |
| 148 | 143 |
| 149 String format(double d, int fractionDigits, int width) { | 144 String format(double d, int fractionDigits, int width) { |
| 150 return d.toStringAsFixed(fractionDigits).padLeft(width); | 145 return d.toStringAsFixed(fractionDigits).padLeft(width); |
| 151 } | 146 } |
| OLD | NEW |