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

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

Issue 1520293002: Add token invariant to DiagnosticReporter (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Rebase + status update Created 5 years 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
« no previous file with comments | « no previous file | pkg/compiler/lib/src/diagnostics/diagnostic_listener.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 1785
1786 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { 1786 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) {
1787 if (begin == null || end == null) { 1787 if (begin == null || end == null) {
1788 // TODO(ahe): We can almost always do better. Often it is only 1788 // TODO(ahe): We can almost always do better. Often it is only
1789 // end that is null. Otherwise, we probably know the current 1789 // end that is null. Otherwise, we probably know the current
1790 // URI. 1790 // URI.
1791 throw 'Cannot find tokens to produce error message.'; 1791 throw 'Cannot find tokens to produce error message.';
1792 } 1792 }
1793 if (uri == null && currentElement != null) { 1793 if (uri == null && currentElement != null) {
1794 uri = currentElement.compilationUnit.script.resourceUri; 1794 uri = currentElement.compilationUnit.script.resourceUri;
1795 assert(invariant(currentElement, () {
1796
1797 /// Check that [begin] and [end] can be found between [from] and [to].
1798 validateToken(Token from, Token to) {
1799 if (from == null || to == null) return true;
1800 bool foundBegin = false;
1801 bool foundEnd = false;
1802 Token token = from;
1803 while (true) {
1804 if (token == begin) {
1805 foundBegin = true;
1806 }
1807 if (token == end) {
1808 foundEnd = true;
1809 }
1810 if (foundBegin && foundEnd) {
1811 return true;
1812 }
1813 if (token == to || token == token.next || token.next == null) {
1814 break;
1815 }
1816 token = token.next;
1817 }
1818
1819 // Create a good message for when the tokens were not found.
1820 StringBuffer sb = new StringBuffer();
1821 sb.write('Invalid current element: $currentElement. ');
1822 sb.write('Looking for ');
1823 sb.write('[${begin} (${begin.hashCode}),');
1824 sb.write('${end} (${end.hashCode})] in');
1825
1826 token = from;
1827 while (true) {
1828 sb.write('\n ${token} (${token.hashCode})');
1829 if (token == to || token == token.next || token.next == null) {
1830 break;
1831 }
1832 token = token.next;
1833 }
1834 return sb.toString();
1835 }
1836
1837 if (currentElement.enclosingClass != null &&
1838 currentElement.enclosingClass.isEnumClass) {
1839 // Enums ASTs are synthesized (and give messed up messages).
1840 return true;
1841 }
1842
1843 if (currentElement is AstElement) {
1844 AstElement astElement = currentElement;
1845 if (astElement.hasNode) {
1846 Token from = astElement.node.getBeginToken();
1847 Token to = astElement.node.getEndToken();
1848 if (astElement.metadata.isNotEmpty) {
1849 from = astElement.metadata.first.beginToken;
1850 }
1851 return validateToken(from, to);
1852 }
1853 }
1854 return true;
1855 }, message: "Invalid current element: $currentElement [$begin,$end]."));
1795 } 1856 }
1796 return new SourceSpan.fromTokens(uri, begin, end); 1857 return new SourceSpan.fromTokens(uri, begin, end);
1797 } 1858 }
1798 1859
1799 SourceSpan spanFromNode(Node node) { 1860 SourceSpan spanFromNode(Node node) {
1800 return spanFromTokens(node.getBeginToken(), node.getEndToken()); 1861 return spanFromTokens(node.getBeginToken(), node.getEndToken());
1801 } 1862 }
1802 1863
1803 SourceSpan spanFromElement(Element element) { 1864 SourceSpan spanFromElement(Element element) {
1804 if (element != null && element.sourcePosition != null) { 1865 if (element != null && element.sourcePosition != null) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 if (_otherDependencies == null) { 2189 if (_otherDependencies == null) {
2129 _otherDependencies = new Setlet<Element>(); 2190 _otherDependencies = new Setlet<Element>();
2130 } 2191 }
2131 _otherDependencies.add(element.implementation); 2192 _otherDependencies.add(element.implementation);
2132 } 2193 }
2133 2194
2134 Iterable<Element> get otherDependencies { 2195 Iterable<Element> get otherDependencies {
2135 return _otherDependencies != null ? _otherDependencies : const <Element>[]; 2196 return _otherDependencies != null ? _otherDependencies : const <Element>[];
2136 } 2197 }
2137 } 2198 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/diagnostics/diagnostic_listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698