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 14 #include "lldb/Symbol/SymbolFile.h" 15 #include "lldb/Symbol/SymbolVendor.h" 16 #include "lldb/Symbol/Type.h" 17 #include "lldb/Symbol/TypeList.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 TypeList::TypeList() : m_types() {} 23 24 // Destructor 25 TypeList::~TypeList() = default; 26 27 void 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 58 void TypeList::Clear() { m_types.clear(); } 59 60 uint32_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 66 TypeSP TypeList::GetTypeAtIndex(uint32_t idx) { 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 78 void TypeList::ForEach( 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 86 void TypeList::ForEach( 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 94 void 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 } 99