Type::GetName(...) for inspecting Types in the debugger
BUG= R=rossberg@chromium.org Review URL: https://codereview.chromium.org/18587007 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15586 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
865ce5806f
commit
c5f20ef8dc
46
src/types.cc
46
src/types.cc
@ -26,6 +26,7 @@
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include "types.h"
|
||||
#include "string-stream.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
@ -486,4 +487,49 @@ Representation Representation::FromType(Handle<Type> type) {
|
||||
}
|
||||
|
||||
|
||||
#ifdef OBJECT_PRINT
|
||||
void Type::TypePrint() {
|
||||
TypePrint(stdout);
|
||||
PrintF(stdout, "\n");
|
||||
Flush(stdout);
|
||||
}
|
||||
|
||||
|
||||
void Type::TypePrint(FILE* out) {
|
||||
if (is_bitset()) {
|
||||
int val = as_bitset();
|
||||
const char* composed_name = GetComposedName(val);
|
||||
if (composed_name != NULL) {
|
||||
PrintF(out, "%s", composed_name);
|
||||
return;
|
||||
}
|
||||
bool first_entry = true;
|
||||
PrintF(out, "{");
|
||||
for (unsigned i = 0; i < sizeof(val)*8; ++i) {
|
||||
int mask = (1<<i);
|
||||
if ((val & mask) != 0) {
|
||||
if (!first_entry) PrintF(out, ",");
|
||||
first_entry = false;
|
||||
PrintF(out, "%s", GetPrimitiveName(mask));
|
||||
}
|
||||
}
|
||||
PrintF(out, "}");
|
||||
} else if (is_constant()) {
|
||||
PrintF(out, "Constant(%p)", reinterpret_cast<void*>(*as_constant()));
|
||||
} else if (is_class()) {
|
||||
PrintF(out, "Class(%p)", reinterpret_cast<void*>(*as_class()));
|
||||
} else if (is_union()) {
|
||||
PrintF(out, "{");
|
||||
Handle<Unioned> unioned = as_union();
|
||||
for (int i = 0; i < unioned->length(); ++i) {
|
||||
Handle<Type> type_i = union_get(unioned, i);
|
||||
if (i > 0) PrintF(out, ",");
|
||||
type_i->TypePrint(out);
|
||||
}
|
||||
PrintF(out, "}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} } // namespace v8::internal
|
||||
|
141
src/types.h
141
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); }
|
||||
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) {
|
||||
@ -191,6 +206,11 @@ class Type : public Object {
|
||||
return t;
|
||||
}
|
||||
|
||||
#ifdef OBJECT_PRINT
|
||||
void TypePrint();
|
||||
void TypePrint(FILE* out);
|
||||
#endif
|
||||
|
||||
private:
|
||||
// A union is a fixed array containing types. Invariants:
|
||||
// - its length is at least 2
|
||||
@ -199,37 +219,10 @@ 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
|
||||
#define DECLARE_TYPE(type, value) k##type = (value),
|
||||
TYPE_LIST(DECLARE_TYPE)
|
||||
#undef DECLARE_TYPE
|
||||
kUnusedEOL = 0
|
||||
};
|
||||
|
||||
bool is_bitset() { return this->IsSmi(); }
|
||||
@ -272,6 +265,30 @@ class Type : public Object {
|
||||
int ExtendUnion(Handle<Unioned> unioned, int current_size);
|
||||
int ExtendIntersection(
|
||||
Handle<Unioned> unioned, Handle<Type> type, int current_size);
|
||||
|
||||
static const char* GetComposedName(int type) {
|
||||
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";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} } // namespace v8::internal
|
||||
|
Loading…
Reference in New Issue
Block a user