1 //===-- FormatCache.cpp ------------------------------------------*- 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 //===----------------------------------------------------------------------===//
15 // Other libraries and framework includes
18 #include "lldb/DataFormatters/FormatCache.h"
21 using namespace lldb_private;
23 FormatCache::Entry::Entry()
24 : m_format_cached(false), m_summary_cached(false),
25 m_synthetic_cached(false), m_validator_cached(false), m_format_sp(),
26 m_summary_sp(), m_synthetic_sp(), m_validator_sp() {}
28 FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp)
29 : m_summary_cached(false), m_synthetic_cached(false),
30 m_validator_cached(false), m_summary_sp(), m_synthetic_sp(),
35 FormatCache::Entry::Entry(lldb::TypeSummaryImplSP summary_sp)
36 : m_format_cached(false), m_synthetic_cached(false),
37 m_validator_cached(false), m_format_sp(), m_synthetic_sp(),
39 SetSummary(summary_sp);
42 FormatCache::Entry::Entry(lldb::SyntheticChildrenSP synthetic_sp)
43 : m_format_cached(false), m_summary_cached(false),
44 m_validator_cached(false), m_format_sp(), m_summary_sp(),
46 SetSynthetic(synthetic_sp);
49 FormatCache::Entry::Entry(lldb::TypeValidatorImplSP validator_sp)
50 : m_format_cached(false), m_summary_cached(false),
51 m_synthetic_cached(false), m_format_sp(), m_summary_sp(),
53 SetValidator(validator_sp);
56 FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp,
57 lldb::TypeSummaryImplSP summary_sp,
58 lldb::SyntheticChildrenSP synthetic_sp,
59 lldb::TypeValidatorImplSP validator_sp) {
61 SetSummary(summary_sp);
62 SetSynthetic(synthetic_sp);
63 SetValidator(validator_sp);
66 bool FormatCache::Entry::IsFormatCached() { return m_format_cached; }
68 bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; }
70 bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; }
72 bool FormatCache::Entry::IsValidatorCached() { return m_validator_cached; }
74 lldb::TypeFormatImplSP FormatCache::Entry::GetFormat() { return m_format_sp; }
76 lldb::TypeSummaryImplSP FormatCache::Entry::GetSummary() {
80 lldb::SyntheticChildrenSP FormatCache::Entry::GetSynthetic() {
81 return m_synthetic_sp;
84 lldb::TypeValidatorImplSP FormatCache::Entry::GetValidator() {
85 return m_validator_sp;
88 void FormatCache::Entry::SetFormat(lldb::TypeFormatImplSP format_sp) {
89 m_format_cached = true;
90 m_format_sp = format_sp;
93 void FormatCache::Entry::SetSummary(lldb::TypeSummaryImplSP summary_sp) {
94 m_summary_cached = true;
95 m_summary_sp = summary_sp;
98 void FormatCache::Entry::SetSynthetic(lldb::SyntheticChildrenSP synthetic_sp) {
99 m_synthetic_cached = true;
100 m_synthetic_sp = synthetic_sp;
103 void FormatCache::Entry::SetValidator(lldb::TypeValidatorImplSP validator_sp) {
104 m_validator_cached = true;
105 m_validator_sp = validator_sp;
108 FormatCache::FormatCache()
110 #ifdef LLDB_CONFIGURATION_DEBUG
112 m_cache_hits(0), m_cache_misses(0)
117 FormatCache::Entry &FormatCache::GetEntry(const ConstString &type) {
118 auto i = m_map.find(type), e = m_map.end();
121 m_map[type] = FormatCache::Entry();
125 bool FormatCache::GetFormat(const ConstString &type,
126 lldb::TypeFormatImplSP &format_sp) {
127 std::lock_guard<std::recursive_mutex> guard(m_mutex);
128 auto entry = GetEntry(type);
129 if (entry.IsFormatCached()) {
130 #ifdef LLDB_CONFIGURATION_DEBUG
133 format_sp = entry.GetFormat();
136 #ifdef LLDB_CONFIGURATION_DEBUG
143 bool FormatCache::GetSummary(const ConstString &type,
144 lldb::TypeSummaryImplSP &summary_sp) {
145 std::lock_guard<std::recursive_mutex> guard(m_mutex);
146 auto entry = GetEntry(type);
147 if (entry.IsSummaryCached()) {
148 #ifdef LLDB_CONFIGURATION_DEBUG
151 summary_sp = entry.GetSummary();
154 #ifdef LLDB_CONFIGURATION_DEBUG
161 bool FormatCache::GetSynthetic(const ConstString &type,
162 lldb::SyntheticChildrenSP &synthetic_sp) {
163 std::lock_guard<std::recursive_mutex> guard(m_mutex);
164 auto entry = GetEntry(type);
165 if (entry.IsSyntheticCached()) {
166 #ifdef LLDB_CONFIGURATION_DEBUG
169 synthetic_sp = entry.GetSynthetic();
172 #ifdef LLDB_CONFIGURATION_DEBUG
175 synthetic_sp.reset();
179 bool FormatCache::GetValidator(const ConstString &type,
180 lldb::TypeValidatorImplSP &validator_sp) {
181 std::lock_guard<std::recursive_mutex> guard(m_mutex);
182 auto entry = GetEntry(type);
183 if (entry.IsValidatorCached()) {
184 #ifdef LLDB_CONFIGURATION_DEBUG
187 validator_sp = entry.GetValidator();
190 #ifdef LLDB_CONFIGURATION_DEBUG
193 validator_sp.reset();
197 void FormatCache::SetFormat(const ConstString &type,
198 lldb::TypeFormatImplSP &format_sp) {
199 std::lock_guard<std::recursive_mutex> guard(m_mutex);
200 GetEntry(type).SetFormat(format_sp);
203 void FormatCache::SetSummary(const ConstString &type,
204 lldb::TypeSummaryImplSP &summary_sp) {
205 std::lock_guard<std::recursive_mutex> guard(m_mutex);
206 GetEntry(type).SetSummary(summary_sp);
209 void FormatCache::SetSynthetic(const ConstString &type,
210 lldb::SyntheticChildrenSP &synthetic_sp) {
211 std::lock_guard<std::recursive_mutex> guard(m_mutex);
212 GetEntry(type).SetSynthetic(synthetic_sp);
215 void FormatCache::SetValidator(const ConstString &type,
216 lldb::TypeValidatorImplSP &validator_sp) {
217 std::lock_guard<std::recursive_mutex> guard(m_mutex);
218 GetEntry(type).SetValidator(validator_sp);
221 void FormatCache::Clear() {
222 std::lock_guard<std::recursive_mutex> guard(m_mutex);