| 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.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import "dart:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 * unit. | 794 * unit. |
| 795 */ | 795 */ |
| 796 class CompilationUnitBuilder { | 796 class CompilationUnitBuilder { |
| 797 /** | 797 /** |
| 798 * Build the compilation unit element for the given [source] based on the | 798 * Build the compilation unit element for the given [source] based on the |
| 799 * compilation [unit] associated with the source. Throw an AnalysisException | 799 * compilation [unit] associated with the source. Throw an AnalysisException |
| 800 * if the element could not be built. | 800 * if the element could not be built. |
| 801 */ | 801 */ |
| 802 CompilationUnitElementImpl buildCompilationUnit(Source source, | 802 CompilationUnitElementImpl buildCompilationUnit(Source source, |
| 803 CompilationUnit unit) { | 803 CompilationUnit unit) { |
| 804 TimeCounter_TimeCounterHandle timeCounter = | 804 PerformanceTag prevTag = PerformanceStatistics.resolve.makeCurrent(); |
| 805 PerformanceStatistics.resolve.start(); | |
| 806 try { | 805 try { |
| 807 if (unit == null) { | 806 if (unit == null) { |
| 808 return null; | 807 return null; |
| 809 } | 808 } |
| 810 ElementHolder holder = new ElementHolder(); | 809 ElementHolder holder = new ElementHolder(); |
| 811 ElementBuilder builder = new ElementBuilder(holder); | 810 ElementBuilder builder = new ElementBuilder(holder); |
| 812 unit.accept(builder); | 811 unit.accept(builder); |
| 813 CompilationUnitElementImpl element = | 812 CompilationUnitElementImpl element = |
| 814 new CompilationUnitElementImpl(source.shortName); | 813 new CompilationUnitElementImpl(source.shortName); |
| 815 element.accessors = holder.accessors; | 814 element.accessors = holder.accessors; |
| 816 element.enums = holder.enums; | 815 element.enums = holder.enums; |
| 817 element.functions = holder.functions; | 816 element.functions = holder.functions; |
| 818 element.source = source; | 817 element.source = source; |
| 819 element.typeAliases = holder.typeAliases; | 818 element.typeAliases = holder.typeAliases; |
| 820 element.types = holder.types; | 819 element.types = holder.types; |
| 821 element.topLevelVariables = holder.topLevelVariables; | 820 element.topLevelVariables = holder.topLevelVariables; |
| 822 unit.element = element; | 821 unit.element = element; |
| 823 holder.validate(); | 822 holder.validate(); |
| 824 return element; | 823 return element; |
| 825 } finally { | 824 } finally { |
| 826 timeCounter.stop(); | 825 prevTag.makeCurrent(); |
| 827 } | 826 } |
| 828 } | 827 } |
| 829 } | 828 } |
| 830 | 829 |
| 831 /** | 830 /** |
| 832 * Instances of the class `ConstantVerifier` traverse an AST structure looking f
or additional | 831 * Instances of the class `ConstantVerifier` traverse an AST structure looking f
or additional |
| 833 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors | 832 * errors and warnings not covered by the parser and resolver. In particular, it
looks for errors |
| 834 * and warnings related to constant expressions. | 833 * and warnings related to constant expressions. |
| 835 */ | 834 */ |
| 836 class ConstantVerifier extends RecursiveAstVisitor<Object> { | 835 class ConstantVerifier extends RecursiveAstVisitor<Object> { |
| (...skipping 3617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4454 | 4453 |
| 4455 HintGenerator(this._compilationUnits, this._context, this._errorListener) { | 4454 HintGenerator(this._compilationUnits, this._context, this._errorListener) { |
| 4456 _library = _compilationUnits[0].element.library; | 4455 _library = _compilationUnits[0].element.library; |
| 4457 _importsVerifier = new ImportsVerifier(_library); | 4456 _importsVerifier = new ImportsVerifier(_library); |
| 4458 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; | 4457 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; |
| 4459 _manager = new InheritanceManager(_compilationUnits[0].element.library); | 4458 _manager = new InheritanceManager(_compilationUnits[0].element.library); |
| 4460 _usedElementsVisitor = new _GatherUsedElementsVisitor(_library); | 4459 _usedElementsVisitor = new _GatherUsedElementsVisitor(_library); |
| 4461 } | 4460 } |
| 4462 | 4461 |
| 4463 void generateForLibrary() { | 4462 void generateForLibrary() { |
| 4464 TimeCounter_TimeCounterHandle timeCounter = | 4463 PerformanceTag prevTag = PerformanceStatistics.hints.makeCurrent(); |
| 4465 PerformanceStatistics.hints.start(); | |
| 4466 try { | 4464 try { |
| 4467 for (int i = 0; i < _compilationUnits.length; i++) { | 4465 for (int i = 0; i < _compilationUnits.length; i++) { |
| 4468 CompilationUnitElement element = _compilationUnits[i].element; | 4466 CompilationUnitElement element = _compilationUnits[i].element; |
| 4469 if (element != null) { | 4467 if (element != null) { |
| 4470 if (i == 0) { | 4468 if (i == 0) { |
| 4471 _importsVerifier.inDefiningCompilationUnit = true; | 4469 _importsVerifier.inDefiningCompilationUnit = true; |
| 4472 _generateForCompilationUnit(_compilationUnits[i], element.source); | 4470 _generateForCompilationUnit(_compilationUnits[i], element.source); |
| 4473 _importsVerifier.inDefiningCompilationUnit = false; | 4471 _importsVerifier.inDefiningCompilationUnit = false; |
| 4474 } else { | 4472 } else { |
| 4475 _generateForCompilationUnit(_compilationUnits[i], element.source); | 4473 _generateForCompilationUnit(_compilationUnits[i], element.source); |
| 4476 } | 4474 } |
| 4477 } | 4475 } |
| 4478 } | 4476 } |
| 4479 ErrorReporter definingCompilationUnitErrorReporter = | 4477 ErrorReporter definingCompilationUnitErrorReporter = |
| 4480 new ErrorReporter(_errorListener, _compilationUnits[0].element.source)
; | 4478 new ErrorReporter(_errorListener, _compilationUnits[0].element.source)
; |
| 4481 _importsVerifier.generateDuplicateImportHints( | 4479 _importsVerifier.generateDuplicateImportHints( |
| 4482 definingCompilationUnitErrorReporter); | 4480 definingCompilationUnitErrorReporter); |
| 4483 _importsVerifier.generateUnusedImportHints( | 4481 _importsVerifier.generateUnusedImportHints( |
| 4484 definingCompilationUnitErrorReporter); | 4482 definingCompilationUnitErrorReporter); |
| 4485 _library.accept( | 4483 _library.accept( |
| 4486 new _UnusedElementsVerifier(_errorListener, _usedElementsVisitor.usedE
lements)); | 4484 new _UnusedElementsVerifier(_errorListener, _usedElementsVisitor.usedE
lements)); |
| 4487 } finally { | 4485 } finally { |
| 4488 timeCounter.stop(); | 4486 prevTag.makeCurrent(); |
| 4489 } | 4487 } |
| 4490 } | 4488 } |
| 4491 | 4489 |
| 4492 void _generateForCompilationUnit(CompilationUnit unit, Source source) { | 4490 void _generateForCompilationUnit(CompilationUnit unit, Source source) { |
| 4493 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); | 4491 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); |
| 4494 unit.accept(_importsVerifier); | 4492 unit.accept(_importsVerifier); |
| 4495 // dead code analysis | 4493 // dead code analysis |
| 4496 unit.accept(new DeadCodeVerifier(errorReporter)); | 4494 unit.accept(new DeadCodeVerifier(errorReporter)); |
| 4497 unit.accept(_usedElementsVisitor); | 4495 unit.accept(_usedElementsVisitor); |
| 4498 // dart2js analysis | 4496 // dart2js analysis |
| (...skipping 3735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8234 } | 8232 } |
| 8235 | 8233 |
| 8236 /** | 8234 /** |
| 8237 * Build the members in enum declarations. This cannot be done while building
the rest of the | 8235 * Build the members in enum declarations. This cannot be done while building
the rest of the |
| 8238 * element model because it depends on being able to access core types, which
cannot happen until | 8236 * element model because it depends on being able to access core types, which
cannot happen until |
| 8239 * the rest of the element model has been built (when resolving the core libra
ry). | 8237 * the rest of the element model has been built (when resolving the core libra
ry). |
| 8240 * | 8238 * |
| 8241 * @throws AnalysisException if any of the enum members could not be built | 8239 * @throws AnalysisException if any of the enum members could not be built |
| 8242 */ | 8240 */ |
| 8243 void _buildEnumMembers() { | 8241 void _buildEnumMembers() { |
| 8244 TimeCounter_TimeCounterHandle timeCounter = | 8242 PerformanceTag prevTag = |
| 8245 PerformanceStatistics.resolve.start(); | 8243 PerformanceStatistics.resolve.makeCurrent(); |
| 8246 try { | 8244 try { |
| 8247 for (Library library in _librariesInCycles) { | 8245 for (Library library in _librariesInCycles) { |
| 8248 for (Source source in library.compilationUnitSources) { | 8246 for (Source source in library.compilationUnitSources) { |
| 8249 EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider); | 8247 EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider); |
| 8250 library.getAST(source).accept(builder); | 8248 library.getAST(source).accept(builder); |
| 8251 } | 8249 } |
| 8252 } | 8250 } |
| 8253 } finally { | 8251 } finally { |
| 8254 timeCounter.stop(); | 8252 prevTag.makeCurrent(); |
| 8255 } | 8253 } |
| 8256 } | 8254 } |
| 8257 | 8255 |
| 8258 /** | 8256 /** |
| 8259 * Finish steps that the [buildTypeHierarchies] could not perform, see | 8257 * Finish steps that the [buildTypeHierarchies] could not perform, see |
| 8260 * [ImplicitConstructorBuilder]. | 8258 * [ImplicitConstructorBuilder]. |
| 8261 * | 8259 * |
| 8262 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 8260 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 8263 */ | 8261 */ |
| 8264 void _buildImplicitConstructors() { | 8262 void _buildImplicitConstructors() { |
| 8265 TimeCounter_TimeCounterHandle timeCounter = | 8263 PerformanceTag prevTag= |
| 8266 PerformanceStatistics.resolve.start(); | 8264 PerformanceStatistics.resolve.makeCurrent(); |
| 8267 try { | 8265 try { |
| 8268 ImplicitConstructorComputer computer = | 8266 ImplicitConstructorComputer computer = |
| 8269 new ImplicitConstructorComputer(_typeProvider); | 8267 new ImplicitConstructorComputer(_typeProvider); |
| 8270 for (Library library in _librariesInCycles) { | 8268 for (Library library in _librariesInCycles) { |
| 8271 for (Source source in library.compilationUnitSources) { | 8269 for (Source source in library.compilationUnitSources) { |
| 8272 computer.add( | 8270 computer.add( |
| 8273 library.getAST(source), | 8271 library.getAST(source), |
| 8274 source, | 8272 source, |
| 8275 library.libraryElement, | 8273 library.libraryElement, |
| 8276 library.libraryScope); | 8274 library.libraryScope); |
| 8277 } | 8275 } |
| 8278 } | 8276 } |
| 8279 computer.compute(); | 8277 computer.compute(); |
| 8280 } finally { | 8278 } finally { |
| 8281 timeCounter.stop(); | 8279 prevTag.makeCurrent(); |
| 8282 } | 8280 } |
| 8283 } | 8281 } |
| 8284 | 8282 |
| 8285 /** | 8283 /** |
| 8286 * Resolve the types referenced by function type aliases across all of the fun
ction type aliases | 8284 * Resolve the types referenced by function type aliases across all of the fun
ction type aliases |
| 8287 * defined in the current cycle. | 8285 * defined in the current cycle. |
| 8288 * | 8286 * |
| 8289 * @throws AnalysisException if any of the function type aliases could not be
resolved | 8287 * @throws AnalysisException if any of the function type aliases could not be
resolved |
| 8290 */ | 8288 */ |
| 8291 void _buildTypeAliases() { | 8289 void _buildTypeAliases() { |
| 8292 TimeCounter_TimeCounterHandle timeCounter = | 8290 PerformanceTag prevTag = |
| 8293 PerformanceStatistics.resolve.start(); | 8291 PerformanceStatistics.resolve.makeCurrent(); |
| 8294 try { | 8292 try { |
| 8295 List<LibraryResolver_TypeAliasInfo> typeAliases = | 8293 List<LibraryResolver_TypeAliasInfo> typeAliases = |
| 8296 new List<LibraryResolver_TypeAliasInfo>(); | 8294 new List<LibraryResolver_TypeAliasInfo>(); |
| 8297 for (Library library in _librariesInCycles) { | 8295 for (Library library in _librariesInCycles) { |
| 8298 for (Source source in library.compilationUnitSources) { | 8296 for (Source source in library.compilationUnitSources) { |
| 8299 CompilationUnit ast = library.getAST(source); | 8297 CompilationUnit ast = library.getAST(source); |
| 8300 for (CompilationUnitMember member in ast.declarations) { | 8298 for (CompilationUnitMember member in ast.declarations) { |
| 8301 if (member is FunctionTypeAlias) { | 8299 if (member is FunctionTypeAlias) { |
| 8302 typeAliases.add( | 8300 typeAliases.add( |
| 8303 new LibraryResolver_TypeAliasInfo(library, source, member)); | 8301 new LibraryResolver_TypeAliasInfo(library, source, member)); |
| 8304 } | 8302 } |
| 8305 } | 8303 } |
| 8306 } | 8304 } |
| 8307 } | 8305 } |
| 8308 // TODO(brianwilkerson) We need to sort the type aliases such that all | 8306 // TODO(brianwilkerson) We need to sort the type aliases such that all |
| 8309 // aliases referenced by an alias T are resolved before we resolve T. | 8307 // aliases referenced by an alias T are resolved before we resolve T. |
| 8310 for (LibraryResolver_TypeAliasInfo info in typeAliases) { | 8308 for (LibraryResolver_TypeAliasInfo info in typeAliases) { |
| 8311 TypeResolverVisitor visitor = | 8309 TypeResolverVisitor visitor = |
| 8312 new TypeResolverVisitor.con1(info._library, info._source, _typeProvi
der); | 8310 new TypeResolverVisitor.con1(info._library, info._source, _typeProvi
der); |
| 8313 info._typeAlias.accept(visitor); | 8311 info._typeAlias.accept(visitor); |
| 8314 } | 8312 } |
| 8315 } finally { | 8313 } finally { |
| 8316 timeCounter.stop(); | 8314 prevTag.makeCurrent(); |
| 8317 } | 8315 } |
| 8318 } | 8316 } |
| 8319 | 8317 |
| 8320 /** | 8318 /** |
| 8321 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 8319 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
| 8322 * cycle. | 8320 * cycle. |
| 8323 * | 8321 * |
| 8324 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 8322 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 8325 */ | 8323 */ |
| 8326 void _buildTypeHierarchies() { | 8324 void _buildTypeHierarchies() { |
| 8327 TimeCounter_TimeCounterHandle timeCounter = | 8325 PerformanceTag prevTag = |
| 8328 PerformanceStatistics.resolve.start(); | 8326 PerformanceStatistics.resolve.makeCurrent(); |
| 8329 try { | 8327 try { |
| 8330 for (Library library in _librariesInCycles) { | 8328 for (Library library in _librariesInCycles) { |
| 8331 for (Source source in library.compilationUnitSources) { | 8329 for (Source source in library.compilationUnitSources) { |
| 8332 TypeResolverVisitor visitor = | 8330 TypeResolverVisitor visitor = |
| 8333 new TypeResolverVisitor.con1(library, source, _typeProvider); | 8331 new TypeResolverVisitor.con1(library, source, _typeProvider); |
| 8334 library.getAST(source).accept(visitor); | 8332 library.getAST(source).accept(visitor); |
| 8335 } | 8333 } |
| 8336 } | 8334 } |
| 8337 } finally { | 8335 } finally { |
| 8338 timeCounter.stop(); | 8336 prevTag.makeCurrent(); |
| 8339 } | 8337 } |
| 8340 } | 8338 } |
| 8341 | 8339 |
| 8342 /** | 8340 /** |
| 8343 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a | 8341 * Compute a dependency map of libraries reachable from the given library. A d
ependency map is a |
| 8344 * table that maps individual libraries to a list of the libraries that either
import or export | 8342 * table that maps individual libraries to a list of the libraries that either
import or export |
| 8345 * those libraries. | 8343 * those libraries. |
| 8346 * | 8344 * |
| 8347 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root | 8345 * This map is used to compute all of the libraries involved in a cycle that i
nclude the root |
| 8348 * library. Given that we only add libraries that are reachable from the root
library, when we | 8346 * library. Given that we only add libraries that are reachable from the root
library, when we |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8534 for (int i = 0; i < count; i++) { | 8532 for (int i = 0; i < count; i++) { |
| 8535 identifiers[i] = names[i].name; | 8533 identifiers[i] = names[i].name; |
| 8536 } | 8534 } |
| 8537 return identifiers; | 8535 return identifiers; |
| 8538 } | 8536 } |
| 8539 | 8537 |
| 8540 /** | 8538 /** |
| 8541 * Compute a value for all of the constants in the libraries being analyzed. | 8539 * Compute a value for all of the constants in the libraries being analyzed. |
| 8542 */ | 8540 */ |
| 8543 void _performConstantEvaluation() { | 8541 void _performConstantEvaluation() { |
| 8544 TimeCounter_TimeCounterHandle timeCounter = | 8542 PerformanceTag prevTag = |
| 8545 PerformanceStatistics.resolve.start(); | 8543 PerformanceStatistics.resolve.makeCurrent(); |
| 8546 try { | 8544 try { |
| 8547 ConstantValueComputer computer = | 8545 ConstantValueComputer computer = |
| 8548 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria
bles); | 8546 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria
bles); |
| 8549 for (Library library in _librariesInCycles) { | 8547 for (Library library in _librariesInCycles) { |
| 8550 for (Source source in library.compilationUnitSources) { | 8548 for (Source source in library.compilationUnitSources) { |
| 8551 try { | 8549 try { |
| 8552 CompilationUnit unit = library.getAST(source); | 8550 CompilationUnit unit = library.getAST(source); |
| 8553 if (unit != null) { | 8551 if (unit != null) { |
| 8554 computer.add(unit); | 8552 computer.add(unit); |
| 8555 } | 8553 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 8574 unit.accept(constantVerifier); | 8572 unit.accept(constantVerifier); |
| 8575 } on AnalysisException catch (exception, stackTrace) { | 8573 } on AnalysisException catch (exception, stackTrace) { |
| 8576 AnalysisEngine.instance.logger.logError( | 8574 AnalysisEngine.instance.logger.logError( |
| 8577 "Internal Error: Could not access AST for ${source.fullName} " | 8575 "Internal Error: Could not access AST for ${source.fullName} " |
| 8578 "during constant verification", | 8576 "during constant verification", |
| 8579 new CaughtException(exception, stackTrace)); | 8577 new CaughtException(exception, stackTrace)); |
| 8580 } | 8578 } |
| 8581 } | 8579 } |
| 8582 } | 8580 } |
| 8583 } finally { | 8581 } finally { |
| 8584 timeCounter.stop(); | 8582 prevTag.makeCurrent(); |
| 8585 } | 8583 } |
| 8586 } | 8584 } |
| 8587 | 8585 |
| 8588 /** | 8586 /** |
| 8589 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 8587 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 8590 * | 8588 * |
| 8591 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | 8589 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
| 8592 * libraries could not have their types analyzed | 8590 * libraries could not have their types analyzed |
| 8593 */ | 8591 */ |
| 8594 void _resolveReferencesAndTypes() { | 8592 void _resolveReferencesAndTypes() { |
| 8595 for (Library library in _librariesInCycles) { | 8593 for (Library library in _librariesInCycles) { |
| 8596 _resolveReferencesAndTypesInLibrary(library); | 8594 _resolveReferencesAndTypesInLibrary(library); |
| 8597 } | 8595 } |
| 8598 } | 8596 } |
| 8599 | 8597 |
| 8600 /** | 8598 /** |
| 8601 * Resolve the identifiers and perform type analysis in the given library. | 8599 * Resolve the identifiers and perform type analysis in the given library. |
| 8602 * | 8600 * |
| 8603 * @param library the library to be resolved | 8601 * @param library the library to be resolved |
| 8604 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 8602 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 8605 * the library cannot be analyzed | 8603 * the library cannot be analyzed |
| 8606 */ | 8604 */ |
| 8607 void _resolveReferencesAndTypesInLibrary(Library library) { | 8605 void _resolveReferencesAndTypesInLibrary(Library library) { |
| 8608 TimeCounter_TimeCounterHandle timeCounter = | 8606 PerformanceTag prevTag = |
| 8609 PerformanceStatistics.resolve.start(); | 8607 PerformanceStatistics.resolve.makeCurrent(); |
| 8610 try { | 8608 try { |
| 8611 for (Source source in library.compilationUnitSources) { | 8609 for (Source source in library.compilationUnitSources) { |
| 8612 CompilationUnit ast = library.getAST(source); | 8610 CompilationUnit ast = library.getAST(source); |
| 8613 ast.accept( | 8611 ast.accept( |
| 8614 new VariableResolverVisitor.con1(library, source, _typeProvider)); | 8612 new VariableResolverVisitor.con1(library, source, _typeProvider)); |
| 8615 ResolverVisitor visitor = | 8613 ResolverVisitor visitor = |
| 8616 new ResolverVisitor.con1(library, source, _typeProvider); | 8614 new ResolverVisitor.con1(library, source, _typeProvider); |
| 8617 ast.accept(visitor); | 8615 ast.accept(visitor); |
| 8618 } | 8616 } |
| 8619 } finally { | 8617 } finally { |
| 8620 timeCounter.stop(); | 8618 prevTag.makeCurrent(); |
| 8621 } | 8619 } |
| 8622 } | 8620 } |
| 8623 | 8621 |
| 8624 /** | 8622 /** |
| 8625 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the | 8623 * Return the result of resolving the URI of the given URI-based directive aga
inst the URI of the |
| 8626 * given library, or `null` if the URI is not valid. | 8624 * given library, or `null` if the URI is not valid. |
| 8627 * | 8625 * |
| 8628 * @param librarySource the source representing the library containing the dir
ective | 8626 * @param librarySource the source representing the library containing the dir
ective |
| 8629 * @param directive the directive which URI should be resolved | 8627 * @param directive the directive which URI should be resolved |
| 8630 * @return the result of resolving the URI against the URI of the library | 8628 * @return the result of resolving the URI against the URI of the library |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8969 } | 8967 } |
| 8970 | 8968 |
| 8971 /** | 8969 /** |
| 8972 * Build the members in enum declarations. This cannot be done while building
the rest of the | 8970 * Build the members in enum declarations. This cannot be done while building
the rest of the |
| 8973 * element model because it depends on being able to access core types, which
cannot happen until | 8971 * element model because it depends on being able to access core types, which
cannot happen until |
| 8974 * the rest of the element model has been built (when resolving the core libra
ry). | 8972 * the rest of the element model has been built (when resolving the core libra
ry). |
| 8975 * | 8973 * |
| 8976 * @throws AnalysisException if any of the enum members could not be built | 8974 * @throws AnalysisException if any of the enum members could not be built |
| 8977 */ | 8975 */ |
| 8978 void _buildEnumMembers() { | 8976 void _buildEnumMembers() { |
| 8979 TimeCounter_TimeCounterHandle timeCounter = | 8977 PerformanceTag prevTag = |
| 8980 PerformanceStatistics.resolve.start(); | 8978 PerformanceStatistics.resolve.makeCurrent(); |
| 8981 try { | 8979 try { |
| 8982 for (ResolvableLibrary library in _librariesInCycle) { | 8980 for (ResolvableLibrary library in _librariesInCycle) { |
| 8983 for (Source source in library.compilationUnitSources) { | 8981 for (Source source in library.compilationUnitSources) { |
| 8984 EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider); | 8982 EnumMemberBuilder builder = new EnumMemberBuilder(_typeProvider); |
| 8985 library.getAST(source).accept(builder); | 8983 library.getAST(source).accept(builder); |
| 8986 } | 8984 } |
| 8987 } | 8985 } |
| 8988 } finally { | 8986 } finally { |
| 8989 timeCounter.stop(); | 8987 prevTag.makeCurrent(); |
| 8990 } | 8988 } |
| 8991 } | 8989 } |
| 8992 | 8990 |
| 8993 /** | 8991 /** |
| 8994 * Finish steps that the [buildTypeHierarchies] could not perform, see | 8992 * Finish steps that the [buildTypeHierarchies] could not perform, see |
| 8995 * [ImplicitConstructorBuilder]. | 8993 * [ImplicitConstructorBuilder]. |
| 8996 * | 8994 * |
| 8997 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 8995 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 8998 */ | 8996 */ |
| 8999 void _buildImplicitConstructors() { | 8997 void _buildImplicitConstructors() { |
| 9000 TimeCounter_TimeCounterHandle timeCounter = | 8998 PerformanceTag prevTag = |
| 9001 PerformanceStatistics.resolve.start(); | 8999 PerformanceStatistics.resolve.makeCurrent(); |
| 9002 try { | 9000 try { |
| 9003 ImplicitConstructorComputer computer = | 9001 ImplicitConstructorComputer computer = |
| 9004 new ImplicitConstructorComputer(_typeProvider); | 9002 new ImplicitConstructorComputer(_typeProvider); |
| 9005 for (ResolvableLibrary library in _librariesInCycle) { | 9003 for (ResolvableLibrary library in _librariesInCycle) { |
| 9006 for (ResolvableCompilationUnit unit in | 9004 for (ResolvableCompilationUnit unit in |
| 9007 library.resolvableCompilationUnits) { | 9005 library.resolvableCompilationUnits) { |
| 9008 Source source = unit.source; | 9006 Source source = unit.source; |
| 9009 CompilationUnit ast = unit.compilationUnit; | 9007 CompilationUnit ast = unit.compilationUnit; |
| 9010 computer.add( | 9008 computer.add( |
| 9011 ast, | 9009 ast, |
| 9012 source, | 9010 source, |
| 9013 library.libraryElement, | 9011 library.libraryElement, |
| 9014 library.libraryScope); | 9012 library.libraryScope); |
| 9015 } | 9013 } |
| 9016 } | 9014 } |
| 9017 computer.compute(); | 9015 computer.compute(); |
| 9018 } finally { | 9016 } finally { |
| 9019 timeCounter.stop(); | 9017 prevTag.makeCurrent(); |
| 9020 } | 9018 } |
| 9021 } | 9019 } |
| 9022 | 9020 |
| 9023 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { | 9021 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { |
| 9024 HashMap<Source, ResolvableLibrary> libraryMap = | 9022 HashMap<Source, ResolvableLibrary> libraryMap = |
| 9025 new HashMap<Source, ResolvableLibrary>(); | 9023 new HashMap<Source, ResolvableLibrary>(); |
| 9026 int libraryCount = _librariesInCycle.length; | 9024 int libraryCount = _librariesInCycle.length; |
| 9027 for (int i = 0; i < libraryCount; i++) { | 9025 for (int i = 0; i < libraryCount; i++) { |
| 9028 ResolvableLibrary library = _librariesInCycle[i]; | 9026 ResolvableLibrary library = _librariesInCycle[i]; |
| 9029 library.errorListener = _errorListener; | 9027 library.errorListener = _errorListener; |
| 9030 libraryMap[library.librarySource] = library; | 9028 libraryMap[library.librarySource] = library; |
| 9031 List<ResolvableLibrary> dependencies = library.importsAndExports; | 9029 List<ResolvableLibrary> dependencies = library.importsAndExports; |
| 9032 int dependencyCount = dependencies.length; | 9030 int dependencyCount = dependencies.length; |
| 9033 for (int j = 0; j < dependencyCount; j++) { | 9031 for (int j = 0; j < dependencyCount; j++) { |
| 9034 ResolvableLibrary dependency = dependencies[j]; | 9032 ResolvableLibrary dependency = dependencies[j]; |
| 9035 //dependency.setErrorListener(errorListener); | 9033 //dependency.setErrorListener(errorListener); |
| 9036 libraryMap[dependency.librarySource] = dependency; | 9034 libraryMap[dependency.librarySource] = dependency; |
| 9037 } | 9035 } |
| 9038 } | 9036 } |
| 9039 return libraryMap; | 9037 return libraryMap; |
| 9040 } | 9038 } |
| 9041 | 9039 |
| 9042 /** | 9040 /** |
| 9043 * Resolve the types referenced by function type aliases across all of the fun
ction type aliases | 9041 * Resolve the types referenced by function type aliases across all of the fun
ction type aliases |
| 9044 * defined in the current cycle. | 9042 * defined in the current cycle. |
| 9045 * | 9043 * |
| 9046 * @throws AnalysisException if any of the function type aliases could not be
resolved | 9044 * @throws AnalysisException if any of the function type aliases could not be
resolved |
| 9047 */ | 9045 */ |
| 9048 void _buildTypeAliases() { | 9046 void _buildTypeAliases() { |
| 9049 TimeCounter_TimeCounterHandle timeCounter = | 9047 PerformanceTag prevTag = |
| 9050 PerformanceStatistics.resolve.start(); | 9048 PerformanceStatistics.resolve.makeCurrent(); |
| 9051 try { | 9049 try { |
| 9052 List<LibraryResolver2_TypeAliasInfo> typeAliases = | 9050 List<LibraryResolver2_TypeAliasInfo> typeAliases = |
| 9053 new List<LibraryResolver2_TypeAliasInfo>(); | 9051 new List<LibraryResolver2_TypeAliasInfo>(); |
| 9054 for (ResolvableLibrary library in _librariesInCycle) { | 9052 for (ResolvableLibrary library in _librariesInCycle) { |
| 9055 for (ResolvableCompilationUnit unit in | 9053 for (ResolvableCompilationUnit unit in |
| 9056 library.resolvableCompilationUnits) { | 9054 library.resolvableCompilationUnits) { |
| 9057 for (CompilationUnitMember member in | 9055 for (CompilationUnitMember member in |
| 9058 unit.compilationUnit.declarations) { | 9056 unit.compilationUnit.declarations) { |
| 9059 if (member is FunctionTypeAlias) { | 9057 if (member is FunctionTypeAlias) { |
| 9060 typeAliases.add( | 9058 typeAliases.add( |
| 9061 new LibraryResolver2_TypeAliasInfo(library, unit.source, membe
r)); | 9059 new LibraryResolver2_TypeAliasInfo(library, unit.source, membe
r)); |
| 9062 } | 9060 } |
| 9063 } | 9061 } |
| 9064 } | 9062 } |
| 9065 } | 9063 } |
| 9066 // TODO(brianwilkerson) We need to sort the type aliases such that all | 9064 // TODO(brianwilkerson) We need to sort the type aliases such that all |
| 9067 // aliases referenced by an alias T are resolved before we resolve T. | 9065 // aliases referenced by an alias T are resolved before we resolve T. |
| 9068 for (LibraryResolver2_TypeAliasInfo info in typeAliases) { | 9066 for (LibraryResolver2_TypeAliasInfo info in typeAliases) { |
| 9069 TypeResolverVisitor visitor = | 9067 TypeResolverVisitor visitor = |
| 9070 new TypeResolverVisitor.con4(info._library, info._source, _typeProvi
der); | 9068 new TypeResolverVisitor.con4(info._library, info._source, _typeProvi
der); |
| 9071 info._typeAlias.accept(visitor); | 9069 info._typeAlias.accept(visitor); |
| 9072 } | 9070 } |
| 9073 } finally { | 9071 } finally { |
| 9074 timeCounter.stop(); | 9072 prevTag.makeCurrent(); |
| 9075 } | 9073 } |
| 9076 } | 9074 } |
| 9077 | 9075 |
| 9078 /** | 9076 /** |
| 9079 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current | 9077 * Resolve the type hierarchy across all of the types declared in the librarie
s in the current |
| 9080 * cycle. | 9078 * cycle. |
| 9081 * | 9079 * |
| 9082 * @throws AnalysisException if any of the type hierarchies could not be resol
ved | 9080 * @throws AnalysisException if any of the type hierarchies could not be resol
ved |
| 9083 */ | 9081 */ |
| 9084 void _buildTypeHierarchies() { | 9082 void _buildTypeHierarchies() { |
| 9085 TimeCounter_TimeCounterHandle timeCounter = | 9083 PerformanceTag prevTag = |
| 9086 PerformanceStatistics.resolve.start(); | 9084 PerformanceStatistics.resolve.makeCurrent(); |
| 9087 try { | 9085 try { |
| 9088 for (ResolvableLibrary library in _librariesInCycle) { | 9086 for (ResolvableLibrary library in _librariesInCycle) { |
| 9089 for (ResolvableCompilationUnit unit in | 9087 for (ResolvableCompilationUnit unit in |
| 9090 library.resolvableCompilationUnits) { | 9088 library.resolvableCompilationUnits) { |
| 9091 Source source = unit.source; | 9089 Source source = unit.source; |
| 9092 CompilationUnit ast = unit.compilationUnit; | 9090 CompilationUnit ast = unit.compilationUnit; |
| 9093 TypeResolverVisitor visitor = | 9091 TypeResolverVisitor visitor = |
| 9094 new TypeResolverVisitor.con4(library, source, _typeProvider); | 9092 new TypeResolverVisitor.con4(library, source, _typeProvider); |
| 9095 ast.accept(visitor); | 9093 ast.accept(visitor); |
| 9096 } | 9094 } |
| 9097 } | 9095 } |
| 9098 } finally { | 9096 } finally { |
| 9099 timeCounter.stop(); | 9097 prevTag.makeCurrent(); |
| 9100 } | 9098 } |
| 9101 } | 9099 } |
| 9102 | 9100 |
| 9103 /** | 9101 /** |
| 9104 * Return an array containing the lexical identifiers associated with the node
s in the given list. | 9102 * Return an array containing the lexical identifiers associated with the node
s in the given list. |
| 9105 * | 9103 * |
| 9106 * @param names the AST nodes representing the identifiers | 9104 * @param names the AST nodes representing the identifiers |
| 9107 * @return the lexical identifiers associated with the nodes in the list | 9105 * @return the lexical identifiers associated with the nodes in the list |
| 9108 */ | 9106 */ |
| 9109 List<String> _getIdentifiers(NodeList<SimpleIdentifier> names) { | 9107 List<String> _getIdentifiers(NodeList<SimpleIdentifier> names) { |
| 9110 int count = names.length; | 9108 int count = names.length; |
| 9111 List<String> identifiers = new List<String>(count); | 9109 List<String> identifiers = new List<String>(count); |
| 9112 for (int i = 0; i < count; i++) { | 9110 for (int i = 0; i < count; i++) { |
| 9113 identifiers[i] = names[i].name; | 9111 identifiers[i] = names[i].name; |
| 9114 } | 9112 } |
| 9115 return identifiers; | 9113 return identifiers; |
| 9116 } | 9114 } |
| 9117 | 9115 |
| 9118 /** | 9116 /** |
| 9119 * Compute a value for all of the constants in the libraries being analyzed. | 9117 * Compute a value for all of the constants in the libraries being analyzed. |
| 9120 */ | 9118 */ |
| 9121 void _performConstantEvaluation() { | 9119 void _performConstantEvaluation() { |
| 9122 TimeCounter_TimeCounterHandle timeCounter = | 9120 PerformanceTag prevTag = |
| 9123 PerformanceStatistics.resolve.start(); | 9121 PerformanceStatistics.resolve.makeCurrent(); |
| 9124 try { | 9122 try { |
| 9125 ConstantValueComputer computer = | 9123 ConstantValueComputer computer = |
| 9126 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria
bles); | 9124 new ConstantValueComputer(_typeProvider, analysisContext.declaredVaria
bles); |
| 9127 for (ResolvableLibrary library in _librariesInCycle) { | 9125 for (ResolvableLibrary library in _librariesInCycle) { |
| 9128 for (ResolvableCompilationUnit unit in | 9126 for (ResolvableCompilationUnit unit in |
| 9129 library.resolvableCompilationUnits) { | 9127 library.resolvableCompilationUnits) { |
| 9130 CompilationUnit ast = unit.compilationUnit; | 9128 CompilationUnit ast = unit.compilationUnit; |
| 9131 if (ast != null) { | 9129 if (ast != null) { |
| 9132 computer.add(ast); | 9130 computer.add(ast); |
| 9133 } | 9131 } |
| 9134 } | 9132 } |
| 9135 } | 9133 } |
| 9136 computer.computeValues(); | 9134 computer.computeValues(); |
| 9137 // As a temporary workaround for issue 21572, run ConstantVerifier now. | 9135 // As a temporary workaround for issue 21572, run ConstantVerifier now. |
| 9138 // TODO(paulberry): remove this workaround once issue 21572 is fixed. | 9136 // TODO(paulberry): remove this workaround once issue 21572 is fixed. |
| 9139 for (ResolvableLibrary library in _librariesInCycle) { | 9137 for (ResolvableLibrary library in _librariesInCycle) { |
| 9140 for (ResolvableCompilationUnit unit in | 9138 for (ResolvableCompilationUnit unit in |
| 9141 library.resolvableCompilationUnits) { | 9139 library.resolvableCompilationUnits) { |
| 9142 CompilationUnit ast = unit.compilationUnit; | 9140 CompilationUnit ast = unit.compilationUnit; |
| 9143 ErrorReporter errorReporter = | 9141 ErrorReporter errorReporter = |
| 9144 new ErrorReporter(_errorListener, unit.source); | 9142 new ErrorReporter(_errorListener, unit.source); |
| 9145 ConstantVerifier constantVerifier = | 9143 ConstantVerifier constantVerifier = |
| 9146 new ConstantVerifier(errorReporter, library.libraryElement, _typeP
rovider); | 9144 new ConstantVerifier(errorReporter, library.libraryElement, _typeP
rovider); |
| 9147 ast.accept(constantVerifier); | 9145 ast.accept(constantVerifier); |
| 9148 } | 9146 } |
| 9149 } | 9147 } |
| 9150 } finally { | 9148 } finally { |
| 9151 timeCounter.stop(); | 9149 prevTag.makeCurrent(); |
| 9152 } | 9150 } |
| 9153 } | 9151 } |
| 9154 | 9152 |
| 9155 /** | 9153 /** |
| 9156 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | 9154 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 9157 * | 9155 * |
| 9158 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | 9156 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
| 9159 * libraries could not have their types analyzed | 9157 * libraries could not have their types analyzed |
| 9160 */ | 9158 */ |
| 9161 void _resolveReferencesAndTypes() { | 9159 void _resolveReferencesAndTypes() { |
| 9162 for (ResolvableLibrary library in _librariesInCycle) { | 9160 for (ResolvableLibrary library in _librariesInCycle) { |
| 9163 _resolveReferencesAndTypesInLibrary(library); | 9161 _resolveReferencesAndTypesInLibrary(library); |
| 9164 } | 9162 } |
| 9165 } | 9163 } |
| 9166 | 9164 |
| 9167 /** | 9165 /** |
| 9168 * Resolve the identifiers and perform type analysis in the given library. | 9166 * Resolve the identifiers and perform type analysis in the given library. |
| 9169 * | 9167 * |
| 9170 * @param library the library to be resolved | 9168 * @param library the library to be resolved |
| 9171 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 9169 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 9172 * the library cannot be analyzed | 9170 * the library cannot be analyzed |
| 9173 */ | 9171 */ |
| 9174 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) { | 9172 void _resolveReferencesAndTypesInLibrary(ResolvableLibrary library) { |
| 9175 TimeCounter_TimeCounterHandle timeCounter = | 9173 PerformanceTag prevTag = |
| 9176 PerformanceStatistics.resolve.start(); | 9174 PerformanceStatistics.resolve.makeCurrent(); |
| 9177 try { | 9175 try { |
| 9178 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) | 9176 for (ResolvableCompilationUnit unit in library.resolvableCompilationUnits) |
| 9179 { | 9177 { |
| 9180 Source source = unit.source; | 9178 Source source = unit.source; |
| 9181 CompilationUnit ast = unit.compilationUnit; | 9179 CompilationUnit ast = unit.compilationUnit; |
| 9182 ast.accept( | 9180 ast.accept( |
| 9183 new VariableResolverVisitor.con3(library, source, _typeProvider)); | 9181 new VariableResolverVisitor.con3(library, source, _typeProvider)); |
| 9184 ResolverVisitor visitor = | 9182 ResolverVisitor visitor = |
| 9185 new ResolverVisitor.con4(library, source, _typeProvider); | 9183 new ResolverVisitor.con4(library, source, _typeProvider); |
| 9186 ast.accept(visitor); | 9184 ast.accept(visitor); |
| 9187 } | 9185 } |
| 9188 } finally { | 9186 } finally { |
| 9189 timeCounter.stop(); | 9187 prevTag.makeCurrent(); |
| 9190 } | 9188 } |
| 9191 } | 9189 } |
| 9192 | 9190 |
| 9193 /** | 9191 /** |
| 9194 * Report that the async library could not be resolved in the given | 9192 * Report that the async library could not be resolved in the given |
| 9195 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour
ce | 9193 * [analysisContext] and throw an exception. [asyncLibrarySource] is the sour
ce |
| 9196 * representing the async library. | 9194 * representing the async library. |
| 9197 */ | 9195 */ |
| 9198 static void missingAsyncLibrary(AnalysisContext analysisContext, | 9196 static void missingAsyncLibrary(AnalysisContext analysisContext, |
| 9199 Source asyncLibrarySource) { | 9197 Source asyncLibrarySource) { |
| (...skipping 6494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15694 * library. | 15692 * library. |
| 15695 */ | 15693 */ |
| 15696 final HashSet<String> members = new HashSet<String>(); | 15694 final HashSet<String> members = new HashSet<String>(); |
| 15697 | 15695 |
| 15698 /** | 15696 /** |
| 15699 * Names of resolved or unresolved class members that are read in the | 15697 * Names of resolved or unresolved class members that are read in the |
| 15700 * library. | 15698 * library. |
| 15701 */ | 15699 */ |
| 15702 final HashSet<String> readMembers = new HashSet<String>(); | 15700 final HashSet<String> readMembers = new HashSet<String>(); |
| 15703 } | 15701 } |
| OLD | NEW |