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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/constants.dart

Issue 94303002: Add another type JSPositiveInt to show a range analysis in the inferrer would be very beneficial :-… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | Annotate | Revision Log
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 part of dart2js; 5 part of dart2js;
6 6
7 abstract class ConstantVisitor<R> { 7 abstract class ConstantVisitor<R> {
8 R visitFunction(FunctionConstant constant); 8 R visitFunction(FunctionConstant constant);
9 R visitNull(NullConstant constant); 9 R visitNull(NullConstant constant);
10 R visitInt(IntConstant constant); 10 R visitInt(IntConstant constant);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 case 10: return const IntConstant._internal(10); 157 case 10: return const IntConstant._internal(10);
158 case -1: return const IntConstant._internal(-1); 158 case -1: return const IntConstant._internal(-1);
159 case -2: return const IntConstant._internal(-2); 159 case -2: return const IntConstant._internal(-2);
160 default: return new IntConstant._internal(value); 160 default: return new IntConstant._internal(value);
161 } 161 }
162 } 162 }
163 const IntConstant._internal(this.value); 163 const IntConstant._internal(this.value);
164 bool isInt() => true; 164 bool isInt() => true;
165 bool isUInt31() => value >= 0 && value < (1 << 31); 165 bool isUInt31() => value >= 0 && value < (1 << 31);
166 bool isUInt32() => value >= 0 && value < (1 << 32); 166 bool isUInt32() => value >= 0 && value < (1 << 32);
167 bool isPositive() => value >= 0;
kasperl 2013/11/28 09:09:47 Stephen would probably insist on this being isNonN
167 168
168 DartType computeType(Compiler compiler) { 169 DartType computeType(Compiler compiler) {
169 return compiler.intClass.computeType(compiler); 170 return compiler.intClass.computeType(compiler);
170 } 171 }
171 172
172 ti.TypeMask computeMask(Compiler compiler) { 173 ti.TypeMask computeMask(Compiler compiler) {
173 if (isUInt31()) return compiler.typesTask.uint31Type; 174 if (isUInt31()) return compiler.typesTask.uint31Type;
174 if (isUInt32()) return compiler.typesTask.uint32Type; 175 if (isUInt32()) return compiler.typesTask.uint32Type;
176 if (isPositive()) return compiler.typesTask.positiveIntType;
175 return compiler.typesTask.intType; 177 return compiler.typesTask.intType;
176 } 178 }
177 179
178 // We have to override the equality operator so that ints and doubles are 180 // We have to override the equality operator so that ints and doubles are
179 // treated as separate constants. 181 // treated as separate constants.
180 // The is [:!IntConstant:] check at the beginning of the function makes sure 182 // The is [:!IntConstant:] check at the beginning of the function makes sure
181 // that we compare only equal to integer constants. 183 // that we compare only equal to integer constants.
182 bool operator ==(var other) { 184 bool operator ==(var other) {
183 if (other is !IntConstant) return false; 185 if (other is !IntConstant) return false;
184 IntConstant otherInt = other; 186 IntConstant otherInt = other;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (i > 0) sb.write(','); 608 if (i > 0) sb.write(',');
607 sb.write(Error.safeToString(field.name)); 609 sb.write(Error.safeToString(field.name));
608 sb.write('='); 610 sb.write('=');
609 sb.write(Error.safeToString(value)); 611 sb.write(Error.safeToString(value));
610 i++; 612 i++;
611 }); 613 });
612 sb.write('))'); 614 sb.write('))');
613 return sb.toString(); 615 return sb.toString();
614 } 616 }
615 } 617 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698