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

Side by Side Diff: src/types-inl.h

Issue 564413004: Re-revert "Use unsigned type bitsets to limit undefined behaviour" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "src/types.h" 8 #include "src/types.h"
9 9
10 #include "src/factory.h" 10 #include "src/factory.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // static 64 // static
65 template<class T> 65 template<class T>
66 T* ZoneTypeConfig::cast(Type* type) { 66 T* ZoneTypeConfig::cast(Type* type) {
67 return static_cast<T*>(type); 67 return static_cast<T*>(type);
68 } 68 }
69 69
70 70
71 // static 71 // static
72 bool ZoneTypeConfig::is_bitset(Type* type) { 72 bool ZoneTypeConfig::is_bitset(Type* type) {
73 return reinterpret_cast<uintptr_t>(type) & 1; 73 return reinterpret_cast<intptr_t>(type) & 1;
74 } 74 }
75 75
76 76
77 // static 77 // static
78 bool ZoneTypeConfig::is_struct(Type* type, int tag) { 78 bool ZoneTypeConfig::is_struct(Type* type, int tag) {
79 return !is_bitset(type) && struct_tag(as_struct(type)) == tag; 79 return !is_bitset(type) && struct_tag(as_struct(type)) == tag;
80 } 80 }
81 81
82 82
83 // static 83 // static
84 bool ZoneTypeConfig::is_class(Type* type) { 84 bool ZoneTypeConfig::is_class(Type* type) {
85 return false; 85 return false;
86 } 86 }
87 87
88 88
89 // static 89 // static
90 ZoneTypeConfig::Type::bitset ZoneTypeConfig::as_bitset(Type* type) { 90 int ZoneTypeConfig::as_bitset(Type* type) {
91 DCHECK(is_bitset(type)); 91 DCHECK(is_bitset(type));
92 return reinterpret_cast<Type::bitset>(type) ^ 1u; 92 return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
93 } 93 }
94 94
95 95
96 // static 96 // static
97 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { 97 ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) {
98 DCHECK(!is_bitset(type)); 98 DCHECK(!is_bitset(type));
99 return reinterpret_cast<Struct*>(type); 99 return reinterpret_cast<Struct*>(type);
100 } 100 }
101 101
102 102
103 // static 103 // static
104 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) { 104 i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
105 UNREACHABLE(); 105 UNREACHABLE();
106 return i::Handle<i::Map>(); 106 return i::Handle<i::Map>();
107 } 107 }
108 108
109 109
110 // static 110 // static
111 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(Type::bitset bitset) { 111 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) {
112 return reinterpret_cast<Type*>(bitset | 1u); 112 return reinterpret_cast<Type*>((bitset << 1) | 1);
113 } 113 }
114 114
115 115
116 // static 116 // static
117 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset( 117 ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
118 Type::bitset bitset, Zone* Zone) {
119 return from_bitset(bitset); 118 return from_bitset(bitset);
120 } 119 }
121 120
122 121
123 // static 122 // static
124 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) { 123 ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structure) {
125 return reinterpret_cast<Type*>(structure); 124 return reinterpret_cast<Type*>(structure);
126 } 125 }
127 126
128 127
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 222 }
224 223
225 224
226 // static 225 // static
227 bool HeapTypeConfig::is_struct(Type* type, int tag) { 226 bool HeapTypeConfig::is_struct(Type* type, int tag) {
228 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag; 227 return type->IsFixedArray() && struct_tag(as_struct(type)) == tag;
229 } 228 }
230 229
231 230
232 // static 231 // static
233 HeapTypeConfig::Type::bitset HeapTypeConfig::as_bitset(Type* type) { 232 int HeapTypeConfig::as_bitset(Type* type) {
234 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way. 233 return i::Smi::cast(type)->value();
235 return reinterpret_cast<Type::bitset>(type);
236 } 234 }
237 235
238 236
239 // static 237 // static
240 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) { 238 i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
241 return i::handle(i::Map::cast(type)); 239 return i::handle(i::Map::cast(type));
242 } 240 }
243 241
244 242
245 // static 243 // static
246 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) { 244 i::Handle<HeapTypeConfig::Struct> HeapTypeConfig::as_struct(Type* type) {
247 return i::handle(Struct::cast(type)); 245 return i::handle(Struct::cast(type));
248 } 246 }
249 247
250 248
251 // static 249 // static
252 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(Type::bitset bitset) { 250 HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
253 // TODO(rossberg): Breaks the Smi abstraction. Fix once there is a better way. 251 return Type::cast(i::Smi::FromInt(bitset));
254 return reinterpret_cast<Type*>(bitset);
255 } 252 }
256 253
257 254
258 // static 255 // static
259 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset( 256 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
260 Type::bitset bitset, Isolate* isolate) { 257 int bitset, Isolate* isolate) {
261 return i::handle(from_bitset(bitset), isolate); 258 return i::handle(from_bitset(bitset), isolate);
262 } 259 }
263 260
264 261
265 // static 262 // static
266 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class( 263 i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class(
267 i::Handle<i::Map> map, Isolate* isolate) { 264 i::Handle<i::Map> map, Isolate* isolate) {
268 return i::Handle<Type>::cast(i::Handle<Object>::cast(map)); 265 return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
269 } 266 }
270 267
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // static 327 // static
331 template<class V> 328 template<class V>
332 void HeapTypeConfig::struct_set_value( 329 void HeapTypeConfig::struct_set_value(
333 i::Handle<Struct> structure, int i, i::Handle<V> x) { 330 i::Handle<Struct> structure, int i, i::Handle<V> x) {
334 structure->set(i + 1, *x); 331 structure->set(i + 1, *x);
335 } 332 }
336 333
337 } } // namespace v8::internal 334 } } // namespace v8::internal
338 335
339 #endif // V8_TYPES_INL_H_ 336 #endif // V8_TYPES_INL_H_
OLDNEW
« no previous file with comments | « src/types.cc ('k') | test/cctest/test-types.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698