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.builder; | 5 library fasta.builder; |
6 | 6 |
7 import '../errors.dart' show | 7 import '../errors.dart' show internalError; |
8 internalError; | |
9 | 8 |
10 import '../messages.dart' show | 9 import '../messages.dart' show nit; |
11 nit; | |
12 | 10 |
13 export 'class_builder.dart' show | 11 export 'class_builder.dart' show ClassBuilder; |
14 ClassBuilder; | |
15 | 12 |
16 export 'field_builder.dart' show | 13 export 'field_builder.dart' show FieldBuilder; |
17 FieldBuilder; | |
18 | 14 |
19 export 'library_builder.dart' show | 15 export 'library_builder.dart' show LibraryBuilder; |
20 LibraryBuilder; | |
21 | 16 |
22 export 'procedure_builder.dart' show | 17 export 'procedure_builder.dart' show ProcedureBuilder; |
23 ProcedureBuilder; | |
24 | 18 |
25 export 'type_builder.dart' show | 19 export 'type_builder.dart' show TypeBuilder; |
26 TypeBuilder; | |
27 | 20 |
28 export 'formal_parameter_builder.dart' show | 21 export 'formal_parameter_builder.dart' show FormalParameterBuilder; |
29 FormalParameterBuilder; | |
30 | 22 |
31 export 'metadata_builder.dart' show | 23 export 'metadata_builder.dart' show MetadataBuilder; |
32 MetadataBuilder; | |
33 | 24 |
34 export 'type_variable_builder.dart' show | 25 export 'type_variable_builder.dart' show TypeVariableBuilder; |
35 TypeVariableBuilder; | |
36 | 26 |
37 export 'function_type_alias_builder.dart' show | 27 export 'function_type_alias_builder.dart' show FunctionTypeAliasBuilder; |
38 FunctionTypeAliasBuilder; | |
39 | 28 |
40 export 'named_mixin_application_builder.dart' show | 29 export 'named_mixin_application_builder.dart' show NamedMixinApplicationBuilder; |
41 NamedMixinApplicationBuilder; | |
42 | 30 |
43 export 'mixin_application_builder.dart' show | 31 export 'mixin_application_builder.dart' show MixinApplicationBuilder; |
44 MixinApplicationBuilder; | |
45 | 32 |
46 export 'enum_builder.dart' show | 33 export 'enum_builder.dart' show EnumBuilder; |
47 EnumBuilder; | |
48 | 34 |
49 export 'type_declaration_builder.dart' show | 35 export 'type_declaration_builder.dart' show TypeDeclarationBuilder; |
50 TypeDeclarationBuilder; | |
51 | 36 |
52 export 'named_type_builder.dart' show | 37 export 'named_type_builder.dart' show NamedTypeBuilder; |
53 NamedTypeBuilder; | |
54 | 38 |
55 export 'constructor_reference_builder.dart' show | 39 export 'constructor_reference_builder.dart' show ConstructorReferenceBuilder; |
56 ConstructorReferenceBuilder; | |
57 | 40 |
58 export '../source/unhandled_listener.dart' show | 41 export '../source/unhandled_listener.dart' show Unhandled; |
59 Unhandled; | |
60 | 42 |
61 export 'member_builder.dart' show | 43 export 'member_builder.dart' show MemberBuilder; |
62 MemberBuilder; | |
63 | 44 |
64 export 'modifier_builder.dart' show | 45 export 'modifier_builder.dart' show ModifierBuilder; |
65 ModifierBuilder; | |
66 | 46 |
67 export 'prefix_builder.dart' show | 47 export 'prefix_builder.dart' show PrefixBuilder; |
68 PrefixBuilder; | |
69 | 48 |
70 export 'invalid_type_builder.dart' show | 49 export 'invalid_type_builder.dart' show InvalidTypeBuilder; |
71 InvalidTypeBuilder; | |
72 | 50 |
73 export 'mixed_accessor.dart' show | 51 export 'mixed_accessor.dart' show MixedAccessor; |
74 MixedAccessor; | |
75 | 52 |
76 export 'scope.dart' show | 53 export 'scope.dart' show AccessErrorBuilder; |
77 AccessErrorBuilder; | |
78 | 54 |
79 export 'dynamic_type_builder.dart' show | 55 export 'dynamic_type_builder.dart' show DynamicTypeBuilder; |
80 DynamicTypeBuilder; | |
81 | 56 |
82 import 'library_builder.dart' show | 57 import 'library_builder.dart' show LibraryBuilder; |
83 LibraryBuilder; | |
84 | 58 |
85 abstract class Builder { | 59 abstract class Builder { |
86 /// Used when multiple things with the same name are declared within the same | 60 /// Used when multiple things with the same name are declared within the same |
87 /// parent. Only used for declarations, not for scopes. | 61 /// parent. Only used for declarations, not for scopes. |
88 /// | 62 /// |
89 // TODO(ahe): Move to member builder or something. Then we can make | 63 // TODO(ahe): Move to member builder or something. Then we can make |
90 // this a const class. | 64 // this a const class. |
91 Builder next; | 65 Builder next; |
92 | 66 |
93 /// The values of [parent], [charOffset], and [fileUri] aren't stored. We | 67 /// The values of [parent], [charOffset], and [fileUri] aren't stored. We |
94 /// need to evaluate the memory impact of doing so, but want to ensure the | 68 /// need to evaluate the memory impact of doing so, but want to ensure the |
95 /// information is always provided. | 69 /// information is always provided. |
96 Builder(Builder parent, int charOffset, Uri fileUri); | 70 Builder(Builder parent, int charOffset, Uri fileUri); |
97 | 71 |
98 int get charOffset => -1; | 72 int get charOffset => -1; |
99 | 73 |
100 Uri get fileUri => null; | 74 Uri get fileUri => null; |
101 | 75 |
102 String get relativeFileUri { | 76 String get relativeFileUri { |
103 throw "The relativeFileUri method should be only called on subclasses " | 77 throw "The relativeFileUri method should be only called on subclasses " |
104 "which have an efficient implementation of `relativeFileUri`!"; | 78 "which have an efficient implementation of `relativeFileUri`!"; |
105 } | 79 } |
106 | 80 |
107 /// Resolve types (lookup names in scope) recorded in this builder and return | 81 /// Resolve types (lookup names in scope) recorded in this builder and return |
108 /// the number of types resolved. | 82 /// the number of types resolved. |
109 int resolveTypes(covariant Builder parent) => 0; | 83 int resolveTypes(covariant Builder parent) => 0; |
110 | 84 |
111 /// Resolve constructors (lookup names in scope) recorded in this builder and | 85 /// Resolve constructors (lookup names in scope) recorded in this builder and |
112 /// return the number of constructors resolved. | 86 /// return the number of constructors resolved. |
113 int resolveConstructors(covariant Builder parent) => 0; | 87 int resolveConstructors(covariant Builder parent) => 0; |
114 | 88 |
115 /// This builder and [other] has been imported into [library] using [name]. | 89 /// This builder and [other] has been imported into [library] using [name]. |
116 /// | 90 /// |
117 /// This method handles this case according to the Dart language | 91 /// This method handles this case according to the Dart language |
118 /// specification. | 92 /// specification. |
119 Builder combineAmbiguousImport(String name, Builder other, | 93 Builder combineAmbiguousImport( |
120 LibraryBuilder library) { | 94 String name, Builder other, LibraryBuilder library) { |
121 if (other == this) return this; | 95 if (other == this) return this; |
122 bool isLocal = false; | 96 bool isLocal = false; |
123 Builder preferred; | 97 Builder preferred; |
124 Builder hidden; | 98 Builder hidden; |
125 if (library.members[name] == this) { | 99 if (library.members[name] == this) { |
126 isLocal = true; | 100 isLocal = true; |
127 preferred = this; | 101 preferred = this; |
128 hidden = other; | 102 hidden = other; |
129 } else if (getUri(other)?.scheme == "dart" && | 103 } else if (getUri(other)?.scheme == "dart" && |
130 getUri(this)?.scheme != "dart") { | 104 getUri(this)?.scheme != "dart") { |
131 preferred = this; | 105 preferred = this; |
132 hidden = other; | 106 hidden = other; |
133 } else if (getUri(this)?.scheme == "dart" && | 107 } else if (getUri(this)?.scheme == "dart" && |
134 getUri(other)?.scheme != "dart") { | 108 getUri(other)?.scheme != "dart") { |
135 preferred = other; | 109 preferred = other; |
136 hidden = this; | 110 hidden = this; |
137 } else { | 111 } else { |
138 nit(library.fileUri, -1, "'$name' is imported from both " | 112 nit( |
| 113 library.fileUri, |
| 114 -1, |
| 115 "'$name' is imported from both " |
139 "'${getUri(this)}' and '${getUri(other)}'."); | 116 "'${getUri(this)}' and '${getUri(other)}'."); |
140 return library.buildAmbiguousBuilder(name, this, other, charOffset); | 117 return library.buildAmbiguousBuilder(name, this, other, charOffset); |
141 } | 118 } |
142 if (isLocal) { | 119 if (isLocal) { |
143 nit(library.fileUri, -1, "Local definition of '$name' hides imported " | 120 nit( |
| 121 library.fileUri, |
| 122 -1, |
| 123 "Local definition of '$name' hides imported " |
144 "version from '${getUri(other)}'."); | 124 "version from '${getUri(other)}'."); |
145 } else { | 125 } else { |
146 nit(library.fileUri, -1, "Import of '$name' " | 126 nit( |
| 127 library.fileUri, |
| 128 -1, |
| 129 "Import of '$name' " |
147 "(from '${getUri(preferred)}') hides imported version from " | 130 "(from '${getUri(preferred)}') hides imported version from " |
148 "'${getUri(hidden)}'."); | 131 "'${getUri(hidden)}'."); |
149 } | 132 } |
150 return preferred; | 133 return preferred; |
151 } | 134 } |
152 | 135 |
153 Builder get parent => null; | 136 Builder get parent => null; |
154 | 137 |
155 bool get isFinal => false; | 138 bool get isFinal => false; |
156 | 139 |
(...skipping 25 matching lines...) Expand all Loading... |
182 | 165 |
183 static Uri getUri(Builder builder) { | 166 static Uri getUri(Builder builder) { |
184 if (builder == null) return internalError("Builder is null."); | 167 if (builder == null) return internalError("Builder is null."); |
185 while (builder != null) { | 168 while (builder != null) { |
186 if (builder is LibraryBuilder) return builder.uri; | 169 if (builder is LibraryBuilder) return builder.uri; |
187 builder = builder.parent; | 170 builder = builder.parent; |
188 } | 171 } |
189 return internalError("No library parent."); | 172 return internalError("No library parent."); |
190 } | 173 } |
191 } | 174 } |
OLD | NEW |