| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 for debugging helpers. The unittest analyze_unused_test checks that | 5 /// Library for debugging helpers. The unittest analyze_unused_test checks that |
| 6 /// the helper are not used in production code. | 6 /// the helper are not used in production code. |
| 7 | 7 |
| 8 library dart2js.helpers; | 8 library dart2js.helpers; |
| 9 | 9 |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 void enableDebugMode() { | 30 void enableDebugMode() { |
| 31 DEBUG_MODE = true; | 31 DEBUG_MODE = true; |
| 32 } | 32 } |
| 33 | 33 |
| 34 class _DebugIndentation extends Indentation { | 34 class _DebugIndentation extends Indentation { |
| 35 final String indentationUnit = " "; | 35 final String indentationUnit = " "; |
| 36 } | 36 } |
| 37 | 37 |
| 38 _DebugIndentation _indentation = new _DebugIndentation(); | 38 _DebugIndentation _indentation = new _DebugIndentation(); |
| 39 | 39 |
| 40 /// Function signature of [debugPrint]. | |
| 41 typedef DebugPrint(s); | |
| 42 | |
| 43 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. | 40 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. |
| 44 DebugPrint get debugPrint { | 41 void Function(dynamic s) get debugPrint { |
| 45 enableDebugMode(); | 42 enableDebugMode(); |
| 46 // TODO(johnniwinther): Maybe disable debug mode after the call. | 43 // TODO(johnniwinther): Maybe disable debug mode after the call. |
| 47 return _debugPrint; | 44 return _debugPrint; |
| 48 } | 45 } |
| 49 | 46 |
| 50 /// Implementation of [debugPrint]. | 47 /// Implementation of [debugPrint]. |
| 51 _debugPrint(s) { | 48 void _debugPrint(s) { |
| 52 if (DEBUG_PRINT_ENABLED) print('${_indentation.indentation}$s'); | 49 if (DEBUG_PRINT_ENABLED) print('${_indentation.indentation}$s'); |
| 53 } | 50 } |
| 54 | 51 |
| 55 /// Function signature of [debugWrapPrint]. | |
| 56 typedef DebugWrapPrint(s, f()); | |
| 57 | |
| 58 /// Wraps the call to [f] with a print of 'start:$s' and 'end:$s' incrementing | 52 /// Wraps the call to [f] with a print of 'start:$s' and 'end:$s' incrementing |
| 59 /// the current indentation used by [debugPrint] during the execution of [f]. | 53 /// the current indentation used by [debugPrint] during the execution of [f]. |
| 60 /// | 54 /// |
| 61 /// Use this to get a tree-like debug printout for nested calls. | 55 /// Use this to get a tree-like debug printout for nested calls. |
| 62 DebugWrapPrint get debugWrapPrint { | 56 dynamic Function(dynamic s, dynamic Function() f) get debugWrapPrint { |
| 63 enableDebugMode(); | 57 enableDebugMode(); |
| 64 return _debugWrapPrint; | 58 return _debugWrapPrint; |
| 65 } | 59 } |
| 66 | 60 |
| 67 /// Implementation of [debugWrapPrint]. | 61 /// Implementation of [debugWrapPrint]. |
| 68 _debugWrapPrint(s, f()) { | 62 _debugWrapPrint(s, f()) { |
| 69 debugPrint('start:$s'); | 63 debugPrint('start:$s'); |
| 70 var result = _indentation.indentBlock(f); | 64 var result = _indentation.indentBlock(f); |
| 71 debugPrint('end:$s'); | 65 debugPrint('end:$s'); |
| 72 return result; | 66 return result; |
| 73 } | 67 } |
| 74 | 68 |
| 75 /// Dummy method to mark breakpoints. | 69 /// Dummy method to mark breakpoints. |
| 76 debugBreak() { | 70 debugBreak() { |
| 77 enableDebugMode(); | 71 enableDebugMode(); |
| 78 } | 72 } |
| 79 | 73 |
| 80 /// Function signature of [reportHere]. | 74 /// Function signature of [reportHere]. |
| 81 typedef ReportHere( | 75 typedef ReportHere( |
| 82 DiagnosticReporter reporter, Spannable node, String debugMessage); | 76 DiagnosticReporter reporter, Spannable node, String debugMessage); |
| 83 | 77 |
| 84 /// Print a message with a source location. | 78 /// Print a message with a source location. |
| 85 ReportHere get reportHere { | 79 dynamic Function(DiagnosticReporter, Spannable node, String debugMessage) |
| 80 get reportHere { |
| 86 enableDebugMode(); | 81 enableDebugMode(); |
| 87 return _reportHere; | 82 return _reportHere; |
| 88 } | 83 } |
| 89 | 84 |
| 90 /// Implementation of [reportHere] | 85 /// Implementation of [reportHere] |
| 91 _reportHere(DiagnosticReporter reporter, Spannable node, String debugMessage) { | 86 _reportHere(DiagnosticReporter reporter, Spannable node, String debugMessage) { |
| 92 reporter | 87 reporter |
| 93 .reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | 88 .reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
| 94 } | 89 } |
| 95 | 90 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (printTrace) { | 129 if (printTrace) { |
| 135 trace(msg); | 130 trace(msg); |
| 136 } else { | 131 } else { |
| 137 debugPrint(msg); | 132 debugPrint(msg); |
| 138 } | 133 } |
| 139 } | 134 } |
| 140 return true; | 135 return true; |
| 141 } | 136 } |
| 142 return false; | 137 return false; |
| 143 } | 138 } |
| OLD | NEW |