OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_TYPES_INL_H_ | 5 #ifndef V8_TYPES_INL_H_ |
6 #define V8_TYPES_INL_H_ | 6 #define V8_TYPES_INL_H_ |
7 | 7 |
8 #include "types.h" | 8 #include "types.h" |
9 | 9 |
10 #include "factory.h" | 10 #include "factory.h" |
11 #include "handles-inl.h" | 11 #include "handles-inl.h" |
12 | 12 |
13 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
| 16 // -------------------------------------------------------------------------- // |
| 17 // TypeImpl |
| 18 |
| 19 template<class Config> |
| 20 typename TypeImpl<Config>::template Iterator<i::Map> |
| 21 TypeImpl<Config>::Classes() { |
| 22 if (this->IsBitset()) return Iterator<i::Map>(); |
| 23 return Iterator<i::Map>(Config::handle(this)); |
| 24 } |
| 25 |
| 26 |
| 27 template<class Config> |
| 28 typename TypeImpl<Config>::template Iterator<i::Object> |
| 29 TypeImpl<Config>::Constants() { |
| 30 if (this->IsBitset()) return Iterator<i::Object>(); |
| 31 return Iterator<i::Object>(Config::handle(this)); |
| 32 } |
| 33 |
| 34 |
| 35 template<class Config> |
| 36 TypeImpl<Config>* TypeImpl<Config>::cast(typename Config::Base* object) { |
| 37 TypeImpl* t = static_cast<TypeImpl*>(object); |
| 38 ASSERT(t->IsBitset() || t->IsClass() || t->IsConstant() || |
| 39 t->IsUnion() || t->IsArray() || t->IsFunction()); |
| 40 return t; |
| 41 } |
| 42 |
| 43 |
16 template<class Config> | 44 template<class Config> |
17 bool TypeImpl<Config>::NowContains(i::Object* value) { | 45 bool TypeImpl<Config>::NowContains(i::Object* value) { |
18 DisallowHeapAllocation no_allocation; | 46 DisallowHeapAllocation no_allocation; |
19 if (this->IsAny()) return true; | 47 if (this->IsAny()) return true; |
20 if (value->IsHeapObject()) { | 48 if (value->IsHeapObject()) { |
21 i::Map* map = i::HeapObject::cast(value)->map(); | 49 i::Map* map = i::HeapObject::cast(value)->map(); |
22 for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) { | 50 for (Iterator<i::Map> it = this->Classes(); !it.Done(); it.Advance()) { |
23 if (*it.Current() == map) return true; | 51 if (*it.Current() == map) return true; |
24 } | 52 } |
25 } | 53 } |
26 return this->Contains(value); | 54 return this->Contains(value); |
27 } | 55 } |
28 | 56 |
29 | 57 |
| 58 // -------------------------------------------------------------------------- // |
| 59 // ZoneTypeConfig |
| 60 |
| 61 // static |
| 62 template<class T> |
| 63 T* ZoneTypeConfig::handle(T* type) { |
| 64 return type; |
| 65 } |
| 66 |
| 67 |
30 // static | 68 // static |
31 Type* ZoneTypeConfig::handle(Type* type) { | 69 template<class T> |
32 return type; | 70 T* ZoneTypeConfig::cast(Type* type) { |
| 71 return static_cast<T*>(type); |
33 } | 72 } |
34 | 73 |
35 | 74 |
36 // static | 75 // static |
37 bool ZoneTypeConfig::is_bitset(Type* type) { | 76 bool ZoneTypeConfig::is_bitset(Type* type) { |
38 return reinterpret_cast<intptr_t>(type) & 1; | 77 return reinterpret_cast<intptr_t>(type) & 1; |
39 } | 78 } |
40 | 79 |
41 | 80 |
42 // static | 81 // static |
43 bool ZoneTypeConfig::is_struct(Type* type) { | 82 bool ZoneTypeConfig::is_struct(Type* type, int tag) { |
44 return !is_bitset(type); | 83 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; |
45 } | 84 } |
46 | 85 |
47 | 86 |
48 // static | 87 // static |
49 bool ZoneTypeConfig::is_class(Type* type) { | 88 bool ZoneTypeConfig::is_class(Type* type) { |
50 return is_struct(type) && struct_tag(as_struct(type)) == Type::kClassTag; | 89 return is_struct(type, Type::StructuralType::kClassTag); |
51 } | 90 } |
52 | 91 |
53 | 92 |
54 // static | 93 // static |
55 bool ZoneTypeConfig::is_constant(Type* type) { | 94 bool ZoneTypeConfig::is_constant(Type* type) { |
56 return is_struct(type) && struct_tag(as_struct(type)) == Type::kConstantTag; | 95 return is_struct(type, Type::StructuralType::kConstantTag); |
57 } | 96 } |
58 | 97 |
59 | 98 |
60 // static | 99 // static |
61 int ZoneTypeConfig::as_bitset(Type* type) { | 100 int ZoneTypeConfig::as_bitset(Type* type) { |
62 ASSERT(is_bitset(type)); | 101 ASSERT(is_bitset(type)); |
63 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); | 102 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1); |
64 } | 103 } |
65 | 104 |
66 | 105 |
67 // static | 106 // static |
68 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { | 107 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { |
69 ASSERT(is_struct(type)); | 108 ASSERT(!is_bitset(type)); |
70 return reinterpret_cast<Struct*>(type); | 109 return reinterpret_cast<Struct*>(type); |
71 } | 110 } |
72 | 111 |
73 | 112 |
74 // static | 113 // static |
75 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { | 114 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { |
76 ASSERT(is_class(type)); | 115 ASSERT(is_class(type)); |
77 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3])); | 116 return i::Handle<i::Map>(static_cast<i::Map**>(as_struct(type)[3])); |
78 } | 117 } |
79 | 118 |
(...skipping 20 matching lines...) Expand all Loading... |
100 | 139 |
101 // static | 140 // static |
102 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { | 141 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { |
103 return reinterpret_cast<Type*>(structured); | 142 return reinterpret_cast<Type*>(structured); |
104 } | 143 } |
105 | 144 |
106 | 145 |
107 // static | 146 // static |
108 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( | 147 ZoneTypeConfig::Type* ZoneTypeConfig::from_class( |
109 i::Handle<i::Map> map, int lub, Zone* zone) { | 148 i::Handle<i::Map> map, int lub, Zone* zone) { |
110 Struct* structured = struct_create(Type::kClassTag, 2, zone); | 149 Struct* structured = struct_create(Type::StructuralType::kClassTag, 2, zone); |
111 structured[2] = from_bitset(lub); | 150 structured[2] = from_bitset(lub); |
112 structured[3] = map.location(); | 151 structured[3] = map.location(); |
113 return from_struct(structured); | 152 return from_struct(structured); |
114 } | 153 } |
115 | 154 |
116 | 155 |
117 // static | 156 // static |
118 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( | 157 ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( |
119 i::Handle<i::Object> value, int lub, Zone* zone) { | 158 i::Handle<i::Object> value, int lub, Zone* zone) { |
120 Struct* structured = struct_create(Type::kConstantTag, 2, zone); | 159 Struct* structured = |
| 160 struct_create(Type::StructuralType::kConstantTag, 2, zone); |
121 structured[2] = from_bitset(lub); | 161 structured[2] = from_bitset(lub); |
122 structured[3] = value.location(); | 162 structured[3] = value.location(); |
123 return from_struct(structured); | 163 return from_struct(structured); |
124 } | 164 } |
125 | 165 |
126 | 166 |
127 // static | 167 // static |
128 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( | 168 ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( |
129 int tag, int length, Zone* zone) { | 169 int tag, int length, Zone* zone) { |
130 Struct* structured = reinterpret_cast<Struct*>( | 170 Struct* structured = reinterpret_cast<Struct*>( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 structured[2 + i] = type; | 207 structured[2 + i] = type; |
168 } | 208 } |
169 | 209 |
170 | 210 |
171 // static | 211 // static |
172 int ZoneTypeConfig::lub_bitset(Type* type) { | 212 int ZoneTypeConfig::lub_bitset(Type* type) { |
173 ASSERT(is_class(type) || is_constant(type)); | 213 ASSERT(is_class(type) || is_constant(type)); |
174 return as_bitset(struct_get(as_struct(type), 0)); | 214 return as_bitset(struct_get(as_struct(type), 0)); |
175 } | 215 } |
176 | 216 |
| 217 |
177 // -------------------------------------------------------------------------- // | 218 // -------------------------------------------------------------------------- // |
| 219 // HeapTypeConfig |
178 | 220 |
179 // static | 221 // static |
180 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::handle(Type* type) { | 222 template<class T> |
| 223 i::Handle<T> HeapTypeConfig::handle(T* type) { |
181 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); | 224 return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); |
182 } | 225 } |
183 | 226 |
184 | 227 |
185 // static | 228 // static |
| 229 template<class T> |
| 230 i::Handle<T> HeapTypeConfig::cast(i::Handle<Type> type) { |
| 231 return i::Handle<T>::cast(type); |
| 232 } |
| 233 |
| 234 |
| 235 // static |
186 bool HeapTypeConfig::is_bitset(Type* type) { | 236 bool HeapTypeConfig::is_bitset(Type* type) { |
187 return type->IsSmi(); | 237 return type->IsSmi(); |
188 } | 238 } |
189 | 239 |
190 | 240 |
191 // static | 241 // static |
192 bool HeapTypeConfig::is_class(Type* type) { | 242 bool HeapTypeConfig::is_class(Type* type) { |
193 return type->IsMap(); | 243 return type->IsMap(); |
194 } | 244 } |
195 | 245 |
196 | 246 |
197 // static | 247 // static |
198 bool HeapTypeConfig::is_constant(Type* type) { | 248 bool HeapTypeConfig::is_constant(Type* type) { |
199 return type->IsBox(); | 249 return type->IsBox(); |
200 } | 250 } |
201 | 251 |
202 | 252 |
203 // static | 253 // static |
204 bool HeapTypeConfig::is_struct(Type* type) { | 254 bool HeapTypeConfig::is_struct(Type* type, int tag) { |
205 return type->IsFixedArray(); | 255 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; |
206 } | 256 } |
207 | 257 |
208 | 258 |
209 // static | 259 // static |
210 int HeapTypeConfig::as_bitset(Type* type) { | 260 int HeapTypeConfig::as_bitset(Type* type) { |
211 return Smi::cast(type)->value(); | 261 return i::Smi::cast(type)->value(); |
212 } | 262 } |
213 | 263 |
214 | 264 |
215 // static | 265 // static |
216 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { | 266 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { |
217 return i::handle(i::Map::cast(type)); | 267 return i::handle(i::Map::cast(type)); |
218 } | 268 } |
219 | 269 |
220 | 270 |
221 // static | 271 // static |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 359 |
310 | 360 |
311 // static | 361 // static |
312 int HeapTypeConfig::lub_bitset(Type* type) { | 362 int HeapTypeConfig::lub_bitset(Type* type) { |
313 return 0; // kNone, which causes recomputation. | 363 return 0; // kNone, which causes recomputation. |
314 } | 364 } |
315 | 365 |
316 } } // namespace v8::internal | 366 } } // namespace v8::internal |
317 | 367 |
318 #endif // V8_TYPES_INL_H_ | 368 #endif // V8_TYPES_INL_H_ |
OLD | NEW |