Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: pkg/compiler/lib/src/compiler.dart

Issue 1661853005: Introduce getPrefixEndToken to avoid too big context in messages. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/diagnostics/source_span.dart » ('j') | pkg/compiler/lib/src/tree/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698