Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: pkg/fasta/lib/src/loader.dart

Issue 2623033007: Fasta targets and loaders. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library fasta.loader;
6
7 import 'dart:async' show
8 Future;
9
10 import 'dart:collection' show
11 Queue;
12
13 import 'ast_kind.dart' show
14 AstKind;
15
16 import 'builder/builder.dart' show
17 LibraryBuilder;
18
19 import 'errors.dart' show
20 InputError,
21 firstSourceUri;
22
23 import 'target_implementation.dart' show
24 TargetImplementation;
25
26 import 'ticker.dart' show
27 Ticker;
28
29 abstract class Loader<L> {
30 final Map<Uri, LibraryBuilder> builders = <Uri, LibraryBuilder>{};
31
32 final Queue<LibraryBuilder> unparsedLibraries = new Queue<LibraryBuilder>();
33
34 final List<L> libraries = <L>[];
35
36 final TargetImplementation target;
37
38 LibraryBuilder coreLibrary;
39
40 LibraryBuilder first;
41
42 int byteCount = 0;
43
44 Uri currentUriForCrashReporting;
45
46 Loader(this.target);
47
48 Ticker get ticker => target.ticker;
49
50 LibraryBuilder read(Uri uri) {
51 firstSourceUri ??= uri;
52 LibraryBuilder builder = builders.putIfAbsent(uri, () {
53 LibraryBuilder library = target.createLibraryBuilder(uri);
54 if (uri.scheme == "dart" && uri.path == "core") {
55 coreLibrary = library;
56 }
57 first ??= library;
58 if (library.loader == this) {
59 unparsedLibraries.addLast(library);
60 }
61 return library;
62 });
63 return builder;
64 }
65
66 void ensureCoreLibrary() {
67 if (coreLibrary == null) {
68 read(Uri.parse("dart:core"));
69 assert(coreLibrary != null);
70 }
71 }
72
73 Future<Null> buildBodies(AstKind astKind) async {
74 assert(coreLibrary != null);
75 for (LibraryBuilder library in builders.values) {
76 currentUriForCrashReporting = library.uri;
77 await buildBody(library, astKind);
78 }
79 currentUriForCrashReporting = null;
80 ticker.log((Duration elapsed, Duration sinceStart) {
81 int libraryCount = builders.length;
82 double ms =
83 elapsed.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
84 String message = "Built $libraryCount compilation units";
85 print("""
86 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is,
87 ${format(byteCount / ms, 3, 12)} bytes/ms, and
88 ${format(ms / libraryCount, 3, 12)} ms/compilation unit.""");
89 });
90 }
91
92 Future<Null> buildOutlines() async {
93 ensureCoreLibrary();
94 while (unparsedLibraries.isNotEmpty) {
95 LibraryBuilder library = unparsedLibraries.removeFirst();
96 currentUriForCrashReporting = library.uri;
97 await buildOutline(library);
98 }
99 currentUriForCrashReporting = null;
100 ticker.log((Duration elapsed, Duration sinceStart) {
Johnni Winther 2017/01/19 09:21:34 Share this code with [buildBodies].
ahe 2017/01/19 10:48:30 I'll add a TODO. These messages are confusing as w
101 int libraryCount = builders.length;
102 double ms =
103 elapsed.inMicroseconds / Duration.MICROSECONDS_PER_MILLISECOND;
104 String message = "Built outlines for $libraryCount compilation units";
105 print("""
106 $sinceStart: $message ($byteCount bytes) in ${format(ms, 3, 0)}ms, that is,
107 ${format(byteCount / ms, 3, 12)} bytes/ms, and
108 ${format(ms / libraryCount, 3, 12)} ms/compilation unit.""");
109 });
110 }
111
112 Future<Null> buildOutline(LibraryBuilder library);
113
114 Future<Null> buildBody(LibraryBuilder library, AstKind astKind);
115
116 List<InputError> collectCompileTimeErrors() {
117 List<InputError> errors = <InputError>[];
118 for (LibraryBuilder library in builders.values) {
119 if (library.loader == this) {
120 errors.addAll(library.compileTimeErrors);
121 }
122 }
123 return errors;
124 }
125 }
126
127 String format(double d, int fractionDigits, int width) {
128 return d.toStringAsFixed(fractionDigits).padLeft(width);
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698