1 //===-- UniqueDWARFASTType.h ------------------------------------*- C++ -*-===// 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 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_UNIQUEDWARFASTTYPE_H 10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_UNIQUEDWARFASTTYPE_H 11 12 #include <vector> 13 14 #include "llvm/ADT/DenseMap.h" 15 16 #include "DWARFDIE.h" 17 #include "lldb/Core/Declaration.h" 18 19 class UniqueDWARFASTType { 20 public: 21 // Constructors and Destructors 22 UniqueDWARFASTType() : m_type_sp(), m_die(), m_declaration() {} 23 24 UniqueDWARFASTType(lldb::TypeSP &type_sp, const DWARFDIE &die, 25 const lldb_private::Declaration &decl, int32_t byte_size) 26 : m_type_sp(type_sp), m_die(die), m_declaration(decl), 27 m_byte_size(byte_size) {} 28 29 UniqueDWARFASTType(const UniqueDWARFASTType &rhs) 30 : m_type_sp(rhs.m_type_sp), m_die(rhs.m_die), 31 m_declaration(rhs.m_declaration), m_byte_size(rhs.m_byte_size) {} 32 33 ~UniqueDWARFASTType() = default; 34 35 UniqueDWARFASTType &operator=(const UniqueDWARFASTType &rhs) { 36 if (this != &rhs) { 37 m_type_sp = rhs.m_type_sp; 38 m_die = rhs.m_die; 39 m_declaration = rhs.m_declaration; 40 m_byte_size = rhs.m_byte_size; 41 } 42 return *this; 43 } 44 45 lldb::TypeSP m_type_sp; 46 DWARFDIE m_die; 47 lldb_private::Declaration m_declaration; 48 int32_t m_byte_size = -1; 49 }; 50 51 class UniqueDWARFASTTypeList { 52 public: 53 UniqueDWARFASTTypeList() : m_collection() {} 54 55 ~UniqueDWARFASTTypeList() = default; 56 57 uint32_t GetSize() { return (uint32_t)m_collection.size(); } 58 59 void Append(const UniqueDWARFASTType &entry) { 60 m_collection.push_back(entry); 61 } 62 63 bool Find(const DWARFDIE &die, const lldb_private::Declaration &decl, 64 const int32_t byte_size, UniqueDWARFASTType &entry) const; 65 66 protected: 67 typedef std::vector<UniqueDWARFASTType> collection; 68 collection m_collection; 69 }; 70 71 class UniqueDWARFASTTypeMap { 72 public: 73 UniqueDWARFASTTypeMap() : m_collection() {} 74 75 ~UniqueDWARFASTTypeMap() = default; 76 77 void Insert(lldb_private::ConstString name, 78 const UniqueDWARFASTType &entry) { 79 m_collection[name.GetCString()].Append(entry); 80 } 81 82 bool Find(lldb_private::ConstString name, const DWARFDIE &die, 83 const lldb_private::Declaration &decl, const int32_t byte_size, 84 UniqueDWARFASTType &entry) const { 85 const char *unique_name_cstr = name.GetCString(); 86 collection::const_iterator pos = m_collection.find(unique_name_cstr); 87 if (pos != m_collection.end()) { 88 return pos->second.Find(die, decl, byte_size, entry); 89 } 90 return false; 91 } 92 93 protected: 94 // A unique name string should be used 95 typedef llvm::DenseMap<const char *, UniqueDWARFASTTypeList> collection; 96 collection m_collection; 97 }; 98 99 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_UNIQUEDWARFASTTYPE_H 100