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