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

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

Issue 11033016: Added TODO. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 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 | 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 abstract class ConstantVisitor<R> { 5 abstract class ConstantVisitor<R> {
6 R visitSentinel(SentinelConstant constant); 6 R visitSentinel(SentinelConstant constant);
7 R visitFunction(FunctionConstant constant); 7 R visitFunction(FunctionConstant constant);
8 R visitNull(NullConstant constant); 8 R visitNull(NullConstant constant);
9 R visitInt(IntConstant constant); 9 R visitInt(IntConstant constant);
10 R visitDouble(DoubleConstant constant); 10 R visitDouble(DoubleConstant constant);
11 R visitTrue(TrueConstant constant); 11 R visitTrue(TrueConstant constant);
12 R visitFalse(FalseConstant constant); 12 R visitFalse(FalseConstant constant);
13 R visitString(StringConstant constant); 13 R visitString(StringConstant constant);
14 R visitList(ListConstant constant); 14 R visitList(ListConstant constant);
15 R visitMap(MapConstant constant); 15 R visitMap(MapConstant constant);
16 R visitConstructed(ConstructedConstant constant); 16 R visitConstructed(ConstructedConstant constant);
17 } 17 }
18 18
19 class Constant { 19 abstract class Constant {
20 const Constant(); 20 const Constant();
21 21
22 bool isNull() => false; 22 bool isNull() => false;
23 bool isBool() => false; 23 bool isBool() => false;
24 bool isTrue() => false; 24 bool isTrue() => false;
25 bool isFalse() => false; 25 bool isFalse() => false;
26 bool isInt() => false; 26 bool isInt() => false;
27 bool isDouble() => false; 27 bool isDouble() => false;
28 bool isNum() => false; 28 bool isNum() => false;
29 bool isString() => false; 29 bool isString() => false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 DartType computeType(Compiler compiler) { 82 DartType computeType(Compiler compiler) {
83 return compiler.functionClass.computeType(compiler); 83 return compiler.functionClass.computeType(compiler);
84 } 84 }
85 85
86 int hashCode() => (17 * element.hashCode()) & 0x7fffffff; 86 int hashCode() => (17 * element.hashCode()) & 0x7fffffff;
87 87
88 accept(ConstantVisitor visitor) => visitor.visitFunction(this); 88 accept(ConstantVisitor visitor) => visitor.visitFunction(this);
89 } 89 }
90 90
91 class PrimitiveConstant extends Constant { 91 abstract class PrimitiveConstant extends Constant {
92 abstract get value; 92 abstract get value;
93 const PrimitiveConstant(); 93 const PrimitiveConstant();
94 bool isPrimitive() => true; 94 bool isPrimitive() => true;
95 95
96 bool operator ==(var other) { 96 bool operator ==(var other) {
97 if (other is !PrimitiveConstant) return false; 97 if (other is !PrimitiveConstant) return false;
98 PrimitiveConstant otherPrimitive = other; 98 PrimitiveConstant otherPrimitive = other;
99 // We use == instead of === so that DartStrings compare correctly. 99 // We use == instead of === so that DartStrings compare correctly.
100 return value == otherPrimitive.value; 100 return value == otherPrimitive.value;
101 } 101 }
(...skipping 21 matching lines...) Expand all
123 buffer.add(JsNull); 123 buffer.add(JsNull);
124 } 124 }
125 125
126 // The magic constant has no meaning. It is just a random value. 126 // The magic constant has no meaning. It is just a random value.
127 int hashCode() => 785965825; 127 int hashCode() => 785965825;
128 DartString toDartString() => const LiteralDartString("null"); 128 DartString toDartString() => const LiteralDartString("null");
129 129
130 accept(ConstantVisitor visitor) => visitor.visitNull(this); 130 accept(ConstantVisitor visitor) => visitor.visitNull(this);
131 } 131 }
132 132
133 class NumConstant extends PrimitiveConstant { 133 abstract class NumConstant extends PrimitiveConstant {
134 abstract num get value; 134 abstract num get value;
135 const NumConstant(); 135 const NumConstant();
136 bool isNum() => true; 136 bool isNum() => true;
137 } 137 }
138 138
139 class IntConstant extends NumConstant { 139 class IntConstant extends NumConstant {
140 final int value; 140 final int value;
141 factory IntConstant(int value) { 141 factory IntConstant(int value) {
142 switch (value) { 142 switch (value) {
143 case 0: return const IntConstant._internal(0); 143 case 0: return const IntConstant._internal(0);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return value == otherValue; 218 return value == otherValue;
219 } 219 }
220 } 220 }
221 221
222 int hashCode() => value.hashCode(); 222 int hashCode() => value.hashCode();
223 DartString toDartString() => new DartString.literal(value.toString()); 223 DartString toDartString() => new DartString.literal(value.toString());
224 224
225 accept(ConstantVisitor visitor) => visitor.visitDouble(this); 225 accept(ConstantVisitor visitor) => visitor.visitDouble(this);
226 } 226 }
227 227
228 class BoolConstant extends PrimitiveConstant { 228 abstract class BoolConstant extends PrimitiveConstant {
229 factory BoolConstant(value) { 229 factory BoolConstant(value) {
230 return value ? new TrueConstant() : new FalseConstant(); 230 return value ? new TrueConstant() : new FalseConstant();
231 } 231 }
232 const BoolConstant._internal(); 232 const BoolConstant._internal();
233 bool isBool() => true; 233 bool isBool() => true;
234 234
235 DartType computeType(Compiler compiler) { 235 DartType computeType(Compiler compiler) {
236 return compiler.boolClass.computeType(compiler); 236 return compiler.boolClass.computeType(compiler);
237 } 237 }
238 238
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 return (_hashCode == otherString._hashCode) && (value == otherString.value); 298 return (_hashCode == otherString._hashCode) && (value == otherString.value);
299 } 299 }
300 300
301 int hashCode() => _hashCode; 301 int hashCode() => _hashCode;
302 DartString toDartString() => value; 302 DartString toDartString() => value;
303 int get length => value.length; 303 int get length => value.length;
304 304
305 accept(ConstantVisitor visitor) => visitor.visitString(this); 305 accept(ConstantVisitor visitor) => visitor.visitString(this);
306 } 306 }
307 307
308 class ObjectConstant extends Constant { 308 abstract class ObjectConstant extends Constant {
309 final DartType type; 309 final DartType type;
310 310
311 ObjectConstant(this.type); 311 ObjectConstant(this.type);
312 bool isObject() => true; 312 bool isObject() => true;
313 313
314 DartType computeType(Compiler compiler) => type; 314 DartType computeType(Compiler compiler) => type;
315 315
316 // TODO(1603): The class should be marked as abstract, but the VM doesn't 316 // TODO(1603): The class should be marked as abstract, but the VM doesn't
317 // currently allow this. 317 // currently allow this.
318 abstract int hashCode(); 318 abstract int hashCode();
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (fields[i] != other.fields[i]) return false; 434 if (fields[i] != other.fields[i]) return false;
435 } 435 }
436 return true; 436 return true;
437 } 437 }
438 438
439 int hashCode() => _hashCode; 439 int hashCode() => _hashCode;
440 List<Constant> getDependencies() => fields; 440 List<Constant> getDependencies() => fields;
441 441
442 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); 442 accept(ConstantVisitor visitor) => visitor.visitConstructed(this);
443 } 443 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/constant_system_dart.dart ('k') | lib/compiler/implementation/dart_backend/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698