OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library types.constants; | 5 library types.constants; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
9 import '../constants/values.dart'; | 9 import '../constants/values.dart'; |
10 import '../js_backend/js_backend.dart' show SyntheticConstantKind; | 10 import '../js_backend/js_backend.dart' show SyntheticConstantKind; |
11 import 'masks.dart'; | 11 import 'masks.dart'; |
12 | 12 |
13 /// Computes the [TypeMask] for the constant [value]. | 13 /// Computes the [TypeMask] for the constant [value]. |
14 TypeMask computeTypeMask(Compiler compiler, ConstantValue value) { | 14 TypeMask computeTypeMask(Compiler compiler, ConstantValue value) { |
15 return value.accept(const ConstantValueTypeMasks(), compiler); | 15 return value.accept(const ConstantValueTypeMasks(), compiler); |
16 } | 16 } |
17 | 17 |
18 class ConstantValueTypeMasks extends ConstantValueVisitor<TypeMask, Compiler> { | 18 class ConstantValueTypeMasks extends ConstantValueVisitor<TypeMask, Compiler> { |
19 const ConstantValueTypeMasks(); | 19 const ConstantValueTypeMasks(); |
20 | 20 |
21 @override | 21 @override |
22 TypeMask visitConstructed( | 22 TypeMask visitConstructed( |
23 ConstructedConstantValue constant, Compiler compiler) { | 23 ConstructedConstantValue constant, Compiler compiler) { |
24 if (compiler.backend.isInterceptorClass(constant.type.element)) { | 24 if (compiler.backend.isInterceptorClass(constant.type.element)) { |
25 return compiler.commonMasks.nonNullType; | 25 return compiler.closedWorld.commonMasks.nonNullType; |
26 } | 26 } |
27 return new TypeMask.nonNullExact( | 27 return new TypeMask.nonNullExact( |
28 constant.type.element, compiler.closedWorld); | 28 constant.type.element, compiler.closedWorld); |
29 } | 29 } |
30 | 30 |
31 @override | 31 @override |
32 TypeMask visitDeferred(DeferredConstantValue constant, Compiler compiler) { | 32 TypeMask visitDeferred(DeferredConstantValue constant, Compiler compiler) { |
33 return constant.referenced.accept(this, compiler); | 33 return constant.referenced.accept(this, compiler); |
34 } | 34 } |
35 | 35 |
36 @override | 36 @override |
37 TypeMask visitDouble(DoubleConstantValue constant, Compiler compiler) { | 37 TypeMask visitDouble(DoubleConstantValue constant, Compiler compiler) { |
38 // We have to recognize double constants that are 'is int'. | 38 // We have to recognize double constants that are 'is int'. |
39 if (compiler.backend.constantSystem.isInt(constant)) { | 39 if (compiler.backend.constantSystem.isInt(constant)) { |
40 if (constant.isMinusZero) { | 40 if (constant.isMinusZero) { |
41 return compiler.commonMasks.uint31Type; | 41 return compiler.closedWorld.commonMasks.uint31Type; |
42 } else { | 42 } else { |
43 assert(constant.isPositiveInfinity || constant.isNegativeInfinity); | 43 assert(constant.isPositiveInfinity || constant.isNegativeInfinity); |
44 return compiler.commonMasks.intType; | 44 return compiler.closedWorld.commonMasks.intType; |
45 } | 45 } |
46 } | 46 } |
47 return compiler.commonMasks.doubleType; | 47 return compiler.closedWorld.commonMasks.doubleType; |
48 } | 48 } |
49 | 49 |
50 @override | 50 @override |
51 TypeMask visitSynthetic(SyntheticConstantValue constant, Compiler compiler) { | 51 TypeMask visitSynthetic(SyntheticConstantValue constant, Compiler compiler) { |
52 switch (constant.valueKind) { | 52 switch (constant.valueKind) { |
53 case SyntheticConstantKind.DUMMY_INTERCEPTOR: | 53 case SyntheticConstantKind.DUMMY_INTERCEPTOR: |
54 return constant.payload; | 54 return constant.payload; |
55 case SyntheticConstantKind.EMPTY_VALUE: | 55 case SyntheticConstantKind.EMPTY_VALUE: |
56 return constant.payload; | 56 return constant.payload; |
57 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: | 57 case SyntheticConstantKind.TYPEVARIABLE_REFERENCE: |
58 return compiler.commonMasks.intType; | 58 return compiler.closedWorld.commonMasks.intType; |
59 case SyntheticConstantKind.NAME: | 59 case SyntheticConstantKind.NAME: |
60 return compiler.commonMasks.stringType; | 60 return compiler.closedWorld.commonMasks.stringType; |
61 default: | 61 default: |
62 DiagnosticReporter reporter = compiler.reporter; | 62 DiagnosticReporter reporter = compiler.reporter; |
63 reporter.internalError( | 63 reporter.internalError( |
64 CURRENT_ELEMENT_SPANNABLE, "Unexpected DummyConstantKind."); | 64 CURRENT_ELEMENT_SPANNABLE, "Unexpected DummyConstantKind."); |
65 return null; | 65 return null; |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 @override | 69 @override |
70 TypeMask visitBool(BoolConstantValue constant, Compiler compiler) { | 70 TypeMask visitBool(BoolConstantValue constant, Compiler compiler) { |
71 return compiler.commonMasks.boolType; | 71 return compiler.closedWorld.commonMasks.boolType; |
72 } | 72 } |
73 | 73 |
74 @override | 74 @override |
75 TypeMask visitFunction(FunctionConstantValue constant, Compiler compiler) { | 75 TypeMask visitFunction(FunctionConstantValue constant, Compiler compiler) { |
76 return compiler.commonMasks.functionType; | 76 return compiler.closedWorld.commonMasks.functionType; |
77 } | 77 } |
78 | 78 |
79 @override | 79 @override |
80 TypeMask visitInt(IntConstantValue constant, Compiler compiler) { | 80 TypeMask visitInt(IntConstantValue constant, Compiler compiler) { |
81 if (constant.isUInt31()) return compiler.commonMasks.uint31Type; | 81 if (constant.isUInt31()) return compiler.closedWorld.commonMasks.uint31Type; |
82 if (constant.isUInt32()) return compiler.commonMasks.uint32Type; | 82 if (constant.isUInt32()) return compiler.closedWorld.commonMasks.uint32Type; |
83 if (constant.isPositive()) return compiler.commonMasks.positiveIntType; | 83 if (constant.isPositive()) |
84 return compiler.commonMasks.intType; | 84 return compiler.closedWorld.commonMasks.positiveIntType; |
| 85 return compiler.closedWorld.commonMasks.intType; |
85 } | 86 } |
86 | 87 |
87 @override | 88 @override |
88 TypeMask visitInterceptor( | 89 TypeMask visitInterceptor( |
89 InterceptorConstantValue constant, Compiler compiler) { | 90 InterceptorConstantValue constant, Compiler compiler) { |
90 return compiler.commonMasks.nonNullType; | 91 return compiler.closedWorld.commonMasks.nonNullType; |
91 } | 92 } |
92 | 93 |
93 @override | 94 @override |
94 TypeMask visitList(ListConstantValue constant, Compiler compiler) { | 95 TypeMask visitList(ListConstantValue constant, Compiler compiler) { |
95 return compiler.commonMasks.constListType; | 96 return compiler.closedWorld.commonMasks.constListType; |
96 } | 97 } |
97 | 98 |
98 @override | 99 @override |
99 TypeMask visitMap(MapConstantValue constant, Compiler compiler) { | 100 TypeMask visitMap(MapConstantValue constant, Compiler compiler) { |
100 return compiler.commonMasks.constMapType; | 101 return compiler.closedWorld.commonMasks.constMapType; |
101 } | 102 } |
102 | 103 |
103 @override | 104 @override |
104 TypeMask visitNull(NullConstantValue constant, Compiler compiler) { | 105 TypeMask visitNull(NullConstantValue constant, Compiler compiler) { |
105 return compiler.commonMasks.nullType; | 106 return compiler.closedWorld.commonMasks.nullType; |
106 } | 107 } |
107 | 108 |
108 @override | 109 @override |
109 TypeMask visitNonConstant(NonConstantValue constant, Compiler compiler) { | 110 TypeMask visitNonConstant(NonConstantValue constant, Compiler compiler) { |
110 return compiler.commonMasks.nullType; | 111 return compiler.closedWorld.commonMasks.nullType; |
111 } | 112 } |
112 | 113 |
113 @override | 114 @override |
114 TypeMask visitString(StringConstantValue constant, Compiler compiler) { | 115 TypeMask visitString(StringConstantValue constant, Compiler compiler) { |
115 return compiler.commonMasks.stringType; | 116 return compiler.closedWorld.commonMasks.stringType; |
116 } | 117 } |
117 | 118 |
118 @override | 119 @override |
119 TypeMask visitType(TypeConstantValue constant, Compiler compiler) { | 120 TypeMask visitType(TypeConstantValue constant, Compiler compiler) { |
120 return compiler.commonMasks.typeType; | 121 return compiler.closedWorld.commonMasks.typeType; |
121 } | 122 } |
122 } | 123 } |
OLD | NEW |