Chromium Code Reviews| 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 4855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4866 * Instances of the class `ImplicitConstructorBuilder` are used to build | 4866 * Instances of the class `ImplicitConstructorBuilder` are used to build |
| 4867 * implicit constructors for mixin applications, and to check for errors | 4867 * implicit constructors for mixin applications, and to check for errors |
| 4868 * related to super constructor calls in class declarations with mixins. | 4868 * related to super constructor calls in class declarations with mixins. |
| 4869 * | 4869 * |
| 4870 * The visitor methods don't directly build the implicit constructors or check | 4870 * The visitor methods don't directly build the implicit constructors or check |
| 4871 * for errors, since they don't in general visit the classes in the proper | 4871 * for errors, since they don't in general visit the classes in the proper |
| 4872 * order to do so correctly. Instead, they pass closures to | 4872 * order to do so correctly. Instead, they pass closures to |
| 4873 * ImplicitConstructorBuilderCallback to inform it of the computations to be | 4873 * ImplicitConstructorBuilderCallback to inform it of the computations to be |
| 4874 * done and their ordering dependencies. | 4874 * done and their ordering dependencies. |
| 4875 */ | 4875 */ |
| 4876 class ImplicitConstructorBuilder extends ScopedVisitor { | 4876 class ImplicitConstructorBuilder extends RecursiveElementVisitor { |
|
Brian Wilkerson
2015/03/19 17:57:31
This doesn't need to be a RecursiveElementVisitor
| |
| 4877 final AnalysisErrorListener errorListener; | |
| 4878 | |
| 4877 /** | 4879 /** |
| 4878 * Callback to receive the computations to be performed. | 4880 * Callback to receive the computations to be performed. |
| 4879 */ | 4881 */ |
| 4880 final ImplicitConstructorBuilderCallback _callback; | 4882 final ImplicitConstructorBuilderCallback _callback; |
| 4881 | 4883 |
| 4882 /** | 4884 /** |
| 4883 * Initialize a newly created visitor to build implicit constructors for file | 4885 * Initialize a newly created visitor to build implicit constructors. |
| 4884 * [source], in library [libraryElement], which has scope [libraryScope]. Use | |
| 4885 * [typeProvider] to access types from the core library. | |
| 4886 * | 4886 * |
| 4887 * The visit methods will pass closures to [_callback] to indicate what | 4887 * The visit methods will pass closures to [_callback] to indicate what |
| 4888 * computation needs to be performed, and its dependency order. | 4888 * computation needs to be performed, and its dependency order. |
| 4889 */ | 4889 */ |
| 4890 ImplicitConstructorBuilder(Source source, LibraryElement libraryElement, | 4890 ImplicitConstructorBuilder(this.errorListener, this._callback); |
| 4891 LibraryScope libraryScope, TypeProvider typeProvider, this._callback) | |
| 4892 : super.con3(libraryElement, source, typeProvider, libraryScope, | |
| 4893 libraryScope.errorListener); | |
| 4894 | 4891 |
| 4895 @override | 4892 @override |
| 4896 Object visitClassDeclaration(ClassDeclaration node) { | 4893 void visitClassElement(ClassElementImpl classElement) { |
| 4897 ClassElementImpl classElement = node.element; | |
| 4898 classElement.mixinErrorsReported = false; | 4894 classElement.mixinErrorsReported = false; |
| 4899 if (node.extendsClause != null && node.withClause != null) { | 4895 if (classElement.isTypedef) { |
| 4896 _visitClassTypeAlias(classElement); | |
| 4897 } else { | |
| 4898 _visitClassDeclaration(classElement); | |
| 4899 } | |
| 4900 } | |
| 4901 | |
| 4902 @override | |
| 4903 void visitCompilationUnitElement(CompilationUnitElement element) { | |
| 4904 for (ClassElement classElement in element.types) { | |
| 4905 classElement.accept(this); | |
| 4906 } | |
| 4907 } | |
| 4908 | |
| 4909 void _visitClassDeclaration(ClassElementImpl classElement) { | |
| 4910 DartType superType = classElement.supertype; | |
| 4911 if (superType != null && classElement.mixins.isNotEmpty) { | |
| 4900 // We don't need to build any implicitly constructors for the mixin | 4912 // We don't need to build any implicitly constructors for the mixin |
| 4901 // application (since there isn't an explicit element for it), but we | 4913 // application (since there isn't an explicit element for it), but we |
| 4902 // need to verify that they _could_ be built. | 4914 // need to verify that they _could_ be built. |
| 4903 InterfaceType superclassType = null; | 4915 if (superType is! InterfaceType) { |
| 4904 TypeName superclassName = node.extendsClause.superclass; | 4916 TypeProvider typeProvider = classElement.context.typeProvider; |
| 4905 DartType type = superclassName.type; | 4917 superType = typeProvider.objectType; |
| 4906 if (type is InterfaceType) { | |
| 4907 superclassType = type; | |
| 4908 } else { | |
| 4909 superclassType = typeProvider.objectType; | |
| 4910 } | 4918 } |
| 4911 ClassElement superclassElement = classElement.supertype.element; | 4919 ClassElement superElement = superType.element; |
| 4912 if (superclassElement != null) { | 4920 if (superElement != null) { |
| 4913 _callback(classElement, superclassElement, () { | 4921 _callback(classElement, superElement, () { |
| 4914 bool constructorFound = false; | 4922 bool constructorFound = false; |
| 4915 void callback(ConstructorElement explicitConstructor, | 4923 void callback(ConstructorElement explicitConstructor, |
| 4916 List<DartType> parameterTypes, List<DartType> argumentTypes) { | 4924 List<DartType> parameterTypes, List<DartType> argumentTypes) { |
| 4917 constructorFound = true; | 4925 constructorFound = true; |
| 4918 } | 4926 } |
| 4919 if (_findForwardedConstructors( | 4927 if (_findForwardedConstructors(classElement, superType, callback) && |
| 4920 classElement, superclassName, superclassType, callback) && | |
| 4921 !constructorFound) { | 4928 !constructorFound) { |
| 4922 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, | 4929 SourceRange withRange = classElement.withClauseRange; |
| 4923 node.withClause, [superclassType.element.name]); | 4930 errorListener.onError(new AnalysisError.con2(classElement.source, |
| 4931 withRange.offset, withRange.length, | |
| 4932 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, | |
| 4933 [superElement.name])); | |
| 4924 classElement.mixinErrorsReported = true; | 4934 classElement.mixinErrorsReported = true; |
| 4925 } | 4935 } |
| 4926 }); | 4936 }); |
| 4927 } | 4937 } |
| 4928 } | 4938 } |
| 4929 return null; | |
| 4930 } | 4939 } |
| 4931 | 4940 |
| 4932 @override | 4941 void _visitClassTypeAlias(ClassElementImpl classElement) { |
| 4933 Object visitClassTypeAlias(ClassTypeAlias node) { | 4942 InterfaceType superType = classElement.supertype; |
| 4934 super.visitClassTypeAlias(node); | 4943 if (superType is InterfaceType) { |
| 4935 InterfaceType superclassType = null; | 4944 ClassElement superElement = superType.element; |
| 4936 TypeName superclassName = node.superclass; | 4945 _callback(classElement, superElement, () { |
| 4937 DartType type = superclassName.type; | 4946 List<ConstructorElement> implicitConstructors = |
| 4938 if (type is InterfaceType) { | 4947 new List<ConstructorElement>(); |
| 4939 superclassType = type; | 4948 void callback(ConstructorElement explicitConstructor, |
| 4940 } else { | 4949 List<DartType> parameterTypes, List<DartType> argumentTypes) { |
| 4941 superclassType = typeProvider.objectType; | 4950 implicitConstructors.add(_createImplicitContructor(classElement.type, |
| 4951 explicitConstructor, parameterTypes, argumentTypes)); | |
| 4952 } | |
| 4953 if (_findForwardedConstructors(classElement, superType, callback)) { | |
| 4954 if (implicitConstructors.isEmpty) { | |
| 4955 errorListener.onError(new AnalysisError.con2(classElement.source, | |
| 4956 classElement.nameOffset, classElement.name.length, | |
| 4957 CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, | |
| 4958 [superElement.name])); | |
| 4959 } else { | |
| 4960 classElement.constructors = implicitConstructors; | |
| 4961 } | |
| 4962 } | |
| 4963 }); | |
| 4942 } | 4964 } |
| 4943 ClassElementImpl classElement = node.element as ClassElementImpl; | |
| 4944 if (classElement != null) { | |
| 4945 ClassElement superclassElement = superclassType.element; | |
| 4946 if (superclassElement != null) { | |
| 4947 _callback(classElement, superclassElement, () { | |
| 4948 List<ConstructorElement> implicitConstructors = | |
| 4949 new List<ConstructorElement>(); | |
| 4950 void callback(ConstructorElement explicitConstructor, | |
| 4951 List<DartType> parameterTypes, List<DartType> argumentTypes) { | |
| 4952 implicitConstructors.add(_createImplicitContructor( | |
| 4953 classElement.type, explicitConstructor, parameterTypes, | |
| 4954 argumentTypes)); | |
| 4955 } | |
| 4956 if (_findForwardedConstructors( | |
| 4957 classElement, superclassName, superclassType, callback)) { | |
| 4958 if (implicitConstructors.isEmpty) { | |
| 4959 reportErrorForNode(CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS, | |
| 4960 node, [superclassElement.name]); | |
| 4961 } else { | |
| 4962 classElement.constructors = implicitConstructors; | |
| 4963 } | |
| 4964 } | |
| 4965 }); | |
| 4966 } | |
| 4967 } | |
| 4968 return null; | |
| 4969 } | 4965 } |
| 4970 | 4966 |
| 4971 @override | |
| 4972 Object visitEnumDeclaration(EnumDeclaration node) => null; | |
| 4973 | |
| 4974 @override | |
| 4975 Object visitFunctionDeclaration(FunctionDeclaration node) => null; | |
| 4976 | |
| 4977 @override | |
| 4978 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) => | |
| 4979 null; | |
| 4980 | |
| 4981 /** | 4967 /** |
| 4982 * Create an implicit constructor that is copied from the given constructor, b ut that is in the | 4968 * Create an implicit constructor that is copied from the given constructor, b ut that is in the |
| 4983 * given class. | 4969 * given class. |
| 4984 * | 4970 * |
| 4985 * @param classType the class in which the implicit constructor is defined | 4971 * @param classType the class in which the implicit constructor is defined |
| 4986 * @param explicitConstructor the constructor on which the implicit constructo r is modeled | 4972 * @param explicitConstructor the constructor on which the implicit constructo r is modeled |
| 4987 * @param parameterTypes the types to be replaced when creating parameters | 4973 * @param parameterTypes the types to be replaced when creating parameters |
| 4988 * @param argumentTypes the types with which the parameters are to be replaced | 4974 * @param argumentTypes the types with which the parameters are to be replaced |
| 4989 * @return the implicit constructor that was created | 4975 * @return the implicit constructor that was created |
| 4990 */ | 4976 */ |
| 4991 ConstructorElement _createImplicitContructor(InterfaceType classType, | 4977 static ConstructorElement _createImplicitContructor(InterfaceType classType, |
|
Brian Wilkerson
2015/03/19 17:57:31
I don't like making methods like this 'static'. I
| |
| 4992 ConstructorElement explicitConstructor, List<DartType> parameterTypes, | 4978 ConstructorElement explicitConstructor, List<DartType> parameterTypes, |
| 4993 List<DartType> argumentTypes) { | 4979 List<DartType> argumentTypes) { |
| 4994 ConstructorElementImpl implicitConstructor = | 4980 ConstructorElementImpl implicitConstructor = |
| 4995 new ConstructorElementImpl(explicitConstructor.name, -1); | 4981 new ConstructorElementImpl(explicitConstructor.name, -1); |
| 4996 implicitConstructor.synthetic = true; | 4982 implicitConstructor.synthetic = true; |
| 4997 implicitConstructor.redirectedConstructor = explicitConstructor; | 4983 implicitConstructor.redirectedConstructor = explicitConstructor; |
| 4998 implicitConstructor.const2 = explicitConstructor.isConst; | 4984 implicitConstructor.const2 = explicitConstructor.isConst; |
| 4999 implicitConstructor.returnType = classType; | 4985 implicitConstructor.returnType = classType; |
| 5000 List<ParameterElement> explicitParameters = explicitConstructor.parameters; | 4986 List<ParameterElement> explicitParameters = explicitConstructor.parameters; |
| 5001 int count = explicitParameters.length; | 4987 int count = explicitParameters.length; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 5016 } | 5002 } |
| 5017 implicitConstructor.parameters = implicitParameters; | 5003 implicitConstructor.parameters = implicitParameters; |
| 5018 } | 5004 } |
| 5019 FunctionTypeImpl type = new FunctionTypeImpl.con1(implicitConstructor); | 5005 FunctionTypeImpl type = new FunctionTypeImpl.con1(implicitConstructor); |
| 5020 type.typeArguments = classType.typeArguments; | 5006 type.typeArguments = classType.typeArguments; |
| 5021 implicitConstructor.type = type; | 5007 implicitConstructor.type = type; |
| 5022 return implicitConstructor; | 5008 return implicitConstructor; |
| 5023 } | 5009 } |
| 5024 | 5010 |
| 5025 /** | 5011 /** |
| 5026 * Find all the constructors that should be forwarded from the superclass | 5012 * Find all the constructors that should be forwarded from the given |
| 5027 * named [superclassName], having type [superclassType], to the class or | 5013 * [superclassType], to the class or mixin application [classElement], |
| 5028 * mixin application [classElement], and pass information about them to | 5014 * and pass information about them to [callback]. |
| 5029 * [callback]. | |
| 5030 * | 5015 * |
| 5031 * Return true if some constructors were considered. (A false return value | 5016 * Return true if some constructors were considered. (A false return value |
| 5032 * can only happen if the supeclass is a built-in type, in which case it | 5017 * can only happen if the supeclass is a built-in type, in which case it |
| 5033 * can't be used as a mixin anyway). | 5018 * can't be used as a mixin anyway). |
| 5034 */ | 5019 */ |
| 5035 bool _findForwardedConstructors(ClassElementImpl classElement, | 5020 static bool _findForwardedConstructors(ClassElementImpl classElement, |
| 5036 TypeName superclassName, InterfaceType superclassType, void callback( | 5021 InterfaceType superclassType, void callback( |
| 5037 ConstructorElement explicitConstructor, List<DartType> parameterTypes, | 5022 ConstructorElement explicitConstructor, List<DartType> parameterTypes, |
| 5038 List<DartType> argumentTypes)) { | 5023 List<DartType> argumentTypes)) { |
| 5039 ClassElement superclassElement = superclassType.element; | 5024 ClassElement superclassElement = superclassType.element; |
| 5040 List<ConstructorElement> constructors = superclassElement.constructors; | 5025 List<ConstructorElement> constructors = superclassElement.constructors; |
| 5041 int count = constructors.length; | 5026 int count = constructors.length; |
| 5042 if (count == 0) { | 5027 if (count == 0) { |
| 5043 return false; | 5028 return false; |
| 5044 } | 5029 } |
| 5045 List<DartType> parameterTypes = | 5030 List<DartType> parameterTypes = |
| 5046 TypeParameterTypeImpl.getTypes(superclassType.typeParameters); | 5031 TypeParameterTypeImpl.getTypes(superclassType.typeParameters); |
| 5047 List<DartType> argumentTypes = | 5032 List<DartType> argumentTypes = |
| 5048 _getArgumentTypes(superclassName.typeArguments, parameterTypes); | 5033 _getArgumentTypes(superclassType, parameterTypes); |
| 5049 for (int i = 0; i < count; i++) { | 5034 for (int i = 0; i < count; i++) { |
| 5050 ConstructorElement explicitConstructor = constructors[i]; | 5035 ConstructorElement explicitConstructor = constructors[i]; |
| 5051 if (!explicitConstructor.isFactory && | 5036 if (!explicitConstructor.isFactory && |
| 5052 classElement.isSuperConstructorAccessible(explicitConstructor)) { | 5037 classElement.isSuperConstructorAccessible(explicitConstructor)) { |
| 5053 callback(explicitConstructor, parameterTypes, argumentTypes); | 5038 callback(explicitConstructor, parameterTypes, argumentTypes); |
| 5054 } | 5039 } |
| 5055 } | 5040 } |
| 5056 return true; | 5041 return true; |
| 5057 } | 5042 } |
| 5058 | 5043 |
| 5059 /** | 5044 /** |
| 5060 * Return an array of argument types that corresponds to the array of paramete r types and that are | 5045 * Return a list of argument types that corresponds to the [parameterTypes] |
| 5061 * derived from the given list of type arguments. | 5046 * and that are derived from the type arguments of the given [supertype]. |
| 5062 * | |
| 5063 * @param typeArguments the type arguments from which the types will be taken | |
| 5064 * @param parameterTypes the parameter types that must be matched by the type arguments | |
| 5065 * @return the argument types that correspond to the parameter types | |
| 5066 */ | 5047 */ |
| 5067 List<DartType> _getArgumentTypes( | 5048 static List<DartType> _getArgumentTypes( |
| 5068 TypeArgumentList typeArguments, List<DartType> parameterTypes) { | 5049 InterfaceType supertype, List<DartType> parameterTypes) { |
| 5069 DynamicTypeImpl dynamic = DynamicTypeImpl.instance; | 5050 DynamicTypeImpl dynamic = DynamicTypeImpl.instance; |
| 5070 int parameterCount = parameterTypes.length; | 5051 int parameterCount = parameterTypes.length; |
| 5071 List<DartType> types = new List<DartType>(parameterCount); | 5052 List<DartType> types = new List<DartType>(parameterCount); |
| 5072 if (typeArguments == null) { | 5053 if (supertype == null) { |
| 5073 for (int i = 0; i < parameterCount; i++) { | 5054 types = new List<DartType>.filled(parameterCount, dynamic); |
| 5074 types[i] = dynamic; | |
| 5075 } | |
| 5076 } else { | 5055 } else { |
| 5077 NodeList<TypeName> arguments = typeArguments.arguments; | 5056 List<DartType> typeArguments = supertype.typeArguments; |
| 5078 int argumentCount = math.min(arguments.length, parameterCount); | 5057 int argumentCount = math.min(typeArguments.length, parameterCount); |
| 5079 for (int i = 0; i < argumentCount; i++) { | 5058 for (int i = 0; i < argumentCount; i++) { |
| 5080 types[i] = arguments[i].type; | 5059 types[i] = typeArguments[i]; |
| 5081 } | 5060 } |
| 5082 for (int i = argumentCount; i < parameterCount; i++) { | 5061 for (int i = argumentCount; i < parameterCount; i++) { |
| 5083 types[i] = dynamic; | 5062 types[i] = dynamic; |
| 5084 } | 5063 } |
| 5085 } | 5064 } |
| 5086 return types; | 5065 return types; |
| 5087 } | 5066 } |
| 5088 } | 5067 } |
| 5089 | 5068 |
| 5090 /** | 5069 /** |
| 5091 * An instance of this class is capable of running ImplicitConstructorBuilder | 5070 * An instance of this class is capable of running ImplicitConstructorBuilder |
| 5092 * over all classes in a library cycle. | 5071 * over all classes in a library cycle. |
| 5093 */ | 5072 */ |
| 5094 class ImplicitConstructorComputer { | 5073 class ImplicitConstructorComputer { |
| 5095 /** | 5074 /** |
| 5096 * The object used to access the types from the core library. | |
| 5097 */ | |
| 5098 final TypeProvider typeProvider; | |
| 5099 | |
| 5100 /** | |
| 5101 * Directed graph of dependencies between classes that need to have their | 5075 * Directed graph of dependencies between classes that need to have their |
| 5102 * implicit constructors computed. Each edge in the graph points from a | 5076 * implicit constructors computed. Each edge in the graph points from a |
| 5103 * derived class to its superclass. Implicit constructors will be computed | 5077 * derived class to its superclass. Implicit constructors will be computed |
| 5104 * for the superclass before they are compute for the derived class. | 5078 * for the superclass before they are compute for the derived class. |
| 5105 */ | 5079 */ |
| 5106 DirectedGraph<ClassElement> _dependencies = new DirectedGraph<ClassElement>(); | 5080 DirectedGraph<ClassElement> _dependencies = new DirectedGraph<ClassElement>(); |
| 5107 | 5081 |
| 5108 /** | 5082 /** |
| 5109 * Map from ClassElement to the function which will compute the class's | 5083 * Map from ClassElement to the function which will compute the class's |
| 5110 * implicit constructors. | 5084 * implicit constructors. |
| 5111 */ | 5085 */ |
| 5112 Map<ClassElement, VoidFunction> _computations = | 5086 Map<ClassElement, VoidFunction> _computations = |
| 5113 new HashMap<ClassElement, VoidFunction>(); | 5087 new HashMap<ClassElement, VoidFunction>(); |
| 5114 | 5088 |
| 5115 /** | 5089 /** |
| 5116 * Create an ImplicitConstructorComputer which will use [typeProvider] to | 5090 * Add the given [libraryElement] to the list of libraries which need to have |
| 5117 * access types from the core library. | 5091 * implicit constructors built for them. |
| 5118 */ | 5092 */ |
| 5119 ImplicitConstructorComputer(this.typeProvider); | 5093 void add(AnalysisErrorListener errorListener, LibraryElement libraryElement) { |
| 5120 | 5094 libraryElement |
| 5121 /** | 5095 .accept(new ImplicitConstructorBuilder(errorListener, _defer)); |
| 5122 * Add the given [unit] to the list of units which need to have implicit | |
| 5123 * constructors built for them. [source] is the source file corresponding to | |
| 5124 * the compilation unit, [libraryElement] is the library element containing | |
| 5125 * that source, and [libraryScope] is the scope for the library element. | |
| 5126 */ | |
| 5127 void add(CompilationUnit unit, Source source, LibraryElement libraryElement, | |
| 5128 LibraryScope libraryScope) { | |
| 5129 unit.accept(new ImplicitConstructorBuilder( | |
| 5130 source, libraryElement, libraryScope, typeProvider, _defer)); | |
| 5131 } | 5096 } |
| 5132 | 5097 |
| 5133 /** | 5098 /** |
| 5134 * Compute the implicit constructors for all compilation units that have been | 5099 * Compute the implicit constructors for all compilation units that have been |
| 5135 * passed to [add]. | 5100 * passed to [add]. |
| 5136 */ | 5101 */ |
| 5137 void compute() { | 5102 void compute() { |
| 5138 List<List<ClassElement>> topologicalSort = | 5103 List<List<ClassElement>> topologicalSort = |
| 5139 _dependencies.computeTopologicalSort(); | 5104 _dependencies.computeTopologicalSort(); |
| 5140 for (List<ClassElement> classesInCycle in topologicalSort) { | 5105 for (List<ClassElement> classesInCycle in topologicalSort) { |
| (...skipping 2906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8047 } | 8012 } |
| 8048 | 8013 |
| 8049 /** | 8014 /** |
| 8050 * Finish steps that the [buildTypeHierarchies] could not perform, see | 8015 * Finish steps that the [buildTypeHierarchies] could not perform, see |
| 8051 * [ImplicitConstructorBuilder]. | 8016 * [ImplicitConstructorBuilder]. |
| 8052 * | 8017 * |
| 8053 * @throws AnalysisException if any of the type hierarchies could not be resol ved | 8018 * @throws AnalysisException if any of the type hierarchies could not be resol ved |
| 8054 */ | 8019 */ |
| 8055 void _buildImplicitConstructors() { | 8020 void _buildImplicitConstructors() { |
| 8056 PerformanceStatistics.resolve.makeCurrentWhile(() { | 8021 PerformanceStatistics.resolve.makeCurrentWhile(() { |
| 8057 ImplicitConstructorComputer computer = | 8022 ImplicitConstructorComputer computer = new ImplicitConstructorComputer(); |
| 8058 new ImplicitConstructorComputer(_typeProvider); | |
| 8059 for (Library library in _librariesInCycles) { | 8023 for (Library library in _librariesInCycles) { |
| 8060 for (Source source in library.compilationUnitSources) { | 8024 computer.add(_errorListener, library.libraryElement); |
| 8061 computer.add(library.getAST(source), source, library.libraryElement, | |
| 8062 library.libraryScope); | |
| 8063 } | |
| 8064 } | 8025 } |
| 8065 computer.compute(); | 8026 computer.compute(); |
| 8066 }); | 8027 }); |
| 8067 } | 8028 } |
| 8068 | 8029 |
| 8069 /** | 8030 /** |
| 8070 * Resolve the types referenced by function type aliases across all of the fun ction type aliases | 8031 * Resolve the types referenced by function type aliases across all of the fun ction type aliases |
| 8071 * defined in the current cycle. | 8032 * defined in the current cycle. |
| 8072 * | 8033 * |
| 8073 * @throws AnalysisException if any of the function type aliases could not be resolved | 8034 * @throws AnalysisException if any of the function type aliases could not be resolved |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8752 } | 8713 } |
| 8753 | 8714 |
| 8754 /** | 8715 /** |
| 8755 * Finish steps that the [buildTypeHierarchies] could not perform, see | 8716 * Finish steps that the [buildTypeHierarchies] could not perform, see |
| 8756 * [ImplicitConstructorBuilder]. | 8717 * [ImplicitConstructorBuilder]. |
| 8757 * | 8718 * |
| 8758 * @throws AnalysisException if any of the type hierarchies could not be resol ved | 8719 * @throws AnalysisException if any of the type hierarchies could not be resol ved |
| 8759 */ | 8720 */ |
| 8760 void _buildImplicitConstructors() { | 8721 void _buildImplicitConstructors() { |
| 8761 PerformanceStatistics.resolve.makeCurrentWhile(() { | 8722 PerformanceStatistics.resolve.makeCurrentWhile(() { |
| 8762 ImplicitConstructorComputer computer = | 8723 ImplicitConstructorComputer computer = new ImplicitConstructorComputer(); |
| 8763 new ImplicitConstructorComputer(_typeProvider); | |
| 8764 for (ResolvableLibrary library in _librariesInCycle) { | 8724 for (ResolvableLibrary library in _librariesInCycle) { |
| 8765 for (ResolvableCompilationUnit unit | 8725 computer.add(_errorListener, library.libraryElement); |
| 8766 in library.resolvableCompilationUnits) { | |
| 8767 Source source = unit.source; | |
| 8768 CompilationUnit ast = unit.compilationUnit; | |
| 8769 computer.add( | |
| 8770 ast, source, library.libraryElement, library.libraryScope); | |
| 8771 } | |
| 8772 } | 8726 } |
| 8773 computer.compute(); | 8727 computer.compute(); |
| 8774 }); | 8728 }); |
| 8775 } | 8729 } |
| 8776 | 8730 |
| 8777 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { | 8731 HashMap<Source, ResolvableLibrary> _buildLibraryMap() { |
| 8778 HashMap<Source, ResolvableLibrary> libraryMap = | 8732 HashMap<Source, ResolvableLibrary> libraryMap = |
| 8779 new HashMap<Source, ResolvableLibrary>(); | 8733 new HashMap<Source, ResolvableLibrary>(); |
| 8780 int libraryCount = _librariesInCycle.length; | 8734 int libraryCount = _librariesInCycle.length; |
| 8781 for (int i = 0; i < libraryCount; i++) { | 8735 for (int i = 0; i < libraryCount; i++) { |
| (...skipping 5791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14573 */ | 14527 */ |
| 14574 void _resolve(ClassElementImpl classElement, WithClause withClause, | 14528 void _resolve(ClassElementImpl classElement, WithClause withClause, |
| 14575 ImplementsClause implementsClause) { | 14529 ImplementsClause implementsClause) { |
| 14576 if (withClause != null) { | 14530 if (withClause != null) { |
| 14577 List<InterfaceType> mixinTypes = _resolveTypes(withClause.mixinTypes, | 14531 List<InterfaceType> mixinTypes = _resolveTypes(withClause.mixinTypes, |
| 14578 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, | 14532 CompileTimeErrorCode.MIXIN_OF_NON_CLASS, |
| 14579 CompileTimeErrorCode.MIXIN_OF_ENUM, | 14533 CompileTimeErrorCode.MIXIN_OF_ENUM, |
| 14580 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); | 14534 CompileTimeErrorCode.MIXIN_OF_NON_CLASS); |
| 14581 if (classElement != null) { | 14535 if (classElement != null) { |
| 14582 classElement.mixins = mixinTypes; | 14536 classElement.mixins = mixinTypes; |
| 14537 classElement.withClauseRange = | |
| 14538 new SourceRange(withClause.offset, withClause.length); | |
| 14583 } | 14539 } |
| 14584 } | 14540 } |
| 14585 if (implementsClause != null) { | 14541 if (implementsClause != null) { |
| 14586 NodeList<TypeName> interfaces = implementsClause.interfaces; | 14542 NodeList<TypeName> interfaces = implementsClause.interfaces; |
| 14587 List<InterfaceType> interfaceTypes = _resolveTypes(interfaces, | 14543 List<InterfaceType> interfaceTypes = _resolveTypes(interfaces, |
| 14588 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, | 14544 CompileTimeErrorCode.IMPLEMENTS_NON_CLASS, |
| 14589 CompileTimeErrorCode.IMPLEMENTS_ENUM, | 14545 CompileTimeErrorCode.IMPLEMENTS_ENUM, |
| 14590 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); | 14546 CompileTimeErrorCode.IMPLEMENTS_DYNAMIC); |
| 14591 if (classElement != null) { | 14547 if (classElement != null) { |
| 14592 classElement.interfaces = interfaceTypes; | 14548 classElement.interfaces = interfaceTypes; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14817 ExecutableElement outerFunction = _enclosingFunction; | 14773 ExecutableElement outerFunction = _enclosingFunction; |
| 14818 try { | 14774 try { |
| 14819 _enclosingFunction = node.element; | 14775 _enclosingFunction = node.element; |
| 14820 return super.visitFunctionDeclaration(node); | 14776 return super.visitFunctionDeclaration(node); |
| 14821 } finally { | 14777 } finally { |
| 14822 _enclosingFunction = outerFunction; | 14778 _enclosingFunction = outerFunction; |
| 14823 } | 14779 } |
| 14824 } | 14780 } |
| 14825 | 14781 |
| 14826 @override | 14782 @override |
| 14827 Object visitMethodDeclaration(MethodDeclaration node) { | |
| 14828 ExecutableElement outerFunction = _enclosingFunction; | |
| 14829 try { | |
| 14830 _enclosingFunction = node.element; | |
| 14831 return super.visitMethodDeclaration(node); | |
| 14832 } finally { | |
| 14833 _enclosingFunction = outerFunction; | |
| 14834 } | |
| 14835 } | |
| 14836 | |
| 14837 @override | |
| 14838 Object visitFunctionExpression(FunctionExpression node) { | 14783 Object visitFunctionExpression(FunctionExpression node) { |
| 14839 if (node.parent is! FunctionDeclaration) { | 14784 if (node.parent is! FunctionDeclaration) { |
| 14840 ExecutableElement outerFunction = _enclosingFunction; | 14785 ExecutableElement outerFunction = _enclosingFunction; |
| 14841 try { | 14786 try { |
| 14842 _enclosingFunction = node.element; | 14787 _enclosingFunction = node.element; |
| 14843 return super.visitFunctionExpression(node); | 14788 return super.visitFunctionExpression(node); |
| 14844 } finally { | 14789 } finally { |
| 14845 _enclosingFunction = outerFunction; | 14790 _enclosingFunction = outerFunction; |
| 14846 } | 14791 } |
| 14847 } else { | 14792 } else { |
| 14848 return super.visitFunctionExpression(node); | 14793 return super.visitFunctionExpression(node); |
| 14849 } | 14794 } |
| 14850 } | 14795 } |
| 14851 | 14796 |
| 14852 @override | 14797 @override |
| 14853 Object visitImportDirective(ImportDirective node) => null; | 14798 Object visitImportDirective(ImportDirective node) => null; |
| 14854 | 14799 |
| 14855 @override | 14800 @override |
| 14801 Object visitMethodDeclaration(MethodDeclaration node) { | |
| 14802 ExecutableElement outerFunction = _enclosingFunction; | |
| 14803 try { | |
| 14804 _enclosingFunction = node.element; | |
| 14805 return super.visitMethodDeclaration(node); | |
| 14806 } finally { | |
| 14807 _enclosingFunction = outerFunction; | |
| 14808 } | |
| 14809 } | |
| 14810 | |
| 14811 @override | |
| 14856 Object visitSimpleIdentifier(SimpleIdentifier node) { | 14812 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 14857 // Ignore if already resolved - declaration or type. | 14813 // Ignore if already resolved - declaration or type. |
| 14858 if (node.staticElement != null) { | 14814 if (node.staticElement != null) { |
| 14859 return null; | 14815 return null; |
| 14860 } | 14816 } |
| 14861 // Ignore if qualified. | 14817 // Ignore if qualified. |
| 14862 AstNode parent = node.parent; | 14818 AstNode parent = node.parent; |
| 14863 if (parent is PrefixedIdentifier && identical(parent.identifier, node)) { | 14819 if (parent is PrefixedIdentifier && identical(parent.identifier, node)) { |
| 14864 return null; | 14820 return null; |
| 14865 } | 14821 } |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15386 * library. | 15342 * library. |
| 15387 */ | 15343 */ |
| 15388 final HashSet<String> members = new HashSet<String>(); | 15344 final HashSet<String> members = new HashSet<String>(); |
| 15389 | 15345 |
| 15390 /** | 15346 /** |
| 15391 * Names of resolved or unresolved class members that are read in the | 15347 * Names of resolved or unresolved class members that are read in the |
| 15392 * library. | 15348 * library. |
| 15393 */ | 15349 */ |
| 15394 final HashSet<String> readMembers = new HashSet<String>(); | 15350 final HashSet<String> readMembers = new HashSet<String>(); |
| 15395 } | 15351 } |
| OLD | NEW |