Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart2js.dart

Issue 15891015: Allow a space after -o in dart2js option parsing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use iterator. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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.cmdline; 5 library dart2js.cmdline;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show Queue, LinkedHashMap; 8 import 'dart:collection' show Queue, LinkedHashMap;
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:utf'; 10 import 'dart:utf';
(...skipping 11 matching lines...) Expand all
22 /** 22 /**
23 * A string to identify the revision or build. 23 * A string to identify the revision or build.
24 * 24 *
25 * This ID is displayed if the compiler crashes and in verbose mode, and is 25 * This ID is displayed if the compiler crashes and in verbose mode, and is
26 * an aid in reproducing bug reports. 26 * an aid in reproducing bug reports.
27 * 27 *
28 * The actual string is rewritten by a wrapper script when included in the sdk. 28 * The actual string is rewritten by a wrapper script when included in the sdk.
29 */ 29 */
30 String BUILD_ID = null; 30 String BUILD_ID = null;
31 31
32 typedef void HandleOption(String option); 32 typedef void HandleOption(var argument, [Iterator<String> rest]);
33 33
34 class OptionHandler { 34 class OptionHandler {
35 String pattern; 35 final String pattern;
36 HandleOption handle; 36 final HandleOption handle;
37 final bool multipleArguments;
37 38
38 OptionHandler(this.pattern, this.handle); 39 OptionHandler(this.pattern, this.handle, {this.multipleArguments: false});
39 } 40 }
40 41
41 /** 42 /**
42 * Extract the parameter of an option. 43 * Extract the parameter of an option.
43 * 44 *
44 * For example, in ['--out=fisk.js'] and ['-ohest.js'], the parameters 45 * For example, in ['--out=fisk.js'] and ['-ohest.js'], the parameters
45 * are ['fisk.js'] and ['hest.js'], respectively. 46 * are ['fisk.js'] and ['hest.js'], respectively.
46 */ 47 */
47 String extractParameter(String argument) { 48 String extractParameter(String argument) {
48 // m[0] is the entire match (which will be equal to argument). m[1] 49 // m[0] is the entire match (which will be equal to argument). m[1]
49 // is something like "-o" or "--out=", and m[2] is the parameter. 50 // is something like "-o" or "--out=", and m[2] is the parameter.
50 Match m = new RegExp('^(-[a-z]|--.+=)(.*)').firstMatch(argument); 51 Match m = new RegExp('^(-[a-z]|--.+=)(.*)').firstMatch(argument);
51 if (m == null) helpAndFail('Error: Unknown option "$argument".'); 52 if (m == null) helpAndFail('Error: Unknown option "$argument".');
52 return m[2]; 53 return m[2];
53 } 54 }
54 55
55 String extractPath(String argument) { 56 String extractPath(String argument) {
56 String path = nativeToUriPath(extractParameter(argument)); 57 String path = nativeToUriPath(extractParameter(argument));
57 return path.endsWith("/") ? path : "$path/"; 58 return path.endsWith("/") ? path : "$path/";
58 } 59 }
59 60
60 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) { 61 void parseCommandLine(List<OptionHandler> handlers, List<String> argv) {
61 // TODO(ahe): Use ../../args/args.dart for parsing options instead. 62 // TODO(ahe): Use ../../args/args.dart for parsing options instead.
62 var patterns = <String>[]; 63 var patterns = <String>[];
63 for (OptionHandler handler in handlers) { 64 for (OptionHandler handler in handlers) {
64 patterns.add(handler.pattern); 65 patterns.add(handler.pattern);
65 } 66 }
66 var pattern = new RegExp('^(${patterns.join(")\$|(")})\$'); 67 var pattern = new RegExp('^(${patterns.join(")\$|(")})\$');
67 OUTER: for (String argument in argv) { 68
69 Iterator<String> arguments = argv.iterator;
70 OUTER: while (arguments.moveNext()) {
71 String argument = arguments.current;
68 Match match = pattern.firstMatch(argument); 72 Match match = pattern.firstMatch(argument);
69 assert(match.groupCount == handlers.length); 73 assert(match.groupCount == handlers.length);
70 for (int i = 0; i < handlers.length; i++) { 74 for (int i = 0; i < handlers.length; i++) {
71 if (match[i + 1] != null) { 75 if (match[i + 1] != null) {
72 handlers[i].handle(argument); 76 OptionHandler handler = handlers[i];
77 if (handler.multipleArguments) {
78 handler.handle(argument, arguments);
79 } else {
80 handler.handle(argument);
81 }
73 continue OUTER; 82 continue OUTER;
74 } 83 }
75 } 84 }
76 throw 'Internal error: "$argument" did not match'; 85 throw 'Internal error: "$argument" did not match';
77 } 86 }
78 } 87 }
79 88
80 void compile(List<String> argv) { 89 void compile(List<String> argv) {
81 bool isWindows = (Platform.operatingSystem == 'windows'); 90 bool isWindows = (Platform.operatingSystem == 'windows');
82 Uri libraryRoot = currentDirectory; 91 Uri libraryRoot = currentDirectory;
(...skipping 18 matching lines...) Expand all
101 } 110 }
102 111
103 setLibraryRoot(String argument) { 112 setLibraryRoot(String argument) {
104 libraryRoot = currentDirectory.resolve(extractPath(argument)); 113 libraryRoot = currentDirectory.resolve(extractPath(argument));
105 } 114 }
106 115
107 setPackageRoot(String argument) { 116 setPackageRoot(String argument) {
108 packageRoot = currentDirectory.resolve(extractPath(argument)); 117 packageRoot = currentDirectory.resolve(extractPath(argument));
109 } 118 }
110 119
111 setOutput(String argument) { 120 setOutput(String argument, Iterator<String> rest) {
121 String path;
122 if (argument == '-o') {
123 if (!rest.moveNext()) {
124 helpAndFail('Error: Missing file after -o option.');
125 }
126 path = rest.current;
127 } else {
128 path = extractParameter(argument);
129 }
112 explicitOut = true; 130 explicitOut = true;
113 out = currentDirectory.resolve(nativeToUriPath(extractParameter(argument))); 131 out = currentDirectory.resolve(nativeToUriPath(path));
114 sourceMapOut = Uri.parse('$out.map'); 132 sourceMapOut = Uri.parse('$out.map');
115 } 133 }
116 134
117 setOutputType(String argument) { 135 setOutputType(String argument) {
118 if (argument == '--output-type=dart') { 136 if (argument == '--output-type=dart') {
119 outputLanguage = OUTPUT_LANGUAGE_DART; 137 outputLanguage = OUTPUT_LANGUAGE_DART;
120 if (!explicitOut) { 138 if (!explicitOut) {
121 out = currentDirectory.resolve('out.dart'); 139 out = currentDirectory.resolve('out.dart');
122 sourceMapOut = currentDirectory.resolve('out.dart.map'); 140 sourceMapOut = currentDirectory.resolve('out.dart.map');
123 } 141 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 passThrough('--enable-checked-mode'); 202 passThrough('--enable-checked-mode');
185 break; 203 break;
186 default: 204 default:
187 throw 'Internal error: "$shortOption" did not match'; 205 throw 'Internal error: "$shortOption" did not match';
188 } 206 }
189 } 207 }
190 } 208 }
191 209
192 List<String> arguments = <String>[]; 210 List<String> arguments = <String>[];
193 List<OptionHandler> handlers = <OptionHandler>[ 211 List<OptionHandler> handlers = <OptionHandler>[
194 new OptionHandler('-[chv?]+', handleShortOptions), 212 new OptionHandler('-[chv?]+', handleShortOptions),
ahe 2013/05/30 10:02:49 I would expect a type error here in checked mode.
195 new OptionHandler('--throw-on-error', 213 new OptionHandler('--throw-on-error',
196 (_) => diagnosticHandler.throwOnError = true), 214 (_) => diagnosticHandler.throwOnError = true),
197 new OptionHandler('--suppress-warnings', 215 new OptionHandler('--suppress-warnings',
198 (_) => diagnosticHandler.showWarnings = false), 216 (_) => diagnosticHandler.showWarnings = false),
199 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), 217 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
200 new OptionHandler('--verbose', setVerbose), 218 new OptionHandler('--verbose', setVerbose),
201 new OptionHandler('--version', (_) => wantVersion = true), 219 new OptionHandler('--version', (_) => wantVersion = true),
202 new OptionHandler('--library-root=.+', setLibraryRoot), 220 new OptionHandler('--library-root=.+', setLibraryRoot),
203 new OptionHandler('--out=.+|-o.+', setOutput), 221 new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true),
204 new OptionHandler('--allow-mock-compilation', passThrough), 222 new OptionHandler('--allow-mock-compilation', passThrough),
205 new OptionHandler('--minify', passThrough), 223 new OptionHandler('--minify', passThrough),
206 new OptionHandler('--force-strip=.*', setStrip), 224 new OptionHandler('--force-strip=.*', setStrip),
207 // TODO(ahe): Remove the --no-colors option. 225 // TODO(ahe): Remove the --no-colors option.
208 new OptionHandler('--disable-diagnostic-colors', 226 new OptionHandler('--disable-diagnostic-colors',
209 (_) => diagnosticHandler.enableColors = false), 227 (_) => diagnosticHandler.enableColors = false),
210 new OptionHandler('--enable-diagnostic-colors', 228 new OptionHandler('--enable-diagnostic-colors',
211 (_) => diagnosticHandler.enableColors = true), 229 (_) => diagnosticHandler.enableColors = true),
212 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 230 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
213 (_) => passThrough('--enable-checked-mode')), 231 (_) => passThrough('--enable-checked-mode')),
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // This message should be no longer than 20 lines. The default 404 // This message should be no longer than 20 lines. The default
387 // terminal size normally 80x24. Two lines are used for the prompts 405 // terminal size normally 80x24. Two lines are used for the prompts
388 // before and after running the compiler. Another two lines may be 406 // before and after running the compiler. Another two lines may be
389 // used to print an error message. 407 // used to print an error message.
390 print(''' 408 print('''
391 Usage: dart2js [options] dartfile 409 Usage: dart2js [options] dartfile
392 410
393 Compiles Dart to JavaScript. 411 Compiles Dart to JavaScript.
394 412
395 Common options: 413 Common options:
396 -o<file> Generate the output into <file>. 414 -o <file> Generate the output into <file>.
397 -c Insert runtime type checks and enable assertions (checked mode). 415 -c Insert runtime type checks and enable assertions (checked mode).
398 -h Display this message (add -v for information about all options).'''); 416 -h Display this message (add -v for information about all options).''') ;
399 } 417 }
400 418
401 void verboseHelp() { 419 void verboseHelp() {
402 print(''' 420 print('''
403 Usage: dart2js [options] dartfile 421 Usage: dart2js [options] dartfile
404 422
405 Compiles Dart to JavaScript. 423 Compiles Dart to JavaScript.
406 424
407 Supported options: 425 Supported options:
408 -o<file>, --out=<file> 426 -o <file>, --out=<file>
409 Generate the output into <file>. 427 Generate the output into <file>.
410 428
411 -c, --enable-checked-mode, --checked 429 -c, --enable-checked-mode, --checked
412 Insert runtime type checks and enable assertions (checked mode). 430 Insert runtime type checks and enable assertions (checked mode).
413 431
414 -h, /h, /?, --help 432 -h, /h, /?, --help
415 Display this message (add -v for information about all options). 433 Display this message (add -v for information about all options).
416 434
417 -v, --verbose 435 -v, --verbose
418 Display verbose information. 436 Display verbose information.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 print(trace); 548 print(trace);
531 } finally { 549 } finally {
532 exit(253); // 253 is recognized as a crash by our test scripts. 550 exit(253); // 253 is recognized as a crash by our test scripts.
533 } 551 }
534 } 552 }
535 } 553 }
536 554
537 void main() { 555 void main() {
538 mainWithErrorHandler(new Options()); 556 mainWithErrorHandler(new Options());
539 } 557 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698