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

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

Issue 10963055: [dart2dart] Make removal of asserts and forcing type strips go under (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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'); 5 #library('dart2js');
6 6
7 #import('dart:io'); 7 #import('dart:io');
8 #import('dart:uri'); 8 #import('dart:uri');
9 #import('dart:utf'); 9 #import('dart:utf');
10 10
11 #import('../compiler.dart', prefix: 'api'); 11 #import('../compiler.dart', prefix: 'api');
12 #import('colors.dart', prefix: 'colors'); 12 #import('colors.dart', prefix: 'colors');
13 #import('source_file.dart'); 13 #import('source_file.dart');
14 #import('filenames.dart'); 14 #import('filenames.dart');
15 #import('util/uri_extras.dart'); 15 #import('util/uri_extras.dart');
16 16
17 const String LIBRARY_ROOT = '../../../..'; 17 const String LIBRARY_ROOT = '../../../..';
18 const String OUTPUT_LANGUAGE_DART = 'Dart';
18 19
19 typedef void HandleOption(String option); 20 typedef void HandleOption(String option);
20 21
21 class OptionHandler { 22 class OptionHandler {
22 String pattern; 23 String pattern;
23 HandleOption handle; 24 HandleOption handle;
24 25
25 OptionHandler(this.pattern, this.handle); 26 OptionHandler(this.pattern, this.handle);
26 } 27 }
27 28
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 bool verbose = false; 73 bool verbose = false;
73 Uri libraryRoot = cwd; 74 Uri libraryRoot = cwd;
74 Uri out = cwd.resolve('out.js'); 75 Uri out = cwd.resolve('out.js');
75 Uri sourceMapOut = cwd.resolve('out.js.map'); 76 Uri sourceMapOut = cwd.resolve('out.js.map');
76 Uri packageRoot = null; 77 Uri packageRoot = null;
77 List<String> options = new List<String>(); 78 List<String> options = new List<String>();
78 bool explicitOut = false; 79 bool explicitOut = false;
79 bool wantHelp = false; 80 bool wantHelp = false;
80 bool enableColors = false; 81 bool enableColors = false;
81 String outputLanguage = 'JavaScript'; 82 String outputLanguage = 'JavaScript';
83 bool stripArgumentSet = false;
82 84
83 passThrough(String argument) => options.add(argument); 85 passThrough(String argument) => options.add(argument);
84 86
85 setLibraryRoot(String argument) { 87 setLibraryRoot(String argument) {
86 libraryRoot = cwd.resolve(extractPath(argument)); 88 libraryRoot = cwd.resolve(extractPath(argument));
87 } 89 }
88 90
89 setPackageRoot(String argument) { 91 setPackageRoot(String argument) {
90 packageRoot = cwd.resolve(extractPath(argument)); 92 packageRoot = cwd.resolve(extractPath(argument));
91 } 93 }
92 94
93 setOutput(String argument) { 95 setOutput(String argument) {
94 explicitOut = true; 96 explicitOut = true;
95 out = cwd.resolve(nativeToUriPath(extractParameter(argument))); 97 out = cwd.resolve(nativeToUriPath(extractParameter(argument)));
96 sourceMapOut = new Uri.fromString('$out.map'); 98 sourceMapOut = new Uri.fromString('$out.map');
97 } 99 }
98 100
99 setOutputType(String argument) { 101 setOutputType(String argument) {
100 if (argument == '--output-type=dart') { 102 if (argument == '--output-type=dart') {
101 outputLanguage = 'Dart'; 103 outputLanguage = OUTPUT_LANGUAGE_DART;
102 if (!explicitOut) { 104 if (!explicitOut) {
103 out = cwd.resolve('out.dart'); 105 out = cwd.resolve('out.dart');
104 sourceMapOut = cwd.resolve('out.dart.map'); 106 sourceMapOut = cwd.resolve('out.dart.map');
105 } 107 }
106 } 108 }
107 passThrough(argument); 109 passThrough(argument);
108 } 110 }
109 111
112 setStrip(String argument) {
113 stripArgumentSet = true;
114 passThrough(argument);
115 }
116
110 handleShortOptions(String argument) { 117 handleShortOptions(String argument) {
111 var shortOptions = argument.substring(1).splitChars(); 118 var shortOptions = argument.substring(1).splitChars();
112 for (var shortOption in shortOptions) { 119 for (var shortOption in shortOptions) {
113 switch (shortOption) { 120 switch (shortOption) {
114 case 'v': 121 case 'v':
115 verbose = true; 122 verbose = true;
116 break; 123 break;
117 case 'h': 124 case 'h':
118 case '?': 125 case '?':
119 wantHelp = true; 126 wantHelp = true;
(...skipping 11 matching lines...) Expand all
131 List<OptionHandler> handlers = <OptionHandler>[ 138 List<OptionHandler> handlers = <OptionHandler>[
132 new OptionHandler('-[chv?]+', handleShortOptions), 139 new OptionHandler('-[chv?]+', handleShortOptions),
133 new OptionHandler('--throw-on-error', (_) => throwOnError = true), 140 new OptionHandler('--throw-on-error', (_) => throwOnError = true),
134 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), 141 new OptionHandler('--suppress-warnings', (_) => showWarnings = false),
135 new OptionHandler('--output-type=dart|--output-type=js', setOutputType), 142 new OptionHandler('--output-type=dart|--output-type=js', setOutputType),
136 new OptionHandler('--verbose', (_) => verbose = true), 143 new OptionHandler('--verbose', (_) => verbose = true),
137 new OptionHandler('--library-root=.+', setLibraryRoot), 144 new OptionHandler('--library-root=.+', setLibraryRoot),
138 new OptionHandler('--out=.+|-o.+', setOutput), 145 new OptionHandler('--out=.+|-o.+', setOutput),
139 new OptionHandler('--allow-mock-compilation', passThrough), 146 new OptionHandler('--allow-mock-compilation', passThrough),
140 new OptionHandler('--minify', passThrough), 147 new OptionHandler('--minify', passThrough),
141 new OptionHandler('--force-cut-declaration-types', passThrough), 148 new OptionHandler('--force-strip=.*', setStrip),
142 // TODO(ahe): Remove the --no-colors option. 149 // TODO(ahe): Remove the --no-colors option.
143 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ), 150 new OptionHandler('--disable-diagnostic-colors', (_) => enableColors = false ),
144 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true), 151 new OptionHandler('--enable-diagnostic-colors', (_) => enableColors = true),
145 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 152 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
146 (_) => passThrough('--enable-checked-mode')), 153 (_) => passThrough('--enable-checked-mode')),
147 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true), 154 new OptionHandler(r'--help|/\?|/h', (_) => wantHelp = true),
148 new OptionHandler(r'--package-root=.+|-p.+', setPackageRoot), 155 new OptionHandler(r'--package-root=.+|-p.+', setPackageRoot),
149 // The following two options must come last. 156 // The following two options must come last.
150 new OptionHandler('-.*', (String argument) { 157 new OptionHandler('-.*', (String argument) {
151 helpAndFail('Error: Unknown option "$argument".'); 158 helpAndFail('Error: Unknown option "$argument".');
152 }), 159 }),
153 new OptionHandler('.*', (String argument) { 160 new OptionHandler('.*', (String argument) {
154 arguments.add(nativeToUriPath(argument)); 161 arguments.add(nativeToUriPath(argument));
155 }) 162 })
156 ]; 163 ];
157 164
158 parseCommandLine(handlers, argv); 165 parseCommandLine(handlers, argv);
159
160 if (wantHelp) helpAndExit(verbose); 166 if (wantHelp) helpAndExit(verbose);
161 167
168 if (outputLanguage != OUTPUT_LANGUAGE_DART && stripArgumentSet) {
169 helpAndFail('Error: --force-strip may only be used with '
170 '--output-type=dart');
171 }
162 if (arguments.isEmpty()) { 172 if (arguments.isEmpty()) {
163 helpAndFail('Error: No Dart file specified.'); 173 helpAndFail('Error: No Dart file specified.');
164 } 174 }
165 if (arguments.length > 1) { 175 if (arguments.length > 1) {
166 var extra = arguments.getRange(1, arguments.length - 1); 176 var extra = arguments.getRange(1, arguments.length - 1);
167 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}'); 177 helpAndFail('Error: Extra arguments: ${Strings.join(extra, " ")}');
168 } 178 }
169 179
170 Map<String, SourceFile> sourceFiles = <String, SourceFile>{}; 180 Map<String, SourceFile> sourceFiles = <String, SourceFile>{};
171 int dartBytesRead = 0; 181 int dartBytesRead = 0;
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } catch (ignored) { 410 } catch (ignored) {
401 print('Internal error: error while printing exception'); 411 print('Internal error: error while printing exception');
402 } 412 }
403 try { 413 try {
404 print(trace); 414 print(trace);
405 } finally { 415 } finally {
406 exit(253); // 253 is recognized as a crash by our test scripts. 416 exit(253); // 253 is recognized as a crash by our test scripts.
407 } 417 }
408 } 418 }
409 } 419 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/compiler.dart ('k') | lib/compiler/implementation/dart_backend/backend.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698