| 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 ProcedureKind, Reference; | 7 import 'package:kernel/ast.dart' show ProcedureKind; |
| 8 | 8 |
| 9 import '../../base/resolve_relative_uri.dart' show resolveRelativeUri; | 9 import '../../base/resolve_relative_uri.dart' show resolveRelativeUri; |
| 10 | 10 |
| 11 import '../../scanner/token.dart' show Token; | 11 import '../../scanner/token.dart' show Token; |
| 12 | 12 |
| 13 import '../builder/builder.dart' | 13 import '../builder/builder.dart' |
| 14 show | 14 show |
| 15 Builder, | 15 Builder, |
| 16 BuiltinTypeBuilder, | |
| 17 ClassBuilder, | 16 ClassBuilder, |
| 18 ConstructorReferenceBuilder, | 17 ConstructorReferenceBuilder, |
| 19 FormalParameterBuilder, | 18 FormalParameterBuilder, |
| 20 FunctionTypeBuilder, | 19 FunctionTypeBuilder, |
| 20 InvalidTypeBuilder, |
| 21 LibraryBuilder, | 21 LibraryBuilder, |
| 22 MemberBuilder, | 22 MemberBuilder, |
| 23 MetadataBuilder, | 23 MetadataBuilder, |
| 24 NamedTypeBuilder, | 24 NamedTypeBuilder, |
| 25 PrefixBuilder, | 25 PrefixBuilder, |
| 26 ProcedureBuilder, | 26 ProcedureBuilder, |
| 27 Scope, | 27 Scope, |
| 28 TypeBuilder, | 28 TypeBuilder, |
| 29 TypeDeclarationBuilder, | 29 TypeDeclarationBuilder, |
| 30 TypeVariableBuilder, | 30 TypeVariableBuilder, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 47 templateMissingPartOf, | 47 templateMissingPartOf, |
| 48 templatePartOfLibraryNameMismatch, | 48 templatePartOfLibraryNameMismatch, |
| 49 templatePartOfUriMismatch, | 49 templatePartOfUriMismatch, |
| 50 templatePartOfUseUri, | 50 templatePartOfUseUri, |
| 51 templatePartTwice; | 51 templatePartTwice; |
| 52 | 52 |
| 53 import '../import.dart' show Import; | 53 import '../import.dart' show Import; |
| 54 | 54 |
| 55 import '../problems.dart' show unhandled; | 55 import '../problems.dart' show unhandled; |
| 56 | 56 |
| 57 import '../util/relativize.dart' show relativizeUri; |
| 58 |
| 57 import 'source_loader.dart' show SourceLoader; | 59 import 'source_loader.dart' show SourceLoader; |
| 58 | 60 |
| 59 abstract class SourceLibraryBuilder<T extends TypeBuilder, R> | 61 abstract class SourceLibraryBuilder<T extends TypeBuilder, R> |
| 60 extends LibraryBuilder<T, R> { | 62 extends LibraryBuilder<T, R> { |
| 61 final SourceLoader loader; | 63 final SourceLoader loader; |
| 62 | 64 |
| 63 final DeclarationBuilder<T> libraryDeclaration; | 65 final DeclarationBuilder<T> libraryDeclaration; |
| 64 | 66 |
| 65 final List<ConstructorReferenceBuilder> constructorReferences = | 67 final List<ConstructorReferenceBuilder> constructorReferences = |
| 66 <ConstructorReferenceBuilder>[]; | 68 <ConstructorReferenceBuilder>[]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 90 List<MetadataBuilder> metadata; | 92 List<MetadataBuilder> metadata; |
| 91 | 93 |
| 92 /// The current declaration that is being built. When we start parsing a | 94 /// The current declaration that is being built. When we start parsing a |
| 93 /// declaration (class, method, and so on), we don't have enough information | 95 /// declaration (class, method, and so on), we don't have enough information |
| 94 /// to create a builder and this object records its members and types until, | 96 /// to create a builder and this object records its members and types until, |
| 95 /// for example, [addClass] is called. | 97 /// for example, [addClass] is called. |
| 96 DeclarationBuilder<T> currentDeclaration; | 98 DeclarationBuilder<T> currentDeclaration; |
| 97 | 99 |
| 98 bool canAddImplementationBuilders = false; | 100 bool canAddImplementationBuilders = false; |
| 99 | 101 |
| 100 /// References to nodes exported by `export` declarations that: | 102 /// Exports in addition to the members declared in this library. |
| 101 /// - aren't ambiguous, or | 103 /// |
| 102 /// - aren't hidden by local declarations. | 104 /// See [../dill/dill_library_builder.dart] for additional details on the |
| 103 List<Reference> additionalExports; | 105 /// format used. |
| 106 List<List<String>> additionalExports; |
| 104 | 107 |
| 105 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) | 108 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) |
| 106 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), | 109 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), |
| 107 new Scope.top()); | 110 new Scope.top()); |
| 108 | 111 |
| 109 SourceLibraryBuilder.fromScopes( | 112 SourceLibraryBuilder.fromScopes( |
| 110 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) | 113 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) |
| 111 : disableTypeInference = loader.target.disableTypeInference, | 114 : disableTypeInference = loader.target.disableTypeInference, |
| 112 currentDeclaration = libraryDeclaration, | 115 currentDeclaration = libraryDeclaration, |
| 113 super( | 116 super( |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 517 } |
| 515 import.finalizeImports(this); | 518 import.finalizeImports(this); |
| 516 } | 519 } |
| 517 if (!explicitCoreImport) { | 520 if (!explicitCoreImport) { |
| 518 loader.coreLibrary.exportScope.forEach((String name, Builder member) { | 521 loader.coreLibrary.exportScope.forEach((String name, Builder member) { |
| 519 addToScope(name, member, -1, true); | 522 addToScope(name, member, -1, true); |
| 520 }); | 523 }); |
| 521 } | 524 } |
| 522 exportScope.forEach((String name, Builder member) { | 525 exportScope.forEach((String name, Builder member) { |
| 523 if (member.parent != this) { | 526 if (member.parent != this) { |
| 524 additionalExports ??= <Reference>[]; | 527 additionalExports ??= <List<String>>[]; |
| 525 Builder parent = member.parent; | 528 Builder parent = member.parent; |
| 526 if (parent is LibraryBuilder && member is! BuiltinTypeBuilder) { | 529 if (parent is LibraryBuilder) { |
| 527 additionalExports.add(member.target.reference); | 530 additionalExports.add(<String>[ |
| 531 relativizeUri(parent.uri, base: uri.resolve(".")), |
| 532 name |
| 533 ]); |
| 534 } else { |
| 535 InvalidTypeBuilder invalidType = member; |
| 536 String message = invalidType.message.message; |
| 537 additionalExports.add(<String>[null, name, message]); |
| 528 } | 538 } |
| 529 } | 539 } |
| 530 }); | 540 }); |
| 531 } | 541 } |
| 532 | 542 |
| 533 @override | 543 @override |
| 534 void addToScope(String name, Builder member, int charOffset, bool isImport) { | 544 void addToScope(String name, Builder member, int charOffset, bool isImport) { |
| 535 Map<String, Builder> map = | 545 Map<String, Builder> map = |
| 536 member.isSetter ? importScope.setters : importScope.local; | 546 member.isSetter ? importScope.setters : importScope.local; |
| 537 Builder existing = map[name]; | 547 Builder existing = map[name]; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 /// synthesize type variables on the factory matching the class'. | 686 /// synthesize type variables on the factory matching the class'. |
| 677 void addFactoryDeclaration( | 687 void addFactoryDeclaration( |
| 678 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 688 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
| 679 factoryDeclarations[procedure] = factoryDeclaration; | 689 factoryDeclarations[procedure] = factoryDeclaration; |
| 680 } | 690 } |
| 681 | 691 |
| 682 Scope toScope(Scope parent) { | 692 Scope toScope(Scope parent) { |
| 683 return new Scope(members, setters, parent, name, isModifiable: false); | 693 return new Scope(members, setters, parent, name, isModifiable: false); |
| 684 } | 694 } |
| 685 } | 695 } |
| OLD | NEW |