Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1151)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/helpers/trace.dart

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of dart2js.helpers; 5 part of dart2js.helpers;
6 6
7 /// Function signature for [trace].
8 typedef void Trace(String message,
9 {bool condition(String stackTrace),
10 int limit,
11 bool throwOnPrint});
12
7 /** 13 /**
8 * Helper method for printing stack traces for debugging. 14 * Helper method for printing stack traces for debugging.
9 * 15 *
10 * [message] is printed as the header of the stack trace. 16 * [message] is printed as the header of the stack trace.
11 * 17 *
12 * If [condition] is provided, the stack trace is only printed if [condition] 18 * If [condition] is provided, the stack trace is only printed if [condition]
13 * returns [:true:] on the stack trace text. This can be used to filter the 19 * returns [:true:] on the stack trace text. This can be used to filter the
14 * printed stack traces based on their content. For instance only print stack 20 * printed stack traces based on their content. For instance only print stack
15 * traces that contain specific paths. 21 * traces that contain specific paths.
16 * 22 *
17 * If [limit] is provided, the stack trace is limited to [limit] entries. 23 * If [limit] is provided, the stack trace is limited to [limit] entries.
18 * 24 *
19 * If [throwOnPrint] is `true`, [message] will be thrown after the stack trace 25 * If [throwOnPrint] is `true`, [message] will be thrown after the stack trace
20 * has been printed. Together with [condition] this can be used to discover 26 * has been printed. Together with [condition] this can be used to discover
21 * unknown call-sites in tests by filtering known call-sites and throwning 27 * unknown call-sites in tests by filtering known call-sites and throwning
22 * otherwise. 28 * otherwise.
23 */ 29 */
24 void trace(String message, {bool condition(String stackTrace), int limit, 30 Trace get trace {
25 bool throwOnPrint: false}) { 31 enableDebugMode();
32 return _trace;
33 }
34
35 void _trace(String message, {bool condition(String stackTrace), int limit,
36 bool throwOnPrint: false}) {
26 try { 37 try {
27 throw ''; 38 throw '';
28 } catch (e, s) { 39 } catch (e, s) {
29 String stackTrace; 40 String stackTrace;
30 try { 41 try {
31 stackTrace = prettifyStackTrace( 42 stackTrace = prettifyStackTrace(
32 s, rangeStart: 1, rangeEnd: limit, filePrefix: stackTraceFilePrefix); 43 s, rangeStart: 1, rangeEnd: limit, filePrefix: stackTraceFilePrefix);
33 } catch (e) { 44 } catch (e) {
34 print(e); 45 print(e);
35 stackTrace = '$s'; 46 stackTrace = '$s';
36 } 47 }
37 if (condition != null) { 48 if (condition != null) {
38 if (!condition(stackTrace)) return; 49 if (!condition(stackTrace)) return;
39 } 50 }
40 print('$message\n$stackTrace'); 51 print('$message\n$stackTrace');
41 if (throwOnPrint) throw message; 52 if (throwOnPrint) throw message;
42 } 53 }
43 } 54 }
44 55
45 void traceAndReport(Compiler compiler, Spannable node, String message, 56 /// Function signature of [traceAndReport].
46 {bool condition(String stackTrace), int limit, 57 typedef void TraceAndReport(Compiler compiler, Spannable node, String message,
47 bool throwOnPrint: false}) { 58 {bool condition(String stackTrace), int limit,
59 bool throwOnPrint});
60
61 /// Calls [reportHere] and [trace] with the same message.
62 TraceAndReport get traceAndReport {
63 enableDebugMode();
64 return _traceAndReport;
65 }
66
67 /// Calls [reportHere] and [trace] with the same message.
68 TraceAndReport get reportAndTrace => traceAndReport;
69
70 /// Implementation of [traceAndReport].
71 void _traceAndReport(Compiler compiler, Spannable node, String message,
72 {bool condition(String stackTrace), int limit,
73 bool throwOnPrint: false}) {
48 74
49 trace(message, limit: limit, throwOnPrint: throwOnPrint, 75 trace(message, limit: limit, throwOnPrint: throwOnPrint,
50 condition: (String stackTrace) { 76 condition: (String stackTrace) {
51 bool result = condition != null ? condition(stackTrace) : true; 77 bool result = condition != null ? condition(stackTrace) : true;
52 if (result) { 78 if (result) {
53 reportHere(compiler, node, message); 79 reportHere(compiler, node, message);
54 } 80 }
55 return result; 81 return result;
56 }); 82 });
57 } 83 }
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 324 }
299 for (int index = text.length ; index < intendedLength ; index ++) { 325 for (int index = text.length ; index < intendedLength ; index ++) {
300 int dotsIndex = index % dotsLength; 326 int dotsIndex = index % dotsLength;
301 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); 327 sb.write(dots.substring(dotsIndex, dotsIndex + 1));
302 } 328 }
303 if (padLeft) { 329 if (padLeft) {
304 sb.write(text); 330 sb.write(text);
305 } 331 }
306 return sb.toString(); 332 return sb.toString();
307 } 333 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698