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