1 //===-- TypeValidator.h ------------------------------------------*- C++
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_TypeValidator_h_
11 #define lldb_TypeValidator_h_
18 #include "lldb/lldb-enumerations.h"
19 #include "lldb/lldb-private-enumerations.h"
20 #include "lldb/lldb-public.h"
22 namespace lldb_private {
24 class TypeValidatorImpl {
28 Flags() : m_flags(lldb::eTypeOptionCascade) {}
30 Flags(const Flags &other) : m_flags(other.m_flags) {}
32 Flags(uint32_t value) : m_flags(value) {}
34 Flags &operator=(const Flags &rhs) {
36 m_flags = rhs.m_flags;
41 Flags &operator=(const uint32_t &rhs) {
51 bool GetCascades() const {
52 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
55 Flags &SetCascades(bool value = true) {
57 m_flags |= lldb::eTypeOptionCascade;
59 m_flags &= ~lldb::eTypeOptionCascade;
63 bool GetSkipPointers() const {
64 return (m_flags & lldb::eTypeOptionSkipPointers) ==
65 lldb::eTypeOptionSkipPointers;
68 Flags &SetSkipPointers(bool value = true) {
70 m_flags |= lldb::eTypeOptionSkipPointers;
72 m_flags &= ~lldb::eTypeOptionSkipPointers;
76 bool GetSkipReferences() const {
77 return (m_flags & lldb::eTypeOptionSkipReferences) ==
78 lldb::eTypeOptionSkipReferences;
81 Flags &SetSkipReferences(bool value = true) {
83 m_flags |= lldb::eTypeOptionSkipReferences;
85 m_flags &= ~lldb::eTypeOptionSkipReferences;
89 bool GetNonCacheable() const {
90 return (m_flags & lldb::eTypeOptionNonCacheable) ==
91 lldb::eTypeOptionNonCacheable;
94 Flags &SetNonCacheable(bool value = true) {
96 m_flags |= lldb::eTypeOptionNonCacheable;
98 m_flags &= ~lldb::eTypeOptionNonCacheable;
102 uint32_t GetValue() { return m_flags; }
104 void SetValue(uint32_t value) { m_flags = value; }
110 TypeValidatorImpl(const Flags &flags = Flags());
112 typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
114 virtual ~TypeValidatorImpl();
116 bool Cascades() const { return m_flags.GetCascades(); }
117 bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
118 bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
119 bool NonCacheable() const { return m_flags.GetNonCacheable(); }
121 void SetCascades(bool value) { m_flags.SetCascades(value); }
123 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
125 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
127 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
129 uint32_t GetOptions() { return m_flags.GetValue(); }
131 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
133 uint32_t &GetRevision() { return m_my_revision; }
135 enum class Type { eTypeUnknown, eTypeCXX };
137 struct ValidationResult {
138 TypeValidatorResult m_result;
139 std::string m_message;
142 virtual Type GetType() { return Type::eTypeUnknown; }
144 // we are using a ValueObject* instead of a ValueObjectSP because we do not
145 // need to hold on to this for extended periods of time and we trust the
146 // ValueObject to stay around for as long as it is required for us to
147 // generate its value
148 virtual ValidationResult FormatObject(ValueObject *valobj) const = 0;
150 virtual std::string GetDescription() = 0;
152 static ValidationResult Success();
154 static ValidationResult Failure(std::string message);
158 uint32_t m_my_revision;
161 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
164 class TypeValidatorImpl_CXX : public TypeValidatorImpl {
166 typedef std::function<TypeValidatorImpl::ValidationResult(
167 ValueObject *valobj)>
170 TypeValidatorImpl_CXX(ValidatorFunction f, std::string d,
171 const TypeValidatorImpl::Flags &flags = Flags());
173 typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
175 ~TypeValidatorImpl_CXX() override;
177 ValidatorFunction GetValidatorFunction() const {
178 return m_validator_function;
181 void SetValidatorFunction(ValidatorFunction f) { m_validator_function = f; }
183 TypeValidatorImpl::Type GetType() override {
184 return TypeValidatorImpl::Type::eTypeCXX;
187 ValidationResult FormatObject(ValueObject *valobj) const override;
189 std::string GetDescription() override;
192 std::string m_description;
193 ValidatorFunction m_validator_function;
196 DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
199 } // namespace lldb_private
201 #endif // lldb_TypeValidator_h_