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

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

Issue 10579015: Update dart2js to use diagnostic kinds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 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
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
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 Uri cwd = getCurrentDirectory(); 68 Uri cwd = getCurrentDirectory();
69 bool throwOnError = false; 69 bool throwOnError = false;
70 bool showWarnings = true; 70 bool showWarnings = true;
71 bool verbose = false; 71 bool verbose = false;
72 Uri libraryRoot = cwd; 72 Uri libraryRoot = cwd;
73 Uri out = cwd.resolve('out.js'); 73 Uri out = cwd.resolve('out.js');
74 Uri packageRoot = null; 74 Uri packageRoot = null;
75 List<String> options = new List<String>(); 75 List<String> options = new List<String>();
76 bool explicitOut = false; 76 bool explicitOut = false;
77 bool wantHelp = false; 77 bool wantHelp = false;
78 bool enableColors = true;
78 79
79 passThrough(String argument) => options.add(argument); 80 passThrough(String argument) => options.add(argument);
80 81
81 setLibraryRoot(String argument) { 82 setLibraryRoot(String argument) {
82 libraryRoot = cwd.resolve(extractPath(argument)); 83 libraryRoot = cwd.resolve(extractPath(argument));
83 } 84 }
84 85
85 setPackageRoot(String argument) { 86 setPackageRoot(String argument) {
86 packageRoot = cwd.resolve(extractPath(argument)); 87 packageRoot = cwd.resolve(extractPath(argument));
87 } 88 }
(...skipping 27 matching lines...) Expand all
115 List<OptionHandler> handlers = <OptionHandler>[ 116 List<OptionHandler> handlers = <OptionHandler>[
116 new OptionHandler('-[chv?]+', handleShortOptions), 117 new OptionHandler('-[chv?]+', handleShortOptions),
117 new OptionHandler('--throw-on-error', (_) => throwOnError = true), 118 new OptionHandler('--throw-on-error', (_) => throwOnError = true),
118 new OptionHandler('--suppress-warnings', (_) => showWarnings = false), 119 new OptionHandler('--suppress-warnings', (_) => showWarnings = false),
119 new OptionHandler('--output-type=dart|--output-type=js', passThrough), 120 new OptionHandler('--output-type=dart|--output-type=js', passThrough),
120 new OptionHandler('--verbose', (_) => verbose = true), 121 new OptionHandler('--verbose', (_) => verbose = true),
121 new OptionHandler('--library-root=.+', setLibraryRoot), 122 new OptionHandler('--library-root=.+', setLibraryRoot),
122 new OptionHandler('--out=.+|-o.+', setOutput), 123 new OptionHandler('--out=.+|-o.+', setOutput),
123 new OptionHandler('--allow-mock-compilation', passThrough), 124 new OptionHandler('--allow-mock-compilation', passThrough),
124 new OptionHandler('--unparse-validation', passThrough), 125 new OptionHandler('--unparse-validation', passThrough),
125 new OptionHandler('--no-colors', (_) => colors.enabled = false), 126 new OptionHandler('--no-colors', (_) => enableColors = false),
126 new OptionHandler('--enable[_-]checked[_-]mode|--checked', 127 new OptionHandler('--enable[_-]checked[_-]mode|--checked',
127 (_) => passThrough('--enable-checked-mode')), 128 (_) => passThrough('--enable-checked-mode')),
128 new OptionHandler(@'--help|/\?|/h', (_) => wantHelp = true), 129 new OptionHandler(@'--help|/\?|/h', (_) => wantHelp = true),
129 new OptionHandler(@'--package-root=.+|-p.+', setPackageRoot), 130 new OptionHandler(@'--package-root=.+|-p.+', setPackageRoot),
130 // The following two options must come last. 131 // The following two options must come last.
131 new OptionHandler('-.*', (String argument) { 132 new OptionHandler('-.*', (String argument) {
132 helpAndFail('Error: Unknown option "$argument".'); 133 helpAndFail('Error: Unknown option "$argument".');
133 }), 134 }),
134 new OptionHandler('.*', (String argument) { 135 new OptionHandler('.*', (String argument) {
135 arguments.add(nativeToUriPath(argument)); 136 arguments.add(nativeToUriPath(argument));
(...skipping 24 matching lines...) Expand all
160 source = readAll(uriPathToNative(uri.path)); 161 source = readAll(uriPathToNative(uri.path));
161 } catch (FileIOException ex) { 162 } catch (FileIOException ex) {
162 throw 'Error: Cannot read "${relativize(cwd, uri)}" (${ex.osError}).'; 163 throw 'Error: Cannot read "${relativize(cwd, uri)}" (${ex.osError}).';
163 } 164 }
164 dartBytesRead += source.length; 165 dartBytesRead += source.length;
165 sourceFiles[uri.toString()] = 166 sourceFiles[uri.toString()] =
166 new SourceFile(relativize(cwd, uri), source); 167 new SourceFile(relativize(cwd, uri), source);
167 return new Future.immediate(source); 168 return new Future.immediate(source);
168 } 169 }
169 170
170 void info(var message) { 171 void info(var message, [api.Diagnostic kind = api.Diagnostic.VERBOSE_INFO]) {
171 if (verbose) print('${colors.green("info:")} $message'); 172 if (!verbose && kind === api.Diagnostic.VERBOSE_INFO) return;
173 print('${colors.green("info:")} $message');
172 } 174 }
173 175
174 bool isAborting = false; 176 bool isAborting = false;
175 177
176 void handler(Uri uri, int begin, int end, String message, bool fatal) { 178 final int FATAL = api.Diagnostic.CRASH.ordinal | api.Diagnostic.ERROR.ordinal;
179 final int INFO =
180 api.Diagnostic.INFO.ordinal | api.Diagnostic.VERBOSE_INFO.ordinal;
181
182 void handler(Uri uri, int begin, int end, String message,
183 api.Diagnostic kind) {
177 if (isAborting) return; 184 if (isAborting) return;
178 if (uri === null && !fatal) { 185 isAborting = kind === api.Diagnostic.CRASH;
179 info(message); 186 bool fatal = (kind.ordinal & FATAL) != 0;
187 bool isInfo = (kind.ordinal & INFO) != 0;
188 if (isInfo) {
189 assert(uri === null);
190 info(message, kind);
180 return; 191 return;
181 } 192 }
193 var color;
194 if (!enableColors) {
195 color = (x) => x;
196 } else if (kind === api.Diagnostic.ERROR) {
197 color = colors.red;
198 } else if (kind === api.Diagnostic.WARNING) {
199 color = colors.magenta;
200 } else if (kind === api.Diagnostic.LINT) {
201 color = colors.magenta;
202 } else if (kind === api.Diagnostic.CRASH) {
203 color = colors.red;
204 } else {
205 throw 'Unknown kind: $kind (${kind.ordinal})';
206 }
182 if (uri === null) { 207 if (uri === null) {
183 assert(fatal); 208 assert(fatal);
184 print(message); 209 print(color(message));
185 } else if (fatal || showWarnings) { 210 } else if (fatal || showWarnings) {
186 SourceFile file = sourceFiles[uri.toString()]; 211 SourceFile file = sourceFiles[uri.toString()];
187 print(file.getLocationMessage(message, begin, end, true)); 212 print(file.getLocationMessage(color(message), begin, end, true,
213 color));
188 } 214 }
189 if (fatal && throwOnError) { 215 if (fatal && throwOnError) {
190 isAborting = true; 216 isAborting = true;
191 throw new AbortLeg(message); 217 throw new AbortLeg(message);
192 } 218 }
193 } 219 }
194 220
195 Uri uri = cwd.resolve(arguments[0]); 221 Uri uri = cwd.resolve(arguments[0]);
196 if (packageRoot === null) { 222 if (packageRoot === null) {
197 packageRoot = uri.resolve('./packages/'); 223 packageRoot = uri.resolve('./packages/');
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 } catch (var ignored) { 364 } catch (var ignored) {
339 print('Internal error: error while printing exception'); 365 print('Internal error: error while printing exception');
340 } 366 }
341 try { 367 try {
342 print(trace); 368 print(trace);
343 } finally { 369 } finally {
344 exit(253); // 253 is recognized as a crash by our test scripts. 370 exit(253); // 253 is recognized as a crash by our test scripts.
345 } 371 }
346 } 372 }
347 } 373 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/compiler.dart ('k') | dart/lib/compiler/implementation/leg.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698