]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeFormat.h
Update compiler-rt to release_39 branch r288513. Since this contains a
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeFormat.h
1 //===-- TypeFormat.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_TypeFormat_h_
11 #define lldb_TypeFormat_h_
12
13 // C Includes
14
15 // C++ Includes
16 #include <functional>
17 #include <string>
18 #include <unordered_map>
19
20 // Other libraries and framework includes
21
22 // Project includes
23 #include "lldb/lldb-public.h"
24 #include "lldb/lldb-enumerations.h"
25
26 #include "lldb/Core/ValueObject.h"
27
28 namespace lldb_private {
29     class TypeFormatImpl
30     {
31     public:
32         class Flags
33         {
34         public:
35             
36             Flags () :
37             m_flags (lldb::eTypeOptionCascade)
38             {}
39             
40             Flags (const Flags& other) :
41             m_flags (other.m_flags)
42             {}
43             
44             Flags (uint32_t value) :
45             m_flags (value)
46             {}
47             
48             Flags&
49             operator = (const Flags& rhs)
50             {
51                 if (&rhs != this)
52                     m_flags = rhs.m_flags;
53                 
54                 return *this;
55             }
56             
57             Flags&
58             operator = (const uint32_t& rhs)
59             {
60                 m_flags = rhs;
61                 return *this;
62             }
63             
64             Flags&
65             Clear()
66             {
67                 m_flags = 0;
68                 return *this;
69             }
70             
71             bool
72             GetCascades () const
73             {
74                 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
75             }
76             
77             Flags&
78             SetCascades (bool value = true)
79             {
80                 if (value)
81                     m_flags |= lldb::eTypeOptionCascade;
82                 else
83                     m_flags &= ~lldb::eTypeOptionCascade;
84                 return *this;
85             }
86             
87             bool
88             GetSkipPointers () const
89             {
90                 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
91             }
92             
93             Flags&
94             SetSkipPointers (bool value = true)
95             {
96                 if (value)
97                     m_flags |= lldb::eTypeOptionSkipPointers;
98                 else
99                     m_flags &= ~lldb::eTypeOptionSkipPointers;
100                 return *this;
101             }
102             
103             bool
104             GetSkipReferences () const
105             {
106                 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
107             }
108             
109             Flags&
110             SetSkipReferences (bool value = true)
111             {
112                 if (value)
113                     m_flags |= lldb::eTypeOptionSkipReferences;
114                 else
115                     m_flags &= ~lldb::eTypeOptionSkipReferences;
116                 return *this;
117             }
118             
119             bool
120             GetNonCacheable () const
121             {
122                 return (m_flags & lldb::eTypeOptionNonCacheable) == lldb::eTypeOptionNonCacheable;
123             }
124             
125             Flags&
126             SetNonCacheable (bool value = true)
127             {
128                 if (value)
129                     m_flags |= lldb::eTypeOptionNonCacheable;
130                 else
131                     m_flags &= ~lldb::eTypeOptionNonCacheable;
132                 return *this;
133             }
134             
135             uint32_t
136             GetValue ()
137             {
138                 return m_flags;
139             }
140             
141             void
142             SetValue (uint32_t value)
143             {
144                 m_flags = value;
145             }
146             
147         private:
148             uint32_t m_flags;
149         };
150         
151         TypeFormatImpl (const Flags& flags = Flags());
152         
153         typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
154         
155         virtual ~TypeFormatImpl ();
156         
157         bool
158         Cascades () const
159         {
160             return m_flags.GetCascades();
161         }
162
163         bool
164         SkipsPointers () const
165         {
166             return m_flags.GetSkipPointers();
167         }
168
169         bool
170         SkipsReferences () const
171         {
172             return m_flags.GetSkipReferences();
173         }
174
175         bool
176         NonCacheable () const
177         {
178             return m_flags.GetNonCacheable();
179         }
180         
181         void
182         SetCascades (bool value)
183         {
184             m_flags.SetCascades(value);
185         }
186         
187         void
188         SetSkipsPointers (bool value)
189         {
190             m_flags.SetSkipPointers(value);
191         }
192         
193         void
194         SetSkipsReferences (bool value)
195         {
196             m_flags.SetSkipReferences(value);
197         }
198         
199         void
200         SetNonCacheable (bool value)
201         {
202             m_flags.SetNonCacheable(value);
203         }
204
205         uint32_t
206         GetOptions ()
207         {
208             return m_flags.GetValue();
209         }
210         
211         void
212         SetOptions (uint32_t value)
213         {
214             m_flags.SetValue(value);
215         }
216         
217         uint32_t&
218         GetRevision ()
219         {
220             return m_my_revision;
221         }
222         
223         enum class Type
224         {
225             eTypeUnknown,
226             eTypeFormat,
227             eTypeEnum
228         };
229         
230         virtual Type
231         GetType ()
232         {
233             return Type::eTypeUnknown;
234         }
235         
236         // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
237         // extended periods of time and we trust the ValueObject to stay around for as long as it is required
238         // for us to generate its value
239         virtual bool
240         FormatObject (ValueObject *valobj,
241                       std::string& dest) const = 0;
242         
243         virtual std::string
244         GetDescription() = 0;
245         
246     protected:
247         Flags m_flags;
248         uint32_t m_my_revision;
249         
250     private:
251         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl);
252     };
253     
254     class TypeFormatImpl_Format : public TypeFormatImpl
255     {
256     public:
257         TypeFormatImpl_Format (lldb::Format f = lldb::eFormatInvalid,
258                                const TypeFormatImpl::Flags& flags = Flags());
259         
260         typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
261         
262         ~TypeFormatImpl_Format() override;
263         
264         lldb::Format
265         GetFormat () const
266         {
267             return m_format;
268         }
269         
270         void
271         SetFormat (lldb::Format fmt)
272         {
273             m_format = fmt;
274         }
275         
276         TypeFormatImpl::Type
277         GetType() override
278         {
279             return TypeFormatImpl::Type::eTypeFormat;
280         }
281         
282         bool
283         FormatObject(ValueObject *valobj,
284                      std::string& dest) const override;
285         
286         std::string
287         GetDescription() override;
288         
289     protected:
290         lldb::Format m_format;
291         
292     private:
293         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_Format);
294     };
295     
296     class TypeFormatImpl_EnumType : public TypeFormatImpl
297     {
298     public:
299         TypeFormatImpl_EnumType (ConstString type_name = ConstString(""),
300                                  const TypeFormatImpl::Flags& flags = Flags());
301         
302         typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
303         
304         ~TypeFormatImpl_EnumType() override;
305         
306         ConstString
307         GetTypeName ()
308         {
309             return m_enum_type;
310         }
311         
312         void
313         SetTypeName (ConstString enum_type)
314         {
315             m_enum_type = enum_type;
316         }
317         
318         TypeFormatImpl::Type
319         GetType() override
320         {
321             return TypeFormatImpl::Type::eTypeEnum;
322         }
323         
324         bool
325         FormatObject(ValueObject *valobj,
326                      std::string& dest) const override;
327         
328         std::string
329         GetDescription() override;
330         
331     protected:
332         ConstString m_enum_type;
333         mutable std::unordered_map<void*,CompilerType> m_types;
334         
335     private:
336         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType);
337     };
338 } // namespace lldb_private
339
340 #endif // lldb_TypeFormat_h_