]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/DataFormatters/TypeValidator.h
Merge ACPICA 20180313.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / DataFormatters / TypeValidator.h
1 //===-- TypeValidator.h ------------------------------------------*- C++
2 //-*-===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef lldb_TypeValidator_h_
12 #define lldb_TypeValidator_h_
13
14 // C Includes
15
16 // C++ Includes
17 #include <functional>
18 #include <string>
19
20 // Other libraries and framework includes
21
22 // Project includes
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-private-enumerations.h"
25 #include "lldb/lldb-public.h"
26
27 namespace lldb_private {
28
29 class TypeValidatorImpl {
30 public:
31   class Flags {
32   public:
33     Flags() : m_flags(lldb::eTypeOptionCascade) {}
34
35     Flags(const Flags &other) : m_flags(other.m_flags) {}
36
37     Flags(uint32_t value) : m_flags(value) {}
38
39     Flags &operator=(const Flags &rhs) {
40       if (&rhs != this)
41         m_flags = rhs.m_flags;
42
43       return *this;
44     }
45
46     Flags &operator=(const uint32_t &rhs) {
47       m_flags = rhs;
48       return *this;
49     }
50
51     Flags &Clear() {
52       m_flags = 0;
53       return *this;
54     }
55
56     bool GetCascades() const {
57       return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
58     }
59
60     Flags &SetCascades(bool value = true) {
61       if (value)
62         m_flags |= lldb::eTypeOptionCascade;
63       else
64         m_flags &= ~lldb::eTypeOptionCascade;
65       return *this;
66     }
67
68     bool GetSkipPointers() const {
69       return (m_flags & lldb::eTypeOptionSkipPointers) ==
70              lldb::eTypeOptionSkipPointers;
71     }
72
73     Flags &SetSkipPointers(bool value = true) {
74       if (value)
75         m_flags |= lldb::eTypeOptionSkipPointers;
76       else
77         m_flags &= ~lldb::eTypeOptionSkipPointers;
78       return *this;
79     }
80
81     bool GetSkipReferences() const {
82       return (m_flags & lldb::eTypeOptionSkipReferences) ==
83              lldb::eTypeOptionSkipReferences;
84     }
85
86     Flags &SetSkipReferences(bool value = true) {
87       if (value)
88         m_flags |= lldb::eTypeOptionSkipReferences;
89       else
90         m_flags &= ~lldb::eTypeOptionSkipReferences;
91       return *this;
92     }
93
94     bool GetNonCacheable() const {
95       return (m_flags & lldb::eTypeOptionNonCacheable) ==
96              lldb::eTypeOptionNonCacheable;
97     }
98
99     Flags &SetNonCacheable(bool value = true) {
100       if (value)
101         m_flags |= lldb::eTypeOptionNonCacheable;
102       else
103         m_flags &= ~lldb::eTypeOptionNonCacheable;
104       return *this;
105     }
106
107     uint32_t GetValue() { return m_flags; }
108
109     void SetValue(uint32_t value) { m_flags = value; }
110
111   private:
112     uint32_t m_flags;
113   };
114
115   TypeValidatorImpl(const Flags &flags = Flags());
116
117   typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
118
119   virtual ~TypeValidatorImpl();
120
121   bool Cascades() const { return m_flags.GetCascades(); }
122   bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
123   bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
124   bool NonCacheable() const { return m_flags.GetNonCacheable(); }
125
126   void SetCascades(bool value) { m_flags.SetCascades(value); }
127
128   void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
129
130   void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
131
132   void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
133
134   uint32_t GetOptions() { return m_flags.GetValue(); }
135
136   void SetOptions(uint32_t value) { m_flags.SetValue(value); }
137
138   uint32_t &GetRevision() { return m_my_revision; }
139
140   enum class Type { eTypeUnknown, eTypeCXX };
141
142   struct ValidationResult {
143     TypeValidatorResult m_result;
144     std::string m_message;
145   };
146
147   virtual Type GetType() { return Type::eTypeUnknown; }
148
149   // we are using a ValueObject* instead of a ValueObjectSP because we do not
150   // need to hold on to this for
151   // extended periods of time and we trust the ValueObject to stay around for as
152   // long as it is required
153   // for us to generate its value
154   virtual ValidationResult FormatObject(ValueObject *valobj) const = 0;
155
156   virtual std::string GetDescription() = 0;
157
158   static ValidationResult Success();
159
160   static ValidationResult Failure(std::string message);
161
162 protected:
163   Flags m_flags;
164   uint32_t m_my_revision;
165
166 private:
167   DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
168 };
169
170 class TypeValidatorImpl_CXX : public TypeValidatorImpl {
171 public:
172   typedef std::function<TypeValidatorImpl::ValidationResult(
173       ValueObject *valobj)>
174       ValidatorFunction;
175
176   TypeValidatorImpl_CXX(ValidatorFunction f, std::string d,
177                         const TypeValidatorImpl::Flags &flags = Flags());
178
179   typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
180
181   ~TypeValidatorImpl_CXX() override;
182
183   ValidatorFunction GetValidatorFunction() const {
184     return m_validator_function;
185   }
186
187   void SetValidatorFunction(ValidatorFunction f) { m_validator_function = f; }
188
189   TypeValidatorImpl::Type GetType() override {
190     return TypeValidatorImpl::Type::eTypeCXX;
191   }
192
193   ValidationResult FormatObject(ValueObject *valobj) const override;
194
195   std::string GetDescription() override;
196
197 protected:
198   std::string m_description;
199   ValidatorFunction m_validator_function;
200
201 private:
202   DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
203 };
204
205 } // namespace lldb_private
206
207 #endif // lldb_TypeValidator_h_