Chromium Code Reviews| 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 == '>'; | |
|
ahe
2016/02/08 14:40:13
Also look at character offset?
Johnni Winther
2016/02/09 11:59:58
Done.
| |
| 1804 } | |
| 1805 return false; | |
| 1806 } | |
| 1807 | |
| 1798 /// Check that [begin] and [end] can be found between [from] and [to]. | 1808 /// Check that [begin] and [end] can be found between [from] and [to]. |
| 1799 validateToken(Token from, Token to) { | 1809 validateToken(Token from, Token to) { |
| 1800 if (from == null || to == null) return true; | 1810 if (from == null || to == null) return true; |
| 1801 bool foundBegin = false; | 1811 bool foundBegin = false; |
| 1802 bool foundEnd = false; | 1812 bool foundEnd = false; |
| 1803 Token token = from; | 1813 Token token = from; |
| 1804 while (true) { | 1814 while (true) { |
| 1805 if (token == begin) { | 1815 if (sameToken(token, begin)) { |
| 1806 foundBegin = true; | 1816 foundBegin = true; |
| 1807 } | 1817 } |
| 1808 if (token == end) { | 1818 if (sameToken(token, end)) { |
| 1809 foundEnd = true; | 1819 foundEnd = true; |
| 1810 } | 1820 } |
| 1811 if (foundBegin && foundEnd) { | 1821 if (foundBegin && foundEnd) { |
| 1812 return true; | 1822 return true; |
| 1813 } | 1823 } |
| 1814 if (token == to || token == token.next || token.next == null) { | 1824 if (token == to || token == token.next || token.next == null) { |
| 1815 break; | 1825 break; |
| 1816 } | 1826 } |
| 1817 token = token.next; | 1827 token = token.next; |
| 1818 } | 1828 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1852 return validateToken(from, to); | 1862 return validateToken(from, to); |
| 1853 } | 1863 } |
| 1854 } | 1864 } |
| 1855 return true; | 1865 return true; |
| 1856 }, message: "Invalid current element: $currentElement [$begin,$end].")); | 1866 }, message: "Invalid current element: $currentElement [$begin,$end].")); |
| 1857 } | 1867 } |
| 1858 return new SourceSpan.fromTokens(uri, begin, end); | 1868 return new SourceSpan.fromTokens(uri, begin, end); |
| 1859 } | 1869 } |
| 1860 | 1870 |
| 1861 SourceSpan spanFromNode(Node node) { | 1871 SourceSpan spanFromNode(Node node) { |
| 1862 return spanFromTokens(node.getBeginToken(), node.getEndToken()); | 1872 return spanFromTokens(node.getBeginToken(), node.getPrefixEndToken()); |
| 1863 } | 1873 } |
| 1864 | 1874 |
| 1865 SourceSpan spanFromElement(Element element) { | 1875 SourceSpan spanFromElement(Element element) { |
| 1866 if (element != null && element.sourcePosition != null) { | 1876 if (element != null && element.sourcePosition != null) { |
| 1867 return element.sourcePosition; | 1877 return element.sourcePosition; |
| 1868 } | 1878 } |
| 1869 while (element != null && element.isSynthesized) { | 1879 while (element != null && element.isSynthesized) { |
| 1870 element = element.enclosingElement; | 1880 element = element.enclosingElement; |
| 1871 } | 1881 } |
| 1872 if (element != null && | 1882 if (element != null && |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2190 if (_otherDependencies == null) { | 2200 if (_otherDependencies == null) { |
| 2191 _otherDependencies = new Setlet<Element>(); | 2201 _otherDependencies = new Setlet<Element>(); |
| 2192 } | 2202 } |
| 2193 _otherDependencies.add(element.implementation); | 2203 _otherDependencies.add(element.implementation); |
| 2194 } | 2204 } |
| 2195 | 2205 |
| 2196 Iterable<Element> get otherDependencies { | 2206 Iterable<Element> get otherDependencies { |
| 2197 return _otherDependencies != null ? _otherDependencies : const <Element>[]; | 2207 return _otherDependencies != null ? _otherDependencies : const <Element>[]; |
| 2198 } | 2208 } |
| 2199 } | 2209 } |
| OLD | NEW |