Chromium Code Reviews| Index: src/types.h |
| diff --git a/src/types.h b/src/types.h |
| index a2bcda65791646c57464a5d85a908564efc5587a..3700939a2dcf0f1352175160de306b9612b09be5 100644 |
| --- a/src/types.h |
| +++ b/src/types.h |
| @@ -94,39 +94,54 @@ namespace internal { |
| // The type representation is heap-allocated, so cannot (currently) be used in |
| // a parallel compilation context. |
| + |
| +#define PRIMITIVE_TYPE_LIST(V) \ |
| + V(None, 0) \ |
| + V(Null, 1 << 0) \ |
| + V(Undefined, 1 << 1) \ |
| + V(Boolean, 1 << 2) \ |
| + V(Smi, 1 << 3) \ |
| + V(OtherSigned32, 1 << 4) \ |
| + V(Unsigned32, 1 << 5) \ |
| + V(Double, 1 << 6) \ |
| + V(Symbol, 1 << 7) \ |
| + V(InternalizedString, 1 << 8) \ |
| + V(OtherString, 1 << 9) \ |
| + V(Undetectable, 1 << 10) \ |
| + V(Array, 1 << 11) \ |
| + V(Function, 1 << 12) \ |
| + V(RegExp, 1 << 13) \ |
| + V(OtherObject, 1 << 14) \ |
| + V(Proxy, 1 << 15) \ |
| + V(Internal, 1 << 16) |
| + |
| +#define COMPOSED_TYPE_LIST(V) \ |
| + V(Oddball, kBoolean | kNull | kUndefined) \ |
| + V(Signed32, kSmi | kOtherSigned32) \ |
| + V(Number, kSigned32 | kUnsigned32 | kDouble) \ |
| + V(String, kInternalizedString | kOtherString) \ |
| + V(UniqueName, kSymbol | kInternalizedString) \ |
| + V(Name, kSymbol | kString) \ |
| + V(NumberOrString, kNumber | kString) \ |
| + V(Object, kUndetectable | kArray | kFunction | \ |
| + kRegExp | kOtherObject) \ |
| + V(Receiver, kObject | kProxy) \ |
| + V(Allocated, kDouble | kName | kReceiver) \ |
| + V(Any, kOddball | kNumber | kAllocated | kInternal) \ |
| + V(Detectable, kAllocated - kUndetectable) |
| + |
| +#define TYPE_LIST(V) \ |
| + PRIMITIVE_TYPE_LIST(V) \ |
| + COMPOSED_TYPE_LIST(V) |
| + |
| + |
| + |
| class Type : public Object { |
| public: |
| - static Type* None() { return from_bitset(kNone); } |
| - static Type* Any() { return from_bitset(kAny); } |
| - static Type* Allocated() { return from_bitset(kAllocated); } |
| - static Type* Detectable() { return from_bitset(kDetectable); } |
| - |
| - static Type* Oddball() { return from_bitset(kOddball); } |
| - static Type* Boolean() { return from_bitset(kBoolean); } |
| - static Type* Null() { return from_bitset(kNull); } |
| - static Type* Undefined() { return from_bitset(kUndefined); } |
| - |
| - static Type* Number() { return from_bitset(kNumber); } |
| - static Type* Smi() { return from_bitset(kSmi); } |
| - static Type* Signed32() { return from_bitset(kSigned32); } |
| - static Type* Unsigned32() { return from_bitset(kUnsigned32); } |
| - static Type* Double() { return from_bitset(kDouble); } |
| - static Type* NumberOrString() { return from_bitset(kNumberOrString); } |
| - |
| - static Type* Name() { return from_bitset(kName); } |
| - static Type* UniqueName() { return from_bitset(kUniqueName); } |
| - static Type* String() { return from_bitset(kString); } |
| - static Type* InternalizedString() { return from_bitset(kInternalizedString); } |
| - static Type* Symbol() { return from_bitset(kSymbol); } |
| - |
| - static Type* Receiver() { return from_bitset(kReceiver); } |
| - static Type* Object() { return from_bitset(kObject); } |
| - static Type* Undetectable() { return from_bitset(kUndetectable); } |
| - static Type* Array() { return from_bitset(kArray); } |
| - static Type* Function() { return from_bitset(kFunction); } |
| - static Type* RegExp() { return from_bitset(kRegExp); } |
| - static Type* Proxy() { return from_bitset(kProxy); } |
| - static Type* Internal() { return from_bitset(kInternal); } |
| + #define DEFINE_TYPE_CONSTRUCTOR(type, value) \ |
| + static Type* type() { return from_bitset(k##type); } |
|
rossberg
2013/07/08 11:20:05
This line needs indentation
|
| + TYPE_LIST(DEFINE_TYPE_CONSTRUCTOR) |
| + #undef DEFINE_TYPE_CONSTRUCTOR |
| static Type* Class(Handle<Map> map) { return from_handle(map); } |
| static Type* Constant(Handle<HeapObject> value) { |
| @@ -192,39 +207,37 @@ class Type : public Object { |
| typedef FixedArray Unioned; |
| enum { |
| - kNull = 1 << 0, |
| - kUndefined = 1 << 1, |
| - kBoolean = 1 << 2, |
| - kSmi = 1 << 3, |
| - kOtherSigned32 = 1 << 4, |
| - kUnsigned32 = 1 << 5, |
| - kDouble = 1 << 6, |
| - kSymbol = 1 << 7, |
| - kInternalizedString = 1 << 8, |
| - kOtherString = 1 << 9, |
| - kUndetectable = 1 << 10, |
| - kArray = 1 << 11, |
| - kFunction = 1 << 12, |
| - kRegExp = 1 << 13, |
| - kOtherObject = 1 << 14, |
| - kProxy = 1 << 15, |
| - kInternal = 1 << 16, |
| - |
| - kOddball = kBoolean | kNull | kUndefined, |
| - kSigned32 = kSmi | kOtherSigned32, |
| - kNumber = kSigned32 | kUnsigned32 | kDouble, |
| - kString = kInternalizedString | kOtherString, |
| - kUniqueName = kSymbol | kInternalizedString, |
| - kName = kSymbol | kString, |
| - kNumberOrString = kNumber | kString, |
| - kObject = kUndetectable | kArray | kFunction | kRegExp | kOtherObject, |
| - kReceiver = kObject | kProxy, |
| - kAllocated = kDouble | kName | kReceiver, |
| - kAny = kOddball | kNumber | kAllocated | kInternal, |
| - kDetectable = kAllocated - kUndetectable, |
| - kNone = 0 |
| + // Declare const for all primitive types. |
|
rossberg
2013/07/08 11:20:05
I think this comment is redundant (the "primitive"
|
| + #define DECLARE_PRIMITIVE_TYPE(type, value) k##type = (value), |
|
rossberg
2013/07/08 11:20:05
Rename to DECLARE_TYPE
|
| + TYPE_LIST(DECLARE_PRIMITIVE_TYPE) |
| + #undef DECLARE_OPCODE |
|
rossberg
2013/07/08 11:20:05
Wrong macro name?
|
| + kUnusedEOL = 0 |
| }; |
| + static const char* GetComposedName(int type) { |
|
rossberg
2013/07/08 11:20:05
Can we move these helpers to the bottom?
|
| + switch (type) { |
| + #define PRINT_COMPOSED_TYPE(type, value) \ |
| + case k##type: \ |
| + return # type; |
| + COMPOSED_TYPE_LIST(PRINT_COMPOSED_TYPE) |
| + #undef PRINT_COMPOSED_TYPE |
| + } |
| + return NULL; |
| + } |
| + |
| + static const char* GetPrimitiveName(int type) { |
| + switch (type) { |
| + #define PRINT_PRIMITIVE_TYPE(type, value) \ |
| + case k##type: \ |
| + return # type; |
| + PRIMITIVE_TYPE_LIST(PRINT_PRIMITIVE_TYPE) |
| + #undef PRINT_PRIMITIVE_TYPE |
| + default: |
| + UNREACHABLE(); |
| + return "InvalidType"; |
| + } |
| + } |
| + |
| bool is_bitset() { return this->IsSmi(); } |
| bool is_class() { return this->IsMap(); } |
| bool is_constant() { return this->IsBox(); } |
| @@ -265,6 +278,9 @@ class Type : public Object { |
| int ExtendUnion(Handle<Unioned> unioned, int current_size); |
| int ExtendIntersection( |
| Handle<Unioned> unioned, Handle<Type> type, int current_size); |
| + |
| + void PrintName(StringStream* stream); |
|
rossberg
2013/07/08 11:20:05
It might be worth following the objects.h conventi
|
| + SmartArrayPointer<const char> GetName(); |
| }; |
| } } // namespace v8::internal |