| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
| 6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
| 7 library dev_compiler.src.checker.resolver; | 7 library dev_compiler.src.checker.resolver; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 visit(ClassDeclaration cls) { | 153 visit(ClassDeclaration cls) { |
| 154 var element = cls.element; | 154 var element = cls.element; |
| 155 var type = element.type; | 155 var type = element.type; |
| 156 if (seen.contains(type)) return; | 156 if (seen.contains(type)) return; |
| 157 seen.add(type); | 157 seen.add(type); |
| 158 for (var supertype in element.allSupertypes) { | 158 for (var supertype in element.allSupertypes) { |
| 159 var supertypeClass = typeToDeclaration[supertype]; | 159 var supertypeClass = typeToDeclaration[supertype]; |
| 160 if (supertypeClass != null) visit(supertypeClass); | 160 if (supertypeClass != null) visit(supertypeClass); |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (_options.inferFromOverrides) { | 163 // Infer field types from overrides first, otherwise from initializers. |
| 164 // Infer field types from overrides first, otherwise from initializers. | 164 var pending = new Set<VariableDeclaration>(); |
| 165 var pending = new Set<VariableDeclaration>(); | 165 cls.members |
| 166 cls.members | 166 .where(_isInstanceField) |
| 167 .where(_isInstanceField) | 167 .forEach((f) => _inferFieldTypeFromOverride(f, pending)); |
| 168 .forEach((f) => _inferFieldTypeFromOverride(f, pending)); | 168 if (pending.isNotEmpty) _inferVariableFromInitializer(pending); |
| 169 if (pending.isNotEmpty) _inferVariableFromInitializer(pending); | |
| 170 | 169 |
| 171 // Infer return-types and param-types from overrides | 170 // Infer return-types and param-types from overrides |
| 172 cls.members | 171 cls.members |
| 173 .where((m) => m is MethodDeclaration && !m.isStatic) | 172 .where((m) => m is MethodDeclaration && !m.isStatic) |
| 174 .forEach(_inferMethodTypesFromOverride); | 173 .forEach(_inferMethodTypesFromOverride); |
| 175 } else { | |
| 176 _inferVariableFromInitializer(cls.members | |
| 177 .where(_isInstanceField) | |
| 178 .expand((f) => f.fields.variables)); | |
| 179 } | |
| 180 } | 174 } |
| 181 classes.forEach(visit); | 175 classes.forEach(visit); |
| 182 } | 176 } |
| 183 | 177 |
| 184 void _reanalyzeVar(Map<Source, RestrictedResolverVisitor> visitors, | 178 void _reanalyzeVar(Map<Source, RestrictedResolverVisitor> visitors, |
| 185 VariableDeclaration variable) { | 179 VariableDeclaration variable) { |
| 186 if (variable.initializer == null) return; | 180 if (variable.initializer == null) return; |
| 187 var visitor = visitors[(variable.root as CompilationUnit).element.source]; | 181 var visitor = visitors[(variable.root as CompilationUnit).element.source]; |
| 188 visitor.reanalyzeInitializer(variable); | 182 visitor.reanalyzeInitializer(variable); |
| 189 } | 183 } |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 } | 793 } |
| 800 } | 794 } |
| 801 | 795 |
| 802 // Review note: no longer need to override visitFunctionExpression, this is | 796 // Review note: no longer need to override visitFunctionExpression, this is |
| 803 // handled by the analyzer internally. | 797 // handled by the analyzer internally. |
| 804 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 798 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 805 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 799 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 806 // type in a (...) => expr or just the written type? | 800 // type in a (...) => expr or just the written type? |
| 807 | 801 |
| 808 } | 802 } |
| OLD | NEW |