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

Unified Diff: src/types.cc

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 side-by-side diff with in-line comments
Download patch
« src/types.h ('K') | « src/types.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« src/types.h ('K') | « src/types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698