1 //===-- TypeFormat.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_TypeFormat_h_
11 #define lldb_TypeFormat_h_
16 #include <unordered_map>
19 #include "lldb/lldb-enumerations.h"
20 #include "lldb/lldb-public.h"
22 #include "lldb/Core/ValueObject.h"
24 namespace lldb_private {
25 class TypeFormatImpl {
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 TypeFormatImpl(const Flags &flags = Flags());
113 typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
115 virtual ~TypeFormatImpl();
117 bool Cascades() const { return m_flags.GetCascades(); }
119 bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
121 bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
123 bool NonCacheable() const { return m_flags.GetNonCacheable(); }
125 void SetCascades(bool value) { m_flags.SetCascades(value); }
127 void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
129 void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
131 void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
133 uint32_t GetOptions() { return m_flags.GetValue(); }
135 void SetOptions(uint32_t value) { m_flags.SetValue(value); }
137 uint32_t &GetRevision() { return m_my_revision; }
139 enum class Type { eTypeUnknown, eTypeFormat, eTypeEnum };
141 virtual Type GetType() { return Type::eTypeUnknown; }
143 // we are using a ValueObject* instead of a ValueObjectSP because we do not
144 // need to hold on to this for extended periods of time and we trust the
145 // ValueObject to stay around for as long as it is required for us to
146 // generate its value
147 virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
149 virtual std::string GetDescription() = 0;
153 uint32_t m_my_revision;
156 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl);
159 class TypeFormatImpl_Format : public TypeFormatImpl {
161 TypeFormatImpl_Format(lldb::Format f = lldb::eFormatInvalid,
162 const TypeFormatImpl::Flags &flags = Flags());
164 typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
166 ~TypeFormatImpl_Format() override;
168 lldb::Format GetFormat() const { return m_format; }
170 void SetFormat(lldb::Format fmt) { m_format = fmt; }
172 TypeFormatImpl::Type GetType() override {
173 return TypeFormatImpl::Type::eTypeFormat;
176 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
178 std::string GetDescription() override;
181 lldb::Format m_format;
184 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_Format);
187 class TypeFormatImpl_EnumType : public TypeFormatImpl {
189 TypeFormatImpl_EnumType(ConstString type_name = ConstString(""),
190 const TypeFormatImpl::Flags &flags = Flags());
192 typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
194 ~TypeFormatImpl_EnumType() override;
196 ConstString GetTypeName() { return m_enum_type; }
198 void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
200 TypeFormatImpl::Type GetType() override {
201 return TypeFormatImpl::Type::eTypeEnum;
204 bool FormatObject(ValueObject *valobj, std::string &dest) const override;
206 std::string GetDescription() override;
209 ConstString m_enum_type;
210 mutable std::unordered_map<void *, CompilerType> m_types;
213 DISALLOW_COPY_AND_ASSIGN(TypeFormatImpl_EnumType);
215 } // namespace lldb_private
217 #endif // lldb_TypeFormat_h_