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 /// ----------------------------------------------------------------------- | 5 /// ----------------------------------------------------------------------- |
6 /// ERROR HANDLING | 6 /// ERROR HANDLING |
7 /// ----------------------------------------------------------------------- | 7 /// ----------------------------------------------------------------------- |
8 /// | 8 /// |
9 /// As a rule of thumb, errors that can be detected statically are handled by | 9 /// As a rule of thumb, errors that can be detected statically are handled by |
10 /// the frontend, typically by translating the erroneous code into a 'throw' or | 10 /// the frontend, typically by translating the erroneous code into a 'throw' or |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 /// | 172 /// |
173 /// Classes of an external library are loaded at one of the [ClassLevel]s | 173 /// Classes of an external library are loaded at one of the [ClassLevel]s |
174 /// other than [ClassLevel.Body]. Members in an external library have no | 174 /// other than [ClassLevel.Body]. Members in an external library have no |
175 /// body, but have their typed interface present. | 175 /// body, but have their typed interface present. |
176 /// | 176 /// |
177 /// If the libary is non-external, then its classes are at [ClassLevel.Body] | 177 /// If the libary is non-external, then its classes are at [ClassLevel.Body] |
178 /// and all members are loaded. | 178 /// and all members are loaded. |
179 bool isExternal; | 179 bool isExternal; |
180 | 180 |
181 String name; | 181 String name; |
| 182 final List<DeferredImport> deferredImports; |
182 final List<Class> classes; | 183 final List<Class> classes; |
183 final List<Procedure> procedures; | 184 final List<Procedure> procedures; |
184 final List<Field> fields; | 185 final List<Field> fields; |
185 | 186 |
186 Library(this.importUri, | 187 Library(this.importUri, |
187 {this.name, | 188 {this.name, |
188 this.isExternal: false, | 189 this.isExternal: false, |
| 190 List<DeferredImport> imports, |
189 List<Class> classes, | 191 List<Class> classes, |
190 List<Procedure> procedures, | 192 List<Procedure> procedures, |
191 List<Field> fields}) | 193 List<Field> fields}) |
192 : this.classes = classes ?? <Class>[], | 194 : this.deferredImports = imports ?? <DeferredImport>[], |
| 195 this.classes = classes ?? <Class>[], |
193 this.procedures = procedures ?? <Procedure>[], | 196 this.procedures = procedures ?? <Procedure>[], |
194 this.fields = fields ?? <Field>[] { | 197 this.fields = fields ?? <Field>[] { |
195 setParents(this.classes, this); | 198 setParents(this.classes, this); |
196 setParents(this.procedures, this); | 199 setParents(this.procedures, this); |
197 setParents(this.fields, this); | 200 setParents(this.fields, this); |
198 } | 201 } |
199 | 202 |
200 /// Returns the top-level fields and procedures defined in this library. | 203 /// Returns the top-level fields and procedures defined in this library. |
201 /// | 204 /// |
202 /// This getter is for convenience, not efficiency. Consider manually | 205 /// This getter is for convenience, not efficiency. Consider manually |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 244 |
242 /// Returns a possibly synthesized name for this library, consistent with | 245 /// Returns a possibly synthesized name for this library, consistent with |
243 /// the names across all [toString] calls. | 246 /// the names across all [toString] calls. |
244 String toString() => debugLibraryName(this); | 247 String toString() => debugLibraryName(this); |
245 | 248 |
246 Location _getLocationInEnclosingFile(int offset) { | 249 Location _getLocationInEnclosingFile(int offset) { |
247 return enclosingProgram.getLocation(fileUri, offset); | 250 return enclosingProgram.getLocation(fileUri, offset); |
248 } | 251 } |
249 } | 252 } |
250 | 253 |
| 254 /// An import of form: `import <url> deferred as <name>;`. |
| 255 class DeferredImport extends TreeNode { |
| 256 Library importedLibrary; |
| 257 String name; |
| 258 |
| 259 DeferredImport(this.importedLibrary, this.name); |
| 260 |
| 261 Library get enclosingLibrary => parent; |
| 262 |
| 263 accept(TreeVisitor v) => v.visitDeferredImport(this); |
| 264 |
| 265 visitChildren(Visitor v) {} |
| 266 |
| 267 transformChildren(Transformer v) {} |
| 268 } |
| 269 |
251 /// The degree to which the contents of a class have been loaded into memory. | 270 /// The degree to which the contents of a class have been loaded into memory. |
252 /// | 271 /// |
253 /// Each level imply the requirements of the previous ones. | 272 /// Each level imply the requirements of the previous ones. |
254 enum ClassLevel { | 273 enum ClassLevel { |
255 /// Temporary loading level for internal use by IR producers. Consumers of | 274 /// Temporary loading level for internal use by IR producers. Consumers of |
256 /// kernel code should not expect to see classes at this level. | 275 /// kernel code should not expect to see classes at this level. |
257 Temporary, | 276 Temporary, |
258 | 277 |
259 /// The class may be used as a type, and it may contain members that are | 278 /// The class may be used as a type, and it may contain members that are |
260 /// referenced from this build unit. | 279 /// referenced from this build unit. |
(...skipping 2166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2427 variable = variable.accept(v); | 2446 variable = variable.accept(v); |
2428 variable?.parent = this; | 2447 variable?.parent = this; |
2429 } | 2448 } |
2430 if (body != null) { | 2449 if (body != null) { |
2431 body = body.accept(v); | 2450 body = body.accept(v); |
2432 body?.parent = this; | 2451 body?.parent = this; |
2433 } | 2452 } |
2434 } | 2453 } |
2435 } | 2454 } |
2436 | 2455 |
| 2456 /// Attempt to load the library referred to by a deferred import. |
| 2457 /// |
| 2458 /// This instruction is concerned with: |
| 2459 /// - keeping track whether the deferred import is marked as 'loaded' |
| 2460 /// - keeping track of whether the library code has already been downloaded |
| 2461 /// - actually downloading and linking the library |
| 2462 /// |
| 2463 /// Should return a future. The value in this future will be the same value |
| 2464 /// seen by callers of `loadLibrary` functions. |
| 2465 /// |
| 2466 /// On backends that link the entire program eagerly, this instruction needs |
| 2467 /// to mark the deferred import as 'loaded' and return a future. |
| 2468 class LoadLibrary extends Expression { |
| 2469 /// Reference to a deferred import in the enclosing library. |
| 2470 DeferredImport import; |
| 2471 |
| 2472 LoadLibrary(this.import); |
| 2473 |
| 2474 DartType getStaticType(TypeEnvironment types) { |
| 2475 return types.futureType(const DynamicType()); |
| 2476 } |
| 2477 |
| 2478 accept(ExpressionVisitor v) => v.visitLoadLibrary(this); |
| 2479 |
| 2480 visitChildren(Visitor v) {} |
| 2481 transformChildren(Transformer v) {} |
| 2482 } |
| 2483 |
| 2484 /// Checks that the given deferred import has been marked as 'loaded'. |
| 2485 class CheckLibraryIsLoaded extends Expression { |
| 2486 /// Reference to a deferred import in the enclosing library. |
| 2487 DeferredImport import; |
| 2488 |
| 2489 CheckLibraryIsLoaded(this.import); |
| 2490 |
| 2491 DartType getStaticType(TypeEnvironment types) { |
| 2492 return types.objectType; |
| 2493 } |
| 2494 |
| 2495 accept(ExpressionVisitor v) => v.visitCheckLibraryIsLoaded(this); |
| 2496 |
| 2497 visitChildren(Visitor v) {} |
| 2498 transformChildren(Transformer v) {} |
| 2499 } |
| 2500 |
2437 // ------------------------------------------------------------------------ | 2501 // ------------------------------------------------------------------------ |
2438 // STATEMENTS | 2502 // STATEMENTS |
2439 // ------------------------------------------------------------------------ | 2503 // ------------------------------------------------------------------------ |
2440 | 2504 |
2441 abstract class Statement extends TreeNode { | 2505 abstract class Statement extends TreeNode { |
2442 accept(StatementVisitor v); | 2506 accept(StatementVisitor v); |
2443 } | 2507 } |
2444 | 2508 |
2445 /// A statement with a compile-time error. | 2509 /// A statement with a compile-time error. |
2446 /// | 2510 /// |
(...skipping 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3666 } | 3730 } |
3667 } | 3731 } |
3668 } | 3732 } |
3669 | 3733 |
3670 class Source { | 3734 class Source { |
3671 final List<int> lineStarts; | 3735 final List<int> lineStarts; |
3672 final String source; | 3736 final String source; |
3673 | 3737 |
3674 Source(this.lineStarts, this.source); | 3738 Source(this.lineStarts, this.source); |
3675 } | 3739 } |
OLD | NEW |