LLDB mainline
TypeMap.cpp
Go to the documentation of this file.
1//===-- TypeMap.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 <vector>
10
11#include "llvm/Support/FormattedStream.h"
12#include "llvm/Support/raw_ostream.h"
13
16#include "lldb/Symbol/Type.h"
17#include "lldb/Symbol/TypeMap.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
23
24// Destructor
25TypeMap::~TypeMap() = default;
26
27void TypeMap::Insert(const TypeSP &type_sp) {
28 // Just push each type on the back for now. We will worry about uniquing
29 // later
30 if (type_sp)
31 m_types.insert(std::make_pair(type_sp->GetID(), type_sp));
32}
33
34bool TypeMap::InsertUnique(const TypeSP &type_sp) {
35 if (type_sp) {
36 user_id_t type_uid = type_sp->GetID();
37 iterator pos, end = m_types.end();
38
39 for (pos = m_types.find(type_uid);
40 pos != end && pos->second->GetID() == type_uid; ++pos) {
41 if (pos->second.get() == type_sp.get())
42 return false;
43 }
44 Insert(type_sp);
45 }
46 return true;
47}
48
49void TypeMap::Clear() { m_types.clear(); }
50
51uint32_t TypeMap::GetSize() const { return m_types.size(); }
52
53bool TypeMap::Empty() const { return m_types.empty(); }
54
55// GetTypeAtIndex isn't used a lot for large type lists, currently only for
56// type lists that are returned for "image dump -t TYPENAME" commands and other
57// simple symbol queries that grab the first result...
58
60 iterator pos, end;
61 uint32_t i = idx;
62 for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
63 if (i == 0)
64 return pos->second;
65 --i;
66 }
67 return TypeSP();
68}
69
71 if (m_types.empty())
72 return TypeSP();
73 return m_types.begin()->second;
74}
75
77 std::function<bool(const lldb::TypeSP &type_sp)> const &callback) const {
78 for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
79 if (!callback(pos->second))
80 break;
81 }
82}
83
85 std::function<bool(lldb::TypeSP &type_sp)> const &callback) {
86 for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
87 if (!callback(pos->second))
88 break;
89 }
90}
91
92bool TypeMap::Remove(const lldb::TypeSP &type_sp) {
93 if (type_sp) {
94 lldb::user_id_t uid = type_sp->GetID();
95 for (iterator pos = m_types.find(uid), end = m_types.end();
96 pos != end && pos->first == uid; ++pos) {
97 if (pos->second == type_sp) {
98 m_types.erase(pos);
99 return true;
100 }
101 }
102 }
103 return false;
104}
105
106void TypeMap::Dump(Stream *s, bool show_context,
107 lldb::DescriptionLevel level) const {
108 for (const auto &pair : m_types)
109 pair.second->Dump(s, show_context, level);
110}
A stream class that can stream formatted output to a file.
Definition Stream.h:28
lldb::TypeSP FirstType() const
Definition TypeMap.cpp:70
uint32_t GetSize() const
Definition TypeMap.cpp:51
void Insert(const lldb::TypeSP &type)
Definition TypeMap.cpp:27
bool Empty() const
Definition TypeMap.cpp:53
bool Remove(const lldb::TypeSP &type_sp)
Definition TypeMap.cpp:92
bool InsertUnique(const lldb::TypeSP &type)
Definition TypeMap.cpp:34
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition TypeMap.cpp:76
void Dump(Stream *s, bool show_context, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) const
Definition TypeMap.cpp:106
collection::iterator iterator
Definition TypeMap.h:58
collection m_types
Definition TypeMap.h:61
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition TypeMap.cpp:59
A class that represents a running process on the host machine.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
std::shared_ptr< lldb_private::Type > TypeSP
uint64_t user_id_t
Definition lldb-types.h:82