OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 /// Library for debugging helpers. The unittest analyze_unused_test checks that | |
6 /// the helper are not used in production code. | |
7 | |
8 library dart2js.helpers; | |
9 | |
10 import 'dart:async' show EventSink; | |
11 import 'dart:collection'; | |
12 import 'dart:convert'; | |
13 | |
14 import '../../compiler.dart'; | |
15 import '../dart2jslib.dart'; | |
16 import '../util/util.dart'; | |
17 | |
18 part 'debug_collection.dart'; | |
19 part 'trace.dart'; | |
20 part 'expensive_map.dart'; | |
21 part 'expensive_set.dart'; | |
22 part 'stats.dart'; | |
23 part 'track_map.dart'; | |
24 | |
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 | |
27 /// printouts. | |
28 const bool DEBUG_PRINT_ENABLED = true; | |
29 | |
30 /// Enables debug mode. | |
31 /// | |
32 /// Sets the [DEBUG_MODE] to `true`. | |
33 void enableDebugMode() { | |
34 DEBUG_MODE = true; | |
35 } | |
36 | |
37 class _DebugIndentation extends Indentation { | |
38 final String indentationUnit = " "; | |
39 } | |
40 _DebugIndentation _indentation = new _DebugIndentation(); | |
41 | |
42 /// Function signature of [debugPrint]. | |
43 typedef DebugPrint(s); | |
44 | |
45 /// If [DEBUG_PRINT_ENABLED] is `true` print [s] using the current identation. | |
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) { | |
54 if (DEBUG_PRINT_ENABLED) print('${_indentation.indentation}$s'); | |
55 } | |
56 | |
57 /// Function signature of [debugWrapPrint]. | |
58 typedef DebugWrapPrint(s, f()); | |
59 | |
60 /// Wraps the call to [f] with a print of 'start:$s' and 'end:$s' incrementing | |
61 /// the current indentation used by [debugPrint] during the execution of [f]. | |
62 /// | |
63 /// Use this to get a tree-like debug printout for nested calls. | |
64 DebugWrapPrint get debugWrapPrint { | |
65 enableDebugMode(); | |
66 return _debugWrapPrint; | |
67 } | |
68 | |
69 /// Implementation of [debugWrapPrint]. | |
70 DebugWrapPrint _debugWrapPrint(s, f()) { | |
71 debugPrint('start:$s'); | |
72 var result = _indentation.indentBlock(f); | |
73 debugPrint('end:$s'); | |
74 return result; | |
75 } | |
76 | |
77 /// Dummy method to mark breakpoints. | |
78 debugBreak() { | |
79 enableDebugMode(); | |
80 } | |
81 | |
82 /// Function signature of [reportHere]. | |
83 typedef ReportHere(Compiler compiler, Spannable node, String debugMessage); | |
84 | |
85 /// Print a message with a source location. | |
86 ReportHere get reportHere { | |
87 enableDebugMode(); | |
88 return _reportHere; | |
89 } | |
90 | |
91 /// Implementation of [reportHere] | |
92 _reportHere(Compiler compiler, Spannable node, String debugMessage) { | |
93 compiler.reportInfo(node, | |
94 MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | |
95 } | |
OLD | NEW |