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