| 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 'dart:async' show EventSink; | 10 import 'dart:async' show EventSink; |
| 11 import 'dart:collection'; | 11 import 'dart:collection'; |
| 12 import 'dart:convert'; | 12 import 'dart:convert'; |
| 13 | 13 |
| 14 import '../../compiler.dart'; | 14 import '../../compiler.dart'; |
| 15 import '../dart2jslib.dart'; | 15 import '../dart2jslib.dart'; |
| 16 import '../util/util.dart'; | 16 import '../util/util.dart'; |
| 17 | 17 |
| 18 part 'debug_collection.dart'; | 18 part 'debug_collection.dart'; |
| 19 part 'trace.dart'; | 19 part 'trace.dart'; |
| 20 part 'expensive_map.dart'; | 20 part 'expensive_map.dart'; |
| 21 part 'expensive_set.dart'; | 21 part 'expensive_set.dart'; |
| 22 part 'stats.dart'; | 22 part 'stats.dart'; |
| 23 part 'track_map.dart'; | 23 part 'track_map.dart'; |
| 24 | 24 |
| 25 /// Global flag to enable [debugPrint]. This should always be `true` by default | 25 /// Global flag to enable [debugPrint]. This should always be `true` by default |
| 26 /// and be set to `false` as a means to temporarily turn off all debugging | 26 /// and be set to `false` as a means to temporarily turn off all debugging |
| 27 /// printouts. | 27 /// printouts. |
| 28 const bool DEBUG_PRINT_ENABLED = true; | 28 const bool DEBUG_PRINT_ENABLED = true; |
| 29 | 29 |
| 30 /// Enables debug mode. |
| 31 /// |
| 32 /// Sets the [DEBUG_MODE] to `true`. |
| 33 void enableDebugMode() { |
| 34 DEBUG_MODE = true; |
| 35 } |
| 36 |
| 30 class _DebugIndentation extends Indentation { | 37 class _DebugIndentation extends Indentation { |
| 31 final String indentationUnit = " "; | 38 final String indentationUnit = " "; |
| 32 } | 39 } |
| 33 _DebugIndentation _indentation = new _DebugIndentation(); | 40 _DebugIndentation _indentation = new _DebugIndentation(); |
| 34 | 41 |
| 42 /// Function signature of [debugPrint]. |
| 43 typedef DebugPrint(s); |
| 44 |
| 35 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. | 45 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. |
| 36 debugPrint(s) { | 46 DebugPrint get debugPrint { |
| 47 enableDebugMode(); |
| 48 // TODO(johnniwinther): Maybe disable debug mode after the call. |
| 49 return _debugPrint; |
| 50 } |
| 51 |
| 52 /// Implementation of [debugPrint]. |
| 53 _debugPrint(s) { |
| 37 if (DEBUG_PRINT_ENABLED) print('${_indentation.indentation}$s'); | 54 if (DEBUG_PRINT_ENABLED) print('${_indentation.indentation}$s'); |
| 38 } | 55 } |
| 39 | 56 |
| 57 /// Function signature of [debugWrapPrint]. |
| 58 typedef DebugWrapPrint(s, f()); |
| 59 |
| 40 /// Wraps the call to [f] with a print of 'start:$s' and 'end:$s' incrementing | 60 /// Wraps the call to [f] with a print of 'start:$s' and 'end:$s' incrementing |
| 41 /// the current indentation used by [debugPrint] during the execution of [f]. | 61 /// the current indentation used by [debugPrint] during the execution of [f]. |
| 42 /// | 62 /// |
| 43 /// Use this to get a tree-like debug printout for nested calls. | 63 /// Use this to get a tree-like debug printout for nested calls. |
| 44 debugWrapPrint(s, f()) { | 64 DebugWrapPrint get debugWrapPrint { |
| 65 enableDebugMode(); |
| 66 return _debugWrapPrint; |
| 67 } |
| 68 |
| 69 /// Implementation of [debugWrapPrint]. |
| 70 DebugWrapPrint _debugWrapPrint(s, f()) { |
| 45 debugPrint('start:$s'); | 71 debugPrint('start:$s'); |
| 46 var result = _indentation.indentBlock(f); | 72 var result = _indentation.indentBlock(f); |
| 47 debugPrint('end:$s'); | 73 debugPrint('end:$s'); |
| 48 return result; | 74 return result; |
| 49 } | 75 } |
| 50 | 76 |
| 51 /// Dummy method to mark breakpoints. | 77 /// Dummy method to mark breakpoints. |
| 52 debugBreak() {} | 78 debugBreak() { |
| 79 enableDebugMode(); |
| 80 } |
| 81 |
| 82 /// Function signature of [reportHere]. |
| 83 typedef ReportHere(Compiler compiler, Spannable node, String debugMessage); |
| 53 | 84 |
| 54 /// Print a message with a source location. | 85 /// Print a message with a source location. |
| 55 reportHere(Compiler compiler, Spannable node, String debugMessage) { | 86 ReportHere get reportHere { |
| 87 enableDebugMode(); |
| 88 return _reportHere; |
| 89 } |
| 90 |
| 91 /// Implementation of [reportHere] |
| 92 _reportHere(Compiler compiler, Spannable node, String debugMessage) { |
| 56 compiler.reportInfo(node, | 93 compiler.reportInfo(node, |
| 57 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | 94 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
| 58 } | 95 } |
| OLD | NEW |