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 | 7 import 'common/names.dart' show |
8 Identifiers; | 8 Identifiers; |
9 import 'common/resolution.dart' show | 9 import 'common/resolution.dart' show |
10 Resolution; | 10 Resolution; |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 } else { | 447 } else { |
448 lastSeenNode = node; | 448 lastSeenNode = node; |
449 } | 449 } |
450 bool previouslyInitializer = analyzingInitializer; | 450 bool previouslyInitializer = analyzingInitializer; |
451 analyzingInitializer = inInitializer; | 451 analyzingInitializer = inInitializer; |
452 DartType result = node.accept(this); | 452 DartType result = node.accept(this); |
453 analyzingInitializer = previouslyInitializer; | 453 analyzingInitializer = previouslyInitializer; |
454 if (result == null) { | 454 if (result == null) { |
455 compiler.internalError(node, 'Type is null.'); | 455 compiler.internalError(node, 'Type is null.'); |
456 } | 456 } |
457 return result; | 457 return _record(node, result); |
458 } | 458 } |
459 | 459 |
460 void checkTypePromotion(Node node, TypePromotion typePromotion, | 460 void checkTypePromotion(Node node, TypePromotion typePromotion, |
461 {bool checkAccesses: false}) { | 461 {bool checkAccesses: false}) { |
462 VariableElement variable = typePromotion.variable; | 462 VariableElement variable = typePromotion.variable; |
463 String variableName = variable.name; | 463 String variableName = variable.name; |
464 List<Node> potentialMutationsIn = | 464 List<Node> potentialMutationsIn = |
465 elements.getPotentialMutationsIn(node, variable); | 465 elements.getPotentialMutationsIn(node, variable); |
466 if (!potentialMutationsIn.isEmpty) { | 466 if (!potentialMutationsIn.isEmpty) { |
467 DiagnosticMessage hint = compiler.createMessage( | 467 DiagnosticMessage hint = compiler.createMessage( |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 types.isMoreSpecific(shownTypeGeneric, knownType)) { | 1155 types.isMoreSpecific(shownTypeGeneric, knownType)) { |
1156 // This should be the case but we double-check. | 1156 // This should be the case but we double-check. |
1157 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. | 1157 // TODO(johnniwinther): Ensure that we don't suggest malbounded types. |
1158 return shownTypeGeneric; | 1158 return shownTypeGeneric; |
1159 } | 1159 } |
1160 } | 1160 } |
1161 return null; | 1161 return null; |
1162 | 1162 |
1163 } | 1163 } |
1164 | 1164 |
| 1165 static bool _fyiShown = false; |
| 1166 DartType _record(Node node, DartType type) { |
| 1167 if (node is! Expression) return type; |
| 1168 if (const bool.fromEnvironment('send_stats') && |
| 1169 executableContext != null && |
| 1170 // TODO(sigmund): enable also in core libs. |
| 1171 !executableContext.library.isPlatformLibrary && !type.isDynamic) { |
| 1172 if (!_fyiShown) { |
| 1173 print('FYI experiment to collect send stats is on: ' |
| 1174 'caching types of expressions'); |
| 1175 _fyiShown = true; |
| 1176 } |
| 1177 elements.typesCache[node] = type; |
| 1178 } |
| 1179 return type; |
| 1180 } |
| 1181 |
1165 DartType visitSend(Send node) { | 1182 DartType visitSend(Send node) { |
1166 Element element = elements[node]; | 1183 Element element = elements[node]; |
1167 | 1184 |
1168 if (element != null && element.isConstructor) { | 1185 if (element != null && element.isConstructor) { |
1169 DartType receiverType; | 1186 DartType receiverType; |
1170 if (node.receiver != null) { | 1187 if (node.receiver != null) { |
1171 receiverType = analyze(node.receiver); | 1188 receiverType = analyze(node.receiver); |
1172 } else if (node.selector.isSuper()) { | 1189 } else if (node.selector.isSuper()) { |
1173 // TODO(johnniwinther): Lookup super-member in class members. | 1190 // TODO(johnniwinther): Lookup super-member in class members. |
1174 receiverType = superType; | 1191 receiverType = superType; |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 } | 1745 } |
1729 for (Link<Node> link = node.definitions.nodes; !link.isEmpty; | 1746 for (Link<Node> link = node.definitions.nodes; !link.isEmpty; |
1730 link = link.tail) { | 1747 link = link.tail) { |
1731 Node definition = link.head; | 1748 Node definition = link.head; |
1732 invariant(definition, definition is Identifier || definition is SendSet, | 1749 invariant(definition, definition is Identifier || definition is SendSet, |
1733 message: 'expected identifier or initialization'); | 1750 message: 'expected identifier or initialization'); |
1734 if (definition is SendSet) { | 1751 if (definition is SendSet) { |
1735 SendSet initialization = definition; | 1752 SendSet initialization = definition; |
1736 DartType initializer = analyzeNonVoid(initialization.arguments.head); | 1753 DartType initializer = analyzeNonVoid(initialization.arguments.head); |
1737 checkAssignable(initialization.assignmentOperator, initializer, type); | 1754 checkAssignable(initialization.assignmentOperator, initializer, type); |
| 1755 // TODO(sigmund): explore inferring a type for `var` using the RHS (like |
| 1756 // DDC does), for example: |
| 1757 // if (node.type == null && node.modifiers.isVar && |
| 1758 // !initializer.isDynamic) { |
| 1759 // var variable = elements[definition]; |
| 1760 // if (variable != null) { |
| 1761 // var typePromotion = new TypePromotion( |
| 1762 // node, variable, initializer); |
| 1763 // registerKnownTypePromotion(typePromotion); |
| 1764 // } |
| 1765 // } |
1738 } | 1766 } |
1739 } | 1767 } |
1740 return const StatementType(); | 1768 return const StatementType(); |
1741 } | 1769 } |
1742 | 1770 |
1743 DartType visitWhile(While node) { | 1771 DartType visitWhile(While node) { |
1744 checkCondition(node.condition); | 1772 checkCondition(node.condition); |
1745 analyze(node.body); | 1773 analyze(node.body); |
1746 return const StatementType(); | 1774 return const StatementType(); |
1747 } | 1775 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1973 | 2001 |
1974 visitTypedef(Typedef node) { | 2002 visitTypedef(Typedef node) { |
1975 // Do not typecheck [Typedef] nodes. | 2003 // Do not typecheck [Typedef] nodes. |
1976 } | 2004 } |
1977 | 2005 |
1978 visitNode(Node node) { | 2006 visitNode(Node node) { |
1979 compiler.internalError(node, | 2007 compiler.internalError(node, |
1980 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 2008 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
1981 } | 2009 } |
1982 } | 2010 } |
OLD | NEW |