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

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: address review 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); }
rossberg 2013/07/08 11:20:05 This line needs indentation
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 200 }
186 201
187 private: 202 private:
188 // A union is a fixed array containing types. Invariants: 203 // A union is a fixed array containing types. Invariants:
189 // - its length is at least 2 204 // - its length is at least 2
190 // - at most one field is a bitset, and it must go into index 0 205 // - at most one field is a bitset, and it must go into index 0
191 // - no field is a union 206 // - no field is a union
192 typedef FixedArray Unioned; 207 typedef FixedArray Unioned;
193 208
194 enum { 209 enum {
195 kNull = 1 << 0, 210 // Declare const for all primitive types.
rossberg 2013/07/08 11:20:05 I think this comment is redundant (the "primitive"
196 kUndefined = 1 << 1, 211 #define DECLARE_PRIMITIVE_TYPE(type, value) k##type = (value),
rossberg 2013/07/08 11:20:05 Rename to DECLARE_TYPE
197 kBoolean = 1 << 2, 212 TYPE_LIST(DECLARE_PRIMITIVE_TYPE)
198 kSmi = 1 << 3, 213 #undef DECLARE_OPCODE
rossberg 2013/07/08 11:20:05 Wrong macro name?
199 kOtherSigned32 = 1 << 4, 214 kUnusedEOL = 0
200 kUnsigned32 = 1 << 5, 215 };
201 kDouble = 1 << 6,
202 kSymbol = 1 << 7,
203 kInternalizedString = 1 << 8,
204 kOtherString = 1 << 9,
205 kUndetectable = 1 << 10,
206 kArray = 1 << 11,
207 kFunction = 1 << 12,
208 kRegExp = 1 << 13,
209 kOtherObject = 1 << 14,
210 kProxy = 1 << 15,
211 kInternal = 1 << 16,
212 216
213 kOddball = kBoolean | kNull | kUndefined, 217 static const char* GetComposedName(int type) {
rossberg 2013/07/08 11:20:05 Can we move these helpers to the bottom?
214 kSigned32 = kSmi | kOtherSigned32, 218 switch (type) {
215 kNumber = kSigned32 | kUnsigned32 | kDouble, 219 #define PRINT_COMPOSED_TYPE(type, value) \
216 kString = kInternalizedString | kOtherString, 220 case k##type: \
217 kUniqueName = kSymbol | kInternalizedString, 221 return # type;
218 kName = kSymbol | kString, 222 COMPOSED_TYPE_LIST(PRINT_COMPOSED_TYPE)
219 kNumberOrString = kNumber | kString, 223 #undef PRINT_COMPOSED_TYPE
220 kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject, 224 }
221 kReceiver = kObject | kProxy, 225 return NULL;
222 kAllocated = kDouble | kName | kReceiver, 226 }
223 kAny = kOddball | kNumber | kAllocated | kInternal, 227
224 kDetectable = kAllocated - kUndetectable, 228 static const char* GetPrimitiveName(int type) {
225 kNone = 0 229 switch (type) {
226 }; 230 #define PRINT_PRIMITIVE_TYPE(type, value) \
231 case k##type: \
232 return # type;
233 PRIMITIVE_TYPE_LIST(PRINT_PRIMITIVE_TYPE)
234 #undef PRINT_PRIMITIVE_TYPE
235 default:
236 UNREACHABLE();
237 return "InvalidType";
238 }
239 }
227 240
228 bool is_bitset() { return this->IsSmi(); } 241 bool is_bitset() { return this->IsSmi(); }
229 bool is_class() { return this->IsMap(); } 242 bool is_class() { return this->IsMap(); }
230 bool is_constant() { return this->IsBox(); } 243 bool is_constant() { return this->IsBox(); }
231 bool is_union() { return this->IsFixedArray(); } 244 bool is_union() { return this->IsFixedArray(); }
232 245
233 bool IsSlowCase(Type* that); 246 bool IsSlowCase(Type* that);
234 247
235 int as_bitset() { return Smi::cast(this)->value(); } 248 int as_bitset() { return Smi::cast(this)->value(); }
236 Handle<Map> as_class() { return Handle<Map>::cast(handle()); } 249 Handle<Map> as_class() { return Handle<Map>::cast(handle()); }
(...skipping 21 matching lines...) Expand all
258 ASSERT(!type->is_union()); 271 ASSERT(!type->is_union());
259 return type->handle_via_isolate_of(from_handle(unioned)); 272 return type->handle_via_isolate_of(from_handle(unioned));
260 } 273 }
261 274
262 int LubBitset(); // least upper bound that's a bitset 275 int LubBitset(); // least upper bound that's a bitset
263 int GlbBitset(); // greatest lower bound that's a bitset 276 int GlbBitset(); // greatest lower bound that's a bitset
264 bool InUnion(Handle<Unioned> unioned, int current_size); 277 bool InUnion(Handle<Unioned> unioned, int current_size);
265 int ExtendUnion(Handle<Unioned> unioned, int current_size); 278 int ExtendUnion(Handle<Unioned> unioned, int current_size);
266 int ExtendIntersection( 279 int ExtendIntersection(
267 Handle<Unioned> unioned, Handle<Type> type, int current_size); 280 Handle<Unioned> unioned, Handle<Type> type, int current_size);
281
282 void PrintName(StringStream* stream);
rossberg 2013/07/08 11:20:05 It might be worth following the objects.h conventi
283 SmartArrayPointer<const char> GetName();
268 }; 284 };
269 285
270 } } // namespace v8::internal 286 } } // namespace v8::internal
271 287
272 #endif // V8_TYPES_H_ 288 #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