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.source_library_builder; | 5 library fasta.source_library_builder; |
6 | 6 |
7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; | 7 import 'package:kernel/ast.dart' show AsyncMarker, ProcedureKind; |
8 | 8 |
9 import '../combinator.dart' show Combinator; | 9 import '../combinator.dart' show Combinator; |
10 | 10 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 Uri partOfUri; | 63 Uri partOfUri; |
64 | 64 |
65 List<MetadataBuilder> metadata; | 65 List<MetadataBuilder> metadata; |
66 | 66 |
67 /// The current declaration that is being built. When we start parsing a | 67 /// The current declaration that is being built. When we start parsing a |
68 /// declaration (class, method, and so on), we don't have enough information | 68 /// declaration (class, method, and so on), we don't have enough information |
69 /// to create a builder and this object records its members and types until, | 69 /// to create a builder and this object records its members and types until, |
70 /// for example, [addClass] is called. | 70 /// for example, [addClass] is called. |
71 DeclarationBuilder<T> currentDeclaration; | 71 DeclarationBuilder<T> currentDeclaration; |
72 | 72 |
73 bool canAddImplementationBuilders = false; | |
karlklose
2017/04/03 06:48:14
Could you add a comment here and/or to addImplemen
ahe
2017/04/04 09:46:44
Done.
| |
74 | |
73 SourceLibraryBuilder(this.loader, Uri fileUri) | 75 SourceLibraryBuilder(this.loader, Uri fileUri) |
74 : fileUri = fileUri, | 76 : fileUri = fileUri, |
75 super(fileUri) { | 77 super(fileUri) { |
76 currentDeclaration = libraryDeclaration; | 78 currentDeclaration = libraryDeclaration; |
77 } | 79 } |
78 | 80 |
79 Uri get uri; | 81 Uri get uri; |
80 | 82 |
81 bool get isPart => partOfName != null || partOfUri != null; | 83 bool get isPart => partOfName != null || partOfUri != null; |
82 | 84 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
296 // extends Object with Mixin {}` in the same library. | 298 // extends Object with Mixin {}` in the same library. |
297 return !existing.isMixinApplication || !other.isMixinApplication; | 299 return !existing.isMixinApplication || !other.isMixinApplication; |
298 } | 300 } |
299 return true; | 301 return true; |
300 } | 302 } |
301 | 303 |
302 void buildBuilder(Builder builder); | 304 void buildBuilder(Builder builder); |
303 | 305 |
304 R build() { | 306 R build() { |
305 assert(implementationBuilders.isEmpty); | 307 assert(implementationBuilders.isEmpty); |
308 canAddImplementationBuilders = true; | |
306 forEach((String name, Builder builder) { | 309 forEach((String name, Builder builder) { |
307 do { | 310 do { |
308 buildBuilder(builder); | 311 buildBuilder(builder); |
309 builder = builder.next; | 312 builder = builder.next; |
310 } while (builder != null); | 313 } while (builder != null); |
311 }); | 314 }); |
312 for (List list in implementationBuilders) { | 315 for (List list in implementationBuilders) { |
313 String name = list[0]; | 316 String name = list[0]; |
314 Builder builder = list[1]; | 317 Builder builder = list[1]; |
315 int charOffset = list[2]; | 318 int charOffset = list[2]; |
316 addBuilder(name, builder, charOffset); | 319 addBuilder(name, builder, charOffset); |
317 buildBuilder(builder); | 320 buildBuilder(builder); |
318 } | 321 } |
322 canAddImplementationBuilders = false; | |
319 return null; | 323 return null; |
320 } | 324 } |
321 | 325 |
322 void addImplementationBuilder(String name, Builder builder, int charOffset) { | 326 void addImplementationBuilder(String name, Builder builder, int charOffset) { |
327 assert(canAddImplementationBuilders, "$uri"); | |
323 implementationBuilders.add([name, builder, charOffset]); | 328 implementationBuilders.add([name, builder, charOffset]); |
324 } | 329 } |
325 | 330 |
326 void validatePart() { | 331 void validatePart() { |
327 if (parts.isNotEmpty) { | 332 if (parts.isNotEmpty) { |
328 inputError(fileUri, -1, | 333 inputError(fileUri, -1, |
329 "A file that's a part of a library can't have parts itself."); | 334 "A file that's a part of a library can't have parts itself."); |
330 } | 335 } |
331 if (exporters.isNotEmpty) { | 336 if (exporters.isNotEmpty) { |
332 Export export = exporters.first; | 337 Export export = exporters.first; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 } | 542 } |
538 | 543 |
539 /// Called to register [procedure] as a factory whose types are collected in | 544 /// Called to register [procedure] as a factory whose types are collected in |
540 /// [factoryDeclaration]. Later, once the class has been built, we can | 545 /// [factoryDeclaration]. Later, once the class has been built, we can |
541 /// synthesize type variables on the factory matching the class'. | 546 /// synthesize type variables on the factory matching the class'. |
542 void addFactoryDeclaration( | 547 void addFactoryDeclaration( |
543 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 548 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
544 factoryDeclarations[procedure] = factoryDeclaration; | 549 factoryDeclarations[procedure] = factoryDeclaration; |
545 } | 550 } |
546 } | 551 } |
OLD | NEW |