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_DATAFORMATTERS_TYPEFORMAT_H
11 #define LLDB_DATAFORMATTERS_TYPEFORMAT_H
12 
13 #include <functional>
14 #include <string>
15 #include <unordered_map>
16 
17 
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-public.h"
20 
21 #include "lldb/Core/ValueObject.h"
22 
23 namespace lldb_private {
25 public:
26  class Flags {
27  public:
28  Flags() {}
29 
30  Flags(const Flags &other) : m_flags(other.m_flags) {}
31 
32  Flags(uint32_t value) : m_flags(value) {}
33 
34  Flags &operator=(const Flags &rhs) {
35  if (&rhs != this)
36  m_flags = rhs.m_flags;
37 
38  return *this;
39  }
40 
41  Flags &operator=(const uint32_t &rhs) {
42  m_flags = rhs;
43  return *this;
44  }
45 
46  Flags &Clear() {
47  m_flags = 0;
48  return *this;
49  }
50 
51  bool GetCascades() const {
52  return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
53  }
54 
55  Flags &SetCascades(bool value = true) {
56  if (value)
57  m_flags |= lldb::eTypeOptionCascade;
58  else
59  m_flags &= ~lldb::eTypeOptionCascade;
60  return *this;
61  }
62 
63  bool GetSkipPointers() const {
64  return (m_flags & lldb::eTypeOptionSkipPointers) ==
65  lldb::eTypeOptionSkipPointers;
66  }
67 
68  Flags &SetSkipPointers(bool value = true) {
69  if (value)
70  m_flags |= lldb::eTypeOptionSkipPointers;
71  else
72  m_flags &= ~lldb::eTypeOptionSkipPointers;
73  return *this;
74  }
75 
76  bool GetSkipReferences() const {
77  return (m_flags & lldb::eTypeOptionSkipReferences) ==
78  lldb::eTypeOptionSkipReferences;
79  }
80 
81  Flags &SetSkipReferences(bool value = true) {
82  if (value)
83  m_flags |= lldb::eTypeOptionSkipReferences;
84  else
85  m_flags &= ~lldb::eTypeOptionSkipReferences;
86  return *this;
87  }
88 
89  bool GetNonCacheable() const {
90  return (m_flags & lldb::eTypeOptionNonCacheable) ==
91  lldb::eTypeOptionNonCacheable;
92  }
93 
94  Flags &SetNonCacheable(bool value = true) {
95  if (value)
96  m_flags |= lldb::eTypeOptionNonCacheable;
97  else
98  m_flags &= ~lldb::eTypeOptionNonCacheable;
99  return *this;
100  }
101 
102  uint32_t GetValue() { return m_flags; }
103 
104  void SetValue(uint32_t value) { m_flags = value; }
105 
106  private:
107  uint32_t m_flags = lldb::eTypeOptionCascade;
108  };
109 
110  TypeFormatImpl(const Flags &flags = Flags());
111 
112  typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
113 
114  virtual ~TypeFormatImpl();
115 
116  bool Cascades() const { return m_flags.GetCascades(); }
117 
118  bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
119 
120  bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
121 
122  bool NonCacheable() const { return m_flags.GetNonCacheable(); }
123 
124  void SetCascades(bool value) { m_flags.SetCascades(value); }
125 
126  void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
127 
128  void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
129 
130  void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
131 
133 
134  void SetOptions(uint32_t value) { m_flags.SetValue(value); }
135 
137 
139 
140  virtual Type GetType() { return Type::eTypeUnknown; }
141 
142  // we are using a ValueObject* instead of a ValueObjectSP because we do not
143  // need to hold on to this for extended periods of time and we trust the
144  // ValueObject to stay around for as long as it is required for us to
145  // generate its value
146  virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
147 
148  virtual std::string GetDescription() = 0;
149 
150 protected:
153 
154 private:
155  TypeFormatImpl(const TypeFormatImpl &) = delete;
156  const TypeFormatImpl &operator=(const TypeFormatImpl &) = delete;
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:
185  const TypeFormatImpl_Format &
186  operator=(const TypeFormatImpl_Format &) = delete;
187 };
188 
190 public:
192  const TypeFormatImpl::Flags &flags = Flags());
193 
194  typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
195 
196  ~TypeFormatImpl_EnumType() override;
197 
199 
200  void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
201 
204  }
205 
206  bool FormatObject(ValueObject *valobj, std::string &dest) const override;
207 
208  std::string GetDescription() override;
209 
210 protected:
212  mutable std::unordered_map<void *, CompilerType> m_types;
213 
214 private:
217  operator=(const TypeFormatImpl_EnumType &) = delete;
218 };
219 } // namespace lldb_private
220 
221 #endif // LLDB_DATAFORMATTERS_TYPEFORMAT_H
lldb_private::TypeFormatImpl::Type
Type
Definition: TypeFormat.h:138
lldb_private::TypeFormatImpl_Format::m_format
lldb::Format m_format
Definition: TypeFormat.h:181
lldb_private::TypeFormatImpl::Flags::GetCascades
bool GetCascades() const
Definition: TypeFormat.h:51
lldb-public.h
lldb_private::TypeFormatImpl_EnumType::SharedPointer
std::shared_ptr< TypeFormatImpl_EnumType > SharedPointer
Definition: TypeFormat.h:194
lldb_private::TypeFormatImpl::Type::eTypeUnknown
@ eTypeUnknown
lldb::Format
Format
Display format definitions.
Definition: lldb-enumerations.h:155
lldb_private::TypeFormatImpl_EnumType::~TypeFormatImpl_EnumType
~TypeFormatImpl_EnumType() override
lldb_private::TypeFormatImpl::~TypeFormatImpl
virtual ~TypeFormatImpl()
lldb_private::TypeFormatImpl::Flags::GetSkipReferences
bool GetSkipReferences() const
Definition: TypeFormat.h:76
lldb_private::TypeFormatImpl_EnumType::SetTypeName
void SetTypeName(ConstString enum_type)
Definition: TypeFormat.h:200
lldb_private::TypeFormatImpl_Format::GetType
TypeFormatImpl::Type GetType() override
Definition: TypeFormat.h:172
lldb_private::TypeFormatImpl::SetSkipsReferences
void SetSkipsReferences(bool value)
Definition: TypeFormat.h:128
lldb_private::TypeFormatImpl_EnumType::GetType
TypeFormatImpl::Type GetType() override
Definition: TypeFormat.h:202
lldb_private::TypeFormatImpl::GetDescription
virtual std::string GetDescription()=0
lldb_private::TypeFormatImpl_Format::operator=
const TypeFormatImpl_Format & operator=(const TypeFormatImpl_Format &)=delete
lldb_private::TypeFormatImpl::NonCacheable
bool NonCacheable() const
Definition: TypeFormat.h:122
lldb_private::TypeFormatImpl::TypeFormatImpl
TypeFormatImpl(const Flags &flags=Flags())
Definition: TypeFormat.cpp:30
lldb_private::TypeFormatImpl::SetCascades
void SetCascades(bool value)
Definition: TypeFormat.h:124
lldb_private::TypeFormatImpl_EnumType::FormatObject
bool FormatObject(ValueObject *valobj, std::string &dest) const override
Definition: TypeFormat.cpp:139
lldb_private::TypeFormatImpl::Flags::SetValue
void SetValue(uint32_t value)
Definition: TypeFormat.h:104
lldb_private::TypeFormatImpl_Format::SetFormat
void SetFormat(lldb::Format fmt)
Definition: TypeFormat.h:170
lldb_private::TypeFormatImpl_Format::~TypeFormatImpl_Format
~TypeFormatImpl_Format() override
lldb_private::TypeFormatImpl::SkipsPointers
bool SkipsPointers() const
Definition: TypeFormat.h:118
lldb_private::TypeFormatImpl::FormatObject
virtual bool FormatObject(ValueObject *valobj, std::string &dest) const =0
lldb_private::TypeFormatImpl
Definition: TypeFormat.h:24
lldb_private::TypeFormatImpl::Cascades
bool Cascades() const
Definition: TypeFormat.h:116
lldb_private::TypeFormatImpl::Flags::GetNonCacheable
bool GetNonCacheable() const
Definition: TypeFormat.h:89
lldb_private::TypeFormatImpl::Flags::operator=
Flags & operator=(const uint32_t &rhs)
Definition: TypeFormat.h:41
lldb_private::TypeFormatImpl::Flags::Flags
Flags(const Flags &other)
Definition: TypeFormat.h:30
lldb_private::TypeFormatImpl::Flags::SetSkipReferences
Flags & SetSkipReferences(bool value=true)
Definition: TypeFormat.h:81
lldb_private::TypeFormatImpl::SkipsReferences
bool SkipsReferences() const
Definition: TypeFormat.h:120
lldb_private::TypeFormatImpl::m_my_revision
uint32_t m_my_revision
Definition: TypeFormat.h:152
lldb_private::TypeFormatImpl::GetRevision
uint32_t & GetRevision()
Definition: TypeFormat.h:136
lldb_private::TypeFormatImpl::Flags::Flags
Flags()
Definition: TypeFormat.h:28
lldb_private::TypeFormatImpl_EnumType::m_types
std::unordered_map< void *, CompilerType > m_types
Definition: TypeFormat.h:212
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::TypeFormatImpl_EnumType::m_enum_type
ConstString m_enum_type
Definition: TypeFormat.h:211
lldb-enumerations.h
lldb_private::TypeFormatImpl::Flags::operator=
Flags & operator=(const Flags &rhs)
Definition: TypeFormat.h:34
lldb_private::TypeFormatImpl::Flags::GetValue
uint32_t GetValue()
Definition: TypeFormat.h:102
lldb_private::TypeFormatImpl::GetType
virtual Type GetType()
Definition: TypeFormat.h:140
lldb_private::TypeFormatImpl_Format::GetFormat
lldb::Format GetFormat() const
Definition: TypeFormat.h:168
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::TypeFormatImpl_EnumType::GetTypeName
ConstString GetTypeName()
Definition: TypeFormat.h:198
lldb_private::TypeFormatImpl::SetNonCacheable
void SetNonCacheable(bool value)
Definition: TypeFormat.h:130
lldb_private::TypeFormatImpl::Flags::GetSkipPointers
bool GetSkipPointers() const
Definition: TypeFormat.h:63
ValueObject.h
lldb_private::TypeFormatImpl_EnumType
Definition: TypeFormat.h:189
lldb_private::TypeFormatImpl_Format::SharedPointer
std::shared_ptr< TypeFormatImpl_Format > SharedPointer
Definition: TypeFormat.h:164
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::TypeFormatImpl::Flags::Flags
Flags(uint32_t value)
Definition: TypeFormat.h:32
uint32_t
lldb_private::TypeFormatImpl::Flags
Definition: TypeFormat.h:26
lldb_private::TypeFormatImpl_EnumType::GetDescription
std::string GetDescription() override
Definition: TypeFormat.cpp:197
lldb_private::TypeFormatImpl_Format::GetDescription
std::string GetDescription() override
Definition: TypeFormat.cpp:124
lldb_private::TypeFormatImpl::Type::eTypeEnum
@ eTypeEnum
lldb_private::TypeFormatImpl::SetOptions
void SetOptions(uint32_t value)
Definition: TypeFormat.h:134
lldb_private::TypeFormatImpl::GetOptions
uint32_t GetOptions()
Definition: TypeFormat.h:132
lldb_private::TypeFormatImpl::SetSkipsPointers
void SetSkipsPointers(bool value)
Definition: TypeFormat.h:126
lldb_private::TypeFormatImpl::Type::eTypeFormat
@ eTypeFormat
lldb_private::TypeFormatImpl_EnumType::TypeFormatImpl_EnumType
TypeFormatImpl_EnumType(ConstString type_name=ConstString(""), const TypeFormatImpl::Flags &flags=Flags())
Definition: TypeFormat.cpp:133
lldb_private::TypeFormatImpl::Flags::Clear
Flags & Clear()
Definition: TypeFormat.h:46
lldb_private::TypeFormatImpl::Flags::SetNonCacheable
Flags & SetNonCacheable(bool value=true)
Definition: TypeFormat.h:94
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::TypeFormatImpl_Format
Definition: TypeFormat.h:159
lldb_private::TypeFormatImpl_Format::TypeFormatImpl_Format
TypeFormatImpl_Format(lldb::Format f=lldb::eFormatInvalid, const TypeFormatImpl::Flags &flags=Flags())
Definition: TypeFormat.cpp:34
lldb_private::TypeFormatImpl::m_flags
Flags m_flags
Definition: TypeFormat.h:151
lldb_private::TypeFormatImpl_Format::FormatObject
bool FormatObject(ValueObject *valobj, std::string &dest) const override
Definition: TypeFormat.cpp:40
lldb_private::TypeFormatImpl::operator=
const TypeFormatImpl & operator=(const TypeFormatImpl &)=delete
lldb_private::TypeFormatImpl::Flags::SetCascades
Flags & SetCascades(bool value=true)
Definition: TypeFormat.h:55
lldb_private::TypeFormatImpl::SharedPointer
std::shared_ptr< TypeFormatImpl > SharedPointer
Definition: TypeFormat.h:112
lldb_private::TypeFormatImpl_EnumType::operator=
const TypeFormatImpl_EnumType & operator=(const TypeFormatImpl_EnumType &)=delete
lldb_private::TypeFormatImpl::Flags::SetSkipPointers
Flags & SetSkipPointers(bool value=true)
Definition: TypeFormat.h:68
lldb
Definition: SBAddress.h:15
lldb_private::TypeFormatImpl::Flags::m_flags
uint32_t m_flags
Definition: TypeFormat.h:107
lldb::eFormatInvalid
@ eFormatInvalid
Definition: lldb-enumerations.h:157