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

Unified Diff: sdk/lib/_internal/compiler/implementation/constants.dart

Issue 87783003: Add UInt32 and UInt31 types to better infer bit operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/constants.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/constants.dart (revision 30666)
+++ sdk/lib/_internal/compiler/implementation/constants.dart (working copy)
@@ -48,6 +48,8 @@
// TODO(johnniwinther): Replace with a 'type' getter.
DartType computeType(Compiler compiler);
+ ti.TypeMask computeMask(Compiler compiler);
+
List<Constant> getDependencies();
accept(ConstantVisitor visitor);
@@ -75,6 +77,10 @@
return compiler.functionClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.functionType;
+ }
+
int get hashCode => (17 * element.hashCode) & 0x7fffffff;
accept(ConstantVisitor visitor) => visitor.visitFunction(this);
@@ -113,6 +119,10 @@
return compiler.nullClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.nullType;
+ }
+
void _writeJsCode(CodeBuffer buffer, ConstantHandler handler) {
buffer.write(JsNull);
}
@@ -152,11 +162,19 @@
}
const IntConstant._internal(this.value);
bool isInt() => true;
+ bool isUInt31() => value >= 0 && value < (1 << 31);
+ bool isUInt32() => value >= 0 && value < (1 << 32);
DartType computeType(Compiler compiler) {
return compiler.intClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ if (isUInt31()) return compiler.typesTask.uint31Type;
+ if (isUInt32()) return compiler.typesTask.uint32Type;
+ return compiler.typesTask.intType;
+ }
+
// We have to override the equality operator so that ints and doubles are
// treated as separate constants.
// The is [:!IntConstant:] check at the beginning of the function makes sure
@@ -200,6 +218,10 @@
return compiler.doubleClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.doubleType;
+ }
+
bool operator ==(var other) {
if (other is !DoubleConstant) return false;
DoubleConstant otherDouble = other;
@@ -230,6 +252,10 @@
return compiler.boolClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.boolType;
+ }
+
BoolConstant negate();
}
@@ -286,6 +312,10 @@
return compiler.stringClass.computeType(compiler);
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.stringType;
+ }
+
bool operator ==(var other) {
if (other is !StringConstant) return false;
StringConstant otherString = other;
@@ -323,6 +353,10 @@
return other is TypeConstant && representedType == other.representedType;
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.typeType;
+ }
+
int get hashCode => representedType.hashCode * 13;
List<Constant> getDependencies() => const <Constant>[];
@@ -368,6 +402,10 @@
int get length => entries.length;
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.constListType;
+ }
+
accept(ConstantVisitor visitor) => visitor.visitList(this);
String toString() {
@@ -424,6 +462,10 @@
return hash;
}
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.constMapType;
+ }
+
bool operator ==(var other) {
if (other is !MapConstant) return false;
MapConstant otherMap = other;
@@ -489,6 +531,10 @@
DartType computeType(Compiler compiler) => compiler.types.dynamicType;
+ ti.TypeMask computeMask(Compiler compiler) {
+ return compiler.typesTask.nonNullType;
+ }
+
String toString() {
return 'InterceptorConstant(${Error.safeToString(dispatchedType)})';
}
@@ -530,6 +576,13 @@
List<Constant> getDependencies() => fields;
+ ti.TypeMask computeMask(Compiler compiler) {
+ if (compiler.backend.isInterceptorClass(type.element)) {
+ return compiler.typesTask.nonNullType;
+ }
+ return new ti.TypeMask.nonNullExact(type.element);
+ }
+
accept(ConstantVisitor visitor) => visitor.visitConstructed(this);
Map<Element, Constant> get fieldElements {

Powered by Google App Engine
This is Rietveld 408576698