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 1777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 if (begin == null || end == null) { | 1788 if (begin == null || end == null) { |
1789 // TODO(ahe): We can almost always do better. Often it is only | 1789 // TODO(ahe): We can almost always do better. Often it is only |
1790 // end that is null. Otherwise, we probably know the current | 1790 // end that is null. Otherwise, we probably know the current |
1791 // URI. | 1791 // URI. |
1792 throw 'Cannot find tokens to produce error message.'; | 1792 throw 'Cannot find tokens to produce error message.'; |
1793 } | 1793 } |
1794 if (uri == null && currentElement != null) { | 1794 if (uri == null && currentElement != null) { |
1795 uri = currentElement.compilationUnit.script.resourceUri; | 1795 uri = currentElement.compilationUnit.script.resourceUri; |
1796 assert(invariant(currentElement, () { | 1796 assert(invariant(currentElement, () { |
1797 | 1797 |
| 1798 bool sameToken(Token token, Token sought) { |
| 1799 if (token == sought) return true; |
| 1800 if (token.stringValue == '>>' || |
| 1801 token.stringValue == '>>>') { |
| 1802 // `>>` and `>>>` are converted to `>` in the parser when needed. |
| 1803 return sought.stringValue == '>' && |
| 1804 token.charOffset <= sought.charOffset && |
| 1805 sought.charOffset < token.charEnd; |
| 1806 } |
| 1807 return false; |
| 1808 } |
| 1809 |
1798 /// Check that [begin] and [end] can be found between [from] and [to]. | 1810 /// Check that [begin] and [end] can be found between [from] and [to]. |
1799 validateToken(Token from, Token to) { | 1811 validateToken(Token from, Token to) { |
1800 if (from == null || to == null) return true; | 1812 if (from == null || to == null) return true; |
1801 bool foundBegin = false; | 1813 bool foundBegin = false; |
1802 bool foundEnd = false; | 1814 bool foundEnd = false; |
1803 Token token = from; | 1815 Token token = from; |
1804 while (true) { | 1816 while (true) { |
1805 if (token == begin) { | 1817 if (sameToken(token, begin)) { |
1806 foundBegin = true; | 1818 foundBegin = true; |
1807 } | 1819 } |
1808 if (token == end) { | 1820 if (sameToken(token, end)) { |
1809 foundEnd = true; | 1821 foundEnd = true; |
1810 } | 1822 } |
1811 if (foundBegin && foundEnd) { | 1823 if (foundBegin && foundEnd) { |
1812 return true; | 1824 return true; |
1813 } | 1825 } |
1814 if (token == to || token == token.next || token.next == null) { | 1826 if (token == to || token == token.next || token.next == null) { |
1815 break; | 1827 break; |
1816 } | 1828 } |
1817 token = token.next; | 1829 token = token.next; |
1818 } | 1830 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1852 return validateToken(from, to); | 1864 return validateToken(from, to); |
1853 } | 1865 } |
1854 } | 1866 } |
1855 return true; | 1867 return true; |
1856 }, message: "Invalid current element: $currentElement [$begin,$end].")); | 1868 }, message: "Invalid current element: $currentElement [$begin,$end].")); |
1857 } | 1869 } |
1858 return new SourceSpan.fromTokens(uri, begin, end); | 1870 return new SourceSpan.fromTokens(uri, begin, end); |
1859 } | 1871 } |
1860 | 1872 |
1861 SourceSpan spanFromNode(Node node) { | 1873 SourceSpan spanFromNode(Node node) { |
1862 return spanFromTokens(node.getBeginToken(), node.getEndToken()); | 1874 return spanFromTokens(node.getBeginToken(), node.getPrefixEndToken()); |
1863 } | 1875 } |
1864 | 1876 |
1865 SourceSpan spanFromElement(Element element) { | 1877 SourceSpan spanFromElement(Element element) { |
1866 if (element != null && element.sourcePosition != null) { | 1878 if (element != null && element.sourcePosition != null) { |
1867 return element.sourcePosition; | 1879 return element.sourcePosition; |
1868 } | 1880 } |
1869 while (element != null && element.isSynthesized) { | 1881 while (element != null && element.isSynthesized) { |
1870 element = element.enclosingElement; | 1882 element = element.enclosingElement; |
1871 } | 1883 } |
1872 if (element != null && | 1884 if (element != null && |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 if (_otherDependencies == null) { | 2202 if (_otherDependencies == null) { |
2191 _otherDependencies = new Setlet<Element>(); | 2203 _otherDependencies = new Setlet<Element>(); |
2192 } | 2204 } |
2193 _otherDependencies.add(element.implementation); | 2205 _otherDependencies.add(element.implementation); |
2194 } | 2206 } |
2195 | 2207 |
2196 Iterable<Element> get otherDependencies { | 2208 Iterable<Element> get otherDependencies { |
2197 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | 2209 return _otherDependencies != null ? _otherDependencies : const <Element>[]; |
2198 } | 2210 } |
2199 } | 2211 } |
OLD | NEW |