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