LLDB mainline
TypeList.cpp
Go to the documentation of this file.
1//===-- TypeList.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"
18
19using namespace lldb;
20using namespace lldb_private;
21
22TypeList::TypeList() : m_types() {}
23
24// Destructor
25TypeList::~TypeList() = default;
26
27void TypeList::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.push_back(type_sp);
32}
33
34// Find a base type by its unique ID.
35// TypeSP
36// TypeList::FindType(lldb::user_id_t uid)
37//{
38// iterator pos = m_types.find(uid);
39// if (pos != m_types.end())
40// return pos->second;
41// return TypeSP();
42//}
43
44// Find a type by name.
45// TypeList
46// TypeList::FindTypes (ConstString name)
47//{
48// // Do we ever need to make a lookup by name map? Here we are doing
49// // a linear search which isn't going to be fast.
50// TypeList types(m_ast.getTargetInfo()->getTriple().getTriple().c_str());
51// iterator pos, end;
52// for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
53// if (pos->second->GetName() == name)
54// types.Insert (pos->second);
55// return types;
56//}
57
58void TypeList::Clear() { m_types.clear(); }
59
60uint32_t TypeList::GetSize() const { return m_types.size(); }
61
62// GetTypeAtIndex isn't used a lot for large type lists, currently only for
63// type lists that are returned for "image dump -t TYPENAME" commands and other
64// simple symbol queries that grab the first result...
65
67 iterator pos, end;
68 uint32_t i = idx;
69 assert(i < GetSize() && "Accessing past the end of a TypeList");
70 for (pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
71 if (i == 0)
72 return *pos;
73 --i;
74 }
75 return TypeSP();
76}
77
79 std::function<bool(const lldb::TypeSP &type_sp)> const &callback) const {
80 for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
81 if (!callback(*pos))
82 break;
83 }
84}
85
87 std::function<bool(lldb::TypeSP &type_sp)> const &callback) {
88 for (auto pos = m_types.begin(), end = m_types.end(); pos != end; ++pos) {
89 if (!callback(*pos))
90 break;
91 }
92}
93
94void TypeList::Dump(Stream *s, bool show_context) {
95 for (iterator pos = m_types.begin(), end = m_types.end(); pos != end; ++pos)
96 if (Type *t = pos->get())
97 t->Dump(s, show_context);
98}
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
uint32_t GetSize() const
Definition: TypeList.cpp:60
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition: TypeList.cpp:78
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition: TypeList.cpp:66
collection m_types
Definition: TypeList.h:56
collection::iterator iterator
Definition: TypeList.h:53
void Dump(Stream *s, bool show_context)
Definition: TypeList.cpp:94
void Insert(const lldb::TypeSP &type)
Definition: TypeList.cpp:27
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:449