| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.typechecker; | 5 library dart2js.typechecker; |
| 6 | 6 |
| 7 import 'common/names.dart' show Identifiers; | 7 import 'common/names.dart' show Identifiers; |
| 8 import 'common/resolution.dart' show Resolution; | 8 import 'common/resolution.dart' show Resolution; |
| 9 import 'common/tasks.dart' show CompilerTask; | 9 import 'common/tasks.dart' show CompilerTask; |
| 10 import 'common.dart'; | 10 import 'common.dart'; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 } else { | 436 } else { |
| 437 lastSeenNode = node; | 437 lastSeenNode = node; |
| 438 } | 438 } |
| 439 bool previouslyInitializer = analyzingInitializer; | 439 bool previouslyInitializer = analyzingInitializer; |
| 440 analyzingInitializer = inInitializer; | 440 analyzingInitializer = inInitializer; |
| 441 DartType result = node.accept(this); | 441 DartType result = node.accept(this); |
| 442 analyzingInitializer = previouslyInitializer; | 442 analyzingInitializer = previouslyInitializer; |
| 443 if (result == null) { | 443 if (result == null) { |
| 444 reporter.internalError(node, 'Type is null.'); | 444 reporter.internalError(node, 'Type is null.'); |
| 445 } | 445 } |
| 446 return _record(node, result); | 446 return result; |
| 447 } | 447 } |
| 448 | 448 |
| 449 void checkTypePromotion(Node node, TypePromotion typePromotion, | 449 void checkTypePromotion(Node node, TypePromotion typePromotion, |
| 450 {bool checkAccesses: false}) { | 450 {bool checkAccesses: false}) { |
| 451 VariableElement variable = typePromotion.variable; | 451 VariableElement variable = typePromotion.variable; |
| 452 String variableName = variable.name; | 452 String variableName = variable.name; |
| 453 List<Node> potentialMutationsIn = | 453 List<Node> potentialMutationsIn = |
| 454 elements.getPotentialMutationsIn(node, variable); | 454 elements.getPotentialMutationsIn(node, variable); |
| 455 if (!potentialMutationsIn.isEmpty) { | 455 if (!potentialMutationsIn.isEmpty) { |
| 456 DiagnosticMessage hint = reporter.createMessage( | 456 DiagnosticMessage hint = reporter.createMessage( |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 if (shownTypeGeneric != null && | 1144 if (shownTypeGeneric != null && |
| 1145 types.isMoreSpecific(shownTypeGeneric, knownType)) { | 1145 types.isMoreSpecific(shownTypeGeneric, knownType)) { |
| 1146 // This should be the case but we double-check. | 1146 // This should be the case but we double-check. |
| 1147 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. | 1147 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. |
| 1148 return shownTypeGeneric; | 1148 return shownTypeGeneric; |
| 1149 } | 1149 } |
| 1150 } | 1150 } |
| 1151 return null; | 1151 return null; |
| 1152 } | 1152 } |
| 1153 | 1153 |
| 1154 static bool _fyiShown = false; | |
| 1155 DartType _record(Node node, DartType type) { | |
| 1156 if (node is! Expression) return type; | |
| 1157 if (const bool.fromEnvironment('send_stats') && | |
| 1158 executableContext != null && | |
| 1159 // TODO(sigmund): enable also in core libs. | |
| 1160 !executableContext.library.isPlatformLibrary && | |
| 1161 !type.isDynamic) { | |
| 1162 if (!_fyiShown) { | |
| 1163 print('FYI experiment to collect send stats is on: ' | |
| 1164 'caching types of expressions'); | |
| 1165 _fyiShown = true; | |
| 1166 } | |
| 1167 elements.typesCache[node] = type; | |
| 1168 } | |
| 1169 return type; | |
| 1170 } | |
| 1171 | |
| 1172 DartType visitSend(Send node) { | 1154 DartType visitSend(Send node) { |
| 1173 Element element = elements[node]; | 1155 Element element = elements[node]; |
| 1174 | 1156 |
| 1175 if (element != null && element.isConstructor) { | 1157 if (element != null && element.isConstructor) { |
| 1176 DartType receiverType; | 1158 DartType receiverType; |
| 1177 if (node.receiver != null) { | 1159 if (node.receiver != null) { |
| 1178 receiverType = analyze(node.receiver); | 1160 receiverType = analyze(node.receiver); |
| 1179 } else if (node.selector.isSuper()) { | 1161 } else if (node.selector.isSuper()) { |
| 1180 // TODO(johnniwinther): Lookup super-member in class members. | 1162 // TODO(johnniwinther): Lookup super-member in class members. |
| 1181 receiverType = superType; | 1163 receiverType = superType; |
| (...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 | 2027 |
| 2046 visitTypedef(Typedef node) { | 2028 visitTypedef(Typedef node) { |
| 2047 // Do not typecheck [Typedef] nodes. | 2029 // Do not typecheck [Typedef] nodes. |
| 2048 } | 2030 } |
| 2049 | 2031 |
| 2050 visitNode(Node node) { | 2032 visitNode(Node node) { |
| 2051 reporter.internalError(node, | 2033 reporter.internalError(node, |
| 2052 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2034 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
| 2053 } | 2035 } |
| 2054 } | 2036 } |
| OLD | NEW |