1 //===-- UniqueDWARFASTType.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_UniqueDWARFASTType_h_
11 #define lldb_UniqueDWARFASTType_h_
12 
13 #include <vector>
14 
15 #include "llvm/ADT/DenseMap.h"
16 
17 #include "DWARFDIE.h"
18 #include "lldb/Symbol/Declaration.h"
19 
20 class UniqueDWARFASTType {
21 public:
22   //------------------------------------------------------------------
23   // Constructors and Destructors
24   //------------------------------------------------------------------
UniqueDWARFASTType()25   UniqueDWARFASTType()
26       : m_type_sp(), m_die(), m_declaration(),
27         m_byte_size(
28             -1) // Set to negative value to make sure we have a valid value
29   {}
30 
UniqueDWARFASTType(lldb::TypeSP & type_sp,const DWARFDIE & die,const lldb_private::Declaration & decl,int32_t byte_size)31   UniqueDWARFASTType(lldb::TypeSP &type_sp, const DWARFDIE &die,
32                      const lldb_private::Declaration &decl, int32_t byte_size)
33       : m_type_sp(type_sp), m_die(die), m_declaration(decl),
34         m_byte_size(byte_size) {}
35 
UniqueDWARFASTType(const UniqueDWARFASTType & rhs)36   UniqueDWARFASTType(const UniqueDWARFASTType &rhs)
37       : m_type_sp(rhs.m_type_sp), m_die(rhs.m_die),
38         m_declaration(rhs.m_declaration), m_byte_size(rhs.m_byte_size) {}
39 
~UniqueDWARFASTType()40   ~UniqueDWARFASTType() {}
41 
42   UniqueDWARFASTType &operator=(const UniqueDWARFASTType &rhs) {
43     if (this != &rhs) {
44       m_type_sp = rhs.m_type_sp;
45       m_die = rhs.m_die;
46       m_declaration = rhs.m_declaration;
47       m_byte_size = rhs.m_byte_size;
48     }
49     return *this;
50   }
51 
52   lldb::TypeSP m_type_sp;
53   DWARFDIE m_die;
54   lldb_private::Declaration m_declaration;
55   int32_t m_byte_size;
56 };
57 
58 class UniqueDWARFASTTypeList {
59 public:
UniqueDWARFASTTypeList()60   UniqueDWARFASTTypeList() : m_collection() {}
61 
~UniqueDWARFASTTypeList()62   ~UniqueDWARFASTTypeList() {}
63 
GetSize()64   uint32_t GetSize() { return (uint32_t)m_collection.size(); }
65 
Append(const UniqueDWARFASTType & entry)66   void Append(const UniqueDWARFASTType &entry) {
67     m_collection.push_back(entry);
68   }
69 
70   bool Find(const DWARFDIE &die, const lldb_private::Declaration &decl,
71             const int32_t byte_size, UniqueDWARFASTType &entry) const;
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 
~UniqueDWARFASTTypeMap()82   ~UniqueDWARFASTTypeMap() {}
83 
Insert(const lldb_private::ConstString & name,const UniqueDWARFASTType & entry)84   void Insert(const lldb_private::ConstString &name,
85               const UniqueDWARFASTType &entry) {
86     m_collection[name.GetCString()].Append(entry);
87   }
88 
Find(const lldb_private::ConstString & name,const DWARFDIE & die,const lldb_private::Declaration & decl,const int32_t byte_size,UniqueDWARFASTType & entry)89   bool Find(const lldb_private::ConstString &name, const DWARFDIE &die,
90             const lldb_private::Declaration &decl, const int32_t byte_size,
91             UniqueDWARFASTType &entry) const {
92     const char *unique_name_cstr = name.GetCString();
93     collection::const_iterator pos = m_collection.find(unique_name_cstr);
94     if (pos != m_collection.end()) {
95       return pos->second.Find(die, decl, byte_size, entry);
96     }
97     return false;
98   }
99 
100 protected:
101   // A unique name string should be used
102   typedef llvm::DenseMap<const char *, UniqueDWARFASTTypeList> collection;
103   collection m_collection;
104 };
105 
106 #endif // lldb_UniqueDWARFASTType_h_
107