LLDB  mainline
TypeValidator.h
Go to the documentation of this file.
1 //===-- TypeValidator.h ------------------------------------------*- C++
2 //-*-===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef lldb_TypeValidator_h_
11 #define lldb_TypeValidator_h_
12 
13 
14 #include <functional>
15 #include <string>
16 
17 
18 #include "lldb/lldb-enumerations.h"
20 #include "lldb/lldb-public.h"
21 
22 namespace lldb_private {
23 
25 public:
26  class Flags {
27  public:
28  Flags() : m_flags(lldb::eTypeOptionCascade) {}
29 
30  Flags(const Flags &other) : m_flags(other.m_flags) {}
31 
32  Flags(uint32_t value) : m_flags(value) {}
33 
34  Flags &operator=(const Flags &rhs) {
35  if (&rhs != this)
36  m_flags = rhs.m_flags;
37 
38  return *this;
39  }
40 
41  Flags &operator=(const uint32_t &rhs) {
42  m_flags = rhs;
43  return *this;
44  }
45 
46  Flags &Clear() {
47  m_flags = 0;
48  return *this;
49  }
50 
51  bool GetCascades() const {
52  return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
53  }
54 
55  Flags &SetCascades(bool value = true) {
56  if (value)
57  m_flags |= lldb::eTypeOptionCascade;
58  else
59  m_flags &= ~lldb::eTypeOptionCascade;
60  return *this;
61  }
62 
63  bool GetSkipPointers() const {
64  return (m_flags & lldb::eTypeOptionSkipPointers) ==
65  lldb::eTypeOptionSkipPointers;
66  }
67 
68  Flags &SetSkipPointers(bool value = true) {
69  if (value)
70  m_flags |= lldb::eTypeOptionSkipPointers;
71  else
72  m_flags &= ~lldb::eTypeOptionSkipPointers;
73  return *this;
74  }
75 
76  bool GetSkipReferences() const {
77  return (m_flags & lldb::eTypeOptionSkipReferences) ==
78  lldb::eTypeOptionSkipReferences;
79  }
80 
81  Flags &SetSkipReferences(bool value = true) {
82  if (value)
83  m_flags |= lldb::eTypeOptionSkipReferences;
84  else
85  m_flags &= ~lldb::eTypeOptionSkipReferences;
86  return *this;
87  }
88 
89  bool GetNonCacheable() const {
90  return (m_flags & lldb::eTypeOptionNonCacheable) ==
91  lldb::eTypeOptionNonCacheable;
92  }
93 
94  Flags &SetNonCacheable(bool value = true) {
95  if (value)
96  m_flags |= lldb::eTypeOptionNonCacheable;
97  else
98  m_flags &= ~lldb::eTypeOptionNonCacheable;
99  return *this;
100  }
101 
102  uint32_t GetValue() { return m_flags; }
103 
104  void SetValue(uint32_t value) { m_flags = value; }
105 
106  private:
107  uint32_t m_flags;
108  };
109 
110  TypeValidatorImpl(const Flags &flags = Flags());
111 
112  typedef std::shared_ptr<TypeValidatorImpl> SharedPointer;
113 
114  virtual ~TypeValidatorImpl();
115 
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(); }
120 
121  void SetCascades(bool value) { m_flags.SetCascades(value); }
122 
123  void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
124 
125  void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
126 
127  void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
128 
129  uint32_t GetOptions() { return m_flags.GetValue(); }
130 
131  void SetOptions(uint32_t value) { m_flags.SetValue(value); }
132 
134 
135  enum class Type { eTypeUnknown, eTypeCXX };
136 
139  std::string m_message;
140  };
141 
142  virtual Type GetType() { return Type::eTypeUnknown; }
143 
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;
149 
150  virtual std::string GetDescription() = 0;
151 
152  static ValidationResult Success();
153 
154  static ValidationResult Failure(std::string message);
155 
156 protected:
159 
160 private:
161  DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl);
162 };
163 
165 public:
166  typedef std::function<TypeValidatorImpl::ValidationResult(
167  ValueObject *valobj)>
169 
170  TypeValidatorImpl_CXX(ValidatorFunction f, std::string d,
171  const TypeValidatorImpl::Flags &flags = Flags());
172 
173  typedef std::shared_ptr<TypeValidatorImpl_CXX> SharedPointer;
174 
175  ~TypeValidatorImpl_CXX() override;
176 
178  return m_validator_function;
179  }
180 
181  void SetValidatorFunction(ValidatorFunction f) { m_validator_function = f; }
182 
185  }
186 
187  ValidationResult FormatObject(ValueObject *valobj) const override;
188 
189  std::string GetDescription() override;
190 
191 protected:
192  std::string m_description;
194 
195 private:
196  DISALLOW_COPY_AND_ASSIGN(TypeValidatorImpl_CXX);
197 };
198 
199 } // namespace lldb_private
200 
201 #endif // lldb_TypeValidator_h_
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
static ValidationResult Failure(std::string message)
Flags & SetCascades(bool value=true)
Definition: TypeValidator.h:55
std::shared_ptr< TypeValidatorImpl_CXX > SharedPointer
ValidatorFunction GetValidatorFunction() const
Flags & SetNonCacheable(bool value=true)
Definition: TypeValidator.h:94
Flags & SetSkipReferences(bool value=true)
Definition: TypeValidator.h:81
Flags & SetSkipPointers(bool value=true)
Definition: TypeValidator.h:68
void SetSkipsReferences(bool value)
void SetValidatorFunction(ValidatorFunction f)
TypeValidatorImpl::Type GetType() override
Flags & operator=(const uint32_t &rhs)
Definition: TypeValidator.h:41
static ValidationResult Success()
TypeValidatorImpl(const Flags &flags=Flags())
std::shared_ptr< TypeValidatorImpl > SharedPointer
Definition: SBAddress.h:15
virtual std::string GetDescription()=0
Flags & operator=(const Flags &rhs)
Definition: TypeValidator.h:34
std::function< TypeValidatorImpl::ValidationResult(ValueObject *valobj)> ValidatorFunction
virtual ValidationResult FormatObject(ValueObject *valobj) const =0
void SetOptions(uint32_t value)