| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 analyzer.src.generated.engine; | 5 library analyzer.src.generated.engine; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:typed_data'; |
| 9 | 10 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/ast/visitor.dart'; | 12 import 'package:analyzer/dart/ast/visitor.dart'; |
| 12 import 'package:analyzer/dart/element/element.dart'; | 13 import 'package:analyzer/dart/element/element.dart'; |
| 13 import 'package:analyzer/error/error.dart'; | 14 import 'package:analyzer/error/error.dart'; |
| 14 import 'package:analyzer/exception/exception.dart'; | 15 import 'package:analyzer/exception/exception.dart'; |
| 15 import 'package:analyzer/instrumentation/instrumentation.dart'; | 16 import 'package:analyzer/instrumentation/instrumentation.dart'; |
| 16 import 'package:analyzer/plugin/resolver_provider.dart'; | 17 import 'package:analyzer/plugin/resolver_provider.dart'; |
| 17 import 'package:analyzer/source/error_processor.dart'; | 18 import 'package:analyzer/source/error_processor.dart'; |
| 18 import 'package:analyzer/src/cancelable_future.dart'; | 19 import 'package:analyzer/src/cancelable_future.dart'; |
| 19 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator; | 20 import 'package:analyzer/src/context/builder.dart' show EmbedderYamlLocator; |
| 20 import 'package:analyzer/src/context/cache.dart'; | 21 import 'package:analyzer/src/context/cache.dart'; |
| 21 import 'package:analyzer/src/context/context.dart'; | 22 import 'package:analyzer/src/context/context.dart'; |
| 22 import 'package:analyzer/src/generated/constant.dart'; | 23 import 'package:analyzer/src/generated/constant.dart'; |
| 23 import 'package:analyzer/src/generated/java_engine.dart'; | 24 import 'package:analyzer/src/generated/java_engine.dart'; |
| 24 import 'package:analyzer/src/generated/resolver.dart'; | 25 import 'package:analyzer/src/generated/resolver.dart'; |
| 25 import 'package:analyzer/src/generated/source.dart'; | 26 import 'package:analyzer/src/generated/source.dart'; |
| 26 import 'package:analyzer/src/generated/utilities_general.dart'; | 27 import 'package:analyzer/src/generated/utilities_general.dart'; |
| 27 import 'package:analyzer/src/plugin/engine_plugin.dart'; | 28 import 'package:analyzer/src/plugin/engine_plugin.dart'; |
| 28 import 'package:analyzer/src/services/lint.dart'; | 29 import 'package:analyzer/src/services/lint.dart'; |
| 30 import 'package:analyzer/src/summary/api_signature.dart'; |
| 29 import 'package:analyzer/src/task/dart.dart'; | 31 import 'package:analyzer/src/task/dart.dart'; |
| 30 import 'package:analyzer/src/task/general.dart'; | 32 import 'package:analyzer/src/task/general.dart'; |
| 31 import 'package:analyzer/src/task/html.dart'; | 33 import 'package:analyzer/src/task/html.dart'; |
| 32 import 'package:analyzer/src/task/manager.dart'; | 34 import 'package:analyzer/src/task/manager.dart'; |
| 33 import 'package:analyzer/src/task/options.dart'; | 35 import 'package:analyzer/src/task/options.dart'; |
| 34 import 'package:analyzer/src/task/yaml.dart'; | 36 import 'package:analyzer/src/task/yaml.dart'; |
| 35 import 'package:analyzer/task/dart.dart'; | 37 import 'package:analyzer/task/dart.dart'; |
| 36 import 'package:analyzer/task/model.dart'; | 38 import 'package:analyzer/task/model.dart'; |
| 37 import 'package:front_end/src/base/timestamped_data.dart'; | 39 import 'package:front_end/src/base/timestamped_data.dart'; |
| 38 import 'package:html/dom.dart' show Document; | 40 import 'package:html/dom.dart' show Document; |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 class AnalysisNotScheduledError implements Exception {} | 1126 class AnalysisNotScheduledError implements Exception {} |
| 1125 | 1127 |
| 1126 /** | 1128 /** |
| 1127 * A set of analysis options used to control the behavior of an analysis | 1129 * A set of analysis options used to control the behavior of an analysis |
| 1128 * context. | 1130 * context. |
| 1129 */ | 1131 */ |
| 1130 abstract class AnalysisOptions { | 1132 abstract class AnalysisOptions { |
| 1131 /** | 1133 /** |
| 1132 * The length of the list returned by [encodeCrossContextOptions]. | 1134 * The length of the list returned by [encodeCrossContextOptions]. |
| 1133 */ | 1135 */ |
| 1134 static const int crossContextOptionsLength = 1; | 1136 static const int signatureLength = 4; |
| 1135 | 1137 |
| 1136 /** | 1138 /** |
| 1137 * Function that returns `true` if analysis is to parse and analyze function | 1139 * Function that returns `true` if analysis is to parse and analyze function |
| 1138 * bodies for a given source. | 1140 * bodies for a given source. |
| 1139 */ | 1141 */ |
| 1140 AnalyzeFunctionBodiesPredicate get analyzeFunctionBodiesPredicate; | 1142 AnalyzeFunctionBodiesPredicate get analyzeFunctionBodiesPredicate; |
| 1141 | 1143 |
| 1142 /** | 1144 /** |
| 1143 * DEPRECATED: Return the maximum number of sources for which AST structures s
hould be | 1145 * DEPRECATED: Return the maximum number of sources for which AST structures s
hould be |
| 1144 * kept in the cache. | 1146 * kept in the cache. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 * to patch files that should be applied to the library. | 1302 * to patch files that should be applied to the library. |
| 1301 */ | 1303 */ |
| 1302 Map<String, List<String>> get patchPaths; | 1304 Map<String, List<String>> get patchPaths; |
| 1303 | 1305 |
| 1304 /** | 1306 /** |
| 1305 * Return `true` if analysis is to parse comments. | 1307 * Return `true` if analysis is to parse comments. |
| 1306 */ | 1308 */ |
| 1307 bool get preserveComments; | 1309 bool get preserveComments; |
| 1308 | 1310 |
| 1309 /** | 1311 /** |
| 1312 * Return the opaque signature of the options. |
| 1313 * |
| 1314 * The length of the list is guaranteed to equal [signatureLength]. |
| 1315 */ |
| 1316 Uint32List get signature; |
| 1317 |
| 1318 /** |
| 1310 * Return `true` if strong mode analysis should be used. | 1319 * Return `true` if strong mode analysis should be used. |
| 1311 */ | 1320 */ |
| 1312 bool get strongMode; | 1321 bool get strongMode; |
| 1313 | 1322 |
| 1314 /** | 1323 /** |
| 1315 * Return `true` if dependencies between computed results should be tracked | 1324 * Return `true` if dependencies between computed results should be tracked |
| 1316 * by analysis cache. This option should only be set to `false` if analysis | 1325 * by analysis cache. This option should only be set to `false` if analysis |
| 1317 * is performed in such a way that none of the inputs is ever changed | 1326 * is performed in such a way that none of the inputs is ever changed |
| 1318 * during the life time of the context. | 1327 * during the life time of the context. |
| 1319 */ | 1328 */ |
| 1320 bool get trackCacheDependencies; | 1329 bool get trackCacheDependencies; |
| 1321 | 1330 |
| 1322 /** | 1331 /** |
| 1323 * Return a list of integers encoding of the values of the options that need | |
| 1324 * to be the same across all of the contexts associated with partitions that | |
| 1325 * are to be shared by a single analysis context. | |
| 1326 * | |
| 1327 * The length of the list is guaranteed to equal [crossContextOptionsLength]. | |
| 1328 */ | |
| 1329 List<int> encodeCrossContextOptions(); | |
| 1330 | |
| 1331 /** | |
| 1332 * Reset the state of this set of analysis options to its original state. | 1332 * Reset the state of this set of analysis options to its original state. |
| 1333 */ | 1333 */ |
| 1334 void resetToDefaults(); | 1334 void resetToDefaults(); |
| 1335 | 1335 |
| 1336 /** | 1336 /** |
| 1337 * Set the values of the cross-context options to match those in the given set | 1337 * Set the values of the cross-context options to match those in the given set |
| 1338 * of [options]. | 1338 * of [options]. |
| 1339 */ | 1339 */ |
| 1340 void setCrossContextOptionsFrom(AnalysisOptions options); | 1340 void setCrossContextOptionsFrom(AnalysisOptions options); |
| 1341 | 1341 |
| 1342 /** | 1342 /** |
| 1343 * Determine whether two lists returned by [encodeCrossContextOptions] are | 1343 * Determine whether two signatures returned by [signature] are equal. |
| 1344 * equal. | |
| 1345 */ | 1344 */ |
| 1346 static bool crossContextOptionsEqual(List<int> a, List<int> b) { | 1345 static bool signaturesEqual(Uint32List a, Uint32List b) { |
| 1347 assert(a.length == crossContextOptionsLength); | 1346 assert(a.length == signatureLength); |
| 1348 assert(b.length == crossContextOptionsLength); | 1347 assert(b.length == signatureLength); |
| 1349 if (a.length != b.length) { | 1348 if (a.length != b.length) { |
| 1350 return false; | 1349 return false; |
| 1351 } | 1350 } |
| 1352 for (int i = 0; i < a.length; i++) { | 1351 for (int i = 0; i < a.length; i++) { |
| 1353 if (a[i] != b[i]) { | 1352 if (a[i] != b[i]) { |
| 1354 return false; | 1353 return false; |
| 1355 } | 1354 } |
| 1356 } | 1355 } |
| 1357 return true; | 1356 return true; |
| 1358 } | 1357 } |
| 1359 } | 1358 } |
| 1360 | 1359 |
| 1361 /** | 1360 /** |
| 1362 * A set of analysis options used to control the behavior of an analysis | 1361 * A set of analysis options used to control the behavior of an analysis |
| 1363 * context. | 1362 * context. |
| 1364 */ | 1363 */ |
| 1365 class AnalysisOptionsImpl implements AnalysisOptions { | 1364 class AnalysisOptionsImpl implements AnalysisOptions { |
| 1366 /** | 1365 /** |
| 1367 * DEPRECATED: The maximum number of sources for which data should be kept in | 1366 * DEPRECATED: The maximum number of sources for which data should be kept in |
| 1368 * the cache. | 1367 * the cache. |
| 1369 * | 1368 * |
| 1370 * This constant no longer has any effect. | 1369 * This constant no longer has any effect. |
| 1371 */ | 1370 */ |
| 1372 @deprecated | 1371 @deprecated |
| 1373 static const int DEFAULT_CACHE_SIZE = 64; | 1372 static const int DEFAULT_CACHE_SIZE = 64; |
| 1374 | 1373 |
| 1375 static const int ENABLE_LAZY_ASSIGNMENT_OPERATORS = 0x01; | |
| 1376 static const int ENABLE_STRICT_CALL_CHECKS_FLAG = 0x02; | |
| 1377 static const int ENABLE_STRONG_MODE_FLAG = 0x04; | |
| 1378 static const int ENABLE_STRONG_MODE_HINTS_FLAG = 0x08; | |
| 1379 static const int ENABLE_SUPER_MIXINS_FLAG = 0x10; | |
| 1380 | |
| 1381 /** | 1374 /** |
| 1382 * The default list of non-nullable type names. | 1375 * The default list of non-nullable type names. |
| 1383 */ | 1376 */ |
| 1384 static const List<String> NONNULLABLE_TYPES = const <String>[]; | 1377 static const List<String> NONNULLABLE_TYPES = const <String>[]; |
| 1385 | 1378 |
| 1386 /** | 1379 /** |
| 1387 * A predicate indicating whether analysis is to parse and analyze function | 1380 * A predicate indicating whether analysis is to parse and analyze function |
| 1388 * bodies. | 1381 * bodies. |
| 1389 */ | 1382 */ |
| 1390 AnalyzeFunctionBodiesPredicate _analyzeFunctionBodiesPredicate = | 1383 AnalyzeFunctionBodiesPredicate _analyzeFunctionBodiesPredicate = |
| 1391 _analyzeAllFunctionBodies; | 1384 _analyzeAllFunctionBodies; |
| 1392 | 1385 |
| 1386 /** |
| 1387 * The cached [signature]. |
| 1388 */ |
| 1389 Uint32List _signature; |
| 1390 |
| 1393 @override | 1391 @override |
| 1394 @deprecated | 1392 @deprecated |
| 1395 int cacheSize = 64; | 1393 int cacheSize = 64; |
| 1396 | 1394 |
| 1397 @override | 1395 @override |
| 1398 bool dart2jsHint = false; | 1396 bool dart2jsHint = false; |
| 1399 | 1397 |
| 1400 @override | 1398 @override |
| 1401 bool enableAssertInitializer = false; | 1399 bool enableAssertInitializer = false; |
| 1402 | 1400 |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 | 1638 |
| 1641 /** | 1639 /** |
| 1642 * Set the lint rules that are to be run in an analysis context if [lint] | 1640 * Set the lint rules that are to be run in an analysis context if [lint] |
| 1643 * returns `true`. | 1641 * returns `true`. |
| 1644 */ | 1642 */ |
| 1645 void set lintRules(List<Linter> rules) { | 1643 void set lintRules(List<Linter> rules) { |
| 1646 _lintRules = rules; | 1644 _lintRules = rules; |
| 1647 } | 1645 } |
| 1648 | 1646 |
| 1649 @override | 1647 @override |
| 1650 List<int> encodeCrossContextOptions() { | 1648 Uint32List get signature { |
| 1651 int flags = | 1649 if (_signature == null) { |
| 1652 (enableLazyAssignmentOperators ? ENABLE_LAZY_ASSIGNMENT_OPERATORS : 0) | | 1650 ApiSignature buffer = new ApiSignature(); |
| 1653 (enableStrictCallChecks ? ENABLE_STRICT_CALL_CHECKS_FLAG : 0) | | 1651 |
| 1654 (enableSuperMixins ? ENABLE_SUPER_MIXINS_FLAG : 0) | | 1652 // Append boolean flags. |
| 1655 (strongMode ? ENABLE_STRONG_MODE_FLAG : 0) | | 1653 buffer.addBool(enableLazyAssignmentOperators); |
| 1656 (strongModeHints ? ENABLE_STRONG_MODE_HINTS_FLAG : 0); | 1654 buffer.addBool(enableStrictCallChecks); |
| 1657 return <int>[flags]; | 1655 buffer.addBool(enableSuperMixins); |
| 1656 buffer.addBool(strongMode); |
| 1657 buffer.addBool(strongModeHints); |
| 1658 |
| 1659 // Append lints. |
| 1660 buffer.addInt(lintRules.length); |
| 1661 for (Linter lintRule in lintRules) { |
| 1662 buffer.addString(lintRule.lintCode.uniqueName); |
| 1663 } |
| 1664 |
| 1665 // Hash and convert to Uint32List. |
| 1666 List<int> bytes = buffer.toByteList(); |
| 1667 _signature = new Uint8List.fromList(bytes).buffer.asUint32List(); |
| 1668 } |
| 1669 return _signature; |
| 1658 } | 1670 } |
| 1659 | 1671 |
| 1660 @override | 1672 @override |
| 1661 void resetToDefaults() { | 1673 void resetToDefaults() { |
| 1662 dart2jsHint = false; | 1674 dart2jsHint = false; |
| 1663 disableCacheFlushing = false; | 1675 disableCacheFlushing = false; |
| 1664 enableAssertInitializer = false; | 1676 enableAssertInitializer = false; |
| 1665 enableLazyAssignmentOperators = false; | 1677 enableLazyAssignmentOperators = false; |
| 1666 enableStrictCallChecks = false; | 1678 enableStrictCallChecks = false; |
| 1667 enableSuperMixins = false; | 1679 enableSuperMixins = false; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1693 enableLazyAssignmentOperators = options.enableLazyAssignmentOperators; | 1705 enableLazyAssignmentOperators = options.enableLazyAssignmentOperators; |
| 1694 enableStrictCallChecks = options.enableStrictCallChecks; | 1706 enableStrictCallChecks = options.enableStrictCallChecks; |
| 1695 enableSuperMixins = options.enableSuperMixins; | 1707 enableSuperMixins = options.enableSuperMixins; |
| 1696 strongMode = options.strongMode; | 1708 strongMode = options.strongMode; |
| 1697 if (options is AnalysisOptionsImpl) { | 1709 if (options is AnalysisOptionsImpl) { |
| 1698 strongModeHints = options.strongModeHints; | 1710 strongModeHints = options.strongModeHints; |
| 1699 } | 1711 } |
| 1700 } | 1712 } |
| 1701 | 1713 |
| 1702 /** | 1714 /** |
| 1703 * Produce a human readable list of option names corresponding to the options | |
| 1704 * encoded in the given [encoding], presumably from invoking the method | |
| 1705 * [encodeCrossContextOptions]. | |
| 1706 */ | |
| 1707 static String decodeCrossContextOptions(List<int> encoding) { | |
| 1708 List<String> parts = []; | |
| 1709 int flags = encoding[0]; | |
| 1710 if (flags & ENABLE_LAZY_ASSIGNMENT_OPERATORS > 0) { | |
| 1711 parts.add('lazyAssignmentOperators'); | |
| 1712 } | |
| 1713 if (flags & ENABLE_STRICT_CALL_CHECKS_FLAG > 0) { | |
| 1714 parts.add('strictCallChecks'); | |
| 1715 } | |
| 1716 if (flags & ENABLE_SUPER_MIXINS_FLAG > 0) { | |
| 1717 parts.add('superMixins'); | |
| 1718 } | |
| 1719 if (flags & ENABLE_STRONG_MODE_FLAG > 0) { | |
| 1720 parts.add('strongMode'); | |
| 1721 } | |
| 1722 if (flags & ENABLE_STRONG_MODE_HINTS_FLAG > 0) { | |
| 1723 parts.add('strongModeHints'); | |
| 1724 } | |
| 1725 int patchPlatform = encoding[1]; | |
| 1726 if (patchPlatform != 0) { | |
| 1727 parts.add('patchPlatform=$patchPlatform'); | |
| 1728 } | |
| 1729 if (parts.isEmpty) { | |
| 1730 return 'none'; | |
| 1731 } else { | |
| 1732 return parts.join(', '); | |
| 1733 } | |
| 1734 } | |
| 1735 | |
| 1736 /** | |
| 1737 * Predicate used for [analyzeFunctionBodiesPredicate] when | 1715 * Predicate used for [analyzeFunctionBodiesPredicate] when |
| 1738 * [analyzeFunctionBodies] is set to `true`. | 1716 * [analyzeFunctionBodies] is set to `true`. |
| 1739 */ | 1717 */ |
| 1740 static bool _analyzeAllFunctionBodies(Source _) => true; | 1718 static bool _analyzeAllFunctionBodies(Source _) => true; |
| 1741 | 1719 |
| 1742 /** | 1720 /** |
| 1743 * Predicate used for [analyzeFunctionBodiesPredicate] when | 1721 * Predicate used for [analyzeFunctionBodiesPredicate] when |
| 1744 * [analyzeFunctionBodies] is set to `false`. | 1722 * [analyzeFunctionBodies] is set to `false`. |
| 1745 */ | 1723 */ |
| 1746 static bool _analyzeNoFunctionBodies(Source _) => false; | 1724 static bool _analyzeNoFunctionBodies(Source _) => false; |
| (...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2903 */ | 2881 */ |
| 2904 bool get wereSourcesAdded => _changeSet.addedSources.length > 0; | 2882 bool get wereSourcesAdded => _changeSet.addedSources.length > 0; |
| 2905 | 2883 |
| 2906 /** | 2884 /** |
| 2907 * Return `true` if any sources were removed or deleted. | 2885 * Return `true` if any sources were removed or deleted. |
| 2908 */ | 2886 */ |
| 2909 bool get wereSourcesRemoved => | 2887 bool get wereSourcesRemoved => |
| 2910 _changeSet.removedSources.length > 0 || | 2888 _changeSet.removedSources.length > 0 || |
| 2911 _changeSet.removedContainers.length > 0; | 2889 _changeSet.removedContainers.length > 0; |
| 2912 } | 2890 } |
| OLD | NEW |