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