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'; |
11 import '../diagnostics/invariant.dart' show | 11 import '../diagnostics/invariant.dart' show DEBUG_MODE; |
12 DEBUG_MODE; | |
13 import '../util/util.dart'; | 12 import '../util/util.dart'; |
14 | 13 |
15 import 'trace.dart'; | 14 import 'trace.dart'; |
16 | 15 |
17 export 'debug_collection.dart'; | 16 export 'debug_collection.dart'; |
18 export 'trace.dart'; | 17 export 'trace.dart'; |
19 export 'expensive_map.dart'; | 18 export 'expensive_map.dart'; |
20 export 'expensive_set.dart'; | 19 export 'expensive_set.dart'; |
21 export 'stats.dart'; | 20 export 'stats.dart'; |
22 export 'track_map.dart'; | 21 export 'track_map.dart'; |
23 | 22 |
24 /// Global flag to enable [debugPrint]. This should always be `true` by default | 23 /// Global flag to enable [debugPrint]. This should always be `true` by default |
25 /// and be set to `false` as a means to temporarily turn off all debugging | 24 /// and be set to `false` as a means to temporarily turn off all debugging |
26 /// printouts. | 25 /// printouts. |
27 const bool DEBUG_PRINT_ENABLED = true; | 26 const bool DEBUG_PRINT_ENABLED = true; |
28 | 27 |
29 /// Enables debug mode. | 28 /// Enables debug mode. |
30 /// | 29 /// |
31 /// Sets the [DEBUG_MODE] to `true`. | 30 /// Sets the [DEBUG_MODE] to `true`. |
32 void enableDebugMode() { | 31 void enableDebugMode() { |
33 DEBUG_MODE = true; | 32 DEBUG_MODE = true; |
34 } | 33 } |
35 | 34 |
36 class _DebugIndentation extends Indentation { | 35 class _DebugIndentation extends Indentation { |
37 final String indentationUnit = " "; | 36 final String indentationUnit = " "; |
38 } | 37 } |
| 38 |
39 _DebugIndentation _indentation = new _DebugIndentation(); | 39 _DebugIndentation _indentation = new _DebugIndentation(); |
40 | 40 |
41 /// Function signature of [debugPrint]. | 41 /// Function signature of [debugPrint]. |
42 typedef DebugPrint(s); | 42 typedef DebugPrint(s); |
43 | 43 |
44 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. | 44 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. |
45 DebugPrint get debugPrint { | 45 DebugPrint get debugPrint { |
46 enableDebugMode(); | 46 enableDebugMode(); |
47 // TODO(johnniwinther): Maybe disable debug mode after the call. | 47 // TODO(johnniwinther): Maybe disable debug mode after the call. |
48 return _debugPrint; | 48 return _debugPrint; |
(...skipping 23 matching lines...) Expand all Loading... |
72 debugPrint('end:$s'); | 72 debugPrint('end:$s'); |
73 return result; | 73 return result; |
74 } | 74 } |
75 | 75 |
76 /// Dummy method to mark breakpoints. | 76 /// Dummy method to mark breakpoints. |
77 debugBreak() { | 77 debugBreak() { |
78 enableDebugMode(); | 78 enableDebugMode(); |
79 } | 79 } |
80 | 80 |
81 /// Function signature of [reportHere]. | 81 /// Function signature of [reportHere]. |
82 typedef ReportHere(DiagnosticReporter reporter, | 82 typedef ReportHere( |
83 Spannable node, | 83 DiagnosticReporter reporter, Spannable node, String debugMessage); |
84 String debugMessage); | |
85 | 84 |
86 /// Print a message with a source location. | 85 /// Print a message with a source location. |
87 ReportHere get reportHere { | 86 ReportHere get reportHere { |
88 enableDebugMode(); | 87 enableDebugMode(); |
89 return _reportHere; | 88 return _reportHere; |
90 } | 89 } |
91 | 90 |
92 /// Implementation of [reportHere] | 91 /// Implementation of [reportHere] |
93 _reportHere(DiagnosticReporter reporter, Spannable node, String debugMessage) { | 92 _reportHere(DiagnosticReporter reporter, Spannable node, String debugMessage) { |
94 reporter.reportInfo(node, | 93 reporter |
95 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | 94 .reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
96 } | 95 } |
97 | 96 |
98 /// Set of tracked objects used by [track] and [ifTracked]. | 97 /// Set of tracked objects used by [track] and [ifTracked]. |
99 var _trackedObjects = new Set(); | 98 var _trackedObjects = new Set(); |
100 | 99 |
101 /// Global default value for the `printTrace` option of [track] and [ifTracked]. | 100 /// Global default value for the `printTrace` option of [track] and [ifTracked]. |
102 bool trackWithTrace = false; | 101 bool trackWithTrace = false; |
103 | 102 |
104 /// If [doTrack] is `true`, add [object] to the set of tracked objects. | 103 /// If [doTrack] is `true`, add [object] to the set of tracked objects. |
105 /// | 104 /// |
(...skipping 30 matching lines...) Expand all Loading... |
136 if (printTrace) { | 135 if (printTrace) { |
137 trace(msg); | 136 trace(msg); |
138 } else { | 137 } else { |
139 debugPrint(msg); | 138 debugPrint(msg); |
140 } | 139 } |
141 } | 140 } |
142 return true; | 141 return true; |
143 } | 142 } |
144 return false; | 143 return false; |
145 } | 144 } |
OLD | NEW |