Path: blob/main/contrib/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
39645 views
//===-- DWARFDeclContext.cpp ----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "DWARFDeclContext.h"9#include "llvm/Support/raw_ostream.h"1011using namespace lldb_private::dwarf;12using namespace lldb_private::plugin::dwarf;1314const char *DWARFDeclContext::Entry::GetName() const {15if (name != nullptr)16return name;17if (tag == DW_TAG_namespace)18return "(anonymous namespace)";19if (tag == DW_TAG_class_type)20return "(anonymous class)";21if (tag == DW_TAG_structure_type)22return "(anonymous struct)";23if (tag == DW_TAG_union_type)24return "(anonymous union)";25return "(anonymous)";26}2728const char *DWARFDeclContext::GetQualifiedName() const {29if (m_qualified_name.empty()) {30// The declaration context array for a class named "foo" in namespace31// "a::b::c" will be something like:32// [0] DW_TAG_class_type "foo"33// [1] DW_TAG_namespace "c"34// [2] DW_TAG_namespace "b"35// [3] DW_TAG_namespace "a"36if (!m_entries.empty()) {37if (m_entries.size() == 1) {38if (m_entries[0].name) {39m_qualified_name.append("::");40m_qualified_name.append(m_entries[0].name);41}42} else {43llvm::raw_string_ostream string_stream(m_qualified_name);44llvm::interleave(45llvm::reverse(m_entries), string_stream,46[&](auto entry) { string_stream << entry.GetName(); }, "::");47}48}49}50if (m_qualified_name.empty())51return nullptr;52return m_qualified_name.c_str();53}5455bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {56if (m_entries.size() != rhs.m_entries.size())57return false;5859collection::const_iterator pos;60collection::const_iterator begin = m_entries.begin();61collection::const_iterator end = m_entries.end();6263collection::const_iterator rhs_pos;64collection::const_iterator rhs_begin = rhs.m_entries.begin();65// The two entry arrays have the same size6667// First compare the tags before we do expensive name compares68for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {69if (pos->tag != rhs_pos->tag) {70// Check for DW_TAG_structure_type and DW_TAG_class_type as they are71// often used interchangeably in GCC72if (pos->tag == DW_TAG_structure_type &&73rhs_pos->tag == DW_TAG_class_type)74continue;75if (pos->tag == DW_TAG_class_type &&76rhs_pos->tag == DW_TAG_structure_type)77continue;78return false;79}80}81// The tags all match, now compare the names82for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {83if (!pos->NameMatches(*rhs_pos))84return false;85}86// All tags and names match87return true;88}899091