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

Side by Side Diff: src/types.h

Issue 18587007: Type::GetName() for printing types in debugger (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase Created 7 years, 5 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 | « no previous file | src/types.cc » ('j') | src/types.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // Consequently, do not use pointer equality for type tests, always use Is! 87 // Consequently, do not use pointer equality for type tests, always use Is!
88 // 88 //
89 // Internally, all 'primitive' types, and their unions, are represented as 89 // Internally, all 'primitive' types, and their unions, are represented as
90 // bitsets via smis. Class is a heap pointer to the respective map. Only 90 // bitsets via smis. Class is a heap pointer to the respective map. Only
91 // Constant's, or unions containing Class'es or Constant's, require allocation. 91 // Constant's, or unions containing Class'es or Constant's, require allocation.
92 // Note that the bitset representation is closed under both Union and Intersect. 92 // Note that the bitset representation is closed under both Union and Intersect.
93 // 93 //
94 // The type representation is heap-allocated, so cannot (currently) be used in 94 // The type representation is heap-allocated, so cannot (currently) be used in
95 // a parallel compilation context. 95 // a parallel compilation context.
96 96
97
98 #define PRIMITIVE_TYPE_LIST(V) \
99 V(None, 0) \
100 V(Null, 1 << 0) \
101 V(Undefined, 1 << 1) \
102 V(Boolean, 1 << 2) \
103 V(Smi, 1 << 3) \
104 V(OtherSigned32, 1 << 4) \
105 V(Unsigned32, 1 << 5) \
106 V(Double, 1 << 6) \
107 V(Symbol, 1 << 7) \
108 V(InternalizedString, 1 << 8) \
109 V(OtherString, 1 << 9) \
110 V(Undetectable, 1 << 10) \
111 V(Array, 1 << 11) \
112 V(Function, 1 << 12) \
113 V(RegExp, 1 << 13) \
114 V(OtherObject, 1 << 14) \
115 V(Proxy, 1 << 15) \
116 V(Internal, 1 << 16)
117
118 #define COMPOSED_TYPE_LIST(V) \
119 V(Oddball, kBoolean | kNull | kUndefined) \
120 V(Signed32, kSmi | kOtherSigned32) \
121 V(Number, kSigned32 | kUnsigned32 | kDouble) \
122 V(String, kInternalizedString | kOtherString) \
123 V(UniqueName, kSymbol | kInternalizedString) \
124 V(Name, kSymbol | kString) \
125 V(NumberOrString, kNumber | kString) \
126 V(Object, kUndetectable | kArray | kFunction | \
127 kRegExp | kOtherObject) \
128 V(Receiver, kObject | kProxy) \
129 V(Allocated, kDouble | kName | kReceiver) \
130 V(Any, kOddball | kNumber | kAllocated | kInternal) \
131 V(Detectable, kAllocated - kUndetectable)
132
133 #define TYPE_LIST(V) \
134 PRIMITIVE_TYPE_LIST(V) \
135 COMPOSED_TYPE_LIST(V)
136
137
138
97 class Type : public Object { 139 class Type : public Object {
98 public: 140 public:
99 static Type* None() { return from_bitset(kNone); } 141 #define DEFINE_TYPE_CONSTRUCTOR(type, value) \
100 static Type* Any() { return from_bitset(kAny); } 142 static Type* type() { return from_bitset(k##type); }
101 static Type* Allocated() { return from_bitset(kAllocated); } 143 TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR)
102 static Type* Detectable() { return from_bitset(kDetectable); } 144 #undef DEFINE_TYPE_CONSTRUCTOR
103
104 static Type* Oddball() { return from_bitset(kOddball); }
105 static Type* Boolean() { return from_bitset(kBoolean); }
106 static Type* Null() { return from_bitset(kNull); }
107 static Type* Undefined() { return from_bitset(kUndefined); }
108
109 static Type* Number() { return from_bitset(kNumber); }
110 static Type* Smi() { return from_bitset(kSmi); }
111 static Type* Signed32() { return from_bitset(kSigned32); }
112 static Type* Unsigned32() { return from_bitset(kUnsigned32); }
113 static Type* Double() { return from_bitset(kDouble); }
114 static Type* NumberOrString() { return from_bitset(kNumberOrString); }
115
116 static Type* Name() { return from_bitset(kName); }
117 static Type* UniqueName() { return from_bitset(kUniqueName); }
118 static Type* String() { return from_bitset(kString); }
119 static Type* InternalizedString() { return from_bitset(kInternalizedString); }
120 static Type* Symbol() { return from_bitset(kSymbol); }
121
122 static Type* Receiver() { return from_bitset(kReceiver); }
123 static Type* Object() { return from_bitset(kObject); }
124 static Type* Undetectable() { return from_bitset(kUndetectable); }
125 static Type* Array() { return from_bitset(kArray); }
126 static Type* Function() { return from_bitset(kFunction); }
127 static Type* RegExp() { return from_bitset(kRegExp); }
128 static Type* Proxy() { return from_bitset(kProxy); }
129 static Type* Internal() { return from_bitset(kInternal); }
130 145
131 static Type* Class(Handle<Map> map) { return from_handle(map); } 146 static Type* Class(Handle<Map> map) { return from_handle(map); }
132 static Type* Constant(Handle<HeapObject> value) { 147 static Type* Constant(Handle<HeapObject> value) {
133 return Constant(value, value->GetIsolate()); 148 return Constant(value, value->GetIsolate());
134 } 149 }
135 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) { 150 static Type* Constant(Handle<v8::internal::Object> value, Isolate* isolate) {
136 return from_handle(isolate->factory()->NewBox(value)); 151 return from_handle(isolate->factory()->NewBox(value));
137 } 152 }
138 153
139 static Type* Union(Handle<Type> type1, Handle<Type> type2); 154 static Type* Union(Handle<Type> type1, Handle<Type> type2);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return Iterator<v8::internal::Object>(this->handle()); 199 return Iterator<v8::internal::Object>(this->handle());
185 } 200 }
186 201
187 static Type* cast(v8::internal::Object* object) { 202 static Type* cast(v8::internal::Object* object) {
188 Type* t = static_cast<Type*>(object); 203 Type* t = static_cast<Type*>(object);
189 ASSERT(t->is_bitset() || t->is_class() || 204 ASSERT(t->is_bitset() || t->is_class() ||
190 t->is_constant() || t->is_union()); 205 t->is_constant() || t->is_union());
191 return t; 206 return t;
192 } 207 }
193 208
209 #ifdef OBJECT_PRINT
210 void TypePrint();
211 void TypePrint(FILE* out);
212 #endif
213
194 private: 214 private:
195 // A union is a fixed array containing types. Invariants: 215 // A union is a fixed array containing types. Invariants:
196 // - its length is at least 2 216 // - its length is at least 2
197 // - at most one field is a bitset, and it must go into index 0 217 // - at most one field is a bitset, and it must go into index 0
198 // - no field is a union 218 // - no field is a union
199 typedef FixedArray Unioned; 219 typedef FixedArray Unioned;
200 220
201 enum { 221 enum {
202 kNull = 1 << 0, 222 #define DECLARE_TYPE(type, value) k##type = (value),
203 kUndefined = 1 << 1, 223 TYPE_LIST(DECLARE_TYPE)
204 kBoolean = 1 << 2, 224 #undef DECLARE_TYPE
205 kSmi = 1 << 3, 225 kUnusedEOL = 0
206 kOtherSigned32 = 1 << 4,
207 kUnsigned32 = 1 << 5,
208 kDouble = 1 << 6,
209 kSymbol = 1 << 7,
210 kInternalizedString = 1 << 8,
211 kOtherString = 1 << 9,
212 kUndetectable = 1 << 10,
213 kArray = 1 << 11,
214 kFunction = 1 << 12,
215 kRegExp = 1 << 13,
216 kOtherObject = 1 << 14,
217 kProxy = 1 << 15,
218 kInternal = 1 << 16,
219
220 kOddball = kBoolean | kNull | kUndefined,
221 kSigned32 = kSmi | kOtherSigned32,
222 kNumber = kSigned32 | kUnsigned32 | kDouble,
223 kString = kInternalizedString | kOtherString,
224 kUniqueName = kSymbol | kInternalizedString,
225 kName = kSymbol | kString,
226 kNumberOrString = kNumber | kString,
227 kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject,
228 kReceiver = kObject | kProxy,
229 kAllocated = kDouble | kName | kReceiver,
230 kAny = kOddball | kNumber | kAllocated | kInternal,
231 kDetectable = kAllocated - kUndetectable,
232 kNone = 0
233 }; 226 };
234 227
235 bool is_bitset() { return this->IsSmi(); } 228 bool is_bitset() { return this->IsSmi(); }
236 bool is_class() { return this->IsMap(); } 229 bool is_class() { return this->IsMap(); }
237 bool is_constant() { return this->IsBox(); } 230 bool is_constant() { return this->IsBox(); }
238 bool is_union() { return this->IsFixedArray(); } 231 bool is_union() { return this->IsFixedArray(); }
239 232
240 bool IsSlowCase(Type* that); 233 bool IsSlowCase(Type* that);
241 234
242 int as_bitset() { return Smi::cast(this)->value(); } 235 int as_bitset() { return Smi::cast(this)->value(); }
(...skipping 22 matching lines...) Expand all
265 ASSERT(!type->is_union()); 258 ASSERT(!type->is_union());
266 return type->handle_via_isolate_of(from_handle(unioned)); 259 return type->handle_via_isolate_of(from_handle(unioned));
267 } 260 }
268 261
269 int LubBitset(); // least upper bound that's a bitset 262 int LubBitset(); // least upper bound that's a bitset
270 int GlbBitset(); // greatest lower bound that's a bitset 263 int GlbBitset(); // greatest lower bound that's a bitset
271 bool InUnion(Handle<Unioned> unioned, int current_size); 264 bool InUnion(Handle<Unioned> unioned, int current_size);
272 int ExtendUnion(Handle<Unioned> unioned, int current_size); 265 int ExtendUnion(Handle<Unioned> unioned, int current_size);
273 int ExtendIntersection( 266 int ExtendIntersection(
274 Handle<Unioned> unioned, Handle<Type> type, int current_size); 267 Handle<Unioned> unioned, Handle<Type> type, int current_size);
268
269 static const char* GetComposedName(int type) {
270 switch (type) {
271 #define PRINT_COMPOSED_TYPE(type, value) \
272 case k##type: \
273 return # type;
274 COMPOSED_TYPE_LIST(PRINT_COMPOSED_TYPE)
275 #undef PRINT_COMPOSED_TYPE
276 }
277 return NULL;
278 }
279
280 static const char* GetPrimitiveName(int type) {
281 switch (type) {
282 #define PRINT_PRIMITIVE_TYPE(type, value) \
283 case k##type: \
284 return # type;
285 PRIMITIVE_TYPE_LIST(PRINT_PRIMITIVE_TYPE)
286 #undef PRINT_PRIMITIVE_TYPE
287 default:
288 UNREACHABLE();
289 return "InvalidType";
290 }
291 }
275 }; 292 };
276 293
277 } } // namespace v8::internal 294 } } // namespace v8::internal
278 295
279 #endif // V8_TYPES_H_ 296 #endif // V8_TYPES_H_
OLDNEW
« no previous file with comments | « no previous file | src/types.cc » ('j') | src/types.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698