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 26 matching lines...) Expand all Loading... | |
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 /// Exports in addition to the members declared in this library. |
103 /// | 100 /// |
104 /// See [../dill/dill_library_builder.dart] for additional details on the | 101 /// See [../dill/dill_library_builder.dart] for additional details on the |
105 /// format used. | 102 /// format used. |
ahe
2017/08/29 11:04:23
This documentation should be updated.
scheglov
2017/08/29 15:16:26
Done.
| |
106 List<List<String>> additionalExports; | 103 List<Reference> additionalExports; |
107 | 104 |
108 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) | 105 SourceLibraryBuilder(SourceLoader loader, Uri fileUri) |
109 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), | 106 : this.fromScopes(loader, fileUri, new DeclarationBuilder<T>.library(), |
110 new Scope.top()); | 107 new Scope.top()); |
111 | 108 |
112 SourceLibraryBuilder.fromScopes( | 109 SourceLibraryBuilder.fromScopes( |
113 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) | 110 this.loader, this.fileUri, this.libraryDeclaration, this.importScope) |
114 : disableTypeInference = loader.target.disableTypeInference, | 111 : disableTypeInference = loader.target.disableTypeInference, |
115 currentDeclaration = libraryDeclaration, | 112 currentDeclaration = libraryDeclaration, |
116 super( | 113 super( |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 } | 513 } |
517 import.finalizeImports(this); | 514 import.finalizeImports(this); |
518 } | 515 } |
519 if (!explicitCoreImport) { | 516 if (!explicitCoreImport) { |
520 loader.coreLibrary.exportScope.forEach((String name, Builder member) { | 517 loader.coreLibrary.exportScope.forEach((String name, Builder member) { |
521 addToScope(name, member, -1, true); | 518 addToScope(name, member, -1, true); |
522 }); | 519 }); |
523 } | 520 } |
524 exportScope.forEach((String name, Builder member) { | 521 exportScope.forEach((String name, Builder member) { |
525 if (member.parent != this) { | 522 if (member.parent != this) { |
526 additionalExports ??= <List<String>>[]; | 523 additionalExports ??= <Reference>[]; |
527 Builder parent = member.parent; | 524 Builder parent = member.parent; |
528 if (parent is LibraryBuilder) { | 525 if (parent is LibraryBuilder) { |
529 additionalExports.add(<String>[ | 526 additionalExports.add(member.target.reference); |
530 relativizeUri(parent.uri, base: uri.resolve(".")), | |
531 name | |
532 ]); | |
533 } else { | |
534 InvalidTypeBuilder invalidType = member; | |
535 String message = invalidType.message.message; | |
536 additionalExports.add(<String>[null, name, message]); | |
537 } | 527 } |
538 } | 528 } |
539 }); | 529 }); |
540 } | 530 } |
541 | 531 |
542 @override | 532 @override |
543 void addToScope(String name, Builder member, int charOffset, bool isImport) { | 533 void addToScope(String name, Builder member, int charOffset, bool isImport) { |
544 Map<String, Builder> map = | 534 Map<String, Builder> map = |
545 member.isSetter ? importScope.setters : importScope.local; | 535 member.isSetter ? importScope.setters : importScope.local; |
546 Builder existing = map[name]; | 536 Builder existing = map[name]; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 /// synthesize type variables on the factory matching the class'. | 672 /// synthesize type variables on the factory matching the class'. |
683 void addFactoryDeclaration( | 673 void addFactoryDeclaration( |
684 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { | 674 ProcedureBuilder procedure, DeclarationBuilder<T> factoryDeclaration) { |
685 factoryDeclarations[procedure] = factoryDeclaration; | 675 factoryDeclarations[procedure] = factoryDeclaration; |
686 } | 676 } |
687 | 677 |
688 Scope toScope(Scope parent) { | 678 Scope toScope(Scope parent) { |
689 return new Scope(members, setters, parent, isModifiable: false); | 679 return new Scope(members, setters, parent, isModifiable: false); |
690 } | 680 } |
691 } | 681 } |
OLD | NEW |