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_UniqueDWARFASTType_h_
10#define lldb_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
19class UniqueDWARFASTType {
20public:
21  // Constructors and Destructors
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
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
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
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
55class UniqueDWARFASTTypeList {
56public:
57  UniqueDWARFASTTypeList() : m_collection() {}
58
59  ~UniqueDWARFASTTypeList() {}
60
61  uint32_t GetSize() { return (uint32_t)m_collection.size(); }
62
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
70protected:
71  typedef std::vector<UniqueDWARFASTType> collection;
72  collection m_collection;
73};
74
75class UniqueDWARFASTTypeMap {
76public:
77  UniqueDWARFASTTypeMap() : m_collection() {}
78
79  ~UniqueDWARFASTTypeMap() {}
80
81  void Insert(lldb_private::ConstString name,
82              const UniqueDWARFASTType &entry) {
83    m_collection[name.GetCString()].Append(entry);
84  }
85
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
97protected:
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_UniqueDWARFASTType_h_
104