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

Side by Side Diff: dart/lib/compiler/implementation/compiler.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 5
6 /** 6 /**
7 * If true, print a warning for each method that was resolved, but not 7 * If true, print a warning for each method that was resolved, but not
8 * compiled. 8 * compiled.
9 */ 9 */
10 final bool REPORT_EXCESS_RESOLUTION = false; 10 final bool REPORT_EXCESS_RESOLUTION = false;
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 void unimplemented(String methodName, 225 void unimplemented(String methodName,
226 [Node node, Token token, HInstruction instruction, 226 [Node node, Token token, HInstruction instruction,
227 Element element]) { 227 Element element]) {
228 internalError("$methodName not implemented", 228 internalError("$methodName not implemented",
229 node, token, instruction, element); 229 node, token, instruction, element);
230 } 230 }
231 231
232 void internalError(String message, 232 void internalError(String message,
233 [Node node, Token token, HInstruction instruction, 233 [Node node, Token token, HInstruction instruction,
234 Element element]) { 234 Element element]) {
235 cancel("${red('internal error:')} $message", 235 cancel('Internal error: $message', node, token, instruction, element);
236 node, token, instruction, element);
237 } 236 }
238 237
239 void internalErrorOnElement(Element element, String message) { 238 void internalErrorOnElement(Element element, String message) {
240 internalError(message, element: element); 239 internalError(message, element: element);
241 } 240 }
242 241
243 void unhandledExceptionOnElement(Element element) { 242 void unhandledExceptionOnElement(Element element) {
244 reportDiagnostic(spanFromElement(element), 243 reportDiagnostic(spanFromElement(element),
245 MessageKind.COMPILER_CRASHED.error().toString(), 244 MessageKind.COMPILER_CRASHED.error().toString(),
246 false); 245 api.Diagnostic.CRASH);
247 // TODO(ahe): Obtain the build ID. 246 // TODO(ahe): Obtain the build ID.
248 var buildId = 'build number could not be determined'; 247 var buildId = 'build number could not be determined';
249 print(MessageKind.PLEASE_REPORT_THE_CRASH.message([buildId])); 248 print(MessageKind.PLEASE_REPORT_THE_CRASH.message([buildId]));
250 } 249 }
251 250
252 void cancel([String reason, Node node, Token token, 251 void cancel([String reason, Node node, Token token,
253 HInstruction instruction, Element element]) { 252 HInstruction instruction, Element element]) {
254 assembledCode = null; // Compilation failed. Make sure that we 253 assembledCode = null; // Compilation failed. Make sure that we
255 // don't return a bogus result. 254 // don't return a bogus result.
256 SourceSpan span = const SourceSpan(null, null, null); 255 SourceSpan span = const SourceSpan(null, null, null);
257 if (node !== null) { 256 if (node !== null) {
258 span = spanFromNode(node); 257 span = spanFromNode(node);
259 } else if (token !== null) { 258 } else if (token !== null) {
260 span = spanFromTokens(token, token); 259 span = spanFromTokens(token, token);
261 } else if (instruction !== null) { 260 } else if (instruction !== null) {
262 span = spanFromElement(currentElement); 261 span = spanFromElement(currentElement);
263 } else if (element !== null) { 262 } else if (element !== null) {
264 span = spanFromElement(element); 263 span = spanFromElement(element);
265 } else { 264 } else {
266 throw 'No error location for error: $reason'; 265 throw 'No error location for error: $reason';
267 } 266 }
268 reportDiagnostic(span, red(reason), true); 267 reportDiagnostic(span, reason, api.Diagnostic.ERROR);
269 throw new CompilerCancelledException(reason); 268 throw new CompilerCancelledException(reason);
270 } 269 }
271 270
272 void reportFatalError(String reason, Element element, 271 void reportFatalError(String reason, Element element,
273 [Node node, Token token, HInstruction instruction]) { 272 [Node node, Token token, HInstruction instruction]) {
274 withCurrentElement(element, () { 273 withCurrentElement(element, () {
275 cancel(reason, node, token, instruction, element); 274 cancel(reason, node, token, instruction, element);
276 }); 275 });
277 } 276 }
278 277
279 void log(message) { 278 void log(message) {
280 reportDiagnostic(null, message, false); 279 reportDiagnostic(null, message, api.Diagnostic.VERBOSE_INFO);
281 } 280 }
282 281
283 bool run(Uri uri) { 282 bool run(Uri uri) {
284 try { 283 try {
285 runCompiler(uri); 284 runCompiler(uri);
286 } catch (CompilerCancelledException exception) { 285 } catch (CompilerCancelledException exception) {
287 log(exception.toString()); 286 log(exception.toString());
288 log('compilation failed'); 287 log('compilation failed');
289 return false; 288 return false;
290 } 289 }
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 resolved.remove(e); 511 resolved.remove(e);
513 } 512 }
514 if (e.getLibrary() === interceptorsLibrary) { 513 if (e.getLibrary() === interceptorsLibrary) {
515 resolved.remove(e); 514 resolved.remove(e);
516 } 515 }
517 } 516 }
518 log('Excess resolution work: ${resolved.length}.'); 517 log('Excess resolution work: ${resolved.length}.');
519 if (!REPORT_EXCESS_RESOLUTION) return; 518 if (!REPORT_EXCESS_RESOLUTION) return;
520 for (Element e in resolved) { 519 for (Element e in resolved) {
521 SourceSpan span = spanFromElement(e); 520 SourceSpan span = spanFromElement(e);
522 reportDiagnostic(span, 'Warning: $e resolved but not compiled.', false); 521 reportDiagnostic(span, 'Warning: $e resolved but not compiled.',
522 api.Diagnostic.WARNING);
523 } 523 }
524 } 524 }
525 525
526 TreeElements analyzeElement(Element element) { 526 TreeElements analyzeElement(Element element) {
527 TreeElements elements = enqueuer.resolution.getCachedElements(element); 527 TreeElements elements = enqueuer.resolution.getCachedElements(element);
528 if (elements !== null) return elements; 528 if (elements !== null) return elements;
529 final int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION 529 final int allowed = ElementCategory.VARIABLE | ElementCategory.FUNCTION
530 | ElementCategory.FACTORY; 530 | ElementCategory.FACTORY;
531 ElementKind kind = element.kind; 531 ElementKind kind = element.kind;
532 if (!element.isAccessor() && 532 if (!element.isAccessor() &&
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // TODO(ahe): Don't supress these warning when the type checker 628 // TODO(ahe): Don't supress these warning when the type checker
629 // is more complete. 629 // is more complete.
630 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return; 630 if (message.message.kind === MessageKind.NOT_ASSIGNABLE) return;
631 if (message.message.kind === MessageKind.MISSING_RETURN) return; 631 if (message.message.kind === MessageKind.MISSING_RETURN) return;
632 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return; 632 if (message.message.kind === MessageKind.MAYBE_MISSING_RETURN) return;
633 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return; 633 if (message.message.kind === MessageKind.ADDITIONAL_ARGUMENT) return;
634 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return; 634 if (message.message.kind === MessageKind.METHOD_NOT_FOUND) return;
635 } 635 }
636 SourceSpan span = spanFromNode(node); 636 SourceSpan span = spanFromNode(node);
637 637
638 reportDiagnostic(span, "${magenta('warning:')} $message", false); 638 reportDiagnostic(span, 'Warning: $message', api.Diagnostic.WARNING );
639 } 639 }
640 640
641 reportError(Node node, var message) { 641 reportError(Node node, var message) {
642 SourceSpan span = spanFromNode(node); 642 SourceSpan span = spanFromNode(node);
643 reportDiagnostic(span, "${red('error:')} $message", true); 643 reportDiagnostic(span, 'Error: $message', api.Diagnostic.ERROR);
644 throw new CompilerCancelledException(message.toString()); 644 throw new CompilerCancelledException(message.toString());
645 } 645 }
646 646
647 abstract void reportDiagnostic(SourceSpan span, String message, bool fatal); 647 abstract void reportDiagnostic(SourceSpan span, String message,
648 api.Diagnostic kind);
648 649
649 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) { 650 SourceSpan spanFromTokens(Token begin, Token end, [Uri uri]) {
650 if (begin === null || end === null) { 651 if (begin === null || end === null) {
651 // TODO(ahe): We can almost always do better. Often it is only 652 // TODO(ahe): We can almost always do better. Often it is only
652 // end that is null. Otherwise, we probably know the current 653 // end that is null. Otherwise, we probably know the current
653 // URI. 654 // URI.
654 throw 'Cannot find tokens to produce error message.'; 655 throw 'Cannot find tokens to produce error message.';
655 } 656 }
656 if (uri === null) { 657 if (uri === null) {
657 uri = currentElement.getCompilationUnit().script.uri; 658 uri = currentElement.getCompilationUnit().script.uri;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 // invariant that endOffset > beginOffset, but for EOF the 764 // invariant that endOffset > beginOffset, but for EOF the
764 // charoffset of the next token may be [beginOffset]. This can 765 // charoffset of the next token may be [beginOffset]. This can
765 // also happen for synthetized tokens that are produced during 766 // also happen for synthetized tokens that are produced during
766 // error handling. 767 // error handling.
767 final endOffset = 768 final endOffset =
768 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1); 769 Math.max((end.next !== null) ? end.next.charOffset : 0, beginOffset + 1);
769 assert(endOffset > beginOffset); 770 assert(endOffset > beginOffset);
770 return f(beginOffset, endOffset); 771 return f(beginOffset, endOffset);
771 } 772 }
772 } 773 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/colors.dart ('k') | dart/lib/compiler/implementation/dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698