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_
19 #include "lldb/lldb-enumerations.h"
20 #include "lldb/lldb-private-enumerations.h"
21 #include "lldb/lldb-public.h"
23 namespace lldb_private {
25 class TypeValidatorImpl {
29 Flags() : m_flags(lldb::eTypeOptionCascade) {}
31 Flags(const Flags &other) : m_flags(other.m_flags) {}
33 Flags(uint32_t value) : m_flags(value) {}
35 Flags &operator=(const Flags &rhs) {
37 m_flags = rhs.m_flags;
42 Flags &operator=(const uint32_t &rhs) {
52 bool GetCascades() const {
53 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
56 Flags &SetCascades(bool value = true) {
58 m_flags |= lldb::eTypeOptionCascade;
60 m_flags &= ~lldb::eTypeOptionCascade;
64 bool GetSkipPointers() const {
65 return (m_flags & lldb::eTypeOptionSkipPointers) ==
66 lldb::eTypeOptionSkipPointers;
69 Flags &SetSkipPointers(bool value = true) {
71 m_flags |= lldb::eTypeOptionSkipPointers;
73 m_flags &= ~lldb::eTypeOptionSkipPointers;
77 bool GetSkipReferences() const {
78 return (m_flags & lldb::eTypeOptionSkipReferences) ==
79 lldb::eTypeOptionSkipReferences;
82 Flags &SetSkipReferences(bool value = true) {
84 m_flags |= lldb::eTypeOptionSkipReferences;
86 m_flags &= ~lldb::eTypeOptionSkipReferences;
90 bool GetNonCacheable() const {
91 return (m_flags & lldb::eTypeOptionNonCacheable) ==
92 lldb::eTypeOptionNonCacheable;
95 Flags &SetNonCacheable(bool value = true) {
97 m_flags |= lldb::eTypeOptionNonCacheable;
99 m_flags &= ~lldb::eTypeOptionNonCacheable;
103 uint32_t GetValue() { return m_flags; }
105 void SetValue(uint32_t value) { m_flags = value; }
111 TypeValidatorImpl(const Flags &flags = Flags());
113 typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
115 virtual ~TypeValidatorImpl();
117 bool Cascades() const { return m_flags.GetCascades(); }
118 bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
119 bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
120 bool NonCacheable() const { return m_flags.GetNonCacheable(); }
122 void SetCascades(bool value) { m_flags.SetCascades(value); }
124 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
126 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
128 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
130 uint32_t GetOptions() { return m_flags.GetValue(); }
132 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
134 uint32_t &GetRevision() { return m_my_revision; }
136 enum class Type { eTypeUnknown, eTypeCXX };
138 struct ValidationResult {
139 TypeValidatorResult m_result;
140 std::string m_message;
143 virtual Type GetType() { return Type::eTypeUnknown; }
145 // we are using a ValueObject* instead of a ValueObjectSP because we do not
146 // need to hold on to this for extended periods of time and we trust the
147 // ValueObject to stay around for as long as it is required for us to
148 // generate its value
149 virtual ValidationResult FormatObject(ValueObject *valobj) const = 0;
151 virtual std::string GetDescription() = 0;
153 static ValidationResult Success();
155 static ValidationResult Failure(std::string message);
159 uint32_t m_my_revision;
162 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
165 class TypeValidatorImpl_CXX : public TypeValidatorImpl {
167 typedef std::function<TypeValidatorImpl::ValidationResult(
168 ValueObject *valobj)>
171 TypeValidatorImpl_CXX(ValidatorFunction f, std::string d,
172 const TypeValidatorImpl::Flags &flags = Flags());
174 typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
176 ~TypeValidatorImpl_CXX() override;
178 ValidatorFunction GetValidatorFunction() const {
179 return m_validator_function;
182 void SetValidatorFunction(ValidatorFunction f) { m_validator_function = f; }
184 TypeValidatorImpl::Type GetType() override {
185 return TypeValidatorImpl::Type::eTypeCXX;
188 ValidationResult FormatObject(ValueObject *valobj) const override;
190 std::string GetDescription() override;
193 std::string m_description;
194 ValidatorFunction m_validator_function;
197 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
200 } // namespace lldb_private
202 #endif // lldb_TypeValidator_h_