1 //===-- TypeValidator.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_TypeValidator_h_
11 #define lldb_TypeValidator_h_
19 // Other libraries and framework includes
22 #include "lldb/lldb-public.h"
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-private-enumerations.h"
26 namespace lldb_private {
28 class TypeValidatorImpl
36 m_flags (lldb::eTypeOptionCascade)
39 Flags (const Flags& other) :
40 m_flags (other.m_flags)
43 Flags (uint32_t value) :
48 operator = (const Flags& rhs)
51 m_flags = rhs.m_flags;
57 operator = (const uint32_t& rhs)
73 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
77 SetCascades (bool value = true)
80 m_flags |= lldb::eTypeOptionCascade;
82 m_flags &= ~lldb::eTypeOptionCascade;
87 GetSkipPointers () const
89 return (m_flags & lldb::eTypeOptionSkipPointers) == lldb::eTypeOptionSkipPointers;
93 SetSkipPointers (bool value = true)
96 m_flags |= lldb::eTypeOptionSkipPointers;
98 m_flags &= ~lldb::eTypeOptionSkipPointers;
103 GetSkipReferences () const
105 return (m_flags & lldb::eTypeOptionSkipReferences) == lldb::eTypeOptionSkipReferences;
109 SetSkipReferences (bool value = true)
112 m_flags |= lldb::eTypeOptionSkipReferences;
114 m_flags &= ~lldb::eTypeOptionSkipReferences;
125 SetValue (uint32_t value)
134 TypeValidatorImpl (const Flags& flags = Flags());
136 typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
137 typedef bool(*ValueCallback)(void*, ConstString, const lldb::TypeValidatorImplSP&);
139 virtual ~TypeValidatorImpl ();
144 return m_flags.GetCascades();
147 SkipsPointers () const
149 return m_flags.GetSkipPointers();
152 SkipsReferences () const
154 return m_flags.GetSkipReferences();
158 SetCascades (bool value)
160 m_flags.SetCascades(value);
164 SetSkipsPointers (bool value)
166 m_flags.SetSkipPointers(value);
170 SetSkipsReferences (bool value)
172 m_flags.SetSkipReferences(value);
178 return m_flags.GetValue();
182 SetOptions (uint32_t value)
184 m_flags.SetValue(value);
190 return m_my_revision;
199 struct ValidationResult {
200 TypeValidatorResult m_result;
201 std::string m_message;
207 return Type::eTypeUnknown;
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;
217 GetDescription() = 0;
219 static ValidationResult
222 static ValidationResult
223 Failure (std::string message);
227 uint32_t m_my_revision;
230 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
233 class TypeValidatorImpl_CXX : public TypeValidatorImpl
236 typedef std::function<TypeValidatorImpl::ValidationResult(ValueObject* valobj)> ValidatorFunction;
238 TypeValidatorImpl_CXX (ValidatorFunction f, std::string d, const TypeValidatorImpl::Flags& flags = Flags());
240 typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
241 typedef bool(*ValueCallback)(void*, ConstString, const TypeValidatorImpl_CXX::SharedPointer&);
243 virtual ~TypeValidatorImpl_CXX ();
246 GetValidatorFunction () const
248 return m_validator_function;
252 SetValidatorFunction (ValidatorFunction f)
254 m_validator_function = f;
257 virtual TypeValidatorImpl::Type
260 return TypeValidatorImpl::Type::eTypeCXX;
263 virtual ValidationResult
264 FormatObject (ValueObject *valobj) const;
270 std::string m_description;
271 ValidatorFunction m_validator_function;
274 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
278 } // namespace lldb_private
280 #endif // lldb_TypeValidator_h_