Chromium Code Reviews| Index: src/types.cc |
| diff --git a/src/types.cc b/src/types.cc |
| index 1275deacb744e7b2f60485e6c0deaa9005f1fc59..594947aa651e7766b54cdafc064e586c4d2e5834 100644 |
| --- a/src/types.cc |
| +++ b/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 { |
| @@ -476,4 +477,49 @@ Type* Type::Optional(Handle<Type> type) { |
| : Union(type, Undefined()->handle_via_isolate_of(*type)); |
| } |
| + |
| +SmartArrayPointer<const char> Type::GetName() { |
| + char buffer[200]; |
|
rossberg
2013/07/08 11:20:05
200 seems fragile. I'd drop this method altogether
|
| + NoAllocationStringAllocator allocator(buffer, |
| + static_cast<unsigned>(sizeof(buffer))); |
| + StringStream stream(&allocator); |
| + PrintName(&stream); |
| + return stream.ToCString(); |
| +} |
| + |
| + |
| +void Type::PrintName(StringStream* stream) { |
| + if (is_bitset()) { |
| + int val = as_bitset(); |
| + const char* composed_name = GetComposedName(val); |
| + if (composed_name != NULL) { |
| + stream->Add(composed_name); |
| + return; |
| + } |
| + SimpleListPrinter printer(stream); |
|
rossberg
2013/07/08 11:20:05
Can we put a "{...}" around the list?
|
| + for (unsigned i = 0; i < sizeof(val)*8; ++i) { |
| + int mask = (1<<i); |
| + if ((val & mask) != 0) { |
| + printer.Add(GetPrimitiveName(mask)); |
| + } |
| + } |
| + } else if (is_constant()) { |
| + stream->Add("Constant("); |
| + stream->Add("0x%x", *as_constant()); |
| + stream->Add(")"); |
| + } else if (is_class()) { |
| + stream->Add("Class("); |
| + stream->Add("0x%x", *as_class()); |
| + stream->Add(")"); |
| + } else if (is_union()) { |
| + Handle<Unioned> unioned = as_union(); |
| + SimpleListPrinter printer(stream); |
|
rossberg
2013/07/08 11:20:05
Can we put a "{...}" around the list?
|
| + for (int i = 0; i < unioned->length(); ++i) { |
| + Handle<Type> type_i = union_get(unioned, i); |
| + printer.Add(*type_i->GetName()); |
| + } |
| + } |
| +} |
| + |
| + |
| } } // namespace v8::internal |