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