Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: pkg/compiler/lib/src/ssa/value_range_analyzer.dart

Issue 2941033002: Finish strong mode cleaning of dart2js. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 import '../constant_system_dart.dart'; 5 import '../constant_system_dart.dart';
6 import '../constants/constant_system.dart'; 6 import '../constants/constant_system.dart';
7 import '../constants/values.dart'; 7 import '../constants/values.dart';
8 import '../world.dart' show ClosedWorld; 8 import '../world.dart' show ClosedWorld;
9 import 'nodes.dart'; 9 import 'nodes.dart';
10 import 'optimize.dart'; 10 import 'optimize.dart';
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 /** 127 /**
128 * An [IntValue] contains a constant integer value. 128 * An [IntValue] contains a constant integer value.
129 */ 129 */
130 class IntValue extends Value { 130 class IntValue extends Value {
131 final int value; 131 final int value;
132 132
133 const IntValue(this.value, info) : super(info); 133 const IntValue(this.value, info) : super(info);
134 134
135 Value operator +(other) { 135 Value operator +(dynamic other) {
136 if (other.isZero) return this; 136 if (other.isZero) return this;
137 if (other is! IntValue) return other + this; 137 if (other is! IntValue) return other + this;
138 ConstantSystem constantSystem = info.constantSystem; 138 ConstantSystem constantSystem = info.constantSystem;
139 var constant = constantSystem.add.fold( 139 dynamic constant = constantSystem.add.fold(
140 constantSystem.createInt(value), constantSystem.createInt(other.value)); 140 constantSystem.createInt(value), constantSystem.createInt(other.value));
141 if (!constant.isInt) return const UnknownValue(); 141 if (!constant.isInt) return const UnknownValue();
142 return info.newIntValue(constant.primitiveValue); 142 return info.newIntValue(constant.primitiveValue);
143 } 143 }
144 144
145 Value operator -(other) { 145 Value operator -(dynamic other) {
146 if (other.isZero) return this; 146 if (other.isZero) return this;
147 if (other is! IntValue) return -other + this; 147 if (other is! IntValue) return -other + this;
148 ConstantSystem constantSystem = info.constantSystem; 148 ConstantSystem constantSystem = info.constantSystem;
149 var constant = constantSystem.subtract.fold( 149 dynamic constant = constantSystem.subtract.fold(
150 constantSystem.createInt(value), constantSystem.createInt(other.value)); 150 constantSystem.createInt(value), constantSystem.createInt(other.value));
151 if (!constant.isInt) return const UnknownValue(); 151 if (!constant.isInt) return const UnknownValue();
152 return info.newIntValue(constant.primitiveValue); 152 return info.newIntValue(constant.primitiveValue);
153 } 153 }
154 154
155 Value operator -() { 155 Value operator -() {
156 if (isZero) return this; 156 if (isZero) return this;
157 ConstantSystem constantSystem = info.constantSystem; 157 ConstantSystem constantSystem = info.constantSystem;
158 var constant = constantSystem.negate.fold(constantSystem.createInt(value)); 158 dynamic constant =
159 constantSystem.negate.fold(constantSystem.createInt(value));
159 if (!constant.isInt) return const UnknownValue(); 160 if (!constant.isInt) return const UnknownValue();
160 return info.newIntValue(constant.primitiveValue); 161 return info.newIntValue(constant.primitiveValue);
161 } 162 }
162 163
163 Value operator &(other) { 164 Value operator &(dynamic other) {
164 if (other is! IntValue) return const UnknownValue(); 165 if (other is! IntValue) return const UnknownValue();
165 ConstantSystem constantSystem = info.constantSystem; 166 ConstantSystem constantSystem = info.constantSystem;
166 var constant = constantSystem.bitAnd.fold( 167 dynamic constant = constantSystem.bitAnd.fold(
167 constantSystem.createInt(value), constantSystem.createInt(other.value)); 168 constantSystem.createInt(value), constantSystem.createInt(other.value));
168 return info.newIntValue(constant.primitiveValue); 169 return info.newIntValue(constant.primitiveValue);
169 } 170 }
170 171
171 Value min(other) { 172 Value min(dynamic other) {
172 if (other is! IntValue) return other.min(this); 173 if (other is! IntValue) return other.min(this);
173 return this.value < other.value ? this : other; 174 return this.value < other.value ? this : other;
174 } 175 }
175 176
176 Value max(other) { 177 Value max(dynamic other) {
177 if (other is! IntValue) return other.max(this); 178 if (other is! IntValue) return other.max(this);
178 return this.value < other.value ? other : this; 179 return this.value < other.value ? other : this;
179 } 180 }
180 181
181 bool operator ==(other) { 182 bool operator ==(other) {
182 if (other is! IntValue) return false; 183 if (other is! IntValue) return false;
183 return this.value == other.value; 184 return this.value == other.value;
184 } 185 }
185 186
186 int get hashCode => throw new UnsupportedError('IntValue.hashCode'); 187 int get hashCode => throw new UnsupportedError('IntValue.hashCode');
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 rightRange.lower + info.intOne, const MaxIntValue()); 963 rightRange.lower + info.intOne, const MaxIntValue());
963 } else if (operation == const GreaterEqualOperation()) { 964 } else if (operation == const GreaterEqualOperation()) {
964 range = info.newNormalizedRange(rightRange.lower, const MaxIntValue()); 965 range = info.newNormalizedRange(rightRange.lower, const MaxIntValue());
965 } else { 966 } else {
966 range = info.newUnboundRange(); 967 range = info.newUnboundRange();
967 } 968 }
968 return range.intersection(leftRange); 969 return range.intersection(leftRange);
969 } 970 }
970 971
971 Range visitConditionalBranch(HConditionalBranch branch) { 972 Range visitConditionalBranch(HConditionalBranch branch) {
972 var condition = branch.condition; 973 dynamic condition = branch.condition;
973 // TODO(ngeoffray): Handle complex conditions. 974 // TODO(ngeoffray): Handle complex conditions.
974 if (condition is! HRelational) return info.newUnboundRange(); 975 if (condition is! HRelational) return info.newUnboundRange();
975 if (condition is HIdentity) return info.newUnboundRange(); 976 if (condition is HIdentity) return info.newUnboundRange();
976 HInstruction right = condition.right; 977 HInstruction right = condition.right;
977 HInstruction left = condition.left; 978 HInstruction left = condition.left;
978 if (!left.isInteger(closedWorld)) return info.newUnboundRange(); 979 if (!left.isInteger(closedWorld)) return info.newUnboundRange();
979 if (!right.isInteger(closedWorld)) return info.newUnboundRange(); 980 if (!right.isInteger(closedWorld)) return info.newUnboundRange();
980 981
981 Range rightRange = ranges[right]; 982 Range rightRange = ranges[right];
982 Range leftRange = ranges[left]; 983 Range leftRange = ranges[left];
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 } 1102 }
1102 1103
1103 Range handleBinaryOperation(HBinaryArithmetic instruction) { 1104 Range handleBinaryOperation(HBinaryArithmetic instruction) {
1104 Range leftRange = visit(instruction.left); 1105 Range leftRange = visit(instruction.left);
1105 Range rightRange = visit(instruction.right); 1106 Range rightRange = visit(instruction.right);
1106 if (leftRange == null || rightRange == null) return null; 1107 if (leftRange == null || rightRange == null) return null;
1107 BinaryOperation operation = instruction.operation(info.constantSystem); 1108 BinaryOperation operation = instruction.operation(info.constantSystem);
1108 return operation.apply(leftRange, rightRange); 1109 return operation.apply(leftRange, rightRange);
1109 } 1110 }
1110 } 1111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698