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 'builder/builder.dart' show Builder, LibraryBuilder; | 11 import 'builder/builder.dart' show Builder, LibraryBuilder; |
12 | 12 |
13 import 'errors.dart' show InputError, firstSourceUri, printUnexpected; | 13 import 'errors.dart' show InputError, firstSourceUri, printUnexpected; |
14 | 14 |
15 import 'target_implementation.dart' show TargetImplementation; | 15 import 'target_implementation.dart' show TargetImplementation; |
16 | 16 |
17 import 'ticker.dart' show Ticker; | 17 import 'ticker.dart' show Ticker; |
18 | 18 |
19 abstract class Loader<L> { | 19 abstract class Loader<L> { |
20 final Map<Uri, LibraryBuilder> builders = <Uri, LibraryBuilder>{}; | 20 final Map<Uri, LibraryBuilder> builders = <Uri, LibraryBuilder>{}; |
21 | 21 |
22 final Queue<LibraryBuilder> unparsedLibraries = new Queue<LibraryBuilder>(); | 22 final Queue<LibraryBuilder> unparsedLibraries = new Queue<LibraryBuilder>(); |
23 | 23 |
24 final List<L> libraries = <L>[]; | 24 final List<L> libraries = <L>[]; |
25 | 25 |
26 final TargetImplementation target; | 26 final TargetImplementation target; |
27 | 27 |
28 final List<InputError> errors = <InputError>[]; | 28 /// List of all handled compile-time errors seen so far by libraries loaded |
| 29 /// by this loader. |
| 30 /// |
| 31 /// A handled error is an error that has been added to the generated AST |
| 32 /// already, for example, as a throw expression. |
| 33 final List<InputError> handledErrors = <InputError>[]; |
| 34 |
| 35 /// List of all unhandled compile-time errors seen so far by libraries loaded |
| 36 /// by this loader. |
| 37 /// |
| 38 /// An unhandled error is an error that hasn't been handled, see |
| 39 /// [handledErrors]. |
| 40 final List<InputError> unhandledErrors = <InputError>[]; |
29 | 41 |
30 LibraryBuilder coreLibrary; | 42 LibraryBuilder coreLibrary; |
31 | 43 |
32 LibraryBuilder first; | 44 LibraryBuilder first; |
33 | 45 |
34 int byteCount = 0; | 46 int byteCount = 0; |
35 | 47 |
36 Uri currentUriForCrashReporting; | 48 Uri currentUriForCrashReporting; |
37 | 49 |
38 Loader(this.target); | 50 Loader(this.target); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 first ??= library; | 90 first ??= library; |
79 if (library.loader == this) { | 91 if (library.loader == this) { |
80 unparsedLibraries.addLast(library); | 92 unparsedLibraries.addLast(library); |
81 } | 93 } |
82 return library; | 94 return library; |
83 }); | 95 }); |
84 if (accessor != null && | 96 if (accessor != null && |
85 uri.scheme == "dart" && | 97 uri.scheme == "dart" && |
86 uri.path.startsWith("_") && | 98 uri.path.startsWith("_") && |
87 accessor.uri.scheme != "dart") { | 99 accessor.uri.scheme != "dart") { |
88 const String message = "Can't access platform private library."; | 100 accessor.addCompileTimeError( |
89 printUnexpected(accessor.fileUri, charOffset, message); | 101 charOffset, "Can't access platform private library."); |
90 errors.add(new InputError(accessor.fileUri, charOffset, message)); | |
91 } | 102 } |
92 return builder; | 103 return builder; |
93 } | 104 } |
94 | 105 |
95 void ensureCoreLibrary() { | 106 void ensureCoreLibrary() { |
96 if (coreLibrary == null) { | 107 if (coreLibrary == null) { |
97 read(Uri.parse("dart:core"), -1); | 108 read(Uri.parse("dart:core"), -1); |
98 assert(coreLibrary != null); | 109 assert(coreLibrary != null); |
99 } | 110 } |
100 } | 111 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 ${format(byteCount / ms, 3, 12)} bytes/ms, and | 150 ${format(byteCount / ms, 3, 12)} bytes/ms, and |
140 ${format(ms / libraryCount, 3, 12)} ms/compilation unit."""); | 151 ${format(ms / libraryCount, 3, 12)} ms/compilation unit."""); |
141 }); | 152 }); |
142 } | 153 } |
143 | 154 |
144 Future<Null> buildOutline(covariant LibraryBuilder library); | 155 Future<Null> buildOutline(covariant LibraryBuilder library); |
145 | 156 |
146 /// Builds all the method bodies found in the given [library]. | 157 /// Builds all the method bodies found in the given [library]. |
147 Future<Null> buildBody(covariant LibraryBuilder library); | 158 Future<Null> buildBody(covariant LibraryBuilder library); |
148 | 159 |
149 List<InputError> collectCompileTimeErrors() { | 160 /// Register [message] as a compile-time error. |
150 List<InputError> errors = <InputError>[]..addAll(this.errors); | 161 /// |
151 for (LibraryBuilder library in builders.values) { | 162 /// If [silent] is true, no error is printed as it is assumed the error has |
152 if (library.loader == this) { | 163 /// been previously reported. |
153 errors.addAll(library.compileTimeErrors); | 164 /// |
154 } | 165 /// If [wasHandled] is true, this error is added to [handledErrors], |
| 166 /// otherwise it is added to [unhandledErrors]. |
| 167 void addCompileTimeError(Uri fileUri, int charOffset, Object message, |
| 168 {bool silent: false, bool wasHandled: false}) { |
| 169 if (!silent) { |
| 170 printUnexpected(fileUri, charOffset, message); |
155 } | 171 } |
156 return errors; | 172 (wasHandled ? handledErrors : unhandledErrors) |
| 173 .add(new InputError(fileUri, charOffset, message)); |
157 } | 174 } |
158 | 175 |
159 Builder getAbstractClassInstantiationError() { | 176 Builder getAbstractClassInstantiationError() { |
160 return target.getAbstractClassInstantiationError(this); | 177 return target.getAbstractClassInstantiationError(this); |
161 } | 178 } |
162 | 179 |
163 Builder getCompileTimeError() => target.getCompileTimeError(this); | 180 Builder getCompileTimeError() => target.getCompileTimeError(this); |
164 | 181 |
165 Builder getDuplicatedFieldInitializerError() { | 182 Builder getDuplicatedFieldInitializerError() { |
166 return target.getDuplicatedFieldInitializerError(this); | 183 return target.getDuplicatedFieldInitializerError(this); |
167 } | 184 } |
168 | 185 |
169 Builder getFallThroughError() => target.getFallThroughError(this); | 186 Builder getFallThroughError() => target.getFallThroughError(this); |
170 | 187 |
171 Builder getNativeAnnotation() => target.getNativeAnnotation(this); | 188 Builder getNativeAnnotation() => target.getNativeAnnotation(this); |
172 } | 189 } |
173 | 190 |
174 String format(double d, int fractionDigits, int width) { | 191 String format(double d, int fractionDigits, int width) { |
175 return d.toStringAsFixed(fractionDigits).padLeft(width); | 192 return d.toStringAsFixed(fractionDigits).padLeft(width); |
176 } | 193 } |
OLD | NEW |