Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(332)

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1067903002: Changes in analyzer needed for dev_compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixes analyzer errors in tests (implement added API)" Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 17 matching lines...) Expand all
28 /** 28 /**
29 * Callback signature used by ImplicitConstructorBuilder to register 29 * Callback signature used by ImplicitConstructorBuilder to register
30 * computations to be performed, and their dependencies. A call to this 30 * computations to be performed, and their dependencies. A call to this
31 * callback indicates that [computation] may be used to compute implicit 31 * callback indicates that [computation] may be used to compute implicit
32 * constructors for [classElement], but that the computation may not be invoked 32 * constructors for [classElement], but that the computation may not be invoked
33 * until after implicit constructors have been built for [superclassElement]. 33 * until after implicit constructors have been built for [superclassElement].
34 */ 34 */
35 typedef void ImplicitConstructorBuilderCallback(ClassElement classElement, 35 typedef void ImplicitConstructorBuilderCallback(ClassElement classElement,
36 ClassElement superclassElement, void computation()); 36 ClassElement superclassElement, void computation());
37 37
38 typedef LibraryResolver LibraryResolverFactory(AnalysisContext context);
39
38 typedef ResolverVisitor ResolverVisitorFactory( 40 typedef ResolverVisitor ResolverVisitorFactory(
39 Library library, Source source, TypeProvider typeProvider); 41 Library library, Source source, TypeProvider typeProvider);
40 42
41 typedef StaticTypeAnalyzer StaticTypeAnalyzerFactory(ResolverVisitor visitor); 43 typedef StaticTypeAnalyzer StaticTypeAnalyzerFactory(ResolverVisitor visitor);
42 44
43 typedef TypeResolverVisitor TypeResolverVisitorFactory( 45 typedef TypeResolverVisitor TypeResolverVisitorFactory(
44 Library library, Source source, TypeProvider typeProvider); 46 Library library, Source source, TypeProvider typeProvider);
45 47
46 typedef void VoidFunction(); 48 typedef void VoidFunction();
47 49
(...skipping 7628 matching lines...) Expand 10 before | Expand all | Expand 10 after
7676 * The object representing the async library. 7678 * The object representing the async library.
7677 */ 7679 */
7678 Library _asyncLibrary; 7680 Library _asyncLibrary;
7679 7681
7680 /** 7682 /**
7681 * The object used to access the types from the core library. 7683 * The object used to access the types from the core library.
7682 */ 7684 */
7683 TypeProvider _typeProvider; 7685 TypeProvider _typeProvider;
7684 7686
7685 /** 7687 /**
7688 * The object used to access the types from the core library.
7689 */
7690 TypeProvider get typeProvider => _typeProvider;
7691
7692 /**
7686 * A table mapping library sources to the information being maintained for tho se libraries. 7693 * A table mapping library sources to the information being maintained for tho se libraries.
7687 */ 7694 */
7688 HashMap<Source, Library> _libraryMap = new HashMap<Source, Library>(); 7695 HashMap<Source, Library> _libraryMap = new HashMap<Source, Library>();
7689 7696
7690 /** 7697 /**
7691 * A collection containing the libraries that are being resolved together. 7698 * A collection containing the libraries that are being resolved together.
7692 */ 7699 */
7693 Set<Library> _librariesInCycles; 7700 Set<Library> _librariesInCycles;
7694 7701
7695 /** 7702 /**
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
7811 // 7818 //
7812 // TODO(brianwilkerson) Decide whether we want to resolve all of the 7819 // TODO(brianwilkerson) Decide whether we want to resolve all of the
7813 // libraries or whether we want to only resolve the target library. 7820 // libraries or whether we want to only resolve the target library.
7814 // The advantage to resolving everything is that we have already done part 7821 // The advantage to resolving everything is that we have already done part
7815 // of the work so we'll avoid duplicated effort. The disadvantage of 7822 // of the work so we'll avoid duplicated effort. The disadvantage of
7816 // resolving everything is that we might do extra work that we don't 7823 // resolving everything is that we might do extra work that we don't
7817 // really care about. Another possibility is to add a parameter to this 7824 // really care about. Another possibility is to add a parameter to this
7818 // method and punt the decision to the clients. 7825 // method and punt the decision to the clients.
7819 // 7826 //
7820 //if (analyzeAll) { 7827 //if (analyzeAll) {
7821 _resolveReferencesAndTypes(); 7828 resolveReferencesAndTypes();
7822 //} else { 7829 //} else {
7823 // resolveReferencesAndTypes(targetLibrary); 7830 // resolveReferencesAndTypes(targetLibrary);
7824 //} 7831 //}
7825 _performConstantEvaluation(); 7832 _performConstantEvaluation();
7826 return targetLibrary.libraryElement; 7833 return targetLibrary.libraryElement;
7827 } 7834 }
7828 7835
7829 /** 7836 /**
7830 * Resolve the library specified by the given source in the given context. 7837 * Resolve the library specified by the given source in the given context.
7831 * 7838 *
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
7892 // 7899 //
7893 // TODO(brianwilkerson) Decide whether we want to resolve all of the 7900 // TODO(brianwilkerson) Decide whether we want to resolve all of the
7894 // libraries or whether we want to only resolve the target library. The 7901 // libraries or whether we want to only resolve the target library. The
7895 // advantage to resolving everything is that we have already done part of 7902 // advantage to resolving everything is that we have already done part of
7896 // the work so we'll avoid duplicated effort. The disadvantage of 7903 // the work so we'll avoid duplicated effort. The disadvantage of
7897 // resolving everything is that we might do extra work that we don't 7904 // resolving everything is that we might do extra work that we don't
7898 // really care about. Another possibility is to add a parameter to this 7905 // really care about. Another possibility is to add a parameter to this
7899 // method and punt the decision to the clients. 7906 // method and punt the decision to the clients.
7900 // 7907 //
7901 //if (analyzeAll) { 7908 //if (analyzeAll) {
7902 _resolveReferencesAndTypes(); 7909 resolveReferencesAndTypes();
7903 //} else { 7910 //} else {
7904 // resolveReferencesAndTypes(targetLibrary); 7911 // resolveReferencesAndTypes(targetLibrary);
7905 //} 7912 //}
7906 _performConstantEvaluation(); 7913 _performConstantEvaluation();
7907 return targetLibrary.libraryElement; 7914 return targetLibrary.libraryElement;
7908 } 7915 }
7909 7916
7910 /** 7917 /**
7911 * Add a dependency to the given map from the referencing library to the refer enced library. 7918 * Add a dependency to the given map from the referencing library to the refer enced library.
7912 * 7919 *
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
8460 } 8467 }
8461 }); 8468 });
8462 } 8469 }
8463 8470
8464 /** 8471 /**
8465 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle. 8472 * Resolve the identifiers and perform type analysis in the libraries in the c urrent cycle.
8466 * 8473 *
8467 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the 8474 * @throws AnalysisException if any of the identifiers could not be resolved o r if any of the
8468 * libraries could not have their types analyzed 8475 * libraries could not have their types analyzed
8469 */ 8476 */
8470 void _resolveReferencesAndTypes() { 8477 void resolveReferencesAndTypes() {
8471 for (Library library in _librariesInCycles) { 8478 for (Library library in _librariesInCycles) {
8472 _resolveReferencesAndTypesInLibrary(library); 8479 _resolveReferencesAndTypesInLibrary(library);
8473 } 8480 }
8474 } 8481 }
8475 8482
8476 /** 8483 /**
8477 * Resolve the identifiers and perform type analysis in the given library. 8484 * Resolve the identifiers and perform type analysis in the given library.
8478 * 8485 *
8479 * @param library the library to be resolved 8486 * @param library the library to be resolved
8480 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in 8487 * @throws AnalysisException if any of the identifiers could not be resolved o r if the types in
(...skipping 4321 matching lines...) Expand 10 before | Expand all | Expand 10 after
12802 } 12809 }
12803 12810
12804 /** 12811 /**
12805 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an 12812 * Instances of the class `TypeOverrideManager` manage the ability to override t he type of an
12806 * element within a given context. 12813 * element within a given context.
12807 */ 12814 */
12808 class TypeOverrideManager { 12815 class TypeOverrideManager {
12809 /** 12816 /**
12810 * The current override scope, or `null` if no scope has been entered. 12817 * The current override scope, or `null` if no scope has been entered.
12811 */ 12818 */
12812 TypeOverrideManager_TypeOverrideScope _currentScope; 12819 TypeOverrideManager_TypeOverrideScope currentScope;
12813 12820
12814 /** 12821 /**
12815 * Apply a set of overrides that were previously captured. 12822 * Apply a set of overrides that were previously captured.
12816 * 12823 *
12817 * @param overrides the overrides to be applied 12824 * @param overrides the overrides to be applied
12818 */ 12825 */
12819 void applyOverrides(Map<VariableElement, DartType> overrides) { 12826 void applyOverrides(Map<VariableElement, DartType> overrides) {
12820 if (_currentScope == null) { 12827 if (currentScope == null) {
12821 throw new IllegalStateException("Cannot apply overrides without a scope"); 12828 throw new IllegalStateException("Cannot apply overrides without a scope");
12822 } 12829 }
12823 _currentScope.applyOverrides(overrides); 12830 currentScope.applyOverrides(overrides);
12824 } 12831 }
12825 12832
12826 /** 12833 /**
12827 * Return a table mapping the elements whose type is overridden in the current scope to the 12834 * Return a table mapping the elements whose type is overridden in the current scope to the
12828 * overriding type. 12835 * overriding type.
12829 * 12836 *
12830 * @return the overrides in the current scope 12837 * @return the overrides in the current scope
12831 */ 12838 */
12832 Map<VariableElement, DartType> captureLocalOverrides() { 12839 Map<VariableElement, DartType> captureLocalOverrides() {
12833 if (_currentScope == null) { 12840 if (currentScope == null) {
12834 throw new IllegalStateException( 12841 throw new IllegalStateException(
12835 "Cannot capture local overrides without a scope"); 12842 "Cannot capture local overrides without a scope");
12836 } 12843 }
12837 return _currentScope.captureLocalOverrides(); 12844 return currentScope.captureLocalOverrides();
12838 } 12845 }
12839 12846
12840 /** 12847 /**
12841 * Return a map from the elements for the variables in the given list that hav e their types 12848 * Return a map from the elements for the variables in the given list that hav e their types
12842 * overridden to the overriding type. 12849 * overridden to the overriding type.
12843 * 12850 *
12844 * @param variableList the list of variables whose overriding types are to be captured 12851 * @param variableList the list of variables whose overriding types are to be captured
12845 * @return a table mapping elements to their overriding types 12852 * @return a table mapping elements to their overriding types
12846 */ 12853 */
12847 Map<VariableElement, DartType> captureOverrides( 12854 Map<VariableElement, DartType> captureOverrides(
12848 VariableDeclarationList variableList) { 12855 VariableDeclarationList variableList) {
12849 if (_currentScope == null) { 12856 if (currentScope == null) {
12850 throw new IllegalStateException( 12857 throw new IllegalStateException(
12851 "Cannot capture overrides without a scope"); 12858 "Cannot capture overrides without a scope");
12852 } 12859 }
12853 return _currentScope.captureOverrides(variableList); 12860 return currentScope.captureOverrides(variableList);
12854 } 12861 }
12855 12862
12856 /** 12863 /**
12857 * Enter a new override scope. 12864 * Enter a new override scope.
12858 */ 12865 */
12859 void enterScope() { 12866 void enterScope() {
12860 _currentScope = new TypeOverrideManager_TypeOverrideScope(_currentScope); 12867 currentScope = new TypeOverrideManager_TypeOverrideScope(currentScope);
12861 } 12868 }
12862 12869
12863 /** 12870 /**
12864 * Exit the current override scope. 12871 * Exit the current override scope.
12865 */ 12872 */
12866 void exitScope() { 12873 void exitScope() {
12867 if (_currentScope == null) { 12874 if (currentScope == null) {
12868 throw new IllegalStateException("No scope to exit"); 12875 throw new IllegalStateException("No scope to exit");
12869 } 12876 }
12870 _currentScope = _currentScope._outerScope; 12877 currentScope = currentScope._outerScope;
12871 } 12878 }
12872 12879
12873 /** 12880 /**
12874 * Return the best type information available for the given element. If the ty pe of the element 12881 * Return the best type information available for the given element. If the ty pe of the element
12875 * has been overridden, then return the overriding type. Otherwise, return the static type. 12882 * has been overridden, then return the overriding type. Otherwise, return the static type.
12876 * 12883 *
12877 * @param element the element for which type information is to be returned 12884 * @param element the element for which type information is to be returned
12878 * @return the best type information available for the given element 12885 * @return the best type information available for the given element
12879 */ 12886 */
12880 DartType getBestType(VariableElement element) { 12887 DartType getBestType(VariableElement element) {
12881 DartType bestType = getType(element); 12888 DartType bestType = getType(element);
12882 return bestType == null ? element.type : bestType; 12889 return bestType == null ? element.type : bestType;
12883 } 12890 }
12884 12891
12885 /** 12892 /**
12886 * Return the overridden type of the given element, or `null` if the type of t he element has 12893 * Return the overridden type of the given element, or `null` if the type of t he element has
12887 * not been overridden. 12894 * not been overridden.
12888 * 12895 *
12889 * @param element the element whose type might have been overridden 12896 * @param element the element whose type might have been overridden
12890 * @return the overridden type of the given element 12897 * @return the overridden type of the given element
12891 */ 12898 */
12892 DartType getType(Element element) { 12899 DartType getType(Element element) {
12893 if (_currentScope == null) { 12900 if (currentScope == null) {
12894 return null; 12901 return null;
12895 } 12902 }
12896 return _currentScope.getType(element); 12903 return currentScope.getType(element);
12897 } 12904 }
12898 12905
12899 /** 12906 /**
12900 * Update overrides assuming [perBranchOverrides] is the collection of 12907 * Update overrides assuming [perBranchOverrides] is the collection of
12901 * per-branch overrides for *all* branches flowing into a join point. 12908 * per-branch overrides for *all* branches flowing into a join point.
12902 * 12909 *
12903 * If a variable type in any of branches is not the same as its type before 12910 * If a variable type in any of branches is not the same as its type before
12904 * the branching, then its propagated type is reset to `null`. 12911 * the branching, then its propagated type is reset to `null`.
12905 */ 12912 */
12906 void mergeOverrides(List<Map<VariableElement, DartType>> perBranchOverrides) { 12913 void mergeOverrides(List<Map<VariableElement, DartType>> perBranchOverrides) {
12907 for (Map<VariableElement, DartType> branch in perBranchOverrides) { 12914 for (Map<VariableElement, DartType> branch in perBranchOverrides) {
12908 branch.forEach((VariableElement variable, DartType branchType) { 12915 branch.forEach((VariableElement variable, DartType branchType) {
12909 DartType currentType = _currentScope.getType(variable); 12916 DartType currentType = currentScope.getType(variable);
12910 if (currentType != branchType) { 12917 if (currentType != branchType) {
12911 _currentScope.resetType(variable); 12918 currentScope.resetType(variable);
12912 } 12919 }
12913 }); 12920 });
12914 } 12921 }
12915 } 12922 }
12916 12923
12917 /** 12924 /**
12918 * Set the overridden type of the given element to the given type 12925 * Set the overridden type of the given element to the given type
12919 * 12926 *
12920 * @param element the element whose type might have been overridden 12927 * @param element the element whose type might have been overridden
12921 * @param type the overridden type of the given element 12928 * @param type the overridden type of the given element
12922 */ 12929 */
12923 void setType(VariableElement element, DartType type) { 12930 void setType(VariableElement element, DartType type) {
12924 if (_currentScope == null) { 12931 if (currentScope == null) {
12925 throw new IllegalStateException("Cannot override without a scope"); 12932 throw new IllegalStateException("Cannot override without a scope");
12926 } 12933 }
12927 _currentScope.setType(element, type); 12934 currentScope.setType(element, type);
12928 } 12935 }
12929 } 12936 }
12930 12937
12931 /** 12938 /**
12932 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of 12939 * Instances of the class `TypeOverrideScope` represent a scope in which the typ es of
12933 * elements can be overridden. 12940 * elements can be overridden.
12934 */ 12941 */
12935 class TypeOverrideManager_TypeOverrideScope { 12942 class TypeOverrideManager_TypeOverrideScope {
12936 /** 12943 /**
12937 * The outer scope in which types might be overridden. 12944 * The outer scope in which types might be overridden.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
13066 } 13073 }
13067 13074
13068 /** 13075 /**
13069 * Instances of the class `TypePromotionManager` manage the ability to promote t ypes of local 13076 * Instances of the class `TypePromotionManager` manage the ability to promote t ypes of local
13070 * variables and formal parameters from their declared types based on control fl ow. 13077 * variables and formal parameters from their declared types based on control fl ow.
13071 */ 13078 */
13072 class TypePromotionManager { 13079 class TypePromotionManager {
13073 /** 13080 /**
13074 * The current promotion scope, or `null` if no scope has been entered. 13081 * The current promotion scope, or `null` if no scope has been entered.
13075 */ 13082 */
13076 TypePromotionManager_TypePromoteScope _currentScope; 13083 TypePromotionManager_TypePromoteScope currentScope;
13077 13084
13078 /** 13085 /**
13079 * Returns the elements with promoted types. 13086 * Returns the elements with promoted types.
13080 */ 13087 */
13081 Iterable<Element> get promotedElements => _currentScope.promotedElements; 13088 Iterable<Element> get promotedElements => currentScope.promotedElements;
13082 13089
13083 /** 13090 /**
13084 * Enter a new promotions scope. 13091 * Enter a new promotions scope.
13085 */ 13092 */
13086 void enterScope() { 13093 void enterScope() {
13087 _currentScope = new TypePromotionManager_TypePromoteScope(_currentScope); 13094 currentScope = new TypePromotionManager_TypePromoteScope(currentScope);
13088 } 13095 }
13089 13096
13090 /** 13097 /**
13091 * Exit the current promotion scope. 13098 * Exit the current promotion scope.
13092 */ 13099 */
13093 void exitScope() { 13100 void exitScope() {
13094 if (_currentScope == null) { 13101 if (currentScope == null) {
13095 throw new IllegalStateException("No scope to exit"); 13102 throw new IllegalStateException("No scope to exit");
13096 } 13103 }
13097 _currentScope = _currentScope._outerScope; 13104 currentScope = currentScope._outerScope;
13098 } 13105 }
13099 13106
13100 /** 13107 /**
13101 * Returns static type of the given variable - declared or promoted. 13108 * Returns static type of the given variable - declared or promoted.
13102 * 13109 *
13103 * @return the static type of the given variable - declared or promoted 13110 * @return the static type of the given variable - declared or promoted
13104 */ 13111 */
13105 DartType getStaticType(VariableElement variable) { 13112 DartType getStaticType(VariableElement variable) {
13106 DartType staticType = getType(variable); 13113 DartType staticType = getType(variable);
13107 if (staticType == null) { 13114 if (staticType == null) {
13108 staticType = variable.type; 13115 staticType = variable.type;
13109 } 13116 }
13110 return staticType; 13117 return staticType;
13111 } 13118 }
13112 13119
13113 /** 13120 /**
13114 * Return the promoted type of the given element, or `null` if the type of the element has 13121 * Return the promoted type of the given element, or `null` if the type of the element has
13115 * not been promoted. 13122 * not been promoted.
13116 * 13123 *
13117 * @param element the element whose type might have been promoted 13124 * @param element the element whose type might have been promoted
13118 * @return the promoted type of the given element 13125 * @return the promoted type of the given element
13119 */ 13126 */
13120 DartType getType(Element element) { 13127 DartType getType(Element element) {
13121 if (_currentScope == null) { 13128 if (currentScope == null) {
13122 return null; 13129 return null;
13123 } 13130 }
13124 return _currentScope.getType(element); 13131 return currentScope.getType(element);
13125 } 13132 }
13126 13133
13127 /** 13134 /**
13128 * Set the promoted type of the given element to the given type. 13135 * Set the promoted type of the given element to the given type.
13129 * 13136 *
13130 * @param element the element whose type might have been promoted 13137 * @param element the element whose type might have been promoted
13131 * @param type the promoted type of the given element 13138 * @param type the promoted type of the given element
13132 */ 13139 */
13133 void setType(Element element, DartType type) { 13140 void setType(Element element, DartType type) {
13134 if (_currentScope == null) { 13141 if (currentScope == null) {
13135 throw new IllegalStateException("Cannot promote without a scope"); 13142 throw new IllegalStateException("Cannot promote without a scope");
13136 } 13143 }
13137 _currentScope.setType(element, type); 13144 currentScope.setType(element, type);
13138 } 13145 }
13139 } 13146 }
13140 13147
13141 /** 13148 /**
13142 * Instances of the class `TypePromoteScope` represent a scope in which the type s of 13149 * Instances of the class `TypePromoteScope` represent a scope in which the type s of
13143 * elements can be promoted. 13150 * elements can be promoted.
13144 */ 13151 */
13145 class TypePromotionManager_TypePromoteScope { 13152 class TypePromotionManager_TypePromoteScope {
13146 /** 13153 /**
13147 * The outer scope in which types might be promoter. 13154 * The outer scope in which types might be promoter.
(...skipping 2257 matching lines...) Expand 10 before | Expand all | Expand 10 after
15405 nonFields.add(node); 15412 nonFields.add(node);
15406 return null; 15413 return null;
15407 } 15414 }
15408 15415
15409 @override 15416 @override
15410 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15417 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15411 15418
15412 @override 15419 @override
15413 Object visitWithClause(WithClause node) => null; 15420 Object visitWithClause(WithClause node) => null;
15414 } 15421 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698