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.library_builder; | 5 library fasta.library_builder; |
6 | 6 |
7 import '../combinator.dart' show Combinator; | 7 import '../combinator.dart' show Combinator; |
8 | 8 |
9 import '../deprecated_problems.dart' show deprecated_internalProblem; | 9 import '../problems.dart' show internalProblem; |
10 | 10 |
11 import '../export.dart' show Export; | 11 import '../export.dart' show Export; |
12 | 12 |
13 import '../loader.dart' show Loader; | 13 import '../loader.dart' show Loader; |
14 | 14 |
15 import '../messages.dart' | 15 import '../messages.dart' |
16 show Message, deprecated_nit, deprecated_warning, nit, warning; | 16 show |
| 17 Message, |
| 18 deprecated_nit, |
| 19 deprecated_warning, |
| 20 nit, |
| 21 templateInternalProblemConstructorNotFound, |
| 22 templateInternalProblemNotFoundIn, |
| 23 templateInternalProblemPrivateConstructorAccess, |
| 24 warning; |
17 | 25 |
18 import '../util/relativize.dart' show relativizeUri; | 26 import '../util/relativize.dart' show relativizeUri; |
19 | 27 |
20 import 'builder.dart' | 28 import 'builder.dart' |
21 show | 29 show |
22 Builder, | 30 Builder, |
23 ClassBuilder, | 31 ClassBuilder, |
24 DynamicTypeBuilder, | 32 DynamicTypeBuilder, |
25 PrefixBuilder, | 33 PrefixBuilder, |
26 Scope, | 34 Scope, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 /// It is an error if no such class is found, or if the class doesn't have a | 162 /// It is an error if no such class is found, or if the class doesn't have a |
155 /// matching constructor (or factory). | 163 /// matching constructor (or factory). |
156 /// | 164 /// |
157 /// If [constructorName] is null or the empty string, it's assumed to be an | 165 /// If [constructorName] is null or the empty string, it's assumed to be an |
158 /// unnamed constructor. it's an error if [constructorName] starts with | 166 /// unnamed constructor. it's an error if [constructorName] starts with |
159 /// `"_"`, and [bypassLibraryPrivacy] is false. | 167 /// `"_"`, and [bypassLibraryPrivacy] is false. |
160 Builder getConstructor(String className, | 168 Builder getConstructor(String className, |
161 {String constructorName, bool bypassLibraryPrivacy: false}) { | 169 {String constructorName, bool bypassLibraryPrivacy: false}) { |
162 constructorName ??= ""; | 170 constructorName ??= ""; |
163 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { | 171 if (constructorName.startsWith("_") && !bypassLibraryPrivacy) { |
164 throw deprecated_internalProblem( | 172 return internalProblem( |
165 "Internal error: Can't access private constructor " | 173 templateInternalProblemPrivateConstructorAccess |
166 "'$constructorName'."); | 174 .withArguments(constructorName), |
| 175 -1, |
| 176 null); |
167 } | 177 } |
168 Builder cls = | 178 Builder cls = |
169 (bypassLibraryPrivacy ? scope : exports).lookup(className, -1, null); | 179 (bypassLibraryPrivacy ? scope : exports).lookup(className, -1, null); |
170 if (cls is ClassBuilder) { | 180 if (cls is ClassBuilder) { |
171 // TODO(ahe): This code is similar to code in `endNewExpression` in | 181 // TODO(ahe): This code is similar to code in `endNewExpression` in |
172 // `body_builder.dart`, try to share it. | 182 // `body_builder.dart`, try to share it. |
173 Builder constructor = | 183 Builder constructor = |
174 cls.findConstructorOrFactory(constructorName, -1, null, this); | 184 cls.findConstructorOrFactory(constructorName, -1, null, this); |
175 if (constructor == null) { | 185 if (constructor == null) { |
176 // Fall-through to internal error below. | 186 // Fall-through to internal error below. |
177 } else if (constructor.isConstructor) { | 187 } else if (constructor.isConstructor) { |
178 if (!cls.isAbstract) { | 188 if (!cls.isAbstract) { |
179 return constructor; | 189 return constructor; |
180 } | 190 } |
181 } else if (constructor.isFactory) { | 191 } else if (constructor.isFactory) { |
182 return constructor; | 192 return constructor; |
183 } | 193 } |
184 } | 194 } |
185 throw deprecated_internalProblem("Internal error: No constructor named" | 195 throw internalProblem( |
186 " '$className::$constructorName' in '$uri'."); | 196 templateInternalProblemConstructorNotFound.withArguments( |
| 197 "$className::$constructorName", uri), |
| 198 -1, |
| 199 null); |
187 } | 200 } |
188 | 201 |
189 int finishTypeVariables(ClassBuilder object) => 0; | 202 int finishTypeVariables(ClassBuilder object) => 0; |
190 | 203 |
191 void becomeCoreLibrary(dynamicType, voidType) { | 204 void becomeCoreLibrary(dynamicType, voidType) { |
192 addBuilder("dynamic", | 205 addBuilder("dynamic", |
193 new DynamicTypeBuilder<T, dynamic>(dynamicType, this, -1), -1); | 206 new DynamicTypeBuilder<T, dynamic>(dynamicType, this, -1), -1); |
194 addBuilder("void", new VoidTypeBuilder<T, dynamic>(voidType, this, -1), -1); | 207 addBuilder("void", new VoidTypeBuilder<T, dynamic>(voidType, this, -1), -1); |
195 } | 208 } |
196 | 209 |
197 void forEach(void f(String name, Builder builder)) { | 210 void forEach(void f(String name, Builder builder)) { |
198 scope.forEach(f); | 211 scope.forEach(f); |
199 } | 212 } |
200 | 213 |
201 /// Don't use for scope lookup. Only use when an element is known to exist | 214 /// Don't use for scope lookup. Only use when an element is known to exist |
202 /// (and not a setter). | 215 /// (and not a setter). |
203 Builder operator [](String name) { | 216 Builder operator [](String name) { |
204 return scope.local[name] ?? | 217 return scope.local[name] ?? |
205 deprecated_internalProblem("Not found: '$name'."); | 218 internalProblem( |
| 219 templateInternalProblemNotFoundIn.withArguments( |
| 220 name, relativeFileUri), |
| 221 -1, |
| 222 null); |
206 } | 223 } |
207 | 224 |
208 Builder lookup(String name, int charOffset, Uri fileUri) { | 225 Builder lookup(String name, int charOffset, Uri fileUri) { |
209 return scope.lookup(name, charOffset, fileUri); | 226 return scope.lookup(name, charOffset, fileUri); |
210 } | 227 } |
211 } | 228 } |
OLD | NEW |