LLDB  mainline
TypeFormat.h
Go to the documentation of this file.
1 //===-- TypeFormat.h ----------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_TypeFormat_h_
11 #define lldb_TypeFormat_h_
12 
13 
14 #include <functional>
15 #include <string>
16 #include <unordered_map>
17 
18 
19 #include "lldb/lldb-enumerations.h"
20 #include "lldb/lldb-public.h"
21 
22 #include "lldb/Core/ValueObject.h"
23 
24 namespace lldb_private {
26 public:
27  class Flags {
28  public:
29  Flags() : m_flags(lldb::eTypeOptionCascade) {}
30 
31  Flags(const Flags &other) : m_flags(other.m_flags) {}
32 
33  Flags(uint32_t value) : m_flags(value) {}
34 
35  Flags &operator=(const Flags &rhs) {
36  if (&rhs != this)
37  m_flags = rhs.m_flags;
38 
39  return *this;
40  }
41 
42  Flags &operator=(const uint32_t &rhs) {
43  m_flags = rhs;
44  return *this;
45  }
46 
47  Flags &Clear() {
48  m_flags = 0;
49  return *this;
50  }
51 
52  bool GetCascades() const {
53  return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
54  }
55 
56  Flags &SetCascades(bool value = true) {
57  if (value)
58  m_flags |= lldb::eTypeOptionCascade;
59  else
60  m_flags &= ~lldb::eTypeOptionCascade;
61  return *this;
62  }
63 
64  bool GetSkipPointers() const {
65  return (m_flags & lldb::eTypeOptionSkipPointers) ==
66  lldb::eTypeOptionSkipPointers;
67  }
68 
69  Flags &SetSkipPointers(bool value = true) {
70  if (value)
71  m_flags |= lldb::eTypeOptionSkipPointers;
72  else
73  m_flags &= ~lldb::eTypeOptionSkipPointers;
74  return *this;
75  }
76 
77  bool GetSkipReferences() const {
78  return (m_flags & lldb::eTypeOptionSkipReferences) ==
79  lldb::eTypeOptionSkipReferences;
80  }
81 
82  Flags &SetSkipReferences(bool value = true) {
83  if (value)
84  m_flags |= lldb::eTypeOptionSkipReferences;
85  else
86  m_flags &= ~lldb::eTypeOptionSkipReferences;
87  return *this;
88  }
89 
90  bool GetNonCacheable() const {
91  return (m_flags & lldb::eTypeOptionNonCacheable) ==
92  lldb::eTypeOptionNonCacheable;
93  }
94 
95  Flags &SetNonCacheable(bool value = true) {
96  if (value)
97  m_flags |= lldb::eTypeOptionNonCacheable;
98  else
99  m_flags &= ~lldb::eTypeOptionNonCacheable;
100  return *this;
101  }
102 
103  uint32_t GetValue() { return m_flags; }
104 
105  void SetValue(uint32_t value) { m_flags = value; }
106 
107  private:
108  uint32_t m_flags;
109  };
110 
111  TypeFormatImpl(const Flags &flags = Flags());
112 
113  typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
114 
115  virtual ~TypeFormatImpl();
116 
117  bool Cascades() const { return m_flags.GetCascades(); }
118 
119  bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
120 
121  bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
122 
123  bool NonCacheable() const { return m_flags.GetNonCacheable(); }
124 
125  void SetCascades(bool value) { m_flags.SetCascades(value); }
126 
127  void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
128 
129  void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
130 
131  void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
132 
133  uint32_t GetOptions() { return m_flags.GetValue(); }
134 
135  void SetOptions(uint32_t value) { m_flags.SetValue(value); }
136 
138 
139  enum class Type { eTypeUnknown, eTypeFormat, eTypeEnum };
140 
141  virtual Type GetType() { return Type::eTypeUnknown; }
142 
143  // we are using a ValueObject* instead of a ValueObjectSP because we do not
144  // need to hold on to this for extended periods of time and we trust the
145  // ValueObject to stay around for as long as it is required for us to
146  // generate its value
147  virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
148 
149  virtual std::string GetDescription() = 0;
150 
151 protected:
154 
155 private:
156  DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl);
157 };
158 
160 public:
162  const TypeFormatImpl::Flags &flags = Flags());
163 
164  typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
165 
166  ~TypeFormatImpl_Format() override;
167 
168  lldb::Format GetFormat() const { return m_format; }
169 
170  void SetFormat(lldb::Format fmt) { m_format = fmt; }
171 
174  }
175 
176  bool FormatObject(ValueObject *valobj, std::string &dest) const override;
177 
178  std::string GetDescription() override;
179 
180 protected:
182 
183 private:
184  DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_Format);
185 };
186 
188 public:
190  const TypeFormatImpl::Flags &flags = Flags());
191 
192  typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
193 
194  ~TypeFormatImpl_EnumType() override;
195 
196  ConstString GetTypeName() { return m_enum_type; }
197 
198  void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
199 
202  }
203 
204  bool FormatObject(ValueObject *valobj, std::string &dest) const override;
205 
206  std::string GetDescription() override;
207 
208 protected:
210  mutable std::unordered_map<void *, CompilerType> m_types;
211 
212 private:
213  DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType);
214 };
215 } // namespace lldb_private
216 
217 #endif // lldb_TypeFormat_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
virtual bool FormatObject(ValueObject *valobj, std::string &dest) const =0
std::shared_ptr< TypeFormatImpl_Format > SharedPointer
Definition: TypeFormat.h:164
Flags & SetSkipReferences(bool value=true)
Definition: TypeFormat.h:82
Flags & operator=(const uint32_t &rhs)
Definition: TypeFormat.h:42
std::shared_ptr< TypeFormatImpl > SharedPointer
Definition: TypeFormat.h:113
TypeFormatImpl::Type GetType() override
Definition: TypeFormat.h:200
std::unordered_map< void *, CompilerType > m_types
Definition: TypeFormat.h:210
void SetTypeName(ConstString enum_type)
Definition: TypeFormat.h:198
Flags & operator=(const Flags &rhs)
Definition: TypeFormat.h:35
void SetOptions(uint32_t value)
Definition: TypeFormat.h:135
void SetNonCacheable(bool value)
Definition: TypeFormat.h:131
void SetSkipsPointers(bool value)
Definition: TypeFormat.h:127
void SetValue(uint32_t value)
Definition: TypeFormat.h:105
void SetFormat(lldb::Format fmt)
Definition: TypeFormat.h:170
TypeFormatImpl(const Flags &flags=Flags())
Definition: TypeFormat.cpp:30
void SetSkipsReferences(bool value)
Definition: TypeFormat.h:129
TypeFormatImpl::Type GetType() override
Definition: TypeFormat.h:172
A uniqued constant string class.
Definition: ConstString.h:38
Flags & SetNonCacheable(bool value=true)
Definition: TypeFormat.h:95
Definition: SBAddress.h:15
Flags & SetCascades(bool value=true)
Definition: TypeFormat.h:56
virtual std::string GetDescription()=0
std::shared_ptr< TypeFormatImpl_EnumType > SharedPointer
Definition: TypeFormat.h:192
lldb::Format GetFormat() const
Definition: TypeFormat.h:168
void SetCascades(bool value)
Definition: TypeFormat.h:125
Flags & SetSkipPointers(bool value=true)
Definition: TypeFormat.h:69