LLDB mainline
DWARFDeclContext.cpp
Go to the documentation of this file.
1//===-- DWARFDeclContext.cpp ----------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "DWARFDeclContext.h"
10
11using namespace lldb_private::dwarf;
12using namespace lldb_private::plugin::dwarf;
13
15 if (m_qualified_name.empty()) {
16 // The declaration context array for a class named "foo" in namespace
17 // "a::b::c" will be something like:
18 // [0] DW_TAG_class_type "foo"
19 // [1] DW_TAG_namespace "c"
20 // [2] DW_TAG_namespace "b"
21 // [3] DW_TAG_namespace "a"
22 if (!m_entries.empty()) {
23 if (m_entries.size() == 1) {
24 if (m_entries[0].name) {
25 m_qualified_name.append("::");
26 m_qualified_name.append(m_entries[0].name);
27 }
28 } else {
29 collection::const_reverse_iterator pos;
30 collection::const_reverse_iterator begin = m_entries.rbegin();
31 collection::const_reverse_iterator end = m_entries.rend();
32 for (pos = begin; pos != end; ++pos) {
33 if (pos != begin)
34 m_qualified_name.append("::");
35 if (pos->name == nullptr) {
36 if (pos->tag == DW_TAG_namespace)
37 m_qualified_name.append("(anonymous namespace)");
38 else if (pos->tag == DW_TAG_class_type)
39 m_qualified_name.append("(anonymous class)");
40 else if (pos->tag == DW_TAG_structure_type)
41 m_qualified_name.append("(anonymous struct)");
42 else if (pos->tag == DW_TAG_union_type)
43 m_qualified_name.append("(anonymous union)");
44 else
45 m_qualified_name.append("(anonymous)");
46 } else
47 m_qualified_name.append(pos->name);
48 }
49 }
50 }
51 }
52 if (m_qualified_name.empty())
53 return nullptr;
54 return m_qualified_name.c_str();
55}
56
58 if (m_entries.size() != rhs.m_entries.size())
59 return false;
60
61 collection::const_iterator pos;
62 collection::const_iterator begin = m_entries.begin();
63 collection::const_iterator end = m_entries.end();
64
65 collection::const_iterator rhs_pos;
66 collection::const_iterator rhs_begin = rhs.m_entries.begin();
67 // The two entry arrays have the same size
68
69 // First compare the tags before we do expensive name compares
70 for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {
71 if (pos->tag != rhs_pos->tag) {
72 // Check for DW_TAG_structure_type and DW_TAG_class_type as they are
73 // often used interchangeably in GCC
74 if (pos->tag == DW_TAG_structure_type &&
75 rhs_pos->tag == DW_TAG_class_type)
76 continue;
77 if (pos->tag == DW_TAG_class_type &&
78 rhs_pos->tag == DW_TAG_structure_type)
79 continue;
80 return false;
81 }
82 }
83 // The tags all match, now compare the names
84 for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos) {
85 if (!pos->NameMatches(*rhs_pos))
86 return false;
87 }
88 // All tags and names match
89 return true;
90}
bool operator==(const DWARFDeclContext &rhs) const