| 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 /** The one true [World]. */ | 5 /** The one true [World]. */ |
| 6 World world; | 6 World world; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Experimental phase to enable await, only set when using the | 9 * Experimental phase to enable await, only set when using the |
| 10 * await/awaitc.dart entrypoint. | 10 * await/awaitc.dart entrypoint. |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 379 } |
| 380 | 380 |
| 381 var codeWriter = new CodeWriter(); | 381 var codeWriter = new CodeWriter(); |
| 382 gen = new WorldGenerator(main, codeWriter); | 382 gen = new WorldGenerator(main, codeWriter); |
| 383 gen.run(); | 383 gen.run(); |
| 384 jsBytesWritten = codeWriter.text.length; | 384 jsBytesWritten = codeWriter.text.length; |
| 385 } | 385 } |
| 386 | 386 |
| 387 // ********************** Message support *********************** | 387 // ********************** Message support *********************** |
| 388 | 388 |
| 389 void _message(String message, SourceSpan span, SourceSpan span1, | 389 void _message(String color, String prefix, String message, |
| 390 SourceSpan span2, bool throwing) { | 390 SourceSpan span, SourceSpan span1, SourceSpan span2, bool throwing) { |
| 391 var text = message; | 391 final messageWithPrefix = options.useColors |
| 392 ? (color + prefix + _NO_COLOR + message) : (prefix + message); |
| 393 var text = messageWithPrefix; |
| 392 if (span != null) { | 394 if (span != null) { |
| 393 text = span.toMessageString(message); | 395 text = span.toMessageString(messageWithPrefix); |
| 394 } | 396 } |
| 395 print(text); | 397 print(text); |
| 396 if (span1 != null) { | 398 if (span1 != null) { |
| 397 print(span1.toMessageString(message)); | 399 print(span1.toMessageString(messageWithPrefix)); |
| 398 } | 400 } |
| 399 if (span2 != null) { | 401 if (span2 != null) { |
| 400 print(span2.toMessageString(message)); | 402 print(span2.toMessageString(messageWithPrefix)); |
| 401 } | 403 } |
| 402 | 404 |
| 403 if (throwing) { | 405 if (throwing) { |
| 404 throw new CompilerException(message, span); | 406 throw new CompilerException(messageWithPrefix, span); |
| 405 } | 407 } |
| 406 } | 408 } |
| 407 | 409 |
| 408 /** [message] is considered a static compile-time error by the Dart lang. */ | 410 /** [message] is considered a static compile-time error by the Dart lang. */ |
| 409 void error(String message, [SourceSpan span, SourceSpan span1, SourceSpan span
2]) { | 411 void error(String message, |
| 412 [SourceSpan span, SourceSpan span1, SourceSpan span2]) { |
| 410 errors++; | 413 errors++; |
| 411 _message('error: $message', span, span1, span2, options.throwOnErrors); | 414 _message(_RED_COLOR, 'error: ', message, |
| 415 span, span1, span2, options.throwOnErrors); |
| 412 } | 416 } |
| 413 | 417 |
| 414 /** [message] is considered a type warning by the Dart lang. */ | 418 /** [message] is considered a type warning by the Dart lang. */ |
| 415 void warning(String message, [SourceSpan span, SourceSpan span1, SourceSpan sp
an2]) { | 419 void warning(String message, |
| 420 [SourceSpan span, SourceSpan span1, SourceSpan span2]) { |
| 416 if (options.warningsAsErrors) { | 421 if (options.warningsAsErrors) { |
| 417 error(message, span, span1, span2); | 422 error(message, span, span1, span2); |
| 418 return; | 423 return; |
| 419 } | 424 } |
| 420 warnings++; | 425 warnings++; |
| 421 if (options.showWarnings) { | 426 if (options.showWarnings) { |
| 422 _message('warning: $message', span, span1, span2, options.throwOnWarnings)
; | 427 _message(_MAGENTA_COLOR, 'warning: ', message, |
| 428 span, span1, span2, options.throwOnWarnings); |
| 423 } | 429 } |
| 424 } | 430 } |
| 425 | 431 |
| 426 /** [message] at [location] is so bad we can't generate runnable code. */ | 432 /** [message] at [location] is so bad we can't generate runnable code. */ |
| 427 void fatal(String message, [SourceSpan span, SourceSpan span1, SourceSpan span
2]) { | 433 void fatal(String message, |
| 434 [SourceSpan span, SourceSpan span1, SourceSpan span2]) { |
| 428 errors++; | 435 errors++; |
| 429 seenFatal = true; | 436 seenFatal = true; |
| 430 _message('fatal: $message', span, span1, span2, | 437 _message(_RED_COLOR, 'fatal: ', message, |
| 431 options.throwOnFatal || options.throwOnErrors); | 438 span, span1, span2, options.throwOnFatal || options.throwOnErrors); |
| 432 } | 439 } |
| 433 | 440 |
| 434 /** [message] at [location] is about a bug in the compiler. */ | 441 /** [message] at [location] is about a bug in the compiler. */ |
| 435 void internalError(String message, [SourceSpan span, SourceSpan span1, SourceS
pan span2]) { | 442 void internalError(String message, |
| 436 _message('We are sorry, but... $message', span, span1, span2, true); | 443 [SourceSpan span, SourceSpan span1, SourceSpan span2]) { |
| 444 _message(_NO_COLOR, |
| 445 'We are sorry, but...', message, span, span1, span2, true); |
| 437 } | 446 } |
| 438 | 447 |
| 439 /** | 448 /** |
| 440 * [message] at [location] will tell the user about what the compiler | 449 * [message] at [location] will tell the user about what the compiler |
| 441 * is doing. | 450 * is doing. |
| 442 */ | 451 */ |
| 443 void info(String message, [SourceSpan span, SourceSpan span1, SourceSpan span2
]) { | 452 void info(String message, |
| 453 [SourceSpan span, SourceSpan span1, SourceSpan span2]) { |
| 444 if (options.showInfo) { | 454 if (options.showInfo) { |
| 445 _message('info: $message', span, span1, span2, false); | 455 _message(_GREEN_COLOR, 'info: ', message, span, span1, span2, false); |
| 446 } | 456 } |
| 447 } | 457 } |
| 448 | 458 |
| 449 /** Run [fn] without the forceDynamic option enabeld. */ | 459 /** Run [fn] without the forceDynamic option enabeld. */ |
| 450 withoutForceDynamic(void fn()) { | 460 withoutForceDynamic(void fn()) { |
| 451 var oldForceDynamic = options.forceDynamic; | 461 var oldForceDynamic = options.forceDynamic; |
| 452 options.forceDynamic = false; | 462 options.forceDynamic = false; |
| 453 | 463 |
| 454 try { | 464 try { |
| 455 return fn(); | 465 return fn(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 475 | 485 |
| 476 withTiming(String name, f()) { | 486 withTiming(String name, f()) { |
| 477 final sw = new Stopwatch(); | 487 final sw = new Stopwatch(); |
| 478 sw.start(); | 488 sw.start(); |
| 479 var result = f(); | 489 var result = f(); |
| 480 sw.stop(); | 490 sw.stop(); |
| 481 info('$name in ${sw.elapsedInMs()}msec'); | 491 info('$name in ${sw.elapsedInMs()}msec'); |
| 482 return result; | 492 return result; |
| 483 } | 493 } |
| 484 } | 494 } |
| OLD | NEW |