1 //===-- TypeValidator.h ------------------------------------------*- C++
4 // The LLVM Compiler Infrastructure
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
11 #ifndef lldb_TypeValidator_h_
12 #define lldb_TypeValidator_h_
20 // Other libraries and framework includes
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-private-enumerations.h"
25 #include "lldb/lldb-public.h"
27 namespace lldb_private {
29 class TypeValidatorImpl {
33 Flags() : m_flags(lldb::eTypeOptionCascade) {}
35 Flags(const Flags &other) : m_flags(other.m_flags) {}
37 Flags(uint32_t value) : m_flags(value) {}
39 Flags &operator=(const Flags &rhs) {
41 m_flags = rhs.m_flags;
46 Flags &operator=(const uint32_t &rhs) {
56 bool GetCascades() const {
57 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
60 Flags &SetCascades(bool value = true) {
62 m_flags |= lldb::eTypeOptionCascade;
64 m_flags &= ~lldb::eTypeOptionCascade;
68 bool GetSkipPointers() const {
69 return (m_flags & lldb::eTypeOptionSkipPointers) ==
70 lldb::eTypeOptionSkipPointers;
73 Flags &SetSkipPointers(bool value = true) {
75 m_flags |= lldb::eTypeOptionSkipPointers;
77 m_flags &= ~lldb::eTypeOptionSkipPointers;
81 bool GetSkipReferences() const {
82 return (m_flags & lldb::eTypeOptionSkipReferences) ==
83 lldb::eTypeOptionSkipReferences;
86 Flags &SetSkipReferences(bool value = true) {
88 m_flags |= lldb::eTypeOptionSkipReferences;
90 m_flags &= ~lldb::eTypeOptionSkipReferences;
94 bool GetNonCacheable() const {
95 return (m_flags & lldb::eTypeOptionNonCacheable) ==
96 lldb::eTypeOptionNonCacheable;
99 Flags &SetNonCacheable(bool value = true) {
101 m_flags |= lldb::eTypeOptionNonCacheable;
103 m_flags &= ~lldb::eTypeOptionNonCacheable;
107 uint32_t GetValue() { return m_flags; }
109 void SetValue(uint32_t value) { m_flags = value; }
115 TypeValidatorImpl(const Flags &flags = Flags());
117 typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
119 virtual ~TypeValidatorImpl();
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(); }
126 void SetCascades(bool value) { m_flags.SetCascades(value); }
128 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
130 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
132 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
134 uint32_t GetOptions() { return m_flags.GetValue(); }
136 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
138 uint32_t &GetRevision() { return m_my_revision; }
140 enum class Type { eTypeUnknown, eTypeCXX };
142 struct ValidationResult {
143 TypeValidatorResult m_result;
144 std::string m_message;
147 virtual Type GetType() { return Type::eTypeUnknown; }
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;
156 virtual std::string GetDescription() = 0;
158 static ValidationResult Success();
160 static ValidationResult Failure(std::string message);
164 uint32_t m_my_revision;
167 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
170 class TypeValidatorImpl_CXX : public TypeValidatorImpl {
172 typedef std::function<TypeValidatorImpl::ValidationResult(
173 ValueObject *valobj)>
176 TypeValidatorImpl_CXX(ValidatorFunction f, std::string d,
177 const TypeValidatorImpl::Flags &flags = Flags());
179 typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
181 ~TypeValidatorImpl_CXX() override;
183 ValidatorFunction GetValidatorFunction() const {
184 return m_validator_function;
187 void SetValidatorFunction(ValidatorFunction f) { m_validator_function = f; }
189 TypeValidatorImpl::Type GetType() override {
190 return TypeValidatorImpl::Type::eTypeCXX;
193 ValidationResult FormatObject(ValueObject *valobj) const override;
195 std::string GetDescription() override;
198 std::string m_description;
199 ValidatorFunction m_validator_function;
202 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
205 } // namespace lldb_private
207 #endif // lldb_TypeValidator_h_