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; | 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 ClassBuilder, | 16 ClassBuilder, |
17 ConstructorReferenceBuilder, | 17 ConstructorReferenceBuilder, |
18 FormalParameterBuilder, | 18 FormalParameterBuilder, |
19 FunctionTypeBuilder, | 19 FunctionTypeBuilder, |
20 InvalidTypeBuilder, | |
20 LibraryBuilder, | 21 LibraryBuilder, |
21 MemberBuilder, | 22 MemberBuilder, |
22 MetadataBuilder, | 23 MetadataBuilder, |
23 NamedTypeBuilder, | 24 NamedTypeBuilder, |
24 PrefixBuilder, | 25 PrefixBuilder, |
25 ProcedureBuilder, | 26 ProcedureBuilder, |
26 Scope, | 27 Scope, |
27 TypeBuilder, | 28 TypeBuilder, |
28 TypeDeclarationBuilder, | 29 TypeDeclarationBuilder, |
29 TypeVariableBuilder, | 30 TypeVariableBuilder, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 List<MetadataBuilder> metadata; | 90 List<MetadataBuilder> metadata; |
90 | 91 |
91 /// The current declaration that is being built. When we start parsing a | 92 /// The current declaration that is being built. When we start parsing a |
92 /// declaration (class, method, and so on), we don't have enough information | 93 /// declaration (class, method, and so on), we don't have enough information |
93 /// to create a builder and this object records its members and types until, | 94 /// to create a builder and this object records its members and types until, |
94 /// for example, [addClass] is called. | 95 /// for example, [addClass] is called. |
95 DeclarationBuilder<T> currentDeclaration; | 96 DeclarationBuilder<T> currentDeclaration; |
96 | 97 |
97 bool canAddImplementationBuilders = false; | 98 bool canAddImplementationBuilders = false; |
98 | 99 |
100 /// Exports in addition to the members declared in this library. | |
101 /// | |
102 /// Each entry in the list is a pair of library URI and name of exported | |
103 /// element. | |
104 List<List<String>> additionalExports; | |
105 | |
99 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) | 106 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) |
100 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), | 107 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), |
101 new Scope.top()); | 108 new Scope.top()); |
102 | 109 |
103 SourceLibraryBuilder.fromScopes( | 110 SourceLibraryBuilder.fromScopes( |
104 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) | 111 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) |
105 : disableTypeInference = loader.target.disableTypeInference, | 112 : disableTypeInference = loader.target.disableTypeInference, |
106 currentDeclaration = libraryDeclaration, | 113 currentDeclaration = libraryDeclaration, |
107 super( | 114 super( |
108 fileUri, libraryDeclaration.toScope(importScope), new Scope.top()); | 115 fileUri, libraryDeclaration.toScope(importScope), new Scope.top()); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 if (import.imported == loader.coreLibrary) { | 512 if (import.imported == loader.coreLibrary) { |
506 explicitCoreImport = true; | 513 explicitCoreImport = true; |
507 } | 514 } |
508 import.finalizeImports(this); | 515 import.finalizeImports(this); |
509 } | 516 } |
510 if (!explicitCoreImport) { | 517 if (!explicitCoreImport) { |
511 loader.coreLibrary.exportScope.forEach((String name, Builder member) { | 518 loader.coreLibrary.exportScope.forEach((String name, Builder member) { |
512 addToScope(name, member, -1, true); | 519 addToScope(name, member, -1, true); |
513 }); | 520 }); |
514 } | 521 } |
522 exportScope.forEach((String name, Builder member) { | |
523 if (member.parent != this) { | |
524 additionalExports ??= <List<String>>[]; | |
525 Builder parent = member.parent; | |
526 if (parent is LibraryBuilder) { | |
527 additionalExports.add(<String>["${parent.uri}", name]); | |
Johnni Winther
2017/08/25 11:20:42
Add a TODO here for the absolute name problem ment
| |
528 } else { | |
529 InvalidTypeBuilder invalidType = member; | |
530 String message = invalidType.message.message; | |
531 additionalExports.add(<String>[null, name, message]); | |
532 } | |
533 } | |
534 }); | |
515 } | 535 } |
516 | 536 |
517 @override | 537 @override |
518 void addToScope(String name, Builder member, int charOffset, bool isImport) { | 538 void addToScope(String name, Builder member, int charOffset, bool isImport) { |
519 Map<String, Builder> map = | 539 Map<String, Builder> map = |
520 member.isSetter ? importScope.setters : importScope.local; | 540 member.isSetter ? importScope.setters : importScope.local; |
521 Builder existing = map[name]; | 541 Builder existing = map[name]; |
522 if (existing != null) { | 542 if (existing != null) { |
523 if (existing != member) { | 543 if (existing != member) { |
524 map[name] = buildAmbiguousBuilder(name, existing, member, charOffset, | 544 map[name] = buildAmbiguousBuilder(name, existing, member, charOffset, |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 /// synthesize type variables on the factory matching the class'. | 677 /// synthesize type variables on the factory matching the class'. |
658 void addFactoryDeclaration( | 678 void addFactoryDeclaration( |
659 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 679 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
660 factoryDeclarations[procedure] = factoryDeclaration; | 680 factoryDeclarations[procedure] = factoryDeclaration; |
661 } | 681 } |
662 | 682 |
663 Scope toScope(Scope parent) { | 683 Scope toScope(Scope parent) { |
664 return new Scope(members, setters, parent, isModifiable: false); | 684 return new Scope(members, setters, parent, isModifiable: false); |
665 } | 685 } |
666 } | 686 } |
OLD | NEW |