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

Unified Diff: pkg/compiler/lib/src/helpers/helpers.dart

Issue 1229673006: Generated source mapping through CPS. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/io/position_information.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/helpers/helpers.dart
diff --git a/pkg/compiler/lib/src/helpers/helpers.dart b/pkg/compiler/lib/src/helpers/helpers.dart
index bcfa12c9b5ff6b0d3ce3f92cb1f66d4ddd3bbc8d..9f7e2848fe6aab78a3b36e62fb9aa52c9d37f32e 100644
--- a/pkg/compiler/lib/src/helpers/helpers.dart
+++ b/pkg/compiler/lib/src/helpers/helpers.dart
@@ -93,3 +93,52 @@ _reportHere(Compiler compiler, Spannable node, String debugMessage) {
compiler.reportInfo(node,
MessageKind.GENERIC, {'text': 'HERE: $debugMessage'});
}
+
+/// Set of tracked objects used by [track] and [ifTracked].
+var _trackedObjects = new Set();
+
+/// Global default value for the `printTrace` option of [track] and [ifTracked].
+bool trackWithTrace = false;
+
+/// If [doTrack] is `true`, add [object] to the set of tracked objects.
+///
+/// If tracked, [message] is printed along the hash code and toString of
+/// [object]. If [printTrace] is `true` a trace printed additionally.
+/// If [printTrace] is `null`, [trackWithTrace] determines whether a trace is
+/// printed.
+///
+/// [object] is returned as the result of the method.
+track(bool doTrack, Object object, String message, {bool printTrace}) {
+ if (!doTrack) return object;
+ _trackedObjects.add(object);
+ String msg = 'track: ${object.hashCode}:$object:$message';
+ if (printTrace == null) printTrace = trackWithTrace;
+ if (printTrace) {
+ trace(msg);
+ } else {
+ debugPrint(msg);
+ }
+ return object;
+}
+
+/// Returns `true` if [object] is in the set of tracked objects.
+///
+/// If [message] is provided it is printed along the hash code and toString of
+/// [object]. If [printTrace] is `true` a trace printed additionally. If
+/// [printTrace] is `null`, [trackWithTrace] determines whether a trace is
+/// printed.
+bool ifTracked(Object object, {String message, bool printTrace}) {
+ if (_trackedObjects.contains(object)) {
+ if (message != null) {
+ String msg = 'tracked: ${object.hashCode}:$object:$message';
+ if (printTrace == null) printTrace = trackWithTrace;
+ if (printTrace) {
+ trace(msg);
+ } else {
+ debugPrint(msg);
+ }
+ }
+ return true;
+ }
+ return false;
+}
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_nodes.dart ('k') | pkg/compiler/lib/src/io/position_information.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698