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 #include "lldb/Symbol/Type.h" 19 20 namespace lldb_private::plugin { 21 namespace dwarf { 22 class UniqueDWARFASTType { 23 public: 24 // Constructors and Destructors UniqueDWARFASTType()25 UniqueDWARFASTType() : m_type_sp(), m_die(), m_declaration() {} 26 UniqueDWARFASTType(const UniqueDWARFASTType & rhs)27 UniqueDWARFASTType(const UniqueDWARFASTType &rhs) 28 : m_type_sp(rhs.m_type_sp), m_die(rhs.m_die), 29 m_declaration(rhs.m_declaration), m_byte_size(rhs.m_byte_size), 30 m_is_forward_declaration(rhs.m_is_forward_declaration) {} 31 32 ~UniqueDWARFASTType() = default; 33 34 // This UniqueDWARFASTType might be created from declaration, update its info 35 // to definition DIE. UpdateToDefDIE(const DWARFDIE & def_die,Declaration & declaration,int32_t byte_size)36 void UpdateToDefDIE(const DWARFDIE &def_die, Declaration &declaration, 37 int32_t byte_size) { 38 // Need to update Type ID to refer to the definition DIE, because 39 // it's used in DWARFASTParserClang::ParseCXXMethod to determine if we need 40 // to copy cxx method types from a declaration DIE to this definition DIE. 41 m_type_sp->SetID(def_die.GetID()); 42 if (declaration.IsValid()) 43 m_declaration = declaration; 44 if (byte_size) 45 m_byte_size = byte_size; 46 m_is_forward_declaration = false; 47 } 48 49 lldb::TypeSP m_type_sp; 50 DWARFDIE m_die; 51 Declaration m_declaration; 52 int32_t m_byte_size = -1; 53 // True if the m_die is a forward declaration DIE. 54 bool m_is_forward_declaration = true; 55 }; 56 57 class UniqueDWARFASTTypeList { 58 public: UniqueDWARFASTTypeList()59 UniqueDWARFASTTypeList() : m_collection() {} 60 61 ~UniqueDWARFASTTypeList() = default; 62 GetSize()63 uint32_t GetSize() { return (uint32_t)m_collection.size(); } 64 Append(const UniqueDWARFASTType & entry)65 void Append(const UniqueDWARFASTType &entry) { 66 m_collection.push_back(entry); 67 } 68 69 UniqueDWARFASTType *Find(const DWARFDIE &die, const Declaration &decl, 70 const int32_t byte_size, 71 bool is_forward_declaration); 72 73 protected: 74 typedef std::vector<UniqueDWARFASTType> collection; 75 collection m_collection; 76 }; 77 78 class UniqueDWARFASTTypeMap { 79 public: UniqueDWARFASTTypeMap()80 UniqueDWARFASTTypeMap() : m_collection() {} 81 82 ~UniqueDWARFASTTypeMap() = default; 83 Insert(ConstString name,const UniqueDWARFASTType & entry)84 void Insert(ConstString name, const UniqueDWARFASTType &entry) { 85 m_collection[name.GetCString()].Append(entry); 86 } 87 Find(ConstString name,const DWARFDIE & die,const Declaration & decl,const int32_t byte_size,bool is_forward_declaration)88 UniqueDWARFASTType *Find(ConstString name, const DWARFDIE &die, 89 const Declaration &decl, const int32_t byte_size, 90 bool is_forward_declaration) { 91 const char *unique_name_cstr = name.GetCString(); 92 collection::iterator pos = m_collection.find(unique_name_cstr); 93 if (pos != m_collection.end()) { 94 return pos->second.Find(die, decl, byte_size, is_forward_declaration); 95 } 96 return nullptr; 97 } 98 99 protected: 100 // A unique name string should be used 101 typedef llvm::DenseMap<const char *, UniqueDWARFASTTypeList> collection; 102 collection m_collection; 103 }; 104 } // namespace dwarf 105 } // namespace lldb_private::plugin 106 107 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_UNIQUEDWARFASTTYPE_H 108