// Copyright 2011 Google Inc. All Rights Reserved. // Author: enh@google.com (Elliott Hughes) #include "object.h" #include "utils.h" namespace art { std::string PrettyDescriptor(const StringPiece& descriptor) { // Count the number of '['s to get the dimensionality. const char* c = descriptor.data(); size_t dim = 0; while (*c == '[') { dim++; c++; } // Reference or primitive? if (*c == 'L') { // "[[La/b/C;" -> "a.b.C[][]". c++; // Skip the 'L'. } else { // "[[B" -> "byte[][]". // To make life easier, we make primitives look like unqualified // reference types. switch (*c) { case 'B': c = "byte;"; break; case 'C': c = "char;"; break; case 'D': c = "double;"; break; case 'F': c = "float;"; break; case 'I': c = "int;"; break; case 'J': c = "long;"; break; case 'S': c = "short;"; break; case 'Z': c = "boolean;"; break; default: return descriptor.ToString(); } } // At this point, 'c' is a string of the form "fully/qualified/Type;" // or "primitive;". Rewrite the type with '.' instead of '/': std::string result; const char* p = c; while (*p != ';') { char ch = *p++; if (ch == '/') { ch = '.'; } result.push_back(ch); } // ...and replace the semicolon with 'dim' "[]" pairs: while (dim--) { result += "[]"; } return result; } std::string PrettyType(const Object* obj) { if (obj == NULL) { return "null"; } if (obj->GetClass() == NULL) { return "(raw)"; } std::string result(PrettyDescriptor(obj->GetClass()->GetDescriptor())); if (obj->IsClass()) { result += "<" + PrettyDescriptor(obj->AsClass()->GetDescriptor()) + ">"; } return result; } } // namespace art