OLD | NEW |
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 /// Internal debugging utilities. | 5 /// Internal debugging utilities. |
6 library dart_style.src.debug; | 6 library dart_style.src.debug; |
7 | 7 |
8 import 'dart:math' as math; | 8 import 'dart:math' as math; |
9 | 9 |
10 import 'chunk.dart'; | 10 import 'chunk.dart'; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 spans.addAll(chunk.spans); | 77 spans.addAll(chunk.spans); |
78 | 78 |
79 if (chunk.isBlock) addSpans(chunk.block.chunks); | 79 if (chunk.isBlock) addSpans(chunk.block.chunks); |
80 } | 80 } |
81 } | 81 } |
82 | 82 |
83 addSpans(chunks); | 83 addSpans(chunks); |
84 | 84 |
85 spans = spans.toList(); | 85 spans = spans.toList(); |
86 | 86 |
87 var rules = chunks | 87 var rules = |
88 .map((chunk) => chunk.rule) | 88 chunks.map((chunk) => chunk.rule).where((rule) => rule != null).toSet(); |
89 .where((rule) => rule != null && rule is! HardSplitRule) | |
90 .toSet(); | |
91 | 89 |
92 var rows = []; | 90 var rows = []; |
93 | 91 |
94 addChunk(List<Chunk> chunks, String prefix, int index) { | 92 addChunk(List<Chunk> chunks, String prefix, int index) { |
95 var row = []; | 93 var row = []; |
96 row.add("$prefix$index:"); | 94 row.add("$prefix$index:"); |
97 | 95 |
98 var chunk = chunks[index]; | 96 var chunk = chunks[index]; |
99 if (chunk.text.length > 70) { | 97 if (chunk.text.length > 70) { |
100 row.add(chunk.text.substring(0, 70)); | 98 row.add(chunk.text.substring(0, 70)); |
(...skipping 24 matching lines...) Expand all Loading... |
125 row.add(callback()); | 123 row.add(callback()); |
126 } else { | 124 } else { |
127 row.add(""); | 125 row.add(""); |
128 } | 126 } |
129 } | 127 } |
130 | 128 |
131 if (chunk.rule == null) { | 129 if (chunk.rule == null) { |
132 row.add(""); | 130 row.add(""); |
133 row.add("(no rule)"); | 131 row.add("(no rule)"); |
134 row.add(""); | 132 row.add(""); |
135 } else if (chunk.isHardSplit) { | 133 } else { |
136 row.add(""); | |
137 row.add("(hard)"); | |
138 row.add(""); | |
139 } else if (chunk.rule != null) { | |
140 writeIf(chunk.rule.cost != 0, () => "\$${chunk.rule.cost}"); | 134 writeIf(chunk.rule.cost != 0, () => "\$${chunk.rule.cost}"); |
141 row.add(chunk.rule.toString()); | 135 |
| 136 var ruleString = chunk.rule.toString(); |
| 137 if (chunk.rule.isHardened) ruleString += "!"; |
| 138 row.add(ruleString); |
142 | 139 |
143 var constrainedRules = | 140 var constrainedRules = |
144 chunk.rule.constrainedRules.toSet().intersection(rules); | 141 chunk.rule.constrainedRules.toSet().intersection(rules); |
145 writeIf(constrainedRules.isNotEmpty, | 142 writeIf(constrainedRules.isNotEmpty, |
146 () => "-> ${constrainedRules.join(" ")}"); | 143 () => "-> ${constrainedRules.join(" ")}"); |
147 } | 144 } |
148 | 145 |
149 writeIf(chunk.indent != null && chunk.indent != 0, | 146 writeIf(chunk.indent != null && chunk.indent != 0, |
150 () => "indent ${chunk.indent}"); | 147 () => "indent ${chunk.indent}"); |
151 | 148 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 buffer.write(cell); | 181 buffer.write(cell); |
185 buffer.write(" "); | 182 buffer.write(" "); |
186 } | 183 } |
187 | 184 |
188 buffer.writeln(); | 185 buffer.writeln(); |
189 } | 186 } |
190 | 187 |
191 print(buffer.toString()); | 188 print(buffer.toString()); |
192 } | 189 } |
193 | 190 |
| 191 /// Shows all of the constraints between the rules used by [chunks]. |
| 192 void dumpConstraints(List<Chunk> chunks) { |
| 193 var rules = |
| 194 chunks.map((chunk) => chunk.rule).where((rule) => rule != null).toSet(); |
| 195 |
| 196 for (var rule in rules) { |
| 197 var constrainedValues = []; |
| 198 for (var value = 0; value < rule.numValues; value++) { |
| 199 var constraints = []; |
| 200 for (var other in rules) { |
| 201 if (rule == other) continue; |
| 202 |
| 203 var constraint = rule.constrain(value, other); |
| 204 if (constraint != null) { |
| 205 constraints.add("$other->$constraint"); |
| 206 } |
| 207 } |
| 208 |
| 209 if (constraints.isNotEmpty) { |
| 210 constrainedValues.add("$value:(${constraints.join(' ')})"); |
| 211 } |
| 212 } |
| 213 |
| 214 log("$rule ${constrainedValues.join(' ')}"); |
| 215 } |
| 216 } |
| 217 |
194 /// Convert the line to a [String] representation. | 218 /// Convert the line to a [String] representation. |
195 /// | 219 /// |
196 /// It will determine how best to split it into multiple lines of output and | 220 /// It will determine how best to split it into multiple lines of output and |
197 /// return a single string that may contain one or more newline characters. | 221 /// return a single string that may contain one or more newline characters. |
198 void dumpLines(List<Chunk> chunks, int firstLineIndent, SplitSet splits) { | 222 void dumpLines(List<Chunk> chunks, int firstLineIndent, SplitSet splits) { |
199 var buffer = new StringBuffer(); | 223 var buffer = new StringBuffer(); |
200 | 224 |
201 writeIndent(indent) => buffer.write(gray("| " * (indent ~/ 2))); | 225 writeIndent(indent) => buffer.write(gray("| " * (indent ~/ 2))); |
202 | 226 |
203 writeChunksUnsplit(List<Chunk> chunks) { | 227 writeChunksUnsplit(List<Chunk> chunks) { |
(...skipping 22 matching lines...) Expand all Loading... |
226 | 250 |
227 if (chunk.spaceWhenUnsplit) buffer.write(" "); | 251 if (chunk.spaceWhenUnsplit) buffer.write(" "); |
228 } | 252 } |
229 } | 253 } |
230 | 254 |
231 buffer.write(chunks.last.text); | 255 buffer.write(chunks.last.text); |
232 log(buffer); | 256 log(buffer); |
233 } | 257 } |
234 | 258 |
235 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; | 259 String _color(String ansiEscape) => useAnsiColors ? ansiEscape : ""; |
OLD | NEW |