7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " DWARFDeclContext.h"
10
+ #include " llvm/Support/raw_ostream.h"
10
11
11
12
using namespace lldb_private ::dwarf;
12
13
using namespace lldb_private ::plugin::dwarf;
13
14
15
+ // / Returns the name of `entry` if it has one, or the appropriate "anonymous
16
+ // / {namespace, class, struct, union}".
17
+ static const char *GetName (DWARFDeclContext::Entry entry) {
18
+ if (entry.name != nullptr )
19
+ return entry.name ;
20
+ if (entry.tag == DW_TAG_namespace)
21
+ return " (anonymous namespace)" ;
22
+ if (entry.tag == DW_TAG_class_type)
23
+ return " (anonymous class)" ;
24
+ if (entry.tag == DW_TAG_structure_type)
25
+ return " (anonymous struct)" ;
26
+ if (entry.tag == DW_TAG_union_type)
27
+ return " (anonymous union)" ;
28
+ return " (anonymous)" ;
29
+ }
30
+
14
31
const char *DWARFDeclContext::GetQualifiedName () const {
15
32
if (m_qualified_name.empty ()) {
16
33
// The declaration context array for a class named "foo" in namespace
@@ -26,26 +43,10 @@ const char *DWARFDeclContext::GetQualifiedName() const {
26
43
m_qualified_name.append (m_entries[0 ].name );
27
44
}
28
45
} 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
- }
46
+ llvm::raw_string_ostream string_stream (m_qualified_name);
47
+ llvm::interleave (
48
+ llvm::reverse (m_entries), string_stream,
49
+ [&](auto entry) { string_stream << GetName (entry); }, " ::" );
49
50
}
50
51
}
51
52
}
0 commit comments