Coverage Report

Created: 2022-01-25 06:29

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/DataFormatters/TypeFormat.h
Line
Count
Source (jump to first uncovered line)
1
//===-- TypeFormat.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_DATAFORMATTERS_TYPEFORMAT_H
11
#define LLDB_DATAFORMATTERS_TYPEFORMAT_H
12
13
#include <functional>
14
#include <string>
15
#include <unordered_map>
16
17
18
#include "lldb/lldb-enumerations.h"
19
#include "lldb/lldb-public.h"
20
21
#include "lldb/Core/ValueObject.h"
22
23
namespace lldb_private {
24
class TypeFormatImpl {
25
public:
26
  class Flags {
27
  public:
28
54.7k
    Flags() {}
29
30
55.4k
    Flags(const Flags &other) : m_flags(other.m_flags) {}
31
32
3
    Flags(uint32_t value) : m_flags(value) {}
33
34
0
    Flags &operator=(const Flags &rhs) {
35
0
      if (&rhs != this)
36
0
        m_flags = rhs.m_flags;
37
0
38
0
      return *this;
39
0
    }
40
41
0
    Flags &operator=(const uint32_t &rhs) {
42
0
      m_flags = rhs;
43
0
      return *this;
44
0
    }
45
46
0
    Flags &Clear() {
47
0
      m_flags = 0;
48
0
      return *this;
49
0
    }
50
51
119
    bool GetCascades() const {
52
119
      return (m_flags & lldb::eTypeOptionCascade) == lldb::eTypeOptionCascade;
53
119
    }
54
55
694
    Flags &SetCascades(bool value = true) {
56
694
      if (value)
57
688
        m_flags |= lldb::eTypeOptionCascade;
58
6
      else
59
6
        m_flags &= ~lldb::eTypeOptionCascade;
60
694
      return *this;
61
694
    }
62
63
110
    bool GetSkipPointers() const {
64
110
      return (m_flags & lldb::eTypeOptionSkipPointers) ==
65
110
             lldb::eTypeOptionSkipPointers;
66
110
    }
67
68
694
    Flags &SetSkipPointers(bool value = true) {
69
694
      if (value)
70
662
        m_flags |= lldb::eTypeOptionSkipPointers;
71
32
      else
72
32
        m_flags &= ~lldb::eTypeOptionSkipPointers;
73
694
      return *this;
74
694
    }
75
76
110
    bool GetSkipReferences() const {
77
110
      return (m_flags & lldb::eTypeOptionSkipReferences) ==
78
110
             lldb::eTypeOptionSkipReferences;
79
110
    }
80
81
694
    Flags &SetSkipReferences(bool value = true) {
82
694
      if (value)
83
662
        m_flags |= lldb::eTypeOptionSkipReferences;
84
32
      else
85
32
        m_flags &= ~lldb::eTypeOptionSkipReferences;
86
694
      return *this;
87
694
    }
88
89
74
    bool GetNonCacheable() const {
90
74
      return (m_flags & lldb::eTypeOptionNonCacheable) ==
91
74
             lldb::eTypeOptionNonCacheable;
92
74
    }
93
94
0
    Flags &SetNonCacheable(bool value = true) {
95
0
      if (value)
96
0
        m_flags |= lldb::eTypeOptionNonCacheable;
97
0
      else
98
0
        m_flags &= ~lldb::eTypeOptionNonCacheable;
99
0
      return *this;
100
0
    }
101
102
1
    uint32_t GetValue() { return m_flags; }
103
104
0
    void SetValue(uint32_t value) { m_flags = value; }
105
106
  private:
107
    uint32_t m_flags = lldb::eTypeOptionCascade;
108
  };
109
110
  TypeFormatImpl(const Flags &flags = Flags());
111
112
  typedef std::shared_ptr<TypeFormatImpl> SharedPointer;
113
114
  virtual ~TypeFormatImpl();
115
116
119
  bool Cascades() const { return m_flags.GetCascades(); }
117
118
110
  bool SkipsPointers() const { return m_flags.GetSkipPointers(); }
119
120
110
  bool SkipsReferences() const { return m_flags.GetSkipReferences(); }
121
122
74
  bool NonCacheable() const { return m_flags.GetNonCacheable(); }
123
124
0
  void SetCascades(bool value) { m_flags.SetCascades(value); }
125
126
0
  void SetSkipsPointers(bool value) { m_flags.SetSkipPointers(value); }
127
128
0
  void SetSkipsReferences(bool value) { m_flags.SetSkipReferences(value); }
129
130
0
  void SetNonCacheable(bool value) { m_flags.SetNonCacheable(value); }
131
132
1
  uint32_t GetOptions() { return m_flags.GetValue(); }
133
134
0
  void SetOptions(uint32_t value) { m_flags.SetValue(value); }
135
136
700
  uint32_t &GetRevision() { return m_my_revision; }
137
138
  enum class Type { eTypeUnknown, eTypeFormat, eTypeEnum };
139
140
0
  virtual Type GetType() { return Type::eTypeUnknown; }
141
142
  // we are using a ValueObject* instead of a ValueObjectSP because we do not
143
  // need to hold on to this for extended periods of time and we trust the
144
  // ValueObject to stay around for as long as it is required for us to
145
  // generate its value
146
  virtual bool FormatObject(ValueObject *valobj, std::string &dest) const = 0;
147
148
  virtual std::string GetDescription() = 0;
149
150
protected:
151
  Flags m_flags;
152
  uint32_t m_my_revision = 0;
153
154
private:
155
  TypeFormatImpl(const TypeFormatImpl &) = delete;
156
  const TypeFormatImpl &operator=(const TypeFormatImpl &) = delete;
157
};
158
159
class TypeFormatImpl_Format : public TypeFormatImpl {
160
public:
161
  TypeFormatImpl_Format(lldb::Format f = lldb::eFormatInvalid,
162
                        const TypeFormatImpl::Flags &flags = Flags());
163
164
  typedef std::shared_ptr<TypeFormatImpl_Format> SharedPointer;
165
166
  ~TypeFormatImpl_Format() override;
167
168
84.6k
  lldb::Format GetFormat() const { return m_format; }
169
170
1
  void SetFormat(lldb::Format fmt) { m_format = fmt; }
171
172
1
  TypeFormatImpl::Type GetType() override {
173
1
    return TypeFormatImpl::Type::eTypeFormat;
174
1
  }
175
176
  bool FormatObject(ValueObject *valobj, std::string &dest) const override;
177
178
  std::string GetDescription() override;
179
180
protected:
181
  lldb::Format m_format;
182
183
private:
184
  TypeFormatImpl_Format(const TypeFormatImpl_Format &) = delete;
185
  const TypeFormatImpl_Format &
186
  operator=(const TypeFormatImpl_Format &) = delete;
187
};
188
189
class TypeFormatImpl_EnumType : public TypeFormatImpl {
190
public:
191
  TypeFormatImpl_EnumType(ConstString type_name = ConstString(""),
192
                          const TypeFormatImpl::Flags &flags = Flags());
193
194
  typedef std::shared_ptr<TypeFormatImpl_EnumType> SharedPointer;
195
196
  ~TypeFormatImpl_EnumType() override;
197
198
0
  ConstString GetTypeName() { return m_enum_type; }
199
200
0
  void SetTypeName(ConstString enum_type) { m_enum_type = enum_type; }
201
202
0
  TypeFormatImpl::Type GetType() override {
203
0
    return TypeFormatImpl::Type::eTypeEnum;
204
0
  }
205
206
  bool FormatObject(ValueObject *valobj, std::string &dest) const override;
207
208
  std::string GetDescription() override;
209
210
protected:
211
  ConstString m_enum_type;
212
  mutable std::unordered_map<void *, CompilerType> m_types;
213
214
private:
215
  TypeFormatImpl_EnumType(const TypeFormatImpl_EnumType &) = delete;
216
  const TypeFormatImpl_EnumType &
217
  operator=(const TypeFormatImpl_EnumType &) = delete;
218
};
219
} // namespace lldb_private
220
221
#endif // LLDB_DATAFORMATTERS_TYPEFORMAT_H