OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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.compiler_base; | 5 library dart2js.compiler_base; |
6 | 6 |
7 import 'dart:async' show | 7 import 'dart:async' show |
8 EventSink, | 8 EventSink, |
9 Future; | 9 Future; |
10 | 10 |
(...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1755 | 1755 |
1756 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { | 1756 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { |
1757 if (begin == null || end == null) { | 1757 if (begin == null || end == null) { |
1758 // TODO(ahe): We can almost always do better. Often it is only | 1758 // TODO(ahe): We can almost always do better. Often it is only |
1759 // end that is null. Otherwise, we probably know the current | 1759 // end that is null. Otherwise, we probably know the current |
1760 // URI. | 1760 // URI. |
1761 throw 'Cannot find tokens to produce error message.'; | 1761 throw 'Cannot find tokens to produce error message.'; |
1762 } | 1762 } |
1763 if (uri == null && currentElement != null) { | 1763 if (uri == null && currentElement != null) { |
1764 uri = currentElement.compilationUnit.script.resourceUri; | 1764 uri = currentElement.compilationUnit.script.resourceUri; |
| 1765 assert(invariant(currentElement, () { |
| 1766 |
| 1767 /// Check that [begin] and [end] can be found between [from] and [to]. |
| 1768 validateToken(Token from, Token to) { |
| 1769 if (from == null || to == null) return true; |
| 1770 bool foundBegin = false; |
| 1771 bool foundEnd = false; |
| 1772 Token token = from; |
| 1773 while (true) { |
| 1774 if (token == begin) { |
| 1775 foundBegin = true; |
| 1776 } |
| 1777 if (token == end) { |
| 1778 foundEnd = true; |
| 1779 } |
| 1780 if (foundBegin && foundEnd) { |
| 1781 return true; |
| 1782 } |
| 1783 if (token == to || token == token.next || token.next == null) { |
| 1784 break; |
| 1785 } |
| 1786 token = token.next; |
| 1787 } |
| 1788 |
| 1789 // Create a good message for when the tokens were not found. |
| 1790 StringBuffer sb = new StringBuffer(); |
| 1791 sb.write('Invalid current element: $currentElement. '); |
| 1792 sb.write('Looking for '); |
| 1793 sb.write('[${begin} (${begin.hashCode}),'); |
| 1794 sb.write('${end} (${end.hashCode})] in'); |
| 1795 |
| 1796 token = from; |
| 1797 while (true) { |
| 1798 sb.write('\n ${token} (${token.hashCode})'); |
| 1799 if (token == to || token == token.next || token.next == null) { |
| 1800 break; |
| 1801 } |
| 1802 token = token.next; |
| 1803 } |
| 1804 return sb.toString(); |
| 1805 } |
| 1806 |
| 1807 if (currentElement.enclosingClass != null && |
| 1808 currentElement.enclosingClass.isEnumClass) { |
| 1809 // Enums ASTs are synthesized (and give messed up messages). |
| 1810 return true; |
| 1811 } |
| 1812 |
| 1813 if (currentElement is AstElement) { |
| 1814 AstElement astElement = currentElement; |
| 1815 if (astElement.hasNode) { |
| 1816 Token from = astElement.node.getBeginToken(); |
| 1817 Token to = astElement.node.getEndToken(); |
| 1818 if (astElement.metadata.isNotEmpty) { |
| 1819 from = astElement.metadata.first.beginToken; |
| 1820 } |
| 1821 return validateToken(from, to); |
| 1822 } |
| 1823 } |
| 1824 return true; |
| 1825 }, message: "Invalid current element: $currentElement [$begin,$end].")); |
1765 } | 1826 } |
1766 return new SourceSpan.fromTokens(uri, begin, end); | 1827 return new SourceSpan.fromTokens(uri, begin, end); |
1767 } | 1828 } |
1768 | 1829 |
1769 SourceSpan spanFromNode(Node node) { | 1830 SourceSpan spanFromNode(Node node) { |
1770 return spanFromTokens(node.getBeginToken(), node.getEndToken()); | 1831 return spanFromTokens(node.getBeginToken(), node.getEndToken()); |
1771 } | 1832 } |
1772 | 1833 |
1773 SourceSpan spanFromElement(Element element) { | 1834 SourceSpan spanFromElement(Element element) { |
1774 if (element != null && element.sourcePosition != null) { | 1835 if (element != null && element.sourcePosition != null) { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 if (_otherDependencies == null) { | 2159 if (_otherDependencies == null) { |
2099 _otherDependencies = new Setlet<Element>(); | 2160 _otherDependencies = new Setlet<Element>(); |
2100 } | 2161 } |
2101 _otherDependencies.add(element.implementation); | 2162 _otherDependencies.add(element.implementation); |
2102 } | 2163 } |
2103 | 2164 |
2104 Iterable<Element> get otherDependencies { | 2165 Iterable<Element> get otherDependencies { |
2105 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | 2166 return _otherDependencies != null ? _otherDependencies : const <Element>[]; |
2106 } | 2167 } |
2107 } | 2168 } |
OLD | NEW |