OLD | NEW |
---|---|
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 visitSentinel(SentinelConstant constant); | 8 R visitSentinel(SentinelConstant constant); |
9 R visitFunction(FunctionConstant constant); | 9 R visitFunction(FunctionConstant constant); |
10 R visitNull(NullConstant constant); | 10 R visitNull(NullConstant constant); |
11 R visitInt(IntConstant constant); | 11 R visitInt(IntConstant constant); |
12 R visitDouble(DoubleConstant constant); | 12 R visitDouble(DoubleConstant constant); |
13 R visitTrue(TrueConstant constant); | 13 R visitTrue(TrueConstant constant); |
14 R visitFalse(FalseConstant constant); | 14 R visitFalse(FalseConstant constant); |
15 R visitString(StringConstant constant); | 15 R visitString(StringConstant constant); |
16 R visitList(ListConstant constant); | 16 R visitList(ListConstant constant); |
17 R visitMap(MapConstant constant); | 17 R visitMap(MapConstant constant); |
18 R visitConstructed(ConstructedConstant constant); | 18 R visitConstructed(ConstructedConstant constant); |
19 R visitType(TypeConstant constant); | |
19 } | 20 } |
20 | 21 |
21 abstract class Constant { | 22 abstract class Constant { |
22 const Constant(); | 23 const Constant(); |
23 | 24 |
24 bool isNull() => false; | 25 bool isNull() => false; |
25 bool isBool() => false; | 26 bool isBool() => false; |
26 bool isTrue() => false; | 27 bool isTrue() => false; |
27 bool isFalse() => false; | 28 bool isFalse() => false; |
28 bool isInt() => false; | 29 bool isInt() => false; |
29 bool isDouble() => false; | 30 bool isDouble() => false; |
30 bool isNum() => false; | 31 bool isNum() => false; |
31 bool isString() => false; | 32 bool isString() => false; |
32 bool isList() => false; | 33 bool isList() => false; |
33 bool isMap() => false; | 34 bool isMap() => false; |
34 bool isConstructedObject() => false; | 35 bool isConstructedObject() => false; |
35 bool isFunction() => false; | 36 bool isFunction() => false; |
36 /** Returns true if the constant is null, a bool, a number or a string. */ | 37 /** Returns true if the constant is null, a bool, a number or a string. */ |
37 bool isPrimitive() => false; | 38 bool isPrimitive() => false; |
38 /** Returns true if the constant is a list, a map or a constructed object. */ | 39 /** Returns true if the constant is a list, a map or a constructed object. */ |
39 bool isObject() => false; | 40 bool isObject() => false; |
40 bool isSentinel() => false; | 41 bool isSentinel() => false; |
41 | 42 |
42 bool isNaN() => false; | 43 bool isNaN() => false; |
43 bool isMinusZero() => false; | 44 bool isMinusZero() => false; |
44 | 45 |
46 bool get isType => false; | |
ngeoffray
2012/11/15 16:07:24
bool isType() => false and move it to where the ot
karlklose
2012/11/19 15:08:58
Done.
| |
47 | |
45 DartType computeType(Compiler compiler); | 48 DartType computeType(Compiler compiler); |
46 | 49 |
47 List<Constant> getDependencies(); | 50 List<Constant> getDependencies(); |
48 | 51 |
49 accept(ConstantVisitor); | 52 accept(ConstantVisitor visitor); |
50 } | 53 } |
51 | 54 |
52 class SentinelConstant extends Constant { | 55 class SentinelConstant extends Constant { |
53 const SentinelConstant(); | 56 const SentinelConstant(); |
54 static final SENTINEL = const SentinelConstant(); | 57 static final SENTINEL = const SentinelConstant(); |
55 | 58 |
56 List<Constant> getDependencies() => const <Constant>[]; | 59 List<Constant> getDependencies() => const <Constant>[]; |
57 | 60 |
58 // Just use a random value. | 61 // Just use a random value. |
59 int get hashCode => 24297418; | 62 int get hashCode => 24297418; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 } | 312 } |
310 | 313 |
311 abstract class ObjectConstant extends Constant { | 314 abstract class ObjectConstant extends Constant { |
312 final DartType type; | 315 final DartType type; |
313 | 316 |
314 ObjectConstant(this.type); | 317 ObjectConstant(this.type); |
315 bool isObject() => true; | 318 bool isObject() => true; |
316 | 319 |
317 DartType computeType(Compiler compiler) => type; | 320 DartType computeType(Compiler compiler) => type; |
318 | 321 |
319 // TODO(1603): The class should be marked as abstract, but the VM doesn't | |
320 // currently allow this. | |
321 int get hashCode; | 322 int get hashCode; |
floitsch
2012/11/16 13:53:31
Remove the hashCode line too.
karlklose
2012/11/19 15:08:58
Done.
| |
322 } | 323 } |
323 | 324 |
325 class TypeConstant extends Constant { | |
ngeoffray
2012/11/15 16:07:24
extends ObjectConstant ?
karlklose
2012/11/19 15:08:58
Done.
| |
326 /// The user type that this constant represents. | |
327 final DartType representedType; | |
328 /// The type of the constant (currently always [Type]). | |
ngeoffray
2012/11/15 16:07:24
Should it be something else? Please add a comment.
karlklose
2012/11/19 15:08:58
It could be more specific in the future, but the c
| |
329 final DartType type; | |
330 | |
331 TypeConstant(this.representedType, this.type); | |
332 | |
333 bool get isType => true; | |
334 bool isObject() => true; | |
335 | |
336 DartType computeType(Compiler compiler) { | |
337 return compiler.typeClass.computeType(compiler); | |
ngeoffray
2012/11/15 16:07:24
Remove, it will be inherited with ObjectConstant.
karlklose
2012/11/19 15:08:58
Done.
| |
338 } | |
339 | |
340 bool operator ==(other) { | |
341 return other is TypeConstant && representedType == other.representedType; | |
342 } | |
343 | |
344 int get hashCode => representedType.hashCode * 13; | |
345 | |
346 List<Constant> getDependencies() => const <Constant>[]; | |
347 | |
348 accept(ConstantVisitor visitor) => visitor.visitType(this); | |
349 } | |
350 | |
324 class ListConstant extends ObjectConstant { | 351 class ListConstant extends ObjectConstant { |
325 final List<Constant> entries; | 352 final List<Constant> entries; |
326 final int hashCode; | 353 final int hashCode; |
327 | 354 |
328 ListConstant(DartType type, List<Constant> entries) | 355 ListConstant(DartType type, List<Constant> entries) |
329 : this.entries = entries, | 356 : this.entries = entries, |
330 hashCode = _computeHash(entries), | 357 hashCode = _computeHash(entries), |
331 super(type); | 358 super(type); |
332 bool isList() => true; | 359 bool isList() => true; |
333 | 360 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 for (int i = 0; i < fields.length; i++) { | 474 for (int i = 0; i < fields.length; i++) { |
448 if (fields[i] != other.fields[i]) return false; | 475 if (fields[i] != other.fields[i]) return false; |
449 } | 476 } |
450 return true; | 477 return true; |
451 } | 478 } |
452 | 479 |
453 List<Constant> getDependencies() => fields; | 480 List<Constant> getDependencies() => fields; |
454 | 481 |
455 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); | 482 accept(ConstantVisitor visitor) => visitor.visitConstructed(this); |
456 } | 483 } |
OLD | NEW |