mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-31 06:04:58 +00:00
Introduce the concept of a "display name" for types
Rationale: Pretty simply, the idea is that sometimes type names are way too long and contain way too many details for the average developer to care about. For instance, a plain ol' vector of int might be shown as std::__1::vector<int, std::__1::allocator<.... rather than the much simpler std::vector<int> form, which is what most developers would actually type in their code Proposed solution: Introduce a notion of "display name" and a corresponding API GetDisplayTypeName() to return such a crafted for visual representation type name Obviously, the display name and the fully qualified (or "true") name are not necessarily the same - that's the whole point LLDB could choose to pick the "display name" as its one true notion of a type name, and if somebody really needs the fully qualified version of it, let them deal with the problem Or, LLDB could rename what it currently calls the "type name" to be the "display name", and add new APIs for the fully qualified name, making the display name the default choice The choice that I am making here is that the type name will keep meaning the same, and people who want a type name suited for display will explicitly ask for one It is the less risky/disruptive choice - and it should eventually make it fairly obvious when someone is asking for the wrong type Caveats: - for now, GetDisplayTypeName() == GetTypeName(), there is no logic to produce customized display type names yet. - while the fully-qualified type name is still the main key to the kingdom of data formatters, if we start showing custom names to people, those should match formatters llvm-svn: 209072
This commit is contained in:
parent
210e1aded7
commit
e8daa2f843
@ -161,6 +161,9 @@ public:
|
||||
const char*
|
||||
GetName();
|
||||
|
||||
const char *
|
||||
GetDisplayTypeName ();
|
||||
|
||||
lldb::TypeClass
|
||||
GetTypeClass ();
|
||||
|
||||
|
@ -50,6 +50,9 @@ public:
|
||||
|
||||
const char *
|
||||
GetTypeName ();
|
||||
|
||||
const char *
|
||||
GetDisplayTypeName ();
|
||||
|
||||
size_t
|
||||
GetByteSize ();
|
||||
|
@ -394,6 +394,9 @@ public:
|
||||
virtual ConstString
|
||||
GetTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
|
@ -62,6 +62,9 @@ public:
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual bool
|
||||
IsInScope ();
|
||||
|
||||
|
@ -80,6 +80,9 @@ public:
|
||||
virtual ConstString
|
||||
GetTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual bool
|
||||
IsInScope ();
|
||||
|
||||
|
@ -37,6 +37,9 @@ public:
|
||||
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual size_t
|
||||
CalculateNumChildren();
|
||||
|
@ -47,6 +47,9 @@ public:
|
||||
virtual ConstString
|
||||
GetTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual size_t
|
||||
CalculateNumChildren();
|
||||
|
||||
|
@ -45,6 +45,9 @@ public:
|
||||
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual size_t
|
||||
CalculateNumChildren();
|
||||
|
@ -41,6 +41,9 @@ public:
|
||||
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual bool
|
||||
MightHaveChildren();
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
|
||||
virtual ConstString
|
||||
GetQualifiedTypeName();
|
||||
|
||||
virtual ConstString
|
||||
GetDisplayTypeName();
|
||||
|
||||
virtual size_t
|
||||
CalculateNumChildren();
|
||||
|
@ -264,6 +264,9 @@ public:
|
||||
ConstString
|
||||
GetTypeName () const;
|
||||
|
||||
ConstString
|
||||
GetDisplayTypeName () const;
|
||||
|
||||
uint32_t
|
||||
GetTypeInfo (ClangASTType *pointee_or_element_clang_type = NULL) const;
|
||||
|
||||
|
@ -368,6 +368,16 @@ public:
|
||||
return ConstString ();
|
||||
}
|
||||
|
||||
ConstString
|
||||
GetDisplayTypeName () const
|
||||
{
|
||||
if (type_sp)
|
||||
return type_sp->GetClangForwardType().GetDisplayTypeName();
|
||||
if (clang_type)
|
||||
return clang_type.GetDisplayTypeName();
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
void
|
||||
SetType (ClangASTType type)
|
||||
{
|
||||
@ -511,6 +521,9 @@ public:
|
||||
ConstString
|
||||
GetName () const;
|
||||
|
||||
ConstString
|
||||
GetDisplayTypeName () const;
|
||||
|
||||
TypeImpl
|
||||
GetPointerType () const;
|
||||
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
|
||||
const char *
|
||||
GetName ();
|
||||
|
||||
|
||||
lldb::SBType
|
||||
GetType ();
|
||||
|
||||
@ -216,6 +216,9 @@ public:
|
||||
const char*
|
||||
GetName();
|
||||
|
||||
const char *
|
||||
GetDisplayTypeName ();
|
||||
|
||||
lldb::TypeClass
|
||||
GetTypeClass ();
|
||||
|
||||
|
@ -81,6 +81,9 @@ public:
|
||||
|
||||
const char *
|
||||
GetTypeName ();
|
||||
|
||||
const char *
|
||||
GetDisplayTypeName ();
|
||||
|
||||
size_t
|
||||
GetByteSize ();
|
||||
|
@ -414,6 +414,14 @@ SBType::GetName()
|
||||
return m_opaque_sp->GetName().GetCString();
|
||||
}
|
||||
|
||||
const char *
|
||||
SBType::GetDisplayTypeName ()
|
||||
{
|
||||
if (!IsValid())
|
||||
return "";
|
||||
return m_opaque_sp->GetDisplayTypeName().GetCString();
|
||||
}
|
||||
|
||||
lldb::TypeClass
|
||||
SBType::GetTypeClass ()
|
||||
{
|
||||
|
@ -378,6 +378,31 @@ SBValue::GetTypeName ()
|
||||
return name;
|
||||
}
|
||||
|
||||
const char *
|
||||
SBValue::GetDisplayTypeName ()
|
||||
{
|
||||
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
||||
const char *name = NULL;
|
||||
ValueLocker locker;
|
||||
lldb::ValueObjectSP value_sp(GetSP(locker));
|
||||
if (value_sp)
|
||||
{
|
||||
name = value_sp->GetDisplayTypeName().GetCString();
|
||||
}
|
||||
|
||||
if (log)
|
||||
{
|
||||
if (name)
|
||||
log->Printf ("SBValue(%p)::GetTypeName () => \"%s\"",
|
||||
static_cast<void*>(value_sp.get()), name);
|
||||
else
|
||||
log->Printf ("SBValue(%p)::GetTypeName () => NULL",
|
||||
static_cast<void*>(value_sp.get()));
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
size_t
|
||||
SBValue::GetByteSize ()
|
||||
{
|
||||
|
@ -1952,6 +1952,12 @@ ValueObject::GetTypeName()
|
||||
return GetClangType().GetConstTypeName();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObject::GetDisplayTypeName()
|
||||
{
|
||||
return GetTypeName();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObject::GetQualifiedTypeName()
|
||||
{
|
||||
|
@ -66,25 +66,29 @@ ValueObjectChild::CalculateNumChildren()
|
||||
return GetClangType().GetNumChildren (true);
|
||||
}
|
||||
|
||||
static void
|
||||
AdjustForBitfieldness(ConstString& name,
|
||||
uint8_t bitfield_bit_size)
|
||||
{
|
||||
if (name && bitfield_bit_size)
|
||||
{
|
||||
const char *clang_type_name = name.AsCString();
|
||||
if (clang_type_name)
|
||||
{
|
||||
std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0);
|
||||
::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, bitfield_bit_size);
|
||||
name.SetCString(&bitfield_type_name.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectChild::GetTypeName()
|
||||
{
|
||||
if (m_type_name.IsEmpty())
|
||||
{
|
||||
m_type_name = GetClangType().GetConstTypeName ();
|
||||
if (m_type_name)
|
||||
{
|
||||
if (m_bitfield_bit_size > 0)
|
||||
{
|
||||
const char *clang_type_name = m_type_name.AsCString();
|
||||
if (clang_type_name)
|
||||
{
|
||||
std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0);
|
||||
::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size);
|
||||
m_type_name.SetCString(&bitfield_type_name.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
AdjustForBitfieldness(m_type_name, m_bitfield_bit_size);
|
||||
}
|
||||
return m_type_name;
|
||||
}
|
||||
@ -93,22 +97,18 @@ ConstString
|
||||
ValueObjectChild::GetQualifiedTypeName()
|
||||
{
|
||||
ConstString qualified_name = GetClangType().GetConstTypeName();
|
||||
if (qualified_name)
|
||||
{
|
||||
if (m_bitfield_bit_size > 0)
|
||||
{
|
||||
const char *clang_type_name = qualified_name.AsCString();
|
||||
if (clang_type_name)
|
||||
{
|
||||
std::vector<char> bitfield_type_name (strlen(clang_type_name) + 32, 0);
|
||||
::snprintf (&bitfield_type_name.front(), bitfield_type_name.size(), "%s:%u", clang_type_name, m_bitfield_bit_size);
|
||||
qualified_name.SetCString(&bitfield_type_name.front());
|
||||
}
|
||||
}
|
||||
}
|
||||
AdjustForBitfieldness(qualified_name, m_bitfield_bit_size);
|
||||
return qualified_name;
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectChild::GetDisplayTypeName()
|
||||
{
|
||||
ConstString display_name = GetClangType().GetDisplayTypeName();
|
||||
AdjustForBitfieldness(display_name, m_bitfield_bit_size);
|
||||
return display_name;
|
||||
}
|
||||
|
||||
bool
|
||||
ValueObjectChild::UpdateValue ()
|
||||
{
|
||||
|
@ -276,6 +276,12 @@ ValueObjectConstResult::GetTypeName()
|
||||
return m_type_name;
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectConstResult::GetDisplayTypeName()
|
||||
{
|
||||
return GetClangType().GetDisplayTypeName();
|
||||
}
|
||||
|
||||
bool
|
||||
ValueObjectConstResult::UpdateValue ()
|
||||
{
|
||||
|
@ -71,8 +71,6 @@ ValueObjectDynamicValue::GetTypeName()
|
||||
{
|
||||
if (m_dynamic_type_info.HasName())
|
||||
return m_dynamic_type_info.GetName();
|
||||
if (m_dynamic_type_info.HasType())
|
||||
return GetClangType().GetConstTypeName();
|
||||
}
|
||||
return m_parent->GetTypeName();
|
||||
}
|
||||
@ -96,10 +94,22 @@ ValueObjectDynamicValue::GetQualifiedTypeName()
|
||||
{
|
||||
if (m_dynamic_type_info.HasName())
|
||||
return m_dynamic_type_info.GetName();
|
||||
if (m_dynamic_type_info.HasType())
|
||||
return GetClangType().GetConstQualifiedTypeName ();
|
||||
}
|
||||
return m_parent->GetTypeName();
|
||||
return m_parent->GetQualifiedTypeName();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectDynamicValue::GetDisplayTypeName()
|
||||
{
|
||||
const bool success = UpdateValueIfNeeded(false);
|
||||
if (success)
|
||||
{
|
||||
if (m_dynamic_type_info.HasType())
|
||||
return GetClangType().GetDisplayTypeName();
|
||||
if (m_dynamic_type_info.HasName())
|
||||
return m_dynamic_type_info.GetName();
|
||||
}
|
||||
return m_parent->GetDisplayTypeName();
|
||||
}
|
||||
|
||||
size_t
|
||||
|
@ -147,6 +147,14 @@ ValueObjectMemory::GetTypeName()
|
||||
return m_clang_type.GetConstTypeName();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectMemory::GetDisplayTypeName()
|
||||
{
|
||||
if (m_type_sp)
|
||||
return m_type_sp->GetClangForwardType().GetDisplayTypeName();
|
||||
return m_clang_type.GetDisplayTypeName();
|
||||
}
|
||||
|
||||
size_t
|
||||
ValueObjectMemory::CalculateNumChildren()
|
||||
{
|
||||
|
@ -54,6 +54,12 @@ ValueObjectRegisterContext::GetTypeName()
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectRegisterContext::GetDisplayTypeName()
|
||||
{
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectRegisterContext::GetQualifiedTypeName()
|
||||
{
|
||||
|
@ -101,6 +101,12 @@ ValueObjectSynthetic::GetQualifiedTypeName()
|
||||
return m_parent->GetQualifiedTypeName();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectSynthetic::GetDisplayTypeName()
|
||||
{
|
||||
return m_parent->GetDisplayTypeName();
|
||||
}
|
||||
|
||||
size_t
|
||||
ValueObjectSynthetic::CalculateNumChildren()
|
||||
{
|
||||
|
@ -72,6 +72,15 @@ ValueObjectVariable::GetTypeName()
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectVariable::GetDisplayTypeName()
|
||||
{
|
||||
Type * var_type = m_variable_sp->GetType();
|
||||
if (var_type)
|
||||
return var_type->GetClangForwardType().GetDisplayTypeName();
|
||||
return ConstString();
|
||||
}
|
||||
|
||||
ConstString
|
||||
ValueObjectVariable::GetQualifiedTypeName()
|
||||
{
|
||||
|
@ -185,7 +185,11 @@ FormatManager::GetPossibleMatches (ValueObject& valobj,
|
||||
reason |= lldb_private::eFormatterChoiceCriterionStrippedBitField;
|
||||
}
|
||||
entries.push_back({type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef});
|
||||
|
||||
|
||||
ConstString display_type_name(clang_type.GetDisplayTypeName());
|
||||
if (display_type_name != type_name)
|
||||
entries.push_back({display_type_name,reason,did_strip_ptr,did_strip_ref,did_strip_typedef});
|
||||
|
||||
for (bool is_rvalue_ref = true, j = true; j && clang_type.IsReferenceType(nullptr, &is_rvalue_ref); j = false)
|
||||
{
|
||||
ClangASTType non_ref_type = clang_type.GetNonReferenceType();
|
||||
|
@ -222,7 +222,11 @@ ValueObjectPrinter::PrintTypeIfNeeded ()
|
||||
{
|
||||
// Some ValueObjects don't have types (like registers sets). Only print
|
||||
// the type if there is one to print
|
||||
ConstString qualified_type_name(m_valobj->GetQualifiedTypeName());
|
||||
ConstString qualified_type_name;
|
||||
if (options.m_be_raw)
|
||||
qualified_type_name = m_valobj->GetQualifiedTypeName();
|
||||
else
|
||||
qualified_type_name = m_valobj->GetDisplayTypeName();
|
||||
if (qualified_type_name)
|
||||
m_stream->Printf("(%s) ", qualified_type_name.GetCString());
|
||||
else
|
||||
|
@ -1243,6 +1243,11 @@ ClangASTType::GetTypeName () const
|
||||
return ConstString(type_name);
|
||||
}
|
||||
|
||||
ConstString
|
||||
ClangASTType::GetDisplayTypeName () const
|
||||
{
|
||||
return GetTypeName();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
ClangASTType::GetTypeInfo (ClangASTType *pointee_or_element_clang_type) const
|
||||
|
@ -1053,6 +1053,14 @@ TypeImpl::GetName () const
|
||||
return m_static_type.GetName ();
|
||||
}
|
||||
|
||||
ConstString
|
||||
TypeImpl::GetDisplayTypeName () const
|
||||
{
|
||||
if (m_dynamic_type)
|
||||
return m_dynamic_type.GetDisplayTypeName();
|
||||
return m_static_type.GetDisplayTypeName();
|
||||
}
|
||||
|
||||
TypeImpl
|
||||
TypeImpl::GetPointerType () const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user