Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 dart2js.util; | 5 library dart2js.util; |
| 6 | 6 |
| 7 import "dart:collection"; | 7 import "dart:collection"; |
| 8 import 'util_implementation.dart'; | 8 import 'util_implementation.dart'; |
| 9 import 'characters.dart'; | 9 import 'characters.dart'; |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 /// Helper class for the processing of stack traces in [prettifyStackTrace]. | 70 /// Helper class for the processing of stack traces in [prettifyStackTrace]. |
| 71 class _StackTraceLine { | 71 class _StackTraceLine { |
| 72 final int index; | 72 final int index; |
| 73 final String file; | 73 final String file; |
| 74 final String lineNo; | 74 final String lineNo; |
| 75 final String columnNo; | 75 final String columnNo; |
| 76 final String method; | 76 final String method; |
| 77 | 77 |
| 78 _StackTraceLine(this.index, this.file, this.lineNo, | 78 _StackTraceLine(this.index, this.file, this.lineNo, |
| 79 this.columnNo, this.method); | 79 this.columnNo, this.method); |
| 80 | |
| 81 String toString() { | |
| 82 return 'index=$index, file=$file, ' | |
| 83 'lineNo=$lineNo, columnNo=$columnNo, method=$method'; | |
| 84 } | |
| 80 } | 85 } |
| 81 | 86 |
| 82 // TODO(johnniwinther): Use this format for --throw-on-error. | 87 // TODO(johnniwinther): Use this format for --throw-on-error. |
| 83 /** | 88 /** |
| 84 * Converts the normal VM stack trace into a more compact and readable format. | 89 * Converts the normal VM stack trace into a more compact and readable format. |
| 85 * | 90 * |
| 86 * The output format is [: <file> . . . <lineNo>:<columnNo> <method> :] where | 91 * The output format is [: <file> . . . <lineNo>:<columnNo> <method> :] where |
| 87 * [: <file> :] is file name, [: <lineNo> :] is the line number, | 92 * [: <file> :] is file name, [: <lineNo> :] is the line number, |
| 88 * [: <columnNo> :] is the column number, and [: <method> :] is the method name. | 93 * [: <columnNo> :] is the column number, and [: <method> :] is the method name. |
| 89 * | 94 * |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 116 if (line.isEmpty) continue; | 121 if (line.isEmpty) continue; |
| 117 | 122 |
| 118 // Strip index. | 123 // Strip index. |
| 119 line = line.replaceFirst(new RegExp(r'#\d+\s*'), ''); | 124 line = line.replaceFirst(new RegExp(r'#\d+\s*'), ''); |
| 120 | 125 |
| 121 int leftParenPos = line.indexOf('('); | 126 int leftParenPos = line.indexOf('('); |
| 122 int rightParenPos = line.indexOf(')', leftParenPos); | 127 int rightParenPos = line.indexOf(')', leftParenPos); |
| 123 int lastColon = line.lastIndexOf(':', rightParenPos); | 128 int lastColon = line.lastIndexOf(':', rightParenPos); |
| 124 int nextToLastColon = line.lastIndexOf(':', lastColon-1); | 129 int nextToLastColon = line.lastIndexOf(':', lastColon-1); |
| 125 | 130 |
| 126 String lineNo = line.substring(nextToLastColon+1, lastColon); | 131 String lineNo; |
| 132 String columnNo; | |
| 133 if (nextToLastColon != -1) { | |
| 134 lineNo = line.substring(nextToLastColon+1, lastColon); | |
| 135 columnNo = line.substring(lastColon+1, rightParenPos); | |
| 136 try { | |
| 137 int.parse(lineNo); | |
| 138 } on FormatException catch (e) { | |
| 139 lineNo = columnNo; | |
| 140 columnNo = ''; | |
| 141 nextToLastColon = lastColon; | |
| 142 } | |
| 143 } else { | |
| 144 lineNo = line.substring(lastColon+1, rightParenPos); | |
| 145 columnNo = ''; | |
| 146 nextToLastColon = lastColon; | |
| 147 } | |
| 148 | |
| 127 if (lineNo.length > maxLineNoLength) { | 149 if (lineNo.length > maxLineNoLength) { |
| 128 maxLineNoLength = lineNo.length; | 150 maxLineNoLength = lineNo.length; |
| 129 } | 151 } |
| 130 String columnNo = line.substring(lastColon+1, rightParenPos); | |
| 131 if (columnNo.length > maxColumnNoLength) { | 152 if (columnNo.length > maxColumnNoLength) { |
| 132 maxColumnNoLength = columnNo.length; | 153 maxColumnNoLength = columnNo.length; |
| 133 } | 154 } |
| 155 | |
| 134 String file = line.substring(leftParenPos+1, nextToLastColon); | 156 String file = line.substring(leftParenPos+1, nextToLastColon); |
| 135 if (filePrefix != null && file.startsWith(filePrefix)) { | 157 if (filePrefix != null && file.startsWith(filePrefix)) { |
| 136 file = file.substring(filePrefix.length); | 158 file = file.substring(filePrefix.length); |
| 137 } | 159 } |
| 138 if (file.length > maxFileLength) { | 160 if (file.length > maxFileLength) { |
| 139 maxFileLength = file.length; | 161 maxFileLength = file.length; |
| 140 } | 162 } |
| 141 String method = line.substring(0, leftParenPos-1); | 163 String method = line.substring(0, leftParenPos-1); |
| 142 if (lambda != null) { | 164 if (lambda != null) { |
| 143 method = method.replaceAll('<anonymous closure>', lambda); | 165 method = method.replaceAll('<anonymous closure>', lambda); |
| 144 } | 166 } |
| 145 lines.add(new _StackTraceLine(index, file, lineNo, columnNo, method)); | 167 lines.add(new _StackTraceLine(index, file, lineNo, columnNo, method)); |
| 168 //print(line); | |
| 169 //print(lines.last); | |
|
ahe
2013/09/30 11:05:26
Delete debug code.
Johnni Winther
2013/10/01 11:21:48
Done.
| |
| 146 } | 170 } |
| 147 | 171 |
| 148 StringBuffer sb = new StringBuffer(); | 172 StringBuffer sb = new StringBuffer(); |
| 149 bool dots = true; | 173 bool dots = true; |
| 150 for (_StackTraceLine line in lines) { | 174 for (_StackTraceLine line in lines) { |
| 151 String file = pad('${line.file} ', maxFileLength, | 175 String file = pad('${line.file} ', maxFileLength, |
| 152 dots: showDots && dots ? ' .' : ' '); | 176 dots: showDots && dots ? ' .' : ' '); |
| 153 String lineNo = pad(line.lineNo, maxLineNoLength, padLeft: true); | 177 String lineNo = pad(line.lineNo, maxLineNoLength, padLeft: true); |
| 154 String columnNo = | 178 String columnNo = |
| 155 showColumnNo ? ':${pad(line.columnNo, maxColumnNoLength)}' : ''; | 179 showColumnNo ? ':${pad(line.columnNo, maxColumnNoLength)}' : ''; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 283 } |
| 260 buffer.write(string); | 284 buffer.write(string); |
| 261 } | 285 } |
| 262 | 286 |
| 263 int computeHashCode(part1, [part2, part3, part4]) { | 287 int computeHashCode(part1, [part2, part3, part4]) { |
| 264 return (part1.hashCode | 288 return (part1.hashCode |
| 265 ^ part2.hashCode | 289 ^ part2.hashCode |
| 266 ^ part3.hashCode | 290 ^ part3.hashCode |
| 267 ^ part4.hashCode) & 0x3fffffff; | 291 ^ part4.hashCode) & 0x3fffffff; |
| 268 } | 292 } |
| OLD | NEW |