]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeFormat.h
Merge ^/head r288457 through r288830.
[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             bool
119             GetNonCacheable () const
120             {
121                 return (m_flags & lldb::eTypeOptionNonCacheable) == lldb::eTypeOptionNonCacheable;
122             }
123             
124             Flags&
125             SetNonCacheable (bool value = true)
126             {
127                 if (value)
128                     m_flags |= lldb::eTypeOptionNonCacheable;
129                 else
130                     m_flags &= ~lldb::eTypeOptionNonCacheable;
131                 return *this;
132             }
133             
134             uint32_t
135             GetValue ()
136             {
137                 return m_flags;
138             }
139             
140             void
141             SetValue (uint32_t value)
142             {
143                 m_flags = value;
144             }
145             
146         private:
147             uint32_t m_flags;
148         };
149         
150         TypeFormatImpl (const Flags& flags = Flags());
151         
152         typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
153         typedef bool(*ValueCallback)(void*, ConstString, const lldb::TypeFormatImplSP&);
154         
155         virtual ~TypeFormatImpl ();
156         
157         bool
158         Cascades () const
159         {
160             return m_flags.GetCascades();
161         }
162         bool
163         SkipsPointers () const
164         {
165             return m_flags.GetSkipPointers();
166         }
167         bool
168         SkipsReferences () const
169         {
170             return m_flags.GetSkipReferences();
171         }
172         bool
173         NonCacheable () const
174         {
175             return m_flags.GetNonCacheable();
176         }
177         
178         void
179         SetCascades (bool value)
180         {
181             m_flags.SetCascades(value);
182         }
183         
184         void
185         SetSkipsPointers (bool value)
186         {
187             m_flags.SetSkipPointers(value);
188         }
189         
190         void
191         SetSkipsReferences (bool value)
192         {
193             m_flags.SetSkipReferences(value);
194         }
195         
196         void
197         SetNonCacheable (bool value)
198         {
199             m_flags.SetNonCacheable(value);
200         }
201
202         uint32_t
203         GetOptions ()
204         {
205             return m_flags.GetValue();
206         }
207         
208         void
209         SetOptions (uint32_t value)
210         {
211             m_flags.SetValue(value);
212         }
213         
214         uint32_t&
215         GetRevision ()
216         {
217             return m_my_revision;
218         }
219         
220         enum class Type
221         {
222             eTypeUnknown,
223             eTypeFormat,
224             eTypeEnum
225         };
226         
227         virtual Type
228         GetType ()
229         {
230             return Type::eTypeUnknown;
231         }
232         
233         // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
234         // extended periods of time and we trust the ValueObject to stay around for as long as it is required
235         // for us to generate its value
236         virtual bool
237         FormatObject (ValueObject *valobj,
238                       std::string& dest) const = 0;
239         
240         virtual std::string
241         GetDescription() = 0;
242         
243     protected:
244         Flags m_flags;
245         uint32_t m_my_revision;
246         
247     private:
248         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl);
249     };
250     
251     class TypeFormatImpl_Format : public TypeFormatImpl
252     {
253     public:
254         TypeFormatImpl_Format (lldb::Format f = lldb::eFormatInvalid,
255                                const TypeFormatImpl::Flags& flags = Flags());
256         
257         typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
258         typedef bool(*ValueCallback)(void*, ConstString, const TypeFormatImpl_Format::SharedPointer&);
259         
260         virtual ~TypeFormatImpl_Format ();
261         
262         lldb::Format
263         GetFormat () const
264         {
265             return m_format;
266         }
267         
268         void
269         SetFormat (lldb::Format fmt)
270         {
271             m_format = fmt;
272         }
273         
274         virtual TypeFormatImpl::Type
275         GetType ()
276         {
277             return TypeFormatImpl::Type::eTypeFormat;
278         }
279         
280         virtual bool
281         FormatObject (ValueObject *valobj,
282                       std::string& dest) const;
283         
284         virtual std::string
285         GetDescription();
286         
287     protected:
288         lldb::Format m_format;
289         
290     private:
291         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_Format);
292     };
293     
294     class TypeFormatImpl_EnumType : public TypeFormatImpl
295     {
296     public:
297         TypeFormatImpl_EnumType (ConstString type_name = ConstString(""),
298                                  const TypeFormatImpl::Flags& flags = Flags());
299         
300         typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
301         typedef bool(*ValueCallback)(void*, ConstString, const TypeFormatImpl_EnumType::SharedPointer&);
302         
303         ~TypeFormatImpl_EnumType ();
304         
305         ConstString
306         GetTypeName ()
307         {
308             return m_enum_type;
309         }
310         
311         void
312         SetTypeName (ConstString enum_type)
313         {
314             m_enum_type = enum_type;
315         }
316         
317         virtual TypeFormatImpl::Type
318         GetType ()
319         {
320             return TypeFormatImpl::Type::eTypeEnum;
321         }
322         
323         virtual bool
324         FormatObject (ValueObject *valobj,
325                       std::string& dest) const;
326         
327         virtual std::string
328         GetDescription();
329         
330     protected:
331         ConstString m_enum_type;
332         mutable std::unordered_map<void*,ClangASTType> m_types;
333         
334     private:
335         DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType);
336     };
337 } // namespace lldb_private
338
339 #endif  // lldb_TypeFormat_h_