| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
| 9 * compiled. | 9 * compiled. |
| 10 */ | 10 */ |
| (...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1785 backend.codegen(work); | 1785 backend.codegen(work); |
| 1786 } | 1786 } |
| 1787 | 1787 |
| 1788 void reportError(Spannable node, | 1788 void reportError(Spannable node, |
| 1789 MessageKind messageKind, | 1789 MessageKind messageKind, |
| 1790 [Map arguments = const {}]) { | 1790 [Map arguments = const {}]) { |
| 1791 reportDiagnosticInternal( | 1791 reportDiagnosticInternal( |
| 1792 node, messageKind, arguments, api.Diagnostic.ERROR); | 1792 node, messageKind, arguments, api.Diagnostic.ERROR); |
| 1793 } | 1793 } |
| 1794 | 1794 |
| 1795 /** | |
| 1796 * Reports an error and then aborts the compiler. Avoid using this method. | |
| 1797 * | |
| 1798 * In order to support incremental compilation, it is preferable to use | |
| 1799 * [reportError]. However, care must be taken to leave the compiler in a | |
| 1800 * consistent state, for example, by creating synthetic erroneous objects. | |
| 1801 * | |
| 1802 * If there's absolutely no way to leave the compiler in a consistent state, | |
| 1803 * calling this method is preferred as it will set [compilerWasCancelled] to | |
| 1804 * true which alerts the incremental compiler to discard all state and start | |
| 1805 * a new compiler. Throwing an exception is also better, as this will set | |
| 1806 * [hasCrashed] which the incremental compiler also listens too (but don't | |
| 1807 * throw exceptions, it creates a really bad user experience). | |
| 1808 * | |
| 1809 * In any case, calling this method is a last resort, as it essentially | |
| 1810 * breaks the user experience of the incremental compiler. The purpose of the | |
| 1811 * incremental compiler is to improve developer productivity. Developers | |
| 1812 * frequently make mistakes, so syntax errors and spelling errors are | |
| 1813 * considered normal to the incremental compiler. | |
| 1814 */ | |
| 1815 void reportFatalError(Spannable node, MessageKind messageKind, | |
| 1816 [Map arguments = const {}]) { | |
| 1817 reportError(node, messageKind, arguments); | |
| 1818 // TODO(ahe): Make this only abort the current method. | |
| 1819 throw new CompilerCancelledException( | |
| 1820 'Error: Cannot continue due to previous error.'); | |
| 1821 } | |
| 1822 | |
| 1823 void reportWarning(Spannable node, MessageKind messageKind, | 1795 void reportWarning(Spannable node, MessageKind messageKind, |
| 1824 [Map arguments = const {}]) { | 1796 [Map arguments = const {}]) { |
| 1825 reportDiagnosticInternal( | 1797 reportDiagnosticInternal( |
| 1826 node, messageKind, arguments, api.Diagnostic.WARNING); | 1798 node, messageKind, arguments, api.Diagnostic.WARNING); |
| 1827 } | 1799 } |
| 1828 | 1800 |
| 1829 void reportInfo(Spannable node, MessageKind messageKind, | 1801 void reportInfo(Spannable node, MessageKind messageKind, |
| 1830 [Map arguments = const {}]) { | 1802 [Map arguments = const {}]) { |
| 1831 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO); | 1803 reportDiagnosticInternal(node, messageKind, arguments, api.Diagnostic.INFO); |
| 1832 } | 1804 } |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2152 if (previous != null) previous.watch.start(); | 2124 if (previous != null) previous.watch.start(); |
| 2153 compiler.measuredTask = previous; | 2125 compiler.measuredTask = previous; |
| 2154 } | 2126 } |
| 2155 } | 2127 } |
| 2156 | 2128 |
| 2157 measureElement(Element element, action()) { | 2129 measureElement(Element element, action()) { |
| 2158 compiler.withCurrentElement(element, () => measure(action)); | 2130 compiler.withCurrentElement(element, () => measure(action)); |
| 2159 } | 2131 } |
| 2160 } | 2132 } |
| 2161 | 2133 |
| 2162 class CompilerCancelledException implements Exception { | 2134 /// Don't throw this error. It immediately aborts the compiler which causes the |
| 2135 /// following problems: |
| 2136 /// |
| 2137 /// 1. No further errors and warnings are reported. |
| 2138 /// 2. Breaks incremental compilation. |
| 2139 class CompilerCancelledException extends Error { |
| 2163 final String reason; | 2140 final String reason; |
| 2164 CompilerCancelledException(this.reason); | 2141 CompilerCancelledException(this.reason); |
| 2165 | 2142 |
| 2166 String toString() { | 2143 String toString() { |
| 2167 String banner = 'compiler cancelled'; | 2144 String banner = 'compiler cancelled'; |
| 2168 return (reason != null) ? '$banner: $reason' : '$banner'; | 2145 return (reason != null) ? '$banner: $reason' : '$banner'; |
| 2169 } | 2146 } |
| 2170 } | 2147 } |
| 2171 | 2148 |
| 2172 class SourceSpan implements Spannable { | 2149 class SourceSpan implements Spannable { |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2408 InterfaceType get nullType => nullClass.computeType(compiler); | 2385 InterfaceType get nullType => nullClass.computeType(compiler); |
| 2409 | 2386 |
| 2410 @override | 2387 @override |
| 2411 InterfaceType get numType => numClass.computeType(compiler); | 2388 InterfaceType get numType => numClass.computeType(compiler); |
| 2412 | 2389 |
| 2413 @override | 2390 @override |
| 2414 InterfaceType get stringType => stringClass.computeType(compiler); | 2391 InterfaceType get stringType => stringClass.computeType(compiler); |
| 2415 } | 2392 } |
| 2416 | 2393 |
| 2417 typedef void InternalErrorFunction(Spannable location, String message); | 2394 typedef void InternalErrorFunction(Spannable location, String message); |
| OLD | NEW |