OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.trace_graph; | 5 library sourcemap.trace_graph; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:compiler/src/io/source_information.dart'; | 9 import 'package:compiler/src/io/source_information.dart'; |
10 import 'package:compiler/src/io/position_information.dart'; | 10 import 'package:compiler/src/io/position_information.dart'; |
| 11 import 'package:compiler/src/js/js_debug.dart'; |
11 | 12 |
12 import 'sourcemap_html_helper.dart'; | 13 import 'sourcemap_html_helper.dart'; |
13 | 14 |
14 class TraceGraph { | 15 class TraceGraph { |
15 List<TraceStep> steps = <TraceStep>[]; | 16 List<TraceStep> steps = <TraceStep>[]; |
16 TraceStep entry; | 17 TraceStep entry; |
17 Queue stack = new Queue(); | 18 Queue stack = new Queue(); |
| 19 Map<int, TraceStep> offsetMap = {}; |
18 | 20 |
19 void addStep(TraceStep step) { | 21 void addStep(TraceStep step) { |
20 steps.add(step); | 22 steps.add(step); |
| 23 int offset = step.offset.subexpressionOffset; |
| 24 TraceStep existingStep = offsetMap[offset]; |
| 25 if (existingStep != null) { |
| 26 // TODO(johnniwinther): Fix problems with reuse of JS nodes from |
| 27 // templates. |
| 28 if (identical(existingStep.node, step.node)) { |
| 29 print('duplicate node: ${nodeToString(step.node)}'); |
| 30 } else { |
| 31 print('duplicate offset: ${offset} : ${nodeToString(step.node)}'); |
| 32 } |
| 33 print(' ${existingStep.id}:${existingStep.text}:${existingStep.offset}'); |
| 34 print(' ${step.id}:${step.text}:${step.offset}'); |
| 35 } |
| 36 offsetMap[offset] = step; |
21 step.stack = stack.toList(); | 37 step.stack = stack.toList(); |
22 } | 38 } |
23 | 39 |
24 void pushBranch(branch) { | 40 void pushBranch(branch) { |
25 stack.addLast(branch); | 41 stack.addLast(branch); |
26 } | 42 } |
27 | 43 |
28 void popBranch() { | 44 void popBranch() { |
29 stack.removeLast(); | 45 stack.removeLast(); |
30 } | 46 } |
31 } | 47 } |
32 | 48 |
33 class TraceStep { | 49 class TraceStep { |
| 50 final kind; |
34 final int id; | 51 final int id; |
35 final node; | 52 final node; |
36 final Offset offset; | 53 final Offset offset; |
37 final List text; | 54 final List text; |
38 final SourceLocation sourceLocation; | 55 final SourceLocation sourceLocation; |
39 | 56 |
40 TraceStep next; | 57 TraceStep next; |
41 Map<dynamic, TraceStep> branchMap; | 58 Map<dynamic, TraceStep> branchMap; |
42 | 59 |
43 List stack; | 60 List stack; |
44 | 61 |
45 TraceStep( | 62 TraceStep( |
| 63 this.kind, |
46 this.id, | 64 this.id, |
47 this.node, | 65 this.node, |
48 this.offset, | 66 this.offset, |
49 this.text, | 67 this.text, |
50 [this.sourceLocation]); | 68 [this.sourceLocation]); |
51 | 69 |
52 String toString() => '<span style="background:${toColorCss(id)}">$id</span>'; | 70 String toString() => '<span style="background:${toColorCss(id)}">$id</span>'; |
53 } | 71 } |
54 | 72 |
OLD | NEW |