OLD | NEW |
---|---|
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 part of dart2js; | 5 part of dart2js; |
6 | 6 |
7 /** | 7 /** |
8 * If true, print a warning for each method that was resolved, but not | 8 * If true, print a warning for each method that was resolved, but not |
9 * compiled. | 9 * compiled. |
10 */ | 10 */ |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
386 | 386 |
387 /** | 387 /** |
388 * URI of the main source map if the compiler is generating source | 388 * URI of the main source map if the compiler is generating source |
389 * maps. | 389 * maps. |
390 */ | 390 */ |
391 final Uri sourceMapUri; | 391 final Uri sourceMapUri; |
392 | 392 |
393 /// Emit terse diagnostics without howToFix. | 393 /// Emit terse diagnostics without howToFix. |
394 final bool terseDiagnostics; | 394 final bool terseDiagnostics; |
395 | 395 |
396 /// If `true`, warnings and hints not from user code are not reported. | |
397 final bool hidePackageWarnings; | |
398 | |
399 /// `true` if the last diagnostic was filtered, in which case the | |
400 /// accompanying info message should be filtered as well. | |
401 bool lastDiagnosticWasFiltered = false; | |
402 | |
396 final api.CompilerOutputProvider outputProvider; | 403 final api.CompilerOutputProvider outputProvider; |
397 | 404 |
398 bool disableInlining = false; | 405 bool disableInlining = false; |
399 | 406 |
400 List<Uri> librariesToAnalyzeWhenRun; | 407 List<Uri> librariesToAnalyzeWhenRun; |
401 | 408 |
402 final Tracer tracer; | 409 final Tracer tracer; |
403 | 410 |
404 CompilerTask measuredTask; | 411 CompilerTask measuredTask; |
405 Element _currentElement; | 412 Element _currentElement; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 bool generateSourceMap: true, | 615 bool generateSourceMap: true, |
609 this.analyzeAllFlag: false, | 616 this.analyzeAllFlag: false, |
610 bool analyzeOnly: false, | 617 bool analyzeOnly: false, |
611 bool analyzeSignaturesOnly: false, | 618 bool analyzeSignaturesOnly: false, |
612 this.preserveComments: false, | 619 this.preserveComments: false, |
613 this.verbose: false, | 620 this.verbose: false, |
614 this.sourceMapUri: null, | 621 this.sourceMapUri: null, |
615 this.buildId: UNDETERMINED_BUILD_ID, | 622 this.buildId: UNDETERMINED_BUILD_ID, |
616 this.terseDiagnostics: false, | 623 this.terseDiagnostics: false, |
617 this.dumpInfo: false, | 624 this.dumpInfo: false, |
625 this.hidePackageWarnings: false, | |
618 outputProvider, | 626 outputProvider, |
619 List<String> strips: const []}) | 627 List<String> strips: const []}) |
620 : this.analyzeOnly = analyzeOnly || analyzeSignaturesOnly, | 628 : this.analyzeOnly = analyzeOnly || analyzeSignaturesOnly, |
621 this.analyzeSignaturesOnly = analyzeSignaturesOnly, | 629 this.analyzeSignaturesOnly = analyzeSignaturesOnly, |
622 this.outputProvider = (outputProvider == null) | 630 this.outputProvider = (outputProvider == null) |
623 ? NullSink.outputProvider | 631 ? NullSink.outputProvider |
624 : outputProvider { | 632 : outputProvider { |
625 world = new World(this); | 633 world = new World(this); |
626 | 634 |
627 closureMapping.ClosureNamer closureNamer; | 635 closureMapping.ClosureNamer closureNamer; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
741 return spanFromElement(node); | 749 return spanFromElement(node); |
742 } else if (node is MetadataAnnotation) { | 750 } else if (node is MetadataAnnotation) { |
743 MetadataAnnotation annotation = node; | 751 MetadataAnnotation annotation = node; |
744 Uri uri = annotation.annotatedElement.getCompilationUnit().script.uri; | 752 Uri uri = annotation.annotatedElement.getCompilationUnit().script.uri; |
745 return spanFromTokens(annotation.beginToken, annotation.endToken, uri); | 753 return spanFromTokens(annotation.beginToken, annotation.endToken, uri); |
746 } else { | 754 } else { |
747 throw 'No error location.'; | 755 throw 'No error location.'; |
748 } | 756 } |
749 } | 757 } |
750 | 758 |
759 /// Finds the approximate [Element] for [node]. [currentElement] is used as | |
760 /// the default value. | |
761 Element elementFromSpannable(Spannable node) { | |
762 Element element; | |
763 if (node is Element) { | |
764 element = node; | |
765 } else if (node is HInstruction) { | |
766 element = node.sourceElement; | |
767 } else if (node is MetadataAnnotation) { | |
768 MetadataAnnotation annotation = node; | |
floitsch
2014/02/20 19:24:32
This should not be necessary anymore. The is-check
Johnni Winther
2014/02/21 08:32:14
Done.
| |
769 element = annotation.annotatedElement; | |
770 } | |
771 return element != null ? element : currentElement; | |
772 } | |
773 | |
751 void log(message) { | 774 void log(message) { |
752 reportDiagnostic(null, | 775 reportDiagnostic(null, |
753 MessageKind.GENERIC.error({'text': '$message'}), | 776 MessageKind.GENERIC.error({'text': '$message'}), |
754 api.Diagnostic.VERBOSE_INFO); | 777 api.Diagnostic.VERBOSE_INFO); |
755 } | 778 } |
756 | 779 |
757 Future<bool> run(Uri uri) { | 780 Future<bool> run(Uri uri) { |
758 totalCompileTime.start(); | 781 totalCompileTime.start(); |
759 | 782 |
760 return new Future.sync(() => runCompiler(uri)).catchError((error) { | 783 return new Future.sync(() => runCompiler(uri)).catchError((error) { |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 | 1342 |
1320 FunctionType computeFunctionType(Element element, | 1343 FunctionType computeFunctionType(Element element, |
1321 FunctionSignature signature) { | 1344 FunctionSignature signature) { |
1322 return withCurrentElement(element, | 1345 return withCurrentElement(element, |
1323 () => resolver.computeFunctionType(element, signature)); | 1346 () => resolver.computeFunctionType(element, signature)); |
1324 } | 1347 } |
1325 | 1348 |
1326 void reportError(Spannable node, | 1349 void reportError(Spannable node, |
1327 MessageKind errorCode, | 1350 MessageKind errorCode, |
1328 [Map arguments = const {}]) { | 1351 [Map arguments = const {}]) { |
1329 reportDiagnostic(node, | 1352 reportDiagnosticInternal(node, errorCode, arguments, api.Diagnostic.ERROR); |
1330 errorCode.error(arguments, terseDiagnostics), | |
1331 api.Diagnostic.ERROR); | |
1332 } | 1353 } |
1333 | 1354 |
1334 void reportFatalError(Spannable node, MessageKind errorCode, | 1355 void reportFatalError(Spannable node, MessageKind errorCode, |
1335 [Map arguments = const {}]) { | 1356 [Map arguments = const {}]) { |
1336 reportError(node, errorCode, arguments); | 1357 reportError(node, errorCode, arguments); |
1337 // TODO(ahe): Make this only abort the current method. | 1358 // TODO(ahe): Make this only abort the current method. |
1338 throw new CompilerCancelledException( | 1359 throw new CompilerCancelledException( |
1339 'Error: Cannot continue due to previous error.'); | 1360 'Error: Cannot continue due to previous error.'); |
1340 } | 1361 } |
1341 | 1362 |
1342 void reportWarning(Spannable node, MessageKind errorCode, | 1363 void reportWarning(Spannable node, MessageKind errorCode, |
1343 [Map arguments = const {}]) { | 1364 [Map arguments = const {}]) { |
1344 // TODO(ahe): Don't suppress these warning when the type checker | 1365 // TODO(ahe): Don't suppress these warning when the type checker |
1345 // is more complete. | 1366 // is more complete. |
1346 if (errorCode == MessageKind.MISSING_RETURN) return; | 1367 if (errorCode == MessageKind.MISSING_RETURN) return; |
1347 if (errorCode == MessageKind.MAYBE_MISSING_RETURN) return; | 1368 if (errorCode == MessageKind.MAYBE_MISSING_RETURN) return; |
1348 reportDiagnostic(node, | 1369 reportDiagnosticInternal( |
1349 errorCode.error(arguments, terseDiagnostics), | 1370 node, errorCode, arguments, api.Diagnostic.WARNING); |
1350 api.Diagnostic.WARNING); | |
1351 } | 1371 } |
1352 | 1372 |
1353 void reportInfo(Spannable node, MessageKind errorCode, | 1373 void reportInfo(Spannable node, MessageKind errorCode, |
1354 [Map arguments = const {}]) { | 1374 [Map arguments = const {}]) { |
1355 reportDiagnostic(node, | 1375 reportDiagnosticInternal(node, errorCode, arguments, api.Diagnostic.INFO); |
1356 errorCode.error(arguments, terseDiagnostics), | |
1357 api.Diagnostic.INFO); | |
1358 } | 1376 } |
1359 | 1377 |
1360 void reportHint(Spannable node, MessageKind errorCode, | 1378 void reportHint(Spannable node, MessageKind errorCode, |
1361 [Map arguments = const {}]) { | 1379 [Map arguments = const {}]) { |
1362 reportDiagnostic(node, | 1380 reportDiagnosticInternal(node, errorCode, arguments, api.Diagnostic.HINT); |
1363 errorCode.error(arguments, terseDiagnostics), | |
1364 api.Diagnostic.HINT); | |
1365 } | 1381 } |
1366 | 1382 |
1367 /// For debugging only, print a message with a source location. | 1383 /// For debugging only, print a message with a source location. |
1368 void reportHere(Spannable node, String debugMessage) { | 1384 void reportHere(Spannable node, String debugMessage) { |
1369 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); | 1385 reportInfo(node, MessageKind.GENERIC, {'text': 'HERE: $debugMessage'}); |
1370 } | 1386 } |
1371 | 1387 |
1372 void reportInternalError(Spannable node, String message) { | 1388 void reportInternalError(Spannable node, String message) { |
1373 reportError( | 1389 reportError( |
1374 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'}); | 1390 node, MessageKind.GENERIC, {'text': 'Internal Error: $message'}); |
1375 } | 1391 } |
1376 | 1392 |
1393 void reportDiagnosticInternal(Spannable node, | |
1394 MessageKind errorCode, | |
1395 Map arguments, | |
1396 api.Diagnostic kind) { | |
1397 if (hidePackageWarnings) { | |
1398 switch (kind) { | |
1399 case api.Diagnostic.WARNING: | |
1400 case api.Diagnostic.HINT: | |
1401 if (!inUserCode(elementFromSpannable(node))) { | |
1402 lastDiagnosticWasFiltered = true; | |
1403 return; | |
1404 } | |
1405 break; | |
1406 case api.Diagnostic.INFO: | |
1407 if (lastDiagnosticWasFiltered) { | |
1408 return; | |
1409 } | |
1410 break; | |
1411 } | |
1412 } | |
1413 lastDiagnosticWasFiltered = false; | |
1414 reportDiagnostic(node, errorCode.error(arguments, terseDiagnostics), kind); | |
1415 } | |
1416 | |
1377 // TODO(ahe): The names Diagnostic and api.Diagnostic are in conflict. Fix it. | 1417 // TODO(ahe): The names Diagnostic and api.Diagnostic are in conflict. Fix it. |
1378 void reportDiagnostic(Spannable span, | 1418 void reportDiagnostic(Spannable span, |
1379 Diagnostic message, | 1419 Diagnostic message, |
1380 api.Diagnostic kind); | 1420 api.Diagnostic kind); |
1381 | 1421 |
1382 void reportAssertionFailure(SpannableAssertionFailure ex) { | 1422 void reportAssertionFailure(SpannableAssertionFailure ex) { |
1383 String message = (ex.message != null) ? tryToString(ex.message) | 1423 String message = (ex.message != null) ? tryToString(ex.message) |
1384 : tryToString(ex); | 1424 : tryToString(ex); |
1385 SourceSpan span = spanFromSpannable(ex.node); | 1425 SourceSpan span = spanFromSpannable(ex.node); |
1386 reportError(ex.node, MessageKind.GENERIC, {'text': message}); | 1426 reportError(ex.node, MessageKind.GENERIC, {'text': message}); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1528 // TODO(ahe): Implement better heuristics to discover entry points of | 1568 // TODO(ahe): Implement better heuristics to discover entry points of |
1529 // packages and use that to discover unused implementation details in | 1569 // packages and use that to discover unused implementation details in |
1530 // packages. | 1570 // packages. |
1531 if (library.isPlatformLibrary || library.isPackageLibrary) return; | 1571 if (library.isPlatformLibrary || library.isPackageLibrary) return; |
1532 library.compilationUnits.forEach((unit) { | 1572 library.compilationUnits.forEach((unit) { |
1533 unit.forEachLocalMember(checkLive); | 1573 unit.forEachLocalMember(checkLive); |
1534 }); | 1574 }); |
1535 }); | 1575 }); |
1536 } | 1576 } |
1537 | 1577 |
1538 /// Debugging helper for determining whether the current element is declared | 1578 /// Helper for determining whether the current element is declared within |
1539 /// within 'user code'. | 1579 /// 'user code'. |
1540 /// | 1580 /// |
1541 /// See [inUserCode] for what defines 'user code'. | 1581 /// See [inUserCode] for what defines 'user code'. |
1542 bool currentlyInUserCode() { | 1582 bool currentlyInUserCode() { |
1543 return inUserCode(currentElement); | 1583 return inUserCode(currentElement); |
1544 } | 1584 } |
1545 | 1585 |
1546 /// Debugging helper for determining whether [element] is declared within | 1586 /// Helper for determining whether [element] is declared within 'user code'. |
1547 /// 'user code'. | |
1548 /// | 1587 /// |
1549 /// What constitutes 'user code' is defined by the URI(s) provided by the | 1588 /// What constitutes 'user code' is defined by the URI(s) provided by the |
1550 /// entry point(s) of compilation or analysis: | 1589 /// entry point(s) of compilation or analysis: |
1551 /// | 1590 /// |
1552 /// If an entrypoint URI uses the 'package' scheme then every library from | 1591 /// If an entrypoint URI uses the 'package' scheme then every library from |
1553 /// that same package is considered to be in user code. For instance, if | 1592 /// that same package is considered to be in user code. For instance, if |
1554 /// an entry point URI is 'package:foo/bar.dart' then every library whose | 1593 /// an entry point URI is 'package:foo/bar.dart' then every library whose |
1555 /// canonical URI starts with 'package:foo/' is in user code. | 1594 /// canonical URI starts with 'package:foo/' is in user code. |
1556 /// | 1595 /// |
1557 /// If an entrypoint URI uses another scheme than 'package' then every library | 1596 /// If an entrypoint URI uses another scheme than 'package' then every library |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1722 | 1761 |
1723 void close() {} | 1762 void close() {} |
1724 | 1763 |
1725 toString() => name; | 1764 toString() => name; |
1726 | 1765 |
1727 /// Convenience method for getting an [api.CompilerOutputProvider]. | 1766 /// Convenience method for getting an [api.CompilerOutputProvider]. |
1728 static NullSink outputProvider(String name, String extension) { | 1767 static NullSink outputProvider(String name, String extension) { |
1729 return new NullSink('$name.$extension'); | 1768 return new NullSink('$name.$extension'); |
1730 } | 1769 } |
1731 } | 1770 } |
OLD | NEW |