| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 Element assertMethod; | 135 Element assertMethod; |
| 136 Element identicalFunction; | 136 Element identicalFunction; |
| 137 Element functionApplyMethod; | 137 Element functionApplyMethod; |
| 138 | 138 |
| 139 Element get currentElement => _currentElement; | 139 Element get currentElement => _currentElement; |
| 140 withCurrentElement(Element element, f()) { | 140 withCurrentElement(Element element, f()) { |
| 141 Element old = currentElement; | 141 Element old = currentElement; |
| 142 _currentElement = element; | 142 _currentElement = element; |
| 143 try { | 143 try { |
| 144 return f(); | 144 return f(); |
| 145 } on SpannableAssertionFailure catch (ex) { |
| 146 if (!hasCrashed) { |
| 147 SourceSpan span = spanFromSpannable(ex.node); |
| 148 reportDiagnostic(span, ex.message, api.Diagnostic.ERROR); |
| 149 } |
| 150 hasCrashed = true; |
| 151 throw; |
| 145 } on CompilerCancelledException catch (ex) { | 152 } on CompilerCancelledException catch (ex) { |
| 146 throw; | 153 throw; |
| 147 } on StackOverflowError catch (ex) { | 154 } on StackOverflowError catch (ex) { |
| 148 // We cannot report anything useful in this case, because we | 155 // We cannot report anything useful in this case, because we |
| 149 // do not have enough stack space. | 156 // do not have enough stack space. |
| 150 throw; | 157 throw; |
| 151 } catch (ex) { | 158 } catch (ex) { |
| 152 try { | 159 try { |
| 153 unhandledExceptionOnElement(element); | 160 unhandledExceptionOnElement(element); |
| 154 } catch (doubleFault) { | 161 } catch (doubleFault) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 void cancel(String reason, {Node node, Token token, | 279 void cancel(String reason, {Node node, Token token, |
| 273 HInstruction instruction, Element element}) { | 280 HInstruction instruction, Element element}) { |
| 274 assembledCode = null; // Compilation failed. Make sure that we | 281 assembledCode = null; // Compilation failed. Make sure that we |
| 275 // don't return a bogus result. | 282 // don't return a bogus result. |
| 276 SourceSpan span = null; | 283 SourceSpan span = null; |
| 277 if (node != null) { | 284 if (node != null) { |
| 278 span = spanFromNode(node); | 285 span = spanFromNode(node); |
| 279 } else if (token != null) { | 286 } else if (token != null) { |
| 280 span = spanFromTokens(token, token); | 287 span = spanFromTokens(token, token); |
| 281 } else if (instruction != null) { | 288 } else if (instruction != null) { |
| 282 span = spanFromElement(currentElement); | 289 span = spanFromHInstruction(instruction); |
| 283 } else if (element != null) { | 290 } else if (element != null) { |
| 284 span = spanFromElement(element); | 291 span = spanFromElement(element); |
| 285 } else { | 292 } else { |
| 286 throw 'No error location for error: $reason'; | 293 throw 'No error location for error: $reason'; |
| 287 } | 294 } |
| 288 reportDiagnostic(span, reason, api.Diagnostic.ERROR); | 295 reportDiagnostic(span, reason, api.Diagnostic.ERROR); |
| 289 throw new CompilerCancelledException(reason); | 296 throw new CompilerCancelledException(reason); |
| 290 } | 297 } |
| 291 | 298 |
| 299 SourceSpan spanFromSpannable(Spannable node) { |
| 300 if (node is Node) { |
| 301 return spanFromNode(node); |
| 302 } else if (node is Token) { |
| 303 return spanFromTokens(node, node); |
| 304 } else if (node is HInstruction) { |
| 305 return spanFromHInstruction(node); |
| 306 } else if (node is Element) { |
| 307 return spanFromElement(node); |
| 308 } else { |
| 309 throw 'No error location for error: $reason'; |
| 310 } |
| 311 } |
| 312 |
| 292 void reportFatalError(String reason, Element element, | 313 void reportFatalError(String reason, Element element, |
| 293 {Node node, Token token, HInstruction instruction}) { | 314 {Node node, Token token, HInstruction instruction}) { |
| 294 withCurrentElement(element, () { | 315 withCurrentElement(element, () { |
| 295 cancel(reason, node: node, token: token, instruction: instruction, | 316 cancel(reason, node: node, token: token, instruction: instruction, |
| 296 element: element); | 317 element: element); |
| 297 }); | 318 }); |
| 298 } | 319 } |
| 299 | 320 |
| 300 void log(message) { | 321 void log(message) { |
| 301 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); | 322 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 if (element == null) { | 773 if (element == null) { |
| 753 element = currentElement; | 774 element = currentElement; |
| 754 } | 775 } |
| 755 Token position = element.position(); | 776 Token position = element.position(); |
| 756 Uri uri = element.getCompilationUnit().script.uri; | 777 Uri uri = element.getCompilationUnit().script.uri; |
| 757 return (position == null) | 778 return (position == null) |
| 758 ? new SourceSpan(uri, 0, 0) | 779 ? new SourceSpan(uri, 0, 0) |
| 759 : spanFromTokens(position, position, uri); | 780 : spanFromTokens(position, position, uri); |
| 760 } | 781 } |
| 761 | 782 |
| 783 SourceSpan spanFromHInstruction(HInstruction instruction) { |
| 784 Element element = instruction.sourceElement; |
| 785 if (element == null) element = currentElement; |
| 786 var position = instruction.sourcePosition; |
| 787 if (position == null) return spanFromElement(element); |
| 788 Token token = position.token; |
| 789 if (token == null) return spanFromElement(element); |
| 790 Uri uri = element.getCompilationUnit().script.uri; |
| 791 return spanFromTokens(token, token, uri); |
| 792 } |
| 793 |
| 762 Script readScript(Uri uri, [Node node]) { | 794 Script readScript(Uri uri, [Node node]) { |
| 763 unimplemented('Compiler.readScript'); | 795 unimplemented('Compiler.readScript'); |
| 764 } | 796 } |
| 765 | 797 |
| 766 String get legDirectory { | 798 String get legDirectory { |
| 767 unimplemented('Compiler.legDirectory'); | 799 unimplemented('Compiler.legDirectory'); |
| 768 } | 800 } |
| 769 | 801 |
| 770 // TODO(karlklose): split into findHelperFunction and findHelperClass and | 802 // TODO(karlklose): split into findHelperFunction and findHelperClass and |
| 771 // add a check that the element has the expected kind. | 803 // add a check that the element has the expected kind. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 * | 889 * |
| 858 * [spannable] must be non-null and will be used to provide positional | 890 * [spannable] must be non-null and will be used to provide positional |
| 859 * information in the generated error message. | 891 * information in the generated error message. |
| 860 */ | 892 */ |
| 861 bool invariant(Spannable spannable, var condition, {String message: null}) { | 893 bool invariant(Spannable spannable, var condition, {String message: null}) { |
| 862 // TODO(johnniwinther): Use [spannable] and [message] to provide better | 894 // TODO(johnniwinther): Use [spannable] and [message] to provide better |
| 863 // information on assertion errors. | 895 // information on assertion errors. |
| 864 if (condition is Function){ | 896 if (condition is Function){ |
| 865 condition = condition(); | 897 condition = condition(); |
| 866 } | 898 } |
| 867 if (!condition && message != null) { | 899 if (spannable == null || !condition) { |
| 868 print('assertion failed: $message'); | 900 throw new SpannableAssertionFailure(spannable, message); |
| 869 } | 901 } |
| 870 return spannable != null && condition; | 902 return true; |
| 871 } | 903 } |
| OLD | NEW |