| 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 7669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7680 * The object representing the async library. | 7680 * The object representing the async library. |
| 7681 */ | 7681 */ |
| 7682 Library _asyncLibrary; | 7682 Library _asyncLibrary; |
| 7683 | 7683 |
| 7684 /** | 7684 /** |
| 7685 * The object used to access the types from the core library. | 7685 * The object used to access the types from the core library. |
| 7686 */ | 7686 */ |
| 7687 TypeProvider _typeProvider; | 7687 TypeProvider _typeProvider; |
| 7688 | 7688 |
| 7689 /** | 7689 /** |
| 7690 * The object used to access the types from the core library. | |
| 7691 */ | |
| 7692 TypeProvider get typeProvider => _typeProvider; | |
| 7693 | |
| 7694 /** | |
| 7695 * A table mapping library sources to the information being maintained for tho
se libraries. | 7690 * A table mapping library sources to the information being maintained for tho
se libraries. |
| 7696 */ | 7691 */ |
| 7697 HashMap<Source, Library> _libraryMap = new HashMap<Source, Library>(); | 7692 HashMap<Source, Library> _libraryMap = new HashMap<Source, Library>(); |
| 7698 | 7693 |
| 7699 /** | 7694 /** |
| 7700 * A collection containing the libraries that are being resolved together. | 7695 * A collection containing the libraries that are being resolved together. |
| 7701 */ | 7696 */ |
| 7702 Set<Library> _librariesInCycles; | 7697 Set<Library> _librariesInCycles; |
| 7703 | 7698 |
| 7704 /** | 7699 /** |
| (...skipping 17 matching lines...) Expand all Loading... |
| 7722 RecordingErrorListener get errorListener => _errorListener; | 7717 RecordingErrorListener get errorListener => _errorListener; |
| 7723 | 7718 |
| 7724 /** | 7719 /** |
| 7725 * Return an array containing information about all of the libraries that were
resolved. | 7720 * Return an array containing information about all of the libraries that were
resolved. |
| 7726 * | 7721 * |
| 7727 * @return an array containing the libraries that were resolved | 7722 * @return an array containing the libraries that were resolved |
| 7728 */ | 7723 */ |
| 7729 Set<Library> get resolvedLibraries => _librariesInCycles; | 7724 Set<Library> get resolvedLibraries => _librariesInCycles; |
| 7730 | 7725 |
| 7731 /** | 7726 /** |
| 7727 * The object used to access the types from the core library. |
| 7728 */ |
| 7729 TypeProvider get typeProvider => _typeProvider; |
| 7730 |
| 7731 /** |
| 7732 * Create an object to represent the information about the library defined by
the compilation unit | 7732 * Create an object to represent the information about the library defined by
the compilation unit |
| 7733 * with the given source. | 7733 * with the given source. |
| 7734 * | 7734 * |
| 7735 * @param librarySource the source of the library's defining compilation unit | 7735 * @param librarySource the source of the library's defining compilation unit |
| 7736 * @return the library object that was created | 7736 * @return the library object that was created |
| 7737 * @throws AnalysisException if the library source is not valid | 7737 * @throws AnalysisException if the library source is not valid |
| 7738 */ | 7738 */ |
| 7739 Library createLibrary(Source librarySource) { | 7739 Library createLibrary(Source librarySource) { |
| 7740 Library library = | 7740 Library library = |
| 7741 new Library(analysisContext, _errorListener, librarySource); | 7741 new Library(analysisContext, _errorListener, librarySource); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7910 //if (analyzeAll) { | 7910 //if (analyzeAll) { |
| 7911 resolveReferencesAndTypes(); | 7911 resolveReferencesAndTypes(); |
| 7912 //} else { | 7912 //} else { |
| 7913 // resolveReferencesAndTypes(targetLibrary); | 7913 // resolveReferencesAndTypes(targetLibrary); |
| 7914 //} | 7914 //} |
| 7915 _performConstantEvaluation(); | 7915 _performConstantEvaluation(); |
| 7916 return targetLibrary.libraryElement; | 7916 return targetLibrary.libraryElement; |
| 7917 } | 7917 } |
| 7918 | 7918 |
| 7919 /** | 7919 /** |
| 7920 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. |
| 7921 * |
| 7922 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the |
| 7923 * libraries could not have their types analyzed |
| 7924 */ |
| 7925 void resolveReferencesAndTypes() { |
| 7926 for (Library library in _librariesInCycles) { |
| 7927 _resolveReferencesAndTypesInLibrary(library); |
| 7928 } |
| 7929 } |
| 7930 |
| 7931 /** |
| 7920 * Add a dependency to the given map from the referencing library to the refer
enced library. | 7932 * Add a dependency to the given map from the referencing library to the refer
enced library. |
| 7921 * | 7933 * |
| 7922 * @param dependencyMap the map to which the dependency is to be added | 7934 * @param dependencyMap the map to which the dependency is to be added |
| 7923 * @param referencingLibrary the library that references the referenced librar
y | 7935 * @param referencingLibrary the library that references the referenced librar
y |
| 7924 * @param referencedLibrary the library referenced by the referencing library | 7936 * @param referencedLibrary the library referenced by the referencing library |
| 7925 */ | 7937 */ |
| 7926 void _addDependencyToMap(HashMap<Library, List<Library>> dependencyMap, | 7938 void _addDependencyToMap(HashMap<Library, List<Library>> dependencyMap, |
| 7927 Library referencingLibrary, Library referencedLibrary) { | 7939 Library referencingLibrary, Library referencedLibrary) { |
| 7928 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; | 7940 List<Library> dependentLibraries = dependencyMap[referencedLibrary]; |
| 7929 if (dependentLibraries == null) { | 7941 if (dependentLibraries == null) { |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8464 "Internal Error: Could not access AST for ${source.fullName} " | 8476 "Internal Error: Could not access AST for ${source.fullName} " |
| 8465 "during constant verification", | 8477 "during constant verification", |
| 8466 new CaughtException(exception, stackTrace)); | 8478 new CaughtException(exception, stackTrace)); |
| 8467 } | 8479 } |
| 8468 } | 8480 } |
| 8469 } | 8481 } |
| 8470 }); | 8482 }); |
| 8471 } | 8483 } |
| 8472 | 8484 |
| 8473 /** | 8485 /** |
| 8474 * Resolve the identifiers and perform type analysis in the libraries in the c
urrent cycle. | |
| 8475 * | |
| 8476 * @throws AnalysisException if any of the identifiers could not be resolved o
r if any of the | |
| 8477 * libraries could not have their types analyzed | |
| 8478 */ | |
| 8479 void resolveReferencesAndTypes() { | |
| 8480 for (Library library in _librariesInCycles) { | |
| 8481 _resolveReferencesAndTypesInLibrary(library); | |
| 8482 } | |
| 8483 } | |
| 8484 | |
| 8485 /** | |
| 8486 * Resolve the identifiers and perform type analysis in the given library. | 8486 * Resolve the identifiers and perform type analysis in the given library. |
| 8487 * | 8487 * |
| 8488 * @param library the library to be resolved | 8488 * @param library the library to be resolved |
| 8489 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in | 8489 * @throws AnalysisException if any of the identifiers could not be resolved o
r if the types in |
| 8490 * the library cannot be analyzed | 8490 * the library cannot be analyzed |
| 8491 */ | 8491 */ |
| 8492 void _resolveReferencesAndTypesInLibrary(Library library) { | 8492 void _resolveReferencesAndTypesInLibrary(Library library) { |
| 8493 PerformanceStatistics.resolve.makeCurrentWhile(() { | 8493 PerformanceStatistics.resolve.makeCurrentWhile(() { |
| 8494 for (Source source in library.compilationUnitSources) { | 8494 for (Source source in library.compilationUnitSources) { |
| 8495 CompilationUnit ast = library.getAST(source); | 8495 CompilationUnit ast = library.getAST(source); |
| (...skipping 4773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13269 * Return the type representing the built-in type 'Iterable'. | 13269 * Return the type representing the built-in type 'Iterable'. |
| 13270 */ | 13270 */ |
| 13271 InterfaceType get iterableType; | 13271 InterfaceType get iterableType; |
| 13272 | 13272 |
| 13273 /** | 13273 /** |
| 13274 * Return the type representing the built-in type 'List'. | 13274 * Return the type representing the built-in type 'List'. |
| 13275 */ | 13275 */ |
| 13276 InterfaceType get listType; | 13276 InterfaceType get listType; |
| 13277 | 13277 |
| 13278 /** | 13278 /** |
| 13279 * Return the type representing the built-in type 'Map'. |
| 13280 */ |
| 13281 InterfaceType get mapType; |
| 13282 |
| 13283 /** |
| 13279 * Return a list containing all of the types that cannot be either extended or | 13284 * Return a list containing all of the types that cannot be either extended or |
| 13280 * implemented. | 13285 * implemented. |
| 13281 */ | 13286 */ |
| 13282 List<InterfaceType> get nonSubtypableTypes; | 13287 List<InterfaceType> get nonSubtypableTypes; |
| 13283 | 13288 |
| 13284 /** | 13289 /** |
| 13285 * Return the type representing the built-in type 'Map'. | |
| 13286 */ | |
| 13287 InterfaceType get mapType; | |
| 13288 | |
| 13289 /** | |
| 13290 * Return a [DartObjectImpl] representing the `null` object. | 13290 * Return a [DartObjectImpl] representing the `null` object. |
| 13291 */ | 13291 */ |
| 13292 DartObjectImpl get nullObject; | 13292 DartObjectImpl get nullObject; |
| 13293 | 13293 |
| 13294 /** | 13294 /** |
| 13295 * Return the type representing the built-in type 'Null'. | 13295 * Return the type representing the built-in type 'Null'. |
| 13296 */ | 13296 */ |
| 13297 InterfaceType get nullType; | 13297 InterfaceType get nullType; |
| 13298 | 13298 |
| 13299 /** | 13299 /** |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13771 Element element = exception.staticElement; | 13771 Element element = exception.staticElement; |
| 13772 if (element is VariableElementImpl) { | 13772 if (element is VariableElementImpl) { |
| 13773 element.type = exceptionType; | 13773 element.type = exceptionType; |
| 13774 } else { | 13774 } else { |
| 13775 // TODO(brianwilkerson) Report the internal error | 13775 // TODO(brianwilkerson) Report the internal error |
| 13776 } | 13776 } |
| 13777 } | 13777 } |
| 13778 SimpleIdentifier stackTrace = node.stackTraceParameter; | 13778 SimpleIdentifier stackTrace = node.stackTraceParameter; |
| 13779 if (stackTrace != null) { | 13779 if (stackTrace != null) { |
| 13780 _recordType(stackTrace, typeProvider.stackTraceType); | 13780 _recordType(stackTrace, typeProvider.stackTraceType); |
| 13781 Element element = stackTrace.staticElement; |
| 13782 if (element is VariableElementImpl) { |
| 13783 element.type = typeProvider.stackTraceType; |
| 13784 } else { |
| 13785 // TODO(brianwilkerson) Report the internal error |
| 13786 } |
| 13781 } | 13787 } |
| 13782 return null; | 13788 return null; |
| 13783 } | 13789 } |
| 13784 | 13790 |
| 13785 @override | 13791 @override |
| 13786 Object visitClassDeclaration(ClassDeclaration node) { | 13792 Object visitClassDeclaration(ClassDeclaration node) { |
| 13787 _hasReferenceToSuper = false; | 13793 _hasReferenceToSuper = false; |
| 13788 super.visitClassDeclaration(node); | 13794 super.visitClassDeclaration(node); |
| 13789 ClassElementImpl classElement = _getClassElement(node.name); | 13795 ClassElementImpl classElement = _getClassElement(node.name); |
| 13790 if (classElement != null) { | 13796 if (classElement != null) { |
| (...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15409 nonFields.add(node); | 15415 nonFields.add(node); |
| 15410 return null; | 15416 return null; |
| 15411 } | 15417 } |
| 15412 | 15418 |
| 15413 @override | 15419 @override |
| 15414 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15420 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15415 | 15421 |
| 15416 @override | 15422 @override |
| 15417 Object visitWithClause(WithClause node) => null; | 15423 Object visitWithClause(WithClause node) => null; |
| 15418 } | 15424 } |
| OLD | NEW |