#include "DWARFDeclContext.h"
#include "llvm/Support/raw_ostream.h"
using namespace lldb_private::dwarf;
using namespace lldb_private::plugin::dwarf;
const char *DWARFDeclContext::Entry::GetName() const {
if (name != nullptr)
return name;
if (tag == DW_TAG_namespace)
return "(anonymous namespace)";
if (tag == DW_TAG_class_type)
return "(anonymous class)";
if (tag == DW_TAG_structure_type)
return "(anonymous struct)";
if (tag == DW_TAG_union_type)
return "(anonymous union)";
return "(anonymous)";
}
const char *DWARFDeclContext::GetQualifiedName() const {
if (m_qualified_name.empty()) {
if (!m_entries.empty()) {
if (m_entries.size() == 1) {
if (m_entries[0].name) {
m_qualified_name.append("::");
m_qualified_name.append(m_entries[0].name);
}
} else {
llvm::raw_string_ostream string_stream(m_qualified_name);
llvm::interleave(
llvm::reverse(m_entries), string_stream,
[&](auto entry) { string_stream << entry.GetName(); }, "::");
}
}
}
if (m_qualified_name.empty())
return nullptr;
return m_qualified_name.c_str();
}
bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {
if (m_entries.size() != rhs.m_entries.size())
return false;
collection::const_iterator pos;
collection::const_iterator begin = m_entries.begin();
collection::const_iterator end = m_entries.end();
collection::const_iterator rhs_pos;
collection::const_iterator rhs_begin = rhs.m_entries.begin();
for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {
if (pos->tag != rhs_pos->tag) {
if (pos->tag == DW_TAG_structure_type &&
rhs_pos->tag == DW_TAG_class_type)
continue;
if (pos->tag == DW_TAG_class_type &&
rhs_pos->tag == DW_TAG_structure_type)
continue;
return false;
}
}
for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {
if (!pos->NameMatches(*rhs_pos))
return false;
}
return true;
}