]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeValidator.h
Update nvi to 2.1.3 which fixes the data corruption when locale conversion
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeValidator.h
1 //===-- TypeValidator.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_TypeValidator_h_
11 #define lldb_TypeValidator_h_
12
13 // C Includes
14
15 // C++ Includes
16 #include <string>
17 #include <functional>
18
19 // Other libraries and framework includes
20
21 // Project includes
22 #include "lldb/lldb-public.h"
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-private-enumerations.h"
25
26 namespace lldb_private {
27     
28 class TypeValidatorImpl
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     TypeValidatorImpl (const Flags& flags = Flags());
135     
136     typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
137     typedef bool(*ValueCallback)(void*, ConstString, const lldb::TypeValidatorImplSP&);
138     
139     virtual ~TypeValidatorImpl ();
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         eTypeCXX
197     };
198     
199     struct ValidationResult {
200         TypeValidatorResult m_result;
201         std::string m_message;
202     };
203     
204     virtual Type
205     GetType ()
206     {
207         return Type::eTypeUnknown;
208     }
209     
210     // we are using a ValueObject* instead of a ValueObjectSP because we do not need to hold on to this for
211     // extended periods of time and we trust the ValueObject to stay around for as long as it is required
212     // for us to generate its value
213     virtual ValidationResult
214     FormatObject (ValueObject *valobj) const = 0;
215     
216     virtual std::string
217     GetDescription() = 0;
218     
219     static ValidationResult
220     Success ();
221     
222     static ValidationResult
223     Failure (std::string message);
224     
225 protected:
226     Flags m_flags;
227     uint32_t m_my_revision;
228     
229 private:
230     DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
231 };
232     
233 class TypeValidatorImpl_CXX : public TypeValidatorImpl
234 {
235 public:
236     typedef std::function<TypeValidatorImpl::ValidationResult(ValueObject* valobj)> ValidatorFunction;
237     
238     TypeValidatorImpl_CXX (ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags& flags = Flags());
239     
240     typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
241     typedef bool(*ValueCallback)(void*, ConstString, const TypeValidatorImpl_CXX::SharedPointer&);
242     
243     virtual ~TypeValidatorImpl_CXX ();
244     
245     ValidatorFunction
246     GetValidatorFunction () const
247     {
248         return m_validator_function;
249     }
250     
251     void
252     SetValidatorFunction (ValidatorFunction f)
253     {
254         m_validator_function = f;
255     }
256     
257     virtual TypeValidatorImpl::Type
258     GetType ()
259     {
260         return TypeValidatorImpl::Type::eTypeCXX;
261     }
262     
263     virtual ValidationResult
264     FormatObject (ValueObject *valobj) const;
265     
266     virtual std::string
267     GetDescription();
268     
269 protected:
270     std::string m_description;
271     ValidatorFunction m_validator_function;
272     
273 private:
274     DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
275 };
276
277     
278 } // namespace lldb_private
279
280 #endif  // lldb_TypeValidator_h_