OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 dart2js.resolution_strategy; | 5 library dart2js.resolution_strategy; |
6 | 6 |
7 import 'package:front_end/src/fasta/scanner.dart' show Token; | 7 import 'package:front_end/src/fasta/scanner.dart' show Token; |
8 | 8 |
9 import '../common.dart'; | 9 import '../common.dart'; |
10 import '../common_elements.dart'; | 10 import '../common_elements.dart'; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // end that is null. Otherwise, we probably know the current | 227 // end that is null. Otherwise, we probably know the current |
228 // URI. | 228 // URI. |
229 throw 'Cannot find tokens to produce error message.'; | 229 throw 'Cannot find tokens to produce error message.'; |
230 } | 230 } |
231 if (uri == null && currentElement != null) { | 231 if (uri == null && currentElement != null) { |
232 if (currentElement is! Element) { | 232 if (currentElement is! Element) { |
233 throw 'Can only find tokens from an Element.'; | 233 throw 'Can only find tokens from an Element.'; |
234 } | 234 } |
235 Element element = currentElement; | 235 Element element = currentElement; |
236 uri = element.compilationUnit.script.resourceUri; | 236 uri = element.compilationUnit.script.resourceUri; |
237 assert(invariant(currentElement, () { | 237 assert(() { |
238 bool sameToken(Token token, Token sought) { | 238 bool sameToken(Token token, Token sought) { |
239 if (token == sought) return true; | 239 if (token == sought) return true; |
240 if (token.stringValue == '>>') { | 240 if (token.stringValue == '>>') { |
241 // `>>` is converted to `>` in the parser when needed. | 241 // `>>` is converted to `>` in the parser when needed. |
242 return sought.stringValue == '>' && | 242 return sought.stringValue == '>' && |
243 token.charOffset <= sought.charOffset && | 243 token.charOffset <= sought.charOffset && |
244 sought.charOffset < token.charEnd; | 244 sought.charOffset < token.charEnd; |
245 } | 245 } |
246 return false; | 246 return false; |
247 } | 247 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 // We might try to report an error while parsing the metadata | 302 // We might try to report an error while parsing the metadata |
303 // itself. | 303 // itself. |
304 return true; | 304 return true; |
305 } | 305 } |
306 from = astElement.metadata.first.node.getBeginToken(); | 306 from = astElement.metadata.first.node.getBeginToken(); |
307 } | 307 } |
308 return validateToken(from, to); | 308 return validateToken(from, to); |
309 } | 309 } |
310 } | 310 } |
311 return true; | 311 return true; |
312 }, message: "Invalid current element: $element [$begin,$end].")); | 312 }, |
| 313 failedAt(currentElement, |
| 314 "Invalid current element: $element [$begin,$end].")); |
313 } | 315 } |
314 return new SourceSpan.fromTokens(uri, begin, end); | 316 return new SourceSpan.fromTokens(uri, begin, end); |
315 } | 317 } |
316 | 318 |
317 SourceSpan _spanFromNode(Element currentElement, Node node) { | 319 SourceSpan _spanFromNode(Element currentElement, Node node) { |
318 return _spanFromTokens( | 320 return _spanFromTokens( |
319 currentElement, node.getBeginToken(), node.getPrefixEndToken()); | 321 currentElement, node.getBeginToken(), node.getPrefixEndToken()); |
320 } | 322 } |
321 | 323 |
322 SourceSpan _spanFromElement(Element currentElement, Element element) { | 324 SourceSpan _spanFromElement(Element currentElement, Element element) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 type.computeUnaliased(_resolution); | 613 type.computeUnaliased(_resolution); |
612 return type.unaliased; | 614 return type.unaliased; |
613 } | 615 } |
614 | 616 |
615 @override | 617 @override |
616 Iterable<ConstantValue> getMemberMetadata(MemberElement element) { | 618 Iterable<ConstantValue> getMemberMetadata(MemberElement element) { |
617 List<ConstantValue> values = <ConstantValue>[]; | 619 List<ConstantValue> values = <ConstantValue>[]; |
618 _compiler.reporter.withCurrentElement(element, () { | 620 _compiler.reporter.withCurrentElement(element, () { |
619 for (MetadataAnnotation metadata in element.implementation.metadata) { | 621 for (MetadataAnnotation metadata in element.implementation.metadata) { |
620 metadata.ensureResolved(_compiler.resolution); | 622 metadata.ensureResolved(_compiler.resolution); |
621 assert(invariant(metadata, metadata.constant != null, | 623 assert(metadata.constant != null, |
622 message: "Unevaluated metadata constant.")); | 624 failedAt(metadata, "Unevaluated metadata constant.")); |
623 ConstantValue value = | 625 ConstantValue value = |
624 _compiler.constants.getConstantValue(metadata.constant); | 626 _compiler.constants.getConstantValue(metadata.constant); |
625 values.add(value); | 627 values.add(value); |
626 } | 628 } |
627 }); | 629 }); |
628 return values; | 630 return values; |
629 } | 631 } |
630 } | 632 } |
631 | 633 |
632 /// AST-based logic for processing annotations. These annotations are processed | 634 /// AST-based logic for processing annotations. These annotations are processed |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 | 825 |
824 /// Builder that creates work item necessary for the resolution of a | 826 /// Builder that creates work item necessary for the resolution of a |
825 /// [MemberElement]. | 827 /// [MemberElement]. |
826 class ResolutionWorkItemBuilder extends WorkItemBuilder { | 828 class ResolutionWorkItemBuilder extends WorkItemBuilder { |
827 final Resolution _resolution; | 829 final Resolution _resolution; |
828 | 830 |
829 ResolutionWorkItemBuilder(this._resolution); | 831 ResolutionWorkItemBuilder(this._resolution); |
830 | 832 |
831 @override | 833 @override |
832 WorkItem createWorkItem(MemberElement element) { | 834 WorkItem createWorkItem(MemberElement element) { |
833 assert(invariant(element, element.isDeclaration)); | 835 assert(element.isDeclaration, failedAt(element)); |
834 if (element.isMalformed) return null; | 836 if (element.isMalformed) return null; |
835 | 837 |
836 assert(invariant(element, element is AnalyzableElement, | 838 assert(element is AnalyzableElement, |
837 message: 'Element $element is not analyzable.')); | 839 failedAt(element, 'Element $element is not analyzable.')); |
838 return _resolution.createWorkItem(element); | 840 return _resolution.createWorkItem(element); |
839 } | 841 } |
840 } | 842 } |
OLD | NEW |