| 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; |
| 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 |
| 326 /// Used to add implementation builder during the call to [build] above. |
| 327 /// Currently, only anonymous mixins are using implementation builders (see |
| 328 /// [KernelMixinApplicationBuilder] |
| 329 /// (../kernel/kernel_mixin_application_builder.dart)). |
| 322 void addImplementationBuilder(String name, Builder builder, int charOffset) { | 330 void addImplementationBuilder(String name, Builder builder, int charOffset) { |
| 331 assert(canAddImplementationBuilders, "$uri"); |
| 323 implementationBuilders.add([name, builder, charOffset]); | 332 implementationBuilders.add([name, builder, charOffset]); |
| 324 } | 333 } |
| 325 | 334 |
| 326 void validatePart() { | 335 void validatePart() { |
| 327 if (parts.isNotEmpty) { | 336 if (parts.isNotEmpty) { |
| 328 inputError(fileUri, -1, | 337 inputError(fileUri, -1, |
| 329 "A file that's a part of a library can't have parts itself."); | 338 "A file that's a part of a library can't have parts itself."); |
| 330 } | 339 } |
| 331 if (exporters.isNotEmpty) { | 340 if (exporters.isNotEmpty) { |
| 332 Export export = exporters.first; | 341 Export export = exporters.first; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 } | 546 } |
| 538 | 547 |
| 539 /// Called to register [procedure] as a factory whose types are collected in | 548 /// Called to register [procedure] as a factory whose types are collected in |
| 540 /// [factoryDeclaration]. Later, once the class has been built, we can | 549 /// [factoryDeclaration]. Later, once the class has been built, we can |
| 541 /// synthesize type variables on the factory matching the class'. | 550 /// synthesize type variables on the factory matching the class'. |
| 542 void addFactoryDeclaration( | 551 void addFactoryDeclaration( |
| 543 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 552 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 544 factoryDeclarations[procedure] = factoryDeclaration; | 553 factoryDeclarations[procedure] = factoryDeclaration; |
| 545 } | 554 } |
| 546 } | 555 } |
| OLD | NEW |