OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 sourcemap.js_tracer; | 5 library sourcemap.js_tracer; |
6 | 6 |
7 import 'package:compiler/src/io/source_information.dart'; | 7 import 'package:compiler/src/io/source_information.dart'; |
8 import 'package:compiler/src/io/position_information.dart'; | 8 import 'package:compiler/src/io/position_information.dart'; |
9 import 'package:compiler/src/js/js.dart' as js; | 9 import 'package:compiler/src/js/js.dart' as js; |
10 import 'sourcemap_helper.dart'; | 10 import 'sourcemap_helper.dart'; |
11 import 'trace_graph.dart'; | 11 import 'trace_graph.dart'; |
12 | 12 |
13 /// Create a [TraceGraph] for [info] registering usage in [coverage]. | 13 /// Create a [TraceGraph] for [info] registering usage in [coverage]. |
14 TraceGraph createTraceGraph(SourceMapInfo info, Coverage coverage) { | 14 TraceGraph createTraceGraph(SourceMapInfo info, Coverage coverage) { |
15 TraceGraph graph = new TraceGraph(); | 15 TraceGraph graph = new TraceGraph(); |
16 TraceListener listener = new StepTraceListener(graph); | 16 TraceListener listener = new StepTraceListener(graph); |
17 CodePositionMap codePositions = | 17 CodePositionMap codePositions = |
18 new CodePositionCoverage(info.jsCodePositions, coverage); | 18 new CodePositionCoverage(info.jsCodePositions, coverage); |
19 JavaScriptTracer tracer = new JavaScriptTracer( | 19 JavaScriptTracer tracer = new JavaScriptTracer( |
20 codePositions, [new CoverageListener(coverage), listener]); | 20 codePositions, [new CoverageListener(coverage), listener]); |
21 info.node.accept(tracer); | 21 info.node.accept(tracer); |
22 return graph; | 22 return graph; |
23 } | 23 } |
24 | 24 |
25 class StepTraceListener extends TraceListener { | 25 class StepTraceListener extends TraceListener |
| 26 with NodeToSourceInformationMixin { |
26 Map<js.Node, TraceStep> steppableMap = <js.Node, TraceStep>{}; | 27 Map<js.Node, TraceStep> steppableMap = <js.Node, TraceStep>{}; |
27 final TraceGraph graph; | 28 final TraceGraph graph; |
28 | 29 |
29 StepTraceListener(this.graph); | 30 StepTraceListener(this.graph); |
30 | 31 |
31 @override | 32 @override |
32 void onStep(js.Node node, Offset offset, StepKind kind) { | 33 void onStep(js.Node node, Offset offset, StepKind kind) { |
33 SourceInformation sourceInformation = node.sourceInformation; | 34 SourceInformation sourceInformation = computeSourceInformation(node); |
34 SourcePositionKind sourcePositionKind = SourcePositionKind.START; | 35 SourcePositionKind sourcePositionKind = SourcePositionKind.START; |
35 List text = [node]; | 36 List text = [node]; |
36 switch (kind) { | 37 switch (kind) { |
37 case StepKind.FUN: | 38 case StepKind.FUN: |
38 sourcePositionKind = SourcePositionKind.INNER; | 39 sourcePositionKind = SourcePositionKind.INNER; |
39 text = ['<exit>']; | 40 text = ['<exit>']; |
40 break; | 41 break; |
41 case StepKind.CALL: | 42 case StepKind.CALL: |
42 CallPosition callPosition = | 43 CallPosition callPosition = |
43 CallPosition.getSemanticPositionForCall(node); | 44 CallPosition.getSemanticPositionForCall(node); |
(...skipping 30 matching lines...) Expand all Loading... |
74 js.Do doNode = node; | 75 js.Do doNode = node; |
75 text = ['do {... } (', doNode.condition, ')']; | 76 text = ['do {... } (', doNode.condition, ')']; |
76 break; | 77 break; |
77 case StepKind.SWITCH_EXPRESSION: | 78 case StepKind.SWITCH_EXPRESSION: |
78 js.Switch switchNode = node; | 79 js.Switch switchNode = node; |
79 text = ['switch(', switchNode.key, ') ...']; | 80 text = ['switch(', switchNode.key, ') ...']; |
80 break; | 81 break; |
81 | 82 |
82 } | 83 } |
83 createTraceStep( | 84 createTraceStep( |
| 85 kind, |
84 node, | 86 node, |
85 offset: offset, | 87 offset: offset, |
86 sourceLocation: getSourceLocation( | 88 sourceLocation: getSourceLocation( |
87 node.sourceInformation, sourcePositionKind), | 89 sourceInformation, sourcePositionKind), |
88 text: text); | 90 text: text); |
89 } | 91 } |
90 | 92 |
91 void createTraceStep( | 93 void createTraceStep( |
| 94 StepKind kind, |
92 js.Node node, | 95 js.Node node, |
93 {Offset offset, | 96 {Offset offset, |
94 List text, | 97 List text, |
95 String note, | 98 String note, |
96 SourceLocation sourceLocation}) { | 99 SourceLocation sourceLocation}) { |
97 int id = steppableMap.length; | 100 int id = steppableMap.length; |
98 | 101 |
99 if (text == null) { | 102 if (text == null) { |
100 text = [node]; | 103 text = [node]; |
101 } | 104 } |
102 | 105 |
103 TraceStep step = new TraceStep( | 106 TraceStep step = new TraceStep( |
104 id, node, | 107 kind, |
| 108 id, |
| 109 node, |
105 offset, | 110 offset, |
106 text, sourceLocation); | 111 text, |
| 112 sourceLocation); |
107 graph.addStep(step); | 113 graph.addStep(step); |
108 | 114 |
109 steppableMap[node] = step; | 115 steppableMap[node] = step; |
110 } | 116 } |
111 | 117 |
112 | 118 |
113 void pushBranch(BranchKind kind, [value]) { | 119 void pushBranch(BranchKind kind, [value]) { |
114 var branch; | 120 var branch; |
115 switch (kind) { | 121 switch (kind) { |
116 case BranchKind.CONDITION: | 122 case BranchKind.CONDITION: |
(...skipping 12 matching lines...) Expand all Loading... |
129 branch = '$value'; | 135 branch = '$value'; |
130 break; | 136 break; |
131 } | 137 } |
132 graph.pushBranch(branch); | 138 graph.pushBranch(branch); |
133 } | 139 } |
134 | 140 |
135 void popBranch() { | 141 void popBranch() { |
136 graph.popBranch(); | 142 graph.popBranch(); |
137 } | 143 } |
138 } | 144 } |
OLD | NEW |