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 engine; | 5 library engine; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:math' as math; | 9 import 'dart:math' as math; |
10 | 10 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 * source file is not scheduled to be analyzed within the context of the | 549 * source file is not scheduled to be analyzed within the context of the |
550 * given library. | 550 * given library. |
551 */ | 551 */ |
552 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( | 552 CancelableFuture<CompilationUnit> computeResolvedCompilationUnitAsync( |
553 Source source, Source librarySource); | 553 Source source, Source librarySource); |
554 | 554 |
555 /** | 555 /** |
556 * Perform work until the given [result] has been computed for the given | 556 * Perform work until the given [result] has been computed for the given |
557 * [target]. Return the computed value. | 557 * [target]. Return the computed value. |
558 */ | 558 */ |
559 Object /*V*/ computeResult(AnalysisTarget target, ResultDescriptor /*<V>*/ res
ult); | 559 Object /*V*/ computeResult( |
| 560 AnalysisTarget target, ResultDescriptor /*<V>*/ result); |
560 | 561 |
561 /** | 562 /** |
562 * Notifies the context that the client is going to stop using this context. | 563 * Notifies the context that the client is going to stop using this context. |
563 */ | 564 */ |
564 void dispose(); | 565 void dispose(); |
565 | 566 |
566 /** | 567 /** |
567 * Return `true` if the given [source] exists. | 568 * Return `true` if the given [source] exists. |
568 * | 569 * |
569 * This method should be used rather than the method [Source.exists] because | 570 * This method should be used rather than the method [Source.exists] because |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 */ | 723 */ |
723 @deprecated | 724 @deprecated |
724 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource); | 725 ht.HtmlUnit getResolvedHtmlUnit(Source htmlSource); |
725 | 726 |
726 /** | 727 /** |
727 * Return the value of the given [result] for the given [target]. | 728 * Return the value of the given [result] for the given [target]. |
728 * | 729 * |
729 * If the corresponding [target] does not exist, or the [result] is not | 730 * If the corresponding [target] does not exist, or the [result] is not |
730 * computed yet, then the default value is returned. | 731 * computed yet, then the default value is returned. |
731 */ | 732 */ |
732 Object /*V*/ getResult(AnalysisTarget target, ResultDescriptor /*<V>*/ result)
; | 733 Object /*V*/ getResult( |
| 734 AnalysisTarget target, ResultDescriptor /*<V>*/ result); |
733 | 735 |
734 /** | 736 /** |
735 * Return a list of the sources being analyzed in this context whose full path | 737 * Return a list of the sources being analyzed in this context whose full path |
736 * is equal to the given [path]. | 738 * is equal to the given [path]. |
737 */ | 739 */ |
738 List<Source> getSourcesWithFullName(String path); | 740 List<Source> getSourcesWithFullName(String path); |
739 | 741 |
740 /** | 742 /** |
741 * Invalidates hints in the given [librarySource] and included parts. | 743 * Invalidates hints in the given [librarySource] and included parts. |
742 */ | 744 */ |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 void set analysisOptions(AnalysisOptions options) { | 1126 void set analysisOptions(AnalysisOptions options) { |
1125 bool needsRecompute = this._options.analyzeFunctionBodiesPredicate != | 1127 bool needsRecompute = this._options.analyzeFunctionBodiesPredicate != |
1126 options.analyzeFunctionBodiesPredicate || | 1128 options.analyzeFunctionBodiesPredicate || |
1127 this._options.generateImplicitErrors != | 1129 this._options.generateImplicitErrors != |
1128 options.generateImplicitErrors || | 1130 options.generateImplicitErrors || |
1129 this._options.generateSdkErrors != options.generateSdkErrors || | 1131 this._options.generateSdkErrors != options.generateSdkErrors || |
1130 this._options.dart2jsHint != options.dart2jsHint || | 1132 this._options.dart2jsHint != options.dart2jsHint || |
1131 (this._options.hint && !options.hint) || | 1133 (this._options.hint && !options.hint) || |
1132 this._options.preserveComments != options.preserveComments || | 1134 this._options.preserveComments != options.preserveComments || |
1133 this._options.strongMode != options.strongMode || | 1135 this._options.strongMode != options.strongMode || |
| 1136 this._options.enableAssertMessage != options.enableAssertMessage || |
1134 this._options.enableStrictCallChecks != | 1137 this._options.enableStrictCallChecks != |
1135 options.enableStrictCallChecks || | 1138 options.enableStrictCallChecks || |
1136 this._options.enableSuperMixins != options.enableSuperMixins; | 1139 this._options.enableSuperMixins != options.enableSuperMixins; |
1137 int cacheSize = options.cacheSize; | 1140 int cacheSize = options.cacheSize; |
1138 if (this._options.cacheSize != cacheSize) { | 1141 if (this._options.cacheSize != cacheSize) { |
1139 this._options.cacheSize = cacheSize; | 1142 this._options.cacheSize = cacheSize; |
1140 //cache.setMaxCacheSize(cacheSize); | 1143 //cache.setMaxCacheSize(cacheSize); |
1141 _privatePartition.maxCacheSize = cacheSize; | 1144 _privatePartition.maxCacheSize = cacheSize; |
1142 // | 1145 // |
1143 // Cap the size of the priority list to being less than the cache size. | 1146 // Cap the size of the priority list to being less than the cache size. |
1144 // Failure to do so can result in an infinite loop in | 1147 // Failure to do so can result in an infinite loop in |
1145 // performAnalysisTask() because re-caching one AST structure | 1148 // performAnalysisTask() because re-caching one AST structure |
1146 // can cause another priority source's AST structure to be flushed. | 1149 // can cause another priority source's AST structure to be flushed. |
1147 // | 1150 // |
1148 // TODO(brianwilkerson) Remove this constraint when the new task model is | 1151 // TODO(brianwilkerson) Remove this constraint when the new task model is |
1149 // implemented. | 1152 // implemented. |
1150 // | 1153 // |
1151 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; | 1154 int maxPriorityOrderSize = cacheSize - _PRIORITY_ORDER_SIZE_DELTA; |
1152 if (_priorityOrder.length > maxPriorityOrderSize) { | 1155 if (_priorityOrder.length > maxPriorityOrderSize) { |
1153 _priorityOrder = _priorityOrder.sublist(0, maxPriorityOrderSize); | 1156 _priorityOrder = _priorityOrder.sublist(0, maxPriorityOrderSize); |
1154 } | 1157 } |
1155 } | 1158 } |
1156 this._options.analyzeFunctionBodiesPredicate = | 1159 this._options.analyzeFunctionBodiesPredicate = |
1157 options.analyzeFunctionBodiesPredicate; | 1160 options.analyzeFunctionBodiesPredicate; |
1158 this._options.generateImplicitErrors = options.generateImplicitErrors; | 1161 this._options.generateImplicitErrors = options.generateImplicitErrors; |
1159 this._options.generateSdkErrors = options.generateSdkErrors; | 1162 this._options.generateSdkErrors = options.generateSdkErrors; |
1160 this._options.dart2jsHint = options.dart2jsHint; | 1163 this._options.dart2jsHint = options.dart2jsHint; |
| 1164 this._options.enableAssertMessage = options.enableAssertMessage; |
1161 this._options.enableStrictCallChecks = options.enableStrictCallChecks; | 1165 this._options.enableStrictCallChecks = options.enableStrictCallChecks; |
1162 this._options.enableSuperMixins = options.enableSuperMixins; | 1166 this._options.enableSuperMixins = options.enableSuperMixins; |
1163 this._options.hint = options.hint; | 1167 this._options.hint = options.hint; |
1164 this._options.incremental = options.incremental; | 1168 this._options.incremental = options.incremental; |
1165 this._options.incrementalApi = options.incrementalApi; | 1169 this._options.incrementalApi = options.incrementalApi; |
1166 this._options.incrementalValidation = options.incrementalValidation; | 1170 this._options.incrementalValidation = options.incrementalValidation; |
1167 this._options.lint = options.lint; | 1171 this._options.lint = options.lint; |
1168 this._options.preserveComments = options.preserveComments; | 1172 this._options.preserveComments = options.preserveComments; |
1169 this._options.strongMode = options.strongMode; | 1173 this._options.strongMode = options.strongMode; |
1170 _generateImplicitErrors = options.generateImplicitErrors; | 1174 _generateImplicitErrors = options.generateImplicitErrors; |
(...skipping 5007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6178 * kept in the cache. | 6182 * kept in the cache. |
6179 */ | 6183 */ |
6180 int get cacheSize; | 6184 int get cacheSize; |
6181 | 6185 |
6182 /** | 6186 /** |
6183 * Return `true` if analysis is to generate dart2js related hint results. | 6187 * Return `true` if analysis is to generate dart2js related hint results. |
6184 */ | 6188 */ |
6185 bool get dart2jsHint; | 6189 bool get dart2jsHint; |
6186 | 6190 |
6187 /** | 6191 /** |
| 6192 * Return `true` to enable custom assert messages (DEP 37). |
| 6193 */ |
| 6194 bool get enableAssertMessage; |
| 6195 |
| 6196 /** |
6188 * Return `true` if analysis is to include the new async support. | 6197 * Return `true` if analysis is to include the new async support. |
6189 */ | 6198 */ |
6190 @deprecated // Always true | 6199 @deprecated // Always true |
6191 bool get enableAsync; | 6200 bool get enableAsync; |
6192 | 6201 |
6193 /** | 6202 /** |
6194 * Return `true` if analysis is to include the new deferred loading support. | 6203 * Return `true` if analysis is to include the new deferred loading support. |
6195 */ | 6204 */ |
6196 @deprecated // Always true | 6205 @deprecated // Always true |
6197 bool get enableDeferredLoading; | 6206 bool get enableDeferredLoading; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6311 */ | 6320 */ |
6312 int cacheSize = DEFAULT_CACHE_SIZE; | 6321 int cacheSize = DEFAULT_CACHE_SIZE; |
6313 | 6322 |
6314 /** | 6323 /** |
6315 * A flag indicating whether analysis is to generate dart2js related hint | 6324 * A flag indicating whether analysis is to generate dart2js related hint |
6316 * results. | 6325 * results. |
6317 */ | 6326 */ |
6318 bool dart2jsHint = false; | 6327 bool dart2jsHint = false; |
6319 | 6328 |
6320 /** | 6329 /** |
| 6330 * A flag indicating whether custom assert messages are to be supported (DEP |
| 6331 * 37). |
| 6332 */ |
| 6333 bool enableAssertMessage = false; |
| 6334 |
| 6335 /** |
6321 * A flag indicating whether generic methods are to be supported (DEP 22). | 6336 * A flag indicating whether generic methods are to be supported (DEP 22). |
6322 */ | 6337 */ |
6323 bool enableGenericMethods = false; | 6338 bool enableGenericMethods = false; |
6324 | 6339 |
6325 /** | 6340 /** |
6326 * A flag indicating whether analysis is to strictly follow the specification | 6341 * A flag indicating whether analysis is to strictly follow the specification |
6327 * when generating warnings on "call" methods (fixes dartbug.com/21938). | 6342 * when generating warnings on "call" methods (fixes dartbug.com/21938). |
6328 */ | 6343 */ |
6329 bool enableStrictCallChecks = false; | 6344 bool enableStrictCallChecks = false; |
6330 | 6345 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6392 | 6407 |
6393 /** | 6408 /** |
6394 * Initialize a newly created set of analysis options to have the same values | 6409 * Initialize a newly created set of analysis options to have the same values |
6395 * as those in the given set of analysis [options]. | 6410 * as those in the given set of analysis [options]. |
6396 */ | 6411 */ |
6397 @deprecated // Use new AnalysisOptionsImpl.from(options) | 6412 @deprecated // Use new AnalysisOptionsImpl.from(options) |
6398 AnalysisOptionsImpl.con1(AnalysisOptions options) { | 6413 AnalysisOptionsImpl.con1(AnalysisOptions options) { |
6399 analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; | 6414 analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; |
6400 cacheSize = options.cacheSize; | 6415 cacheSize = options.cacheSize; |
6401 dart2jsHint = options.dart2jsHint; | 6416 dart2jsHint = options.dart2jsHint; |
| 6417 enableAssertMessage = options.enableAssertMessage; |
6402 enableStrictCallChecks = options.enableStrictCallChecks; | 6418 enableStrictCallChecks = options.enableStrictCallChecks; |
6403 enableSuperMixins = options.enableSuperMixins; | 6419 enableSuperMixins = options.enableSuperMixins; |
6404 generateImplicitErrors = options.generateImplicitErrors; | 6420 generateImplicitErrors = options.generateImplicitErrors; |
6405 generateSdkErrors = options.generateSdkErrors; | 6421 generateSdkErrors = options.generateSdkErrors; |
6406 hint = options.hint; | 6422 hint = options.hint; |
6407 incremental = options.incremental; | 6423 incremental = options.incremental; |
6408 incrementalApi = options.incrementalApi; | 6424 incrementalApi = options.incrementalApi; |
6409 incrementalValidation = options.incrementalValidation; | 6425 incrementalValidation = options.incrementalValidation; |
6410 lint = options.lint; | 6426 lint = options.lint; |
6411 preserveComments = options.preserveComments; | 6427 preserveComments = options.preserveComments; |
6412 strongMode = options.strongMode; | 6428 strongMode = options.strongMode; |
6413 } | 6429 } |
6414 | 6430 |
6415 /** | 6431 /** |
6416 * Initialize a newly created set of analysis options to have the same values | 6432 * Initialize a newly created set of analysis options to have the same values |
6417 * as those in the given set of analysis [options]. | 6433 * as those in the given set of analysis [options]. |
6418 */ | 6434 */ |
6419 AnalysisOptionsImpl.from(AnalysisOptions options) { | 6435 AnalysisOptionsImpl.from(AnalysisOptions options) { |
6420 analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; | 6436 analyzeFunctionBodiesPredicate = options.analyzeFunctionBodiesPredicate; |
6421 cacheSize = options.cacheSize; | 6437 cacheSize = options.cacheSize; |
6422 dart2jsHint = options.dart2jsHint; | 6438 dart2jsHint = options.dart2jsHint; |
| 6439 enableAssertMessage = options.enableAssertMessage; |
6423 enableStrictCallChecks = options.enableStrictCallChecks; | 6440 enableStrictCallChecks = options.enableStrictCallChecks; |
6424 enableSuperMixins = options.enableSuperMixins; | 6441 enableSuperMixins = options.enableSuperMixins; |
6425 generateImplicitErrors = options.generateImplicitErrors; | 6442 generateImplicitErrors = options.generateImplicitErrors; |
6426 generateSdkErrors = options.generateSdkErrors; | 6443 generateSdkErrors = options.generateSdkErrors; |
6427 hint = options.hint; | 6444 hint = options.hint; |
6428 incremental = options.incremental; | 6445 incremental = options.incremental; |
6429 incrementalApi = options.incrementalApi; | 6446 incrementalApi = options.incrementalApi; |
6430 incrementalValidation = options.incrementalValidation; | 6447 incrementalValidation = options.incrementalValidation; |
6431 lint = options.lint; | 6448 lint = options.lint; |
6432 preserveComments = options.preserveComments; | 6449 preserveComments = options.preserveComments; |
(...skipping 2848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9281 BooleanErrorListener errorListener = new BooleanErrorListener(); | 9298 BooleanErrorListener errorListener = new BooleanErrorListener(); |
9282 IncrementalScanner scanner = new IncrementalScanner( | 9299 IncrementalScanner scanner = new IncrementalScanner( |
9283 cache.source, reader, errorListener, context.analysisOptions); | 9300 cache.source, reader, errorListener, context.analysisOptions); |
9284 scanner.rescan(cache.resolvedUnit.beginToken, cache.offset, cache.oldLength, | 9301 scanner.rescan(cache.resolvedUnit.beginToken, cache.offset, cache.oldLength, |
9285 cache.newLength); | 9302 cache.newLength); |
9286 if (errorListener.errorReported) { | 9303 if (errorListener.errorReported) { |
9287 return; | 9304 return; |
9288 } | 9305 } |
9289 // Produce an updated AST | 9306 // Produce an updated AST |
9290 IncrementalParser parser = new IncrementalParser( | 9307 IncrementalParser parser = new IncrementalParser( |
9291 cache.source, scanner.tokenMap, AnalysisErrorListener.NULL_LISTENER); | 9308 cache.source, scanner.tokenMap, AnalysisErrorListener.NULL_LISTENER, |
| 9309 enableAssertMessage: context.analysisOptions.enableAssertMessage); |
9292 _updatedUnit = parser.reparse(cache.resolvedUnit, scanner.leftToken, | 9310 _updatedUnit = parser.reparse(cache.resolvedUnit, scanner.leftToken, |
9293 scanner.rightToken, cache.offset, cache.offset + cache.oldLength); | 9311 scanner.rightToken, cache.offset, cache.offset + cache.oldLength); |
9294 // Update the resolution | 9312 // Update the resolution |
9295 TypeProvider typeProvider = this.typeProvider; | 9313 TypeProvider typeProvider = this.typeProvider; |
9296 if (_updatedUnit != null && typeProvider != null) { | 9314 if (_updatedUnit != null && typeProvider != null) { |
9297 CompilationUnitElement element = _updatedUnit.element; | 9315 CompilationUnitElement element = _updatedUnit.element; |
9298 if (element != null) { | 9316 if (element != null) { |
9299 LibraryElement library = element.library; | 9317 LibraryElement library = element.library; |
9300 if (library != null) { | 9318 if (library != null) { |
9301 IncrementalResolver resolver = new IncrementalResolver(null, null, | 9319 IncrementalResolver resolver = new IncrementalResolver(null, null, |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9711 @override | 9729 @override |
9712 accept(AnalysisTaskVisitor visitor) => visitor.visitParseDartTask(this); | 9730 accept(AnalysisTaskVisitor visitor) => visitor.visitParseDartTask(this); |
9713 | 9731 |
9714 @override | 9732 @override |
9715 void internalPerform() { | 9733 void internalPerform() { |
9716 // | 9734 // |
9717 // Then parse the token stream. | 9735 // Then parse the token stream. |
9718 // | 9736 // |
9719 PerformanceStatistics.parse.makeCurrentWhile(() { | 9737 PerformanceStatistics.parse.makeCurrentWhile(() { |
9720 RecordingErrorListener errorListener = new RecordingErrorListener(); | 9738 RecordingErrorListener errorListener = new RecordingErrorListener(); |
9721 Parser parser = new Parser(source, errorListener); | 9739 Parser parser = new Parser(source, errorListener, |
| 9740 enableAssertMessage: context.analysisOptions.enableAssertMessage); |
9722 AnalysisOptions options = context.analysisOptions; | 9741 AnalysisOptions options = context.analysisOptions; |
9723 parser.parseFunctionBodies = | 9742 parser.parseFunctionBodies = |
9724 options.analyzeFunctionBodiesPredicate(source); | 9743 options.analyzeFunctionBodiesPredicate(source); |
9725 parser.parseGenericMethods = options.enableGenericMethods; | 9744 parser.parseGenericMethods = options.enableGenericMethods; |
9726 _unit = parser.parseCompilationUnit(_tokenStream); | 9745 _unit = parser.parseCompilationUnit(_tokenStream); |
9727 _unit.lineInfo = lineInfo; | 9746 _unit.lineInfo = lineInfo; |
9728 AnalysisContext analysisContext = context; | 9747 AnalysisContext analysisContext = context; |
9729 for (Directive directive in _unit.directives) { | 9748 for (Directive directive in _unit.directives) { |
9730 if (directive is PartOfDirective) { | 9749 if (directive is PartOfDirective) { |
9731 _containsPartOfDirective = true; | 9750 _containsPartOfDirective = true; |
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12017 PendingFuture pendingFuture = | 12036 PendingFuture pendingFuture = |
12018 new PendingFuture<T>(_context, source, computeValue); | 12037 new PendingFuture<T>(_context, source, computeValue); |
12019 if (!pendingFuture.evaluate(sourceEntry)) { | 12038 if (!pendingFuture.evaluate(sourceEntry)) { |
12020 _context._pendingFutureSources | 12039 _context._pendingFutureSources |
12021 .putIfAbsent(source, () => <PendingFuture>[]) | 12040 .putIfAbsent(source, () => <PendingFuture>[]) |
12022 .add(pendingFuture); | 12041 .add(pendingFuture); |
12023 } | 12042 } |
12024 return pendingFuture.future; | 12043 return pendingFuture.future; |
12025 } | 12044 } |
12026 } | 12045 } |
OLD | NEW |