| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/context/declared_variables.dart'; | 5 import 'package:analyzer/context/declared_variables.dart'; |
| 6 import 'package:analyzer/dart/ast/ast.dart'; | 6 import 'package:analyzer/dart/ast/ast.dart'; |
| 7 import 'package:analyzer/dart/ast/visitor.dart'; | 7 import 'package:analyzer/dart/ast/visitor.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
| 10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
| 11 import 'package:analyzer/src/context/context.dart'; | 11 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; | 12 import 'package:analyzer/src/dart/analysis/file_state.dart'; |
| 13 import 'package:analyzer/src/dart/ast/ast.dart'; | 13 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 14 import 'package:analyzer/src/dart/ast/utilities.dart'; | 14 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 15 import 'package:analyzer/src/dart/constant/evaluation.dart'; | 15 import 'package:analyzer/src/dart/constant/evaluation.dart'; |
| 16 import 'package:analyzer/src/dart/constant/utilities.dart'; | 16 import 'package:analyzer/src/dart/constant/utilities.dart'; |
| 17 import 'package:analyzer/src/error/codes.dart'; | 17 import 'package:analyzer/src/error/codes.dart'; |
| 18 import 'package:analyzer/src/error/pending_error.dart'; | 18 import 'package:analyzer/src/error/pending_error.dart'; |
| 19 import 'package:analyzer/src/fasta/uri_instrumentation.dart'; | |
| 20 import 'package:analyzer/src/generated/declaration_resolver.dart'; | 19 import 'package:analyzer/src/generated/declaration_resolver.dart'; |
| 21 import 'package:analyzer/src/generated/engine.dart'; | 20 import 'package:analyzer/src/generated/engine.dart'; |
| 22 import 'package:analyzer/src/generated/error_verifier.dart'; | 21 import 'package:analyzer/src/generated/error_verifier.dart'; |
| 23 import 'package:analyzer/src/generated/resolver.dart'; | 22 import 'package:analyzer/src/generated/resolver.dart'; |
| 24 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 25 import 'package:analyzer/src/services/lint.dart'; | 24 import 'package:analyzer/src/services/lint.dart'; |
| 26 import 'package:analyzer/src/summary/package_bundle_reader.dart'; | 25 import 'package:analyzer/src/summary/package_bundle_reader.dart'; |
| 27 import 'package:analyzer/src/task/dart.dart'; | 26 import 'package:analyzer/src/task/dart.dart'; |
| 28 import 'package:analyzer/src/task/strong/checker.dart'; | 27 import 'package:analyzer/src/task/strong/checker.dart'; |
| 29 import 'package:front_end/src/base/instrumentation.dart' as fasta; | |
| 30 import 'package:front_end/src/dependency_walker.dart'; | 28 import 'package:front_end/src/dependency_walker.dart'; |
| 31 | 29 |
| 32 /** | 30 /** |
| 33 * Analyzer of a single library. | 31 * Analyzer of a single library. |
| 34 */ | 32 */ |
| 35 class LibraryAnalyzer { | 33 class LibraryAnalyzer { |
| 36 final AnalysisOptions _analysisOptions; | 34 final AnalysisOptions _analysisOptions; |
| 37 final DeclaredVariables _declaredVariables; | 35 final DeclaredVariables _declaredVariables; |
| 38 final SourceFactory _sourceFactory; | 36 final SourceFactory _sourceFactory; |
| 39 final FileSystemState _fsState; | 37 final FileSystemState _fsState; |
| 40 final SummaryDataStore _store; | 38 final SummaryDataStore _store; |
| 41 final FileState _library; | 39 final FileState _library; |
| 42 final fasta.Instrumentation _instrumentation; | |
| 43 | 40 |
| 44 TypeProvider _typeProvider; | 41 TypeProvider _typeProvider; |
| 45 AnalysisContextImpl _context; | 42 AnalysisContextImpl _context; |
| 46 StoreBasedSummaryResynthesizer _resynthesizer; | 43 StoreBasedSummaryResynthesizer _resynthesizer; |
| 47 LibraryElement _libraryElement; | 44 LibraryElement _libraryElement; |
| 48 | 45 |
| 49 final Map<FileState, LineInfo> _fileToLineInfo = {}; | 46 final Map<FileState, LineInfo> _fileToLineInfo = {}; |
| 50 final Map<FileState, IgnoreInfo> _fileToIgnoreInfo = {}; | 47 final Map<FileState, IgnoreInfo> _fileToIgnoreInfo = {}; |
| 51 | 48 |
| 52 final Map<FileState, RecordingErrorListener> _errorListeners = {}; | 49 final Map<FileState, RecordingErrorListener> _errorListeners = {}; |
| 53 final Map<FileState, ErrorReporter> _errorReporters = {}; | 50 final Map<FileState, ErrorReporter> _errorReporters = {}; |
| 54 final List<UsedImportedElements> _usedImportedElementsList = []; | 51 final List<UsedImportedElements> _usedImportedElementsList = []; |
| 55 final List<UsedLocalElements> _usedLocalElementsList = []; | 52 final List<UsedLocalElements> _usedLocalElementsList = []; |
| 56 final Map<FileState, List<PendingError>> _fileToPendingErrors = {}; | 53 final Map<FileState, List<PendingError>> _fileToPendingErrors = {}; |
| 57 final List<ConstantEvaluationTarget> _constants = []; | 54 final List<ConstantEvaluationTarget> _constants = []; |
| 58 | 55 |
| 59 LibraryAnalyzer( | 56 LibraryAnalyzer(this._analysisOptions, this._declaredVariables, |
| 60 this._analysisOptions, | 57 this._sourceFactory, this._fsState, this._store, this._library); |
| 61 this._declaredVariables, | |
| 62 this._sourceFactory, | |
| 63 this._fsState, | |
| 64 this._store, | |
| 65 this._library, | |
| 66 this._instrumentation); | |
| 67 | 58 |
| 68 /** | 59 /** |
| 69 * Compute analysis results for all units of the library. | 60 * Compute analysis results for all units of the library. |
| 70 */ | 61 */ |
| 71 Map<FileState, UnitAnalysisResult> analyze() { | 62 Map<FileState, UnitAnalysisResult> analyze() { |
| 72 Map<FileState, CompilationUnit> units = {}; | 63 Map<FileState, CompilationUnit> units = {}; |
| 73 | 64 |
| 74 // Parse all files. | 65 // Parse all files. |
| 75 units[_library] = _parse(_library); | 66 units[_library] = _parse(_library); |
| 76 for (FileState part in _library.partedFiles) { | 67 for (FileState part in _library.partedFiles) { |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 505 } |
| 515 | 506 |
| 516 void _resolveFile(FileState file, CompilationUnit unit) { | 507 void _resolveFile(FileState file, CompilationUnit unit) { |
| 517 Source source = file.source; | 508 Source source = file.source; |
| 518 if (source == null) { | 509 if (source == null) { |
| 519 return; | 510 return; |
| 520 } | 511 } |
| 521 | 512 |
| 522 RecordingErrorListener errorListener = _getErrorListener(file); | 513 RecordingErrorListener errorListener = _getErrorListener(file); |
| 523 | 514 |
| 524 UriInstrumentation instrumentation = _instrumentation != null | |
| 525 ? new UriInstrumentation(_instrumentation, file.uri) | |
| 526 : null; | |
| 527 | |
| 528 CompilationUnitElement unitElement = unit.element; | 515 CompilationUnitElement unitElement = unit.element; |
| 529 | 516 |
| 530 // TODO(scheglov) Hack: set types for top-level variables | 517 // TODO(scheglov) Hack: set types for top-level variables |
| 531 // Otherwise TypeResolverVisitor will set declared types, and because we | 518 // Otherwise TypeResolverVisitor will set declared types, and because we |
| 532 // don't run InferStaticVariableTypeTask, we will stuck with these declared | 519 // don't run InferStaticVariableTypeTask, we will stuck with these declared |
| 533 // types. And we don't need to run this task - resynthesized elements have | 520 // types. And we don't need to run this task - resynthesized elements have |
| 534 // inferred types. | 521 // inferred types. |
| 535 for (var e in unitElement.topLevelVariables) { | 522 for (var e in unitElement.topLevelVariables) { |
| 536 if (!e.isSynthetic) { | 523 if (!e.isSynthetic) { |
| 537 e.type; | 524 e.type; |
| 538 if (instrumentation != null && e.hasImplicitType) { | |
| 539 instrumentation.recordTopType(e.nameOffset, e.type); | |
| 540 } | |
| 541 } | 525 } |
| 542 } | 526 } |
| 543 | 527 |
| 544 new DeclarationResolver().resolve(unit, unitElement); | 528 new DeclarationResolver().resolve(unit, unitElement); |
| 545 | 529 |
| 546 // TODO(scheglov) remove EnumMemberBuilder class | 530 // TODO(scheglov) remove EnumMemberBuilder class |
| 547 | 531 |
| 548 new TypeParameterBoundsResolver( | 532 new TypeParameterBoundsResolver( |
| 549 _typeProvider, _libraryElement, source, errorListener) | 533 _typeProvider, _libraryElement, source, errorListener) |
| 550 .resolveTypeBounds(unit); | 534 .resolveTypeBounds(unit); |
| 551 | 535 |
| 552 unit.accept(new TypeResolverVisitor( | 536 unit.accept(new TypeResolverVisitor( |
| 553 _libraryElement, source, _typeProvider, errorListener)); | 537 _libraryElement, source, _typeProvider, errorListener)); |
| 554 | 538 |
| 555 LibraryScope libraryScope = new LibraryScope(_libraryElement); | 539 LibraryScope libraryScope = new LibraryScope(_libraryElement); |
| 556 unit.accept(new VariableResolverVisitor( | 540 unit.accept(new VariableResolverVisitor( |
| 557 _libraryElement, source, _typeProvider, errorListener, | 541 _libraryElement, source, _typeProvider, errorListener, |
| 558 nameScope: libraryScope)); | 542 nameScope: libraryScope)); |
| 559 | 543 |
| 560 unit.accept(new PartialResolverVisitor(_libraryElement, source, | 544 unit.accept(new PartialResolverVisitor(_libraryElement, source, |
| 561 _typeProvider, AnalysisErrorListener.NULL_LISTENER)); | 545 _typeProvider, AnalysisErrorListener.NULL_LISTENER)); |
| 562 | 546 |
| 563 // Nothing for RESOLVED_UNIT8? | 547 // Nothing for RESOLVED_UNIT8? |
| 564 // Nothing for RESOLVED_UNIT9? | 548 // Nothing for RESOLVED_UNIT9? |
| 565 // Nothing for RESOLVED_UNIT10? | 549 // Nothing for RESOLVED_UNIT10? |
| 566 | 550 |
| 567 unit.accept(new ResolverVisitor( | 551 unit.accept(new ResolverVisitor( |
| 568 _libraryElement, source, _typeProvider, errorListener, | 552 _libraryElement, source, _typeProvider, errorListener)); |
| 569 instrumentation: instrumentation)); | |
| 570 | 553 |
| 571 // | 554 // |
| 572 // Find constants to compute. | 555 // Find constants to compute. |
| 573 // | 556 // |
| 574 { | 557 { |
| 575 ConstantFinder constantFinder = new ConstantFinder(); | 558 ConstantFinder constantFinder = new ConstantFinder(); |
| 576 unit.accept(constantFinder); | 559 unit.accept(constantFinder); |
| 577 _constants.addAll(constantFinder.constantsToCompute); | 560 _constants.addAll(constantFinder.constantsToCompute); |
| 578 } | 561 } |
| 579 | 562 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 } | 784 } |
| 802 | 785 |
| 803 /** | 786 /** |
| 804 * Either the name or the source associated with a part-of directive. | 787 * Either the name or the source associated with a part-of directive. |
| 805 */ | 788 */ |
| 806 class _NameOrSource { | 789 class _NameOrSource { |
| 807 final String name; | 790 final String name; |
| 808 final Source source; | 791 final Source source; |
| 809 _NameOrSource(this.name, this.source); | 792 _NameOrSource(this.name, this.source); |
| 810 } | 793 } |
| OLD | NEW |