| 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('parser'); | 5 #library('parser'); |
| 6 | 6 |
| 7 #import('../elements/elements.dart'); | 7 #import('../elements/elements.dart'); |
| 8 #import('../scanner/scanner_implementation.dart'); | 8 #import('../scanner/scanner_implementation.dart'); |
| 9 #import('../scanner/scannerlib.dart'); | 9 #import('../scanner/scannerlib.dart'); |
| 10 #import('../tree/tree.dart'); | 10 #import('../tree/tree.dart'); |
| 11 | 11 |
| 12 #source('../../source.dart'); | 12 #source('../../source.dart'); |
| 13 #source('../scanner/byte_array_scanner.dart'); | 13 #source('../scanner/byte_array_scanner.dart'); |
| 14 #source('../scanner/byte_strings.dart'); | 14 #source('../scanner/byte_strings.dart'); |
| 15 | 15 |
| 16 int charCount = 0; | 16 int charCount = 0; |
| 17 Stopwatch stopwatch; | 17 Stopwatch stopwatch; |
| 18 | 18 |
| 19 void main() { | 19 void main() { |
| 20 filesWithCrashes = []; |
| 20 stopwatch = new Stopwatch(); | 21 stopwatch = new Stopwatch(); |
| 21 MyOptions options = new MyOptions(); | 22 MyOptions options = new MyOptions(); |
| 22 | 23 |
| 23 void printStats() { | 24 void printStats() { |
| 24 int kb = (charCount / 1024).round().toInt(); | 25 int kb = (charCount / 1024).round().toInt(); |
| 25 String stats = | 26 String stats = |
| 26 '$classCount classes (${kb}Kb) in ${stopwatch.elapsedInMs()}ms'; | 27 '$classCount classes (${kb}Kb) in ${stopwatch.elapsedInMs()}ms'; |
| 27 if (errorCount != 0) { | 28 if (errorCount != 0) { |
| 28 stats += ' with $errorCount errors'; | 29 stats += ' with $errorCount errors'; |
| 29 } | 30 } |
| 30 if (options.diet) { | 31 if (options.diet) { |
| 31 print('Diet parsed $stats.'); | 32 print('Diet parsed $stats.'); |
| 32 } else { | 33 } else { |
| 33 print('Parsed $stats.'); | 34 print('Parsed $stats.'); |
| 34 } | 35 } |
| 35 if (filesWithCrashes.length !== 0) { | 36 if (filesWithCrashes.length !== 0) { |
| 36 print('The following files caused a crash:'); | 37 print('The following ${filesWithCrashes.length} files caused a crash:'); |
| 37 for (String file in filesWithCrashes) { | 38 for (String file in filesWithCrashes) { |
| 38 print(file); | 39 print(file); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 } | 42 } |
| 42 | 43 |
| 43 for (String argument in new Options().arguments) { | 44 for (String argument in new Options().arguments) { |
| 44 if (argument == "--diet") { | 45 if (argument == "--diet") { |
| 45 options.diet = true; | 46 options.diet = true; |
| 46 continue; | 47 continue; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 59 } | 60 } |
| 60 if (argument == "--ast") { | 61 if (argument == "--ast") { |
| 61 options.buildAst = true; | 62 options.buildAst = true; |
| 62 continue; | 63 continue; |
| 63 } | 64 } |
| 64 if (argument == "-") { | 65 if (argument == "-") { |
| 65 parseFilesFrom(stdin, options, printStats); | 66 parseFilesFrom(stdin, options, printStats); |
| 66 return; | 67 return; |
| 67 } | 68 } |
| 68 stopwatch.start(); | 69 stopwatch.start(); |
| 69 charCount += parseFile(argument, options); | 70 parseFile(argument, options); |
| 70 stopwatch.stop(); | 71 stopwatch.stop(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 printStats(); | 74 printStats(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void parseFile(String filename, MyOptions options) { | 77 void parseFile(String filename, MyOptions options) { |
| 77 List<int> bytes = read(filename); | 78 List<int> bytes = read(filename); |
| 78 charCount += bytes.length; | 79 charCount += bytes.length; |
| 79 if (options.readOnly) return; | 80 if (options.readOnly) return; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 if (message is !String) message = "unexpected character"; | 120 if (message is !String) message = "unexpected character"; |
| 120 Token fakeToken = new Token(QUESTION_INFO, scanner.charOffset); | 121 Token fakeToken = new Token(QUESTION_INFO, scanner.charOffset); |
| 121 print(formatError(message, fakeToken, fakeToken, source)); | 122 print(formatError(message, fakeToken, fakeToken, source)); |
| 122 throw; | 123 throw; |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 126 var filesWithCrashes; | 127 var filesWithCrashes; |
| 127 | 128 |
| 128 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { | 129 void parseFilesFrom(InputStream input, MyOptions options, Function whenDone) { |
| 129 filesWithCrashes = []; | |
| 130 void readLine(String line) { | 130 void readLine(String line) { |
| 131 stopwatch.start(); | 131 stopwatch.start(); |
| 132 try { | 132 try { |
| 133 parseFile(line, options); | 133 parseFile(line, options); |
| 134 } catch (var ex, var trace) { | 134 } catch (var ex, var trace) { |
| 135 filesWithCrashes.add(line); | 135 filesWithCrashes.add(line); |
| 136 print(ex); | 136 print(ex); |
| 137 print(trace); | 137 print(trace); |
| 138 } | 138 } |
| 139 stopwatch.stop(); | 139 stopwatch.stop(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 183 |
| 184 void beginClassDeclaration(Token token) { | 184 void beginClassDeclaration(Token token) { |
| 185 classCount++; | 185 classCount++; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void beginInterface(Token token) { | 188 void beginInterface(Token token) { |
| 189 classCount++; | 189 classCount++; |
| 190 } | 190 } |
| 191 | 191 |
| 192 void error(String message, Token token) { | 192 void error(String message, Token token) { |
| 193 ++errorCount; | 193 throw new ParserError(formatError(message, token, token, file)); |
| 194 throw new ParserError(formatError(message, beginToken, endToken, file)); | |
| 195 } | 194 } |
| 196 } | 195 } |
| 197 | 196 |
| 198 void formatError(String message, Token beginToken, Token endToken, | 197 void formatError(String message, Token beginToken, Token endToken, |
| 199 SourceFile file) { | 198 SourceFile file) { |
| 199 ++errorCount; |
| 200 if (beginToken === null) return '${file.filename}: $message'; | 200 if (beginToken === null) return '${file.filename}: $message'; |
| 201 String tokenString = endToken.toString(); | 201 String tokenString = endToken.toString(); |
| 202 int begin = beginToken.charOffset; | 202 int begin = beginToken.charOffset; |
| 203 int end = endToken.charOffset + tokenString.length; | 203 int end = endToken.charOffset + tokenString.length; |
| 204 return file.getLocationMessage(message, begin, end, true); | 204 return file.getLocationMessage(message, begin, end, true); |
| 205 } | 205 } |
| 206 | 206 |
| 207 class MyNodeListener extends NodeListener { | 207 class MyNodeListener extends NodeListener { |
| 208 MyNodeListener(SourceFile file, MyOptions options) | 208 MyNodeListener(SourceFile file, MyOptions options) |
| 209 : super(new MyCanceller(file, options), null); | 209 : super(new MyCanceller(file, options), null); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 String _GREEN_COLOR = '\u001b[32m'; | 314 String _GREEN_COLOR = '\u001b[32m'; |
| 315 String _RED_COLOR = '\u001b[31m'; | 315 String _RED_COLOR = '\u001b[31m'; |
| 316 String _MAGENTA_COLOR = '\u001b[35m'; | 316 String _MAGENTA_COLOR = '\u001b[35m'; |
| 317 String _NO_COLOR = '\u001b[0m'; | 317 String _NO_COLOR = '\u001b[0m'; |
| 318 | 318 |
| 319 class Mock { | 319 class Mock { |
| 320 const Mock(); | 320 const Mock(); |
| 321 bool get useColors() => true; | 321 bool get useColors() => true; |
| 322 internalError(message) { throw message.toString(); } | 322 internalError(message) { throw message.toString(); } |
| 323 } | 323 } |
| OLD | NEW |