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