1 //===-- TypeFormat.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_TypeFormat_h_
12 #define lldb_TypeFormat_h_
19 #include <unordered_map>
21 // Other libraries and framework includes
24 #include "lldb/lldb-enumerations.h"
25 #include "lldb/lldb-public.h"
27 #include "lldb/Core/ValueObject.h"
29 namespace lldb_private {
30 class TypeFormatImpl {
34 Flags() : m_flags(lldb::eTypeOptionCascade) {}
36 Flags(const Flags &other) : m_flags(other.m_flags) {}
38 Flags(uint32_t value) : m_flags(value) {}
40 Flags &operator=(const Flags &rhs) {
42 m_flags = rhs.m_flags;
47 Flags &operator=(const uint32_t &rhs) {
57 bool GetCascades() const {
58 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
61 Flags &SetCascades(bool value = true) {
63 m_flags |= lldb::eTypeOptionCascade;
65 m_flags &= ~lldb::eTypeOptionCascade;
69 bool GetSkipPointers() const {
70 return (m_flags & lldb::eTypeOptionSkipPointers) ==
71 lldb::eTypeOptionSkipPointers;
74 Flags &SetSkipPointers(bool value = true) {
76 m_flags |= lldb::eTypeOptionSkipPointers;
78 m_flags &= ~lldb::eTypeOptionSkipPointers;
82 bool GetSkipReferences() const {
83 return (m_flags & lldb::eTypeOptionSkipReferences) ==
84 lldb::eTypeOptionSkipReferences;
87 Flags &SetSkipReferences(bool value = true) {
89 m_flags |= lldb::eTypeOptionSkipReferences;
91 m_flags &= ~lldb::eTypeOptionSkipReferences;
95 bool GetNonCacheable() const {
96 return (m_flags & lldb::eTypeOptionNonCacheable) ==
97 lldb::eTypeOptionNonCacheable;
100 Flags &SetNonCacheable(bool value = true) {
102 m_flags |= lldb::eTypeOptionNonCacheable;
104 m_flags &= ~lldb::eTypeOptionNonCacheable;
108 uint32_t GetValue() { return m_flags; }
110 void SetValue(uint32_t value) { m_flags = value; }
116 TypeFormatImpl(const Flags &flags = Flags());
118 typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
120 virtual ~TypeFormatImpl();
122 bool Cascades() const { return m_flags.GetCascades(); }
124 bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
126 bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
128 bool NonCacheable() const { return m_flags.GetNonCacheable(); }
130 void SetCascades(bool value) { m_flags.SetCascades(value); }
132 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
134 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
136 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
138 uint32_t GetOptions() { return m_flags.GetValue(); }
140 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
142 uint32_t &GetRevision() { return m_my_revision; }
144 enum class Type { eTypeUnknown, eTypeFormat, eTypeEnum };
146 virtual Type GetType() { return Type::eTypeUnknown; }
148 // we are using a ValueObject* instead of a ValueObjectSP because we do not
149 // need to hold on to this for
150 // extended periods of time and we trust the ValueObject to stay around for as
151 // long as it is required
152 // for us to generate its value
153 virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
155 virtual std::string GetDescription() = 0;
159 uint32_t m_my_revision;
162 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl);
165 class TypeFormatImpl_Format : public TypeFormatImpl {
167 TypeFormatImpl_Format(lldb::Format f = lldb::eFormatInvalid,
168 const TypeFormatImpl::Flags &flags = Flags());
170 typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
172 ~TypeFormatImpl_Format() override;
174 lldb::Format GetFormat() const { return m_format; }
176 void SetFormat(lldb::Format fmt) { m_format = fmt; }
178 TypeFormatImpl::Type GetType() override {
179 return TypeFormatImpl::Type::eTypeFormat;
182 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
184 std::string GetDescription() override;
187 lldb::Format m_format;
190 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_Format);
193 class TypeFormatImpl_EnumType : public TypeFormatImpl {
195 TypeFormatImpl_EnumType(ConstString type_name = ConstString(""),
196 const TypeFormatImpl::Flags &flags = Flags());
198 typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
200 ~TypeFormatImpl_EnumType() override;
202 ConstString GetTypeName() { return m_enum_type; }
204 void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
206 TypeFormatImpl::Type GetType() override {
207 return TypeFormatImpl::Type::eTypeEnum;
210 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
212 std::string GetDescription() override;
215 ConstString m_enum_type;
216 mutable std::unordered_map<void *, CompilerType> m_types;
219 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType);
221 } // namespace lldb_private
223 #endif // lldb_TypeFormat_h_