| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 inferrer_visitor; | 5 library inferrer_visitor; |
| 6 | 6 |
| 7 import '../dart2jslib.dart' hide Selector, TypedSelector; | 7 import '../dart2jslib.dart' hide Selector, TypedSelector; |
| 8 import '../dart_types.dart'; | 8 import '../dart_types.dart'; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../tree/tree.dart'; | 10 import '../tree/tree.dart'; |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 narrow(receiverElement, objectType, node); | 828 narrow(receiverElement, objectType, node); |
| 829 } | 829 } |
| 830 if (Elements.isLocal(argumentElement)) { | 830 if (Elements.isLocal(argumentElement)) { |
| 831 narrow(argumentElement, objectType, node); | 831 narrow(argumentElement, objectType, node); |
| 832 } | 832 } |
| 833 } | 833 } |
| 834 } | 834 } |
| 835 } | 835 } |
| 836 } | 836 } |
| 837 | 837 |
| 838 /// Stops the accumulation of is-checks. | |
| 839 /// | |
| 840 /// Nulls the [isChecks] field. | |
| 841 /// | |
| 842 /// Returns the old value of [accumulateIsChecks]. | |
| 843 bool stopAccumulatingIsChecks() { | |
| 844 bool oldAccumulateIsChecks = accumulateIsChecks; | |
| 845 accumulateIsChecks = false; | |
| 846 isChecks = null; | |
| 847 return oldAccumulateIsChecks; | |
| 848 } | |
| 849 | |
| 850 T visitOperatorSend(Send node) { | 838 T visitOperatorSend(Send node) { |
| 851 Operator op = node.selector; | 839 Operator op = node.selector; |
| 852 if ("[]" == op.source) { | 840 if ("[]" == op.source) { |
| 853 return visitDynamicSend(node); | 841 return visitDynamicSend(node); |
| 854 } else if ("&&" == op.source) { | 842 } else if ("&&" == op.source) { |
| 855 conditionIsSimple = false; | 843 conditionIsSimple = false; |
| 856 bool oldAccumulateIsChecks = accumulateIsChecks; | 844 bool oldAccumulateIsChecks = accumulateIsChecks; |
| 857 if (!accumulateIsChecks) { | 845 accumulateIsChecks = true; |
| 858 accumulateIsChecks = true; | 846 if (isChecks == null) isChecks = <Send>[]; |
| 859 isChecks = <Send>[]; | |
| 860 } | |
| 861 visit(node.receiver); | 847 visit(node.receiver); |
| 862 if (!oldAccumulateIsChecks) { | 848 accumulateIsChecks = oldAccumulateIsChecks; |
| 863 accumulateIsChecks = false; | 849 if (!accumulateIsChecks) isChecks = null; |
| 864 isChecks = null; | |
| 865 } | |
| 866 LocalsHandler<T> saved = locals; | 850 LocalsHandler<T> saved = locals; |
| 867 locals = new LocalsHandler<T>.from(locals, node); | 851 locals = new LocalsHandler<T>.from(locals, node); |
| 868 updateIsChecks(isChecks, usePositive: true); | 852 updateIsChecks(isChecks, usePositive: true); |
| 869 visit(node.arguments.head); | 853 visit(node.arguments.head); |
| 870 saved.mergeDiamondFlow(locals, null); | 854 saved.mergeDiamondFlow(locals, null); |
| 871 locals = saved; | 855 locals = saved; |
| 872 return types.boolType; | 856 return types.boolType; |
| 873 } else if ("||" == op.source) { | 857 } else if ("||" == op.source) { |
| 874 conditionIsSimple = false; | 858 conditionIsSimple = false; |
| 875 List<Send> tests = <Send>[]; | 859 List<Send> tests = <Send>[]; |
| 876 bool isSimple = handleCondition(node.receiver, tests); | 860 handleCondition(node.receiver, tests); |
| 877 LocalsHandler<T> saved = locals; | 861 LocalsHandler<T> saved = locals; |
| 878 locals = new LocalsHandler<T>.from(locals, node); | 862 locals = new LocalsHandler<T>.from(locals, node); |
| 879 if (isSimple) updateIsChecks(tests, usePositive: false); | 863 updateIsChecks(tests, usePositive: false); |
| 880 bool oldAccumulateIsChecks = stopAccumulatingIsChecks(); | 864 bool oldAccumulateIsChecks = accumulateIsChecks; |
| 865 accumulateIsChecks = false; |
| 881 visit(node.arguments.head); | 866 visit(node.arguments.head); |
| 882 accumulateIsChecks = oldAccumulateIsChecks; | 867 accumulateIsChecks = oldAccumulateIsChecks; |
| 883 saved.mergeDiamondFlow(locals, null); | 868 saved.mergeDiamondFlow(locals, null); |
| 884 locals = saved; | 869 locals = saved; |
| 885 return types.boolType; | 870 return types.boolType; |
| 886 } else if ("!" == op.source) { | 871 } else if ("!" == op.source) { |
| 887 bool oldAccumulateIsChecks = stopAccumulatingIsChecks(); | 872 bool oldAccumulateIsChecks = accumulateIsChecks; |
| 873 accumulateIsChecks = false; |
| 888 node.visitChildren(this); | 874 node.visitChildren(this); |
| 889 accumulateIsChecks = oldAccumulateIsChecks; | 875 accumulateIsChecks = oldAccumulateIsChecks; |
| 890 return types.boolType; | 876 return types.boolType; |
| 891 } else if ("is" == op.source) { | 877 } else if ("is" == op.source) { |
| 892 potentiallyAddIsCheck(node); | 878 potentiallyAddIsCheck(node); |
| 893 node.visitChildren(this); | 879 node.visitChildren(this); |
| 894 return types.boolType; | 880 return types.boolType; |
| 895 } else if ("as" == op.source) { | 881 } else if ("as" == op.source) { |
| 896 T receiverType = visit(node.receiver); | 882 T receiverType = visit(node.receiver); |
| 897 DartType type = elements.getType(node.arguments.head); | 883 DartType type = elements.getType(node.arguments.head); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1220 return type; | 1206 return type; |
| 1221 } | 1207 } |
| 1222 | 1208 |
| 1223 T visitCascade(Cascade node) { | 1209 T visitCascade(Cascade node) { |
| 1224 // Ignore the result of the cascade send and return the type of the cascade | 1210 // Ignore the result of the cascade send and return the type of the cascade |
| 1225 // receiver. | 1211 // receiver. |
| 1226 visit(node.expression); | 1212 visit(node.expression); |
| 1227 return cascadeReceiverStack.removeLast(); | 1213 return cascadeReceiverStack.removeLast(); |
| 1228 } | 1214 } |
| 1229 } | 1215 } |
| OLD | NEW |