Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
Line
Count
Source (jump to first uncovered line)
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
11
1.50k
const char *DWARFDeclContext::GetQualifiedName() const {
12
1.50k
  if (m_qualified_name.empty()) {
13
    // The declaration context array for a class named "foo" in namespace
14
    // "a::b::c" will be something like:
15
    //  [0] DW_TAG_class_type "foo"
16
    //  [1] DW_TAG_namespace "c"
17
    //  [2] DW_TAG_namespace "b"
18
    //  [3] DW_TAG_namespace "a"
19
1.50k
    if (!m_entries.empty()) {
20
1.50k
      if (m_entries.size() == 1) {
21
981
        if (m_entries[0].name) {
22
981
          m_qualified_name.append("::");
23
981
          m_qualified_name.append(m_entries[0].name);
24
981
        }
25
981
      } else {
26
519
        collection::const_reverse_iterator pos;
27
519
        collection::const_reverse_iterator begin = m_entries.rbegin();
28
519
        collection::const_reverse_iterator end = m_entries.rend();
29
2.02k
        for (pos = begin; pos != end; 
++pos1.51k
) {
30
1.51k
          if (pos != begin)
31
991
            m_qualified_name.append("::");
32
1.51k
          if (pos->name == nullptr) {
33
6
            if (pos->tag == DW_TAG_namespace)
34
6
              m_qualified_name.append("(anonymous namespace)");
35
0
            else if (pos->tag == DW_TAG_class_type)
36
0
              m_qualified_name.append("(anonymous class)");
37
0
            else if (pos->tag == DW_TAG_structure_type)
38
0
              m_qualified_name.append("(anonymous struct)");
39
0
            else if (pos->tag == DW_TAG_union_type)
40
0
              m_qualified_name.append("(anonymous union)");
41
0
            else
42
0
              m_qualified_name.append("(anonymous)");
43
6
          } else
44
1.50k
            m_qualified_name.append(pos->name);
45
1.51k
        }
46
519
      }
47
1.50k
    }
48
1.50k
  }
49
1.50k
  if (m_qualified_name.empty())
50
0
    return nullptr;
51
1.50k
  return m_qualified_name.c_str();
52
1.50k
}
53
54
35
bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {
55
35
  if (m_entries.size() != rhs.m_entries.size())
56
14
    return false;
57
58
21
  collection::const_iterator pos;
59
21
  collection::const_iterator begin = m_entries.begin();
60
21
  collection::const_iterator end = m_entries.end();
61
62
21
  collection::const_iterator rhs_pos;
63
21
  collection::const_iterator rhs_begin = rhs.m_entries.begin();
64
  // The two entry arrays have the same size
65
66
  // First compare the tags before we do expensive name compares
67
43
  for (pos = begin, rhs_pos = rhs_begin; pos != end; 
++pos, ++rhs_pos22
) {
68
22
    if (pos->tag != rhs_pos->tag) {
69
      // Check for DW_TAG_structure_type and DW_TAG_class_type as they are
70
      // often used interchangeably in GCC
71
1
      if (pos->tag == DW_TAG_structure_type &&
72
1
          rhs_pos->tag == DW_TAG_class_type)
73
1
        continue;
74
0
      if (pos->tag == DW_TAG_class_type &&
75
0
          rhs_pos->tag == DW_TAG_structure_type)
76
0
        continue;
77
0
      return false;
78
0
    }
79
22
  }
80
  // The tags all match, now compare the names
81
43
  
for (pos = begin, rhs_pos = rhs_begin; 21
pos != end;
++pos, ++rhs_pos22
) {
82
22
    if (!pos->NameMatches(*rhs_pos))
83
0
      return false;
84
22
  }
85
  // All tags and names match
86
21
  return true;
87
21
}