File indexing completed on 2026-05-10 08:42:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef LLDB_DATAFORMATTERS_TYPEFORMAT_H
0011 #define LLDB_DATAFORMATTERS_TYPEFORMAT_H
0012
0013 #include <functional>
0014 #include <string>
0015 #include <unordered_map>
0016
0017
0018 #include "lldb/lldb-enumerations.h"
0019 #include "lldb/lldb-public.h"
0020
0021 #include "lldb/ValueObject/ValueObject.h"
0022
0023 namespace lldb_private {
0024 class TypeFormatImpl {
0025 public:
0026 class Flags {
0027 public:
0028 Flags() {}
0029
0030 Flags(const Flags &other) : m_flags(other.m_flags) {}
0031
0032 Flags(uint32_t value) : m_flags(value) {}
0033
0034 Flags &operator=(const Flags &rhs) {
0035 if (&rhs != this)
0036 m_flags = rhs.m_flags;
0037
0038 return *this;
0039 }
0040
0041 Flags &operator=(const uint32_t &rhs) {
0042 m_flags = rhs;
0043 return *this;
0044 }
0045
0046 Flags &Clear() {
0047 m_flags = 0;
0048 return *this;
0049 }
0050
0051 bool GetCascades() const {
0052 return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
0053 }
0054
0055 Flags &SetCascades(bool value = true) {
0056 if (value)
0057 m_flags |= lldb::eTypeOptionCascade;
0058 else
0059 m_flags &= ~lldb::eTypeOptionCascade;
0060 return *this;
0061 }
0062
0063 bool GetSkipPointers() const {
0064 return (m_flags & lldb::eTypeOptionSkipPointers) ==
0065 lldb::eTypeOptionSkipPointers;
0066 }
0067
0068 Flags &SetSkipPointers(bool value = true) {
0069 if (value)
0070 m_flags |= lldb::eTypeOptionSkipPointers;
0071 else
0072 m_flags &= ~lldb::eTypeOptionSkipPointers;
0073 return *this;
0074 }
0075
0076 bool GetSkipReferences() const {
0077 return (m_flags & lldb::eTypeOptionSkipReferences) ==
0078 lldb::eTypeOptionSkipReferences;
0079 }
0080
0081 Flags &SetSkipReferences(bool value = true) {
0082 if (value)
0083 m_flags |= lldb::eTypeOptionSkipReferences;
0084 else
0085 m_flags &= ~lldb::eTypeOptionSkipReferences;
0086 return *this;
0087 }
0088
0089 bool GetNonCacheable() const {
0090 return (m_flags & lldb::eTypeOptionNonCacheable) ==
0091 lldb::eTypeOptionNonCacheable;
0092 }
0093
0094 Flags &SetNonCacheable(bool value = true) {
0095 if (value)
0096 m_flags |= lldb::eTypeOptionNonCacheable;
0097 else
0098 m_flags &= ~lldb::eTypeOptionNonCacheable;
0099 return *this;
0100 }
0101
0102 uint32_t GetValue() { return m_flags; }
0103
0104 void SetValue(uint32_t value) { m_flags = value; }
0105
0106 private:
0107 uint32_t m_flags = lldb::eTypeOptionCascade;
0108 };
0109
0110 TypeFormatImpl(const Flags &flags = Flags());
0111
0112 typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
0113
0114 virtual ~TypeFormatImpl();
0115
0116 bool Cascades() const { return m_flags.GetCascades(); }
0117
0118 bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
0119
0120 bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
0121
0122 bool NonCacheable() const { return m_flags.GetNonCacheable(); }
0123
0124 void SetCascades(bool value) { m_flags.SetCascades(value); }
0125
0126 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
0127
0128 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
0129
0130 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
0131
0132 uint32_t GetOptions() { return m_flags.GetValue(); }
0133
0134 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
0135
0136 uint32_t &GetRevision() { return m_my_revision; }
0137
0138 enum class Type { eTypeUnknown, eTypeFormat, eTypeEnum };
0139
0140 virtual Type GetType() { return Type::eTypeUnknown; }
0141
0142
0143
0144
0145
0146 virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
0147
0148 virtual std::string GetDescription() = 0;
0149
0150 protected:
0151 Flags m_flags;
0152 uint32_t m_my_revision = 0;
0153
0154 private:
0155 TypeFormatImpl(const TypeFormatImpl &) = delete;
0156 const TypeFormatImpl &operator=(const TypeFormatImpl &) = delete;
0157 };
0158
0159 class TypeFormatImpl_Format : public TypeFormatImpl {
0160 public:
0161 TypeFormatImpl_Format(lldb::Format f = lldb::eFormatInvalid,
0162 const TypeFormatImpl::Flags &flags = Flags());
0163
0164 typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
0165
0166 ~TypeFormatImpl_Format() override;
0167
0168 lldb::Format GetFormat() const { return m_format; }
0169
0170 void SetFormat(lldb::Format fmt) { m_format = fmt; }
0171
0172 TypeFormatImpl::Type GetType() override {
0173 return TypeFormatImpl::Type::eTypeFormat;
0174 }
0175
0176 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
0177
0178 std::string GetDescription() override;
0179
0180 protected:
0181 lldb::Format m_format;
0182
0183 private:
0184 TypeFormatImpl_Format(const TypeFormatImpl_Format &) = delete;
0185 const TypeFormatImpl_Format &
0186 operator=(const TypeFormatImpl_Format &) = delete;
0187 };
0188
0189 class TypeFormatImpl_EnumType : public TypeFormatImpl {
0190 public:
0191 TypeFormatImpl_EnumType(ConstString type_name = ConstString(""),
0192 const TypeFormatImpl::Flags &flags = Flags());
0193
0194 typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
0195
0196 ~TypeFormatImpl_EnumType() override;
0197
0198 ConstString GetTypeName() { return m_enum_type; }
0199
0200 void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
0201
0202 TypeFormatImpl::Type GetType() override {
0203 return TypeFormatImpl::Type::eTypeEnum;
0204 }
0205
0206 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
0207
0208 std::string GetDescription() override;
0209
0210 protected:
0211 ConstString m_enum_type;
0212 mutable std::unordered_map<void *, CompilerType> m_types;
0213
0214 private:
0215 TypeFormatImpl_EnumType(const TypeFormatImpl_EnumType &) = delete;
0216 const TypeFormatImpl_EnumType &
0217 operator=(const TypeFormatImpl_EnumType &) = delete;
0218 };
0219 }
0220
0221 #endif