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

Unified Diff: tests/compiler/dart2js/sourcemaps/js_tracer.dart

Issue 1617083002: Base JavaScript code position computation on JavaScript tracer. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 11 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
Index: tests/compiler/dart2js/sourcemaps/js_tracer.dart
diff --git a/tests/compiler/dart2js/sourcemaps/js_tracer.dart b/tests/compiler/dart2js/sourcemaps/js_tracer.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1aa40fec21b3f570fe437b07787e035c10fb1b56
--- /dev/null
+++ b/tests/compiler/dart2js/sourcemaps/js_tracer.dart
@@ -0,0 +1,138 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library sourcemap.js_tracer;
+
+import 'package:compiler/src/io/source_information.dart';
+import 'package:compiler/src/io/position_information.dart';
+import 'package:compiler/src/js/js.dart' as js;
+import 'sourcemap_helper.dart';
+import 'trace_graph.dart';
+
+/// Create a [TraceGraph] for [info] registering usage in [coverage].
+TraceGraph createTraceGraph(SourceMapInfo info, Coverage coverage) {
+ TraceGraph graph = new TraceGraph();
+ TraceListener listener = new StepTraceListener(graph);
+ CodePositionMap codePositions =
+ new CodePositionCoverage(info.jsCodePositions, coverage);
+ JavaScriptTracer tracer = new JavaScriptTracer(
+ codePositions, [new CoverageListener(coverage), listener]);
+ info.node.accept(tracer);
+ return graph;
+}
+
+class StepTraceListener extends TraceListener {
+ Map<js.Node, TraceStep> steppableMap = <js.Node, TraceStep>{};
+ final TraceGraph graph;
+
+ StepTraceListener(this.graph);
+
+ @override
+ void onStep(js.Node node, Offset offset, StepKind kind) {
+ SourceInformation sourceInformation = node.sourceInformation;
+ SourcePositionKind sourcePositionKind = SourcePositionKind.START;
+ List text = [node];
+ switch (kind) {
+ case StepKind.FUN:
+ sourcePositionKind = SourcePositionKind.INNER;
+ text = ['<exit>'];
+ break;
+ case StepKind.CALL:
+ CallPosition callPosition =
+ CallPosition.getSemanticPositionForCall(node);
+ sourcePositionKind = callPosition.sourcePositionKind;
+ break;
+ case StepKind.NEW:
+ case StepKind.RETURN:
+ case StepKind.BREAK:
+ case StepKind.CONTINUE:
+ case StepKind.THROW:
+ case StepKind.EXPRESSION_STATEMENT:
+ break;
+ case StepKind.IF_CONDITION:
+ js.If ifNode = node;
+ text = ['if(', ifNode.condition, ') ...'];
+ break;
+ case StepKind.FOR_INITIALIZER:
+ js.For forNode = node;
+ text = ['for(', forNode.init, '; ...) ...'];
+ break;
+ case StepKind.FOR_CONDITION:
+ js.For forNode = node;
+ text = ['for(...;', forNode.condition, '; ...) ...'];
+ break;
+ case StepKind.FOR_UPDATE:
+ js.For forNode = node;
+ text = ['for(...; ...', forNode.update, ') ...'];
+ break;
+ case StepKind.WHILE_CONDITION:
+ js.While whileNode = node;
+ text = ['while(', whileNode.condition, ') ...'];
+ break;
+ case StepKind.DO_CONDITION:
+ js.Do doNode = node;
+ text = ['do {... } (', doNode.condition, ')'];
+ break;
+ case StepKind.SWITCH_EXPRESSION:
+ js.Switch switchNode = node;
+ text = ['switch(', switchNode.key, ') ...'];
+ break;
+
+ }
+ createTraceStep(
+ node,
+ offset: offset,
+ sourceLocation: getSourceLocation(
+ node.sourceInformation, sourcePositionKind),
+ text: text);
+ }
+
+ void createTraceStep(
+ js.Node node,
+ {Offset offset,
+ List text,
+ String note,
+ SourceLocation sourceLocation}) {
+ int id = steppableMap.length;
+
+ if (text == null) {
+ text = [node];
+ }
+
+ TraceStep step = new TraceStep(
+ id, node,
+ offset,
+ text, sourceLocation);
+ graph.addStep(step);
+
+ steppableMap[node] = step;
+ }
+
+
+ void pushBranch(BranchKind kind, [value]) {
+ var branch;
+ switch (kind) {
+ case BranchKind.CONDITION:
+ branch = value ? 't' : 'f';
+ break;
+ case BranchKind.LOOP:
+ branch = 'l';
+ break;
+ case BranchKind.CATCH:
+ branch = 'c';
+ break;
+ case BranchKind.FINALLY:
+ branch = 'F';
+ break;
+ case BranchKind.CASE:
+ branch = '$value';
+ break;
+ }
+ graph.pushBranch(branch);
+ }
+
+ void popBranch() {
+ graph.popBranch();
+ }
+}
« no previous file with comments | « tests/compiler/dart2js/sourcemaps/diff_view.dart ('k') | tests/compiler/dart2js/sourcemaps/sourcemap_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698