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 //===----------------------------------------------------------------------===//
14 #include "lldb/DataFormatters/FormatCache.h"
17 using namespace lldb_private;
19 FormatCache::Entry::Entry()
20 : m_format_cached(false), m_summary_cached(false),
21 m_synthetic_cached(false), m_validator_cached(false), m_format_sp(),
22 m_summary_sp(), m_synthetic_sp(), m_validator_sp() {}
24 FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp)
25 : m_summary_cached(false), m_synthetic_cached(false),
26 m_validator_cached(false), m_summary_sp(), m_synthetic_sp(),
31 FormatCache::Entry::Entry(lldb::TypeSummaryImplSP summary_sp)
32 : m_format_cached(false), m_synthetic_cached(false),
33 m_validator_cached(false), m_format_sp(), m_synthetic_sp(),
35 SetSummary(summary_sp);
38 FormatCache::Entry::Entry(lldb::SyntheticChildrenSP synthetic_sp)
39 : m_format_cached(false), m_summary_cached(false),
40 m_validator_cached(false), m_format_sp(), m_summary_sp(),
42 SetSynthetic(synthetic_sp);
45 FormatCache::Entry::Entry(lldb::TypeValidatorImplSP validator_sp)
46 : m_format_cached(false), m_summary_cached(false),
47 m_synthetic_cached(false), m_format_sp(), m_summary_sp(),
49 SetValidator(validator_sp);
52 FormatCache::Entry::Entry(lldb::TypeFormatImplSP format_sp,
53 lldb::TypeSummaryImplSP summary_sp,
54 lldb::SyntheticChildrenSP synthetic_sp,
55 lldb::TypeValidatorImplSP validator_sp) {
57 SetSummary(summary_sp);
58 SetSynthetic(synthetic_sp);
59 SetValidator(validator_sp);
62 bool FormatCache::Entry::IsFormatCached() { return m_format_cached; }
64 bool FormatCache::Entry::IsSummaryCached() { return m_summary_cached; }
66 bool FormatCache::Entry::IsSyntheticCached() { return m_synthetic_cached; }
68 bool FormatCache::Entry::IsValidatorCached() { return m_validator_cached; }
70 lldb::TypeFormatImplSP FormatCache::Entry::GetFormat() { return m_format_sp; }
72 lldb::TypeSummaryImplSP FormatCache::Entry::GetSummary() {
76 lldb::SyntheticChildrenSP FormatCache::Entry::GetSynthetic() {
77 return m_synthetic_sp;
80 lldb::TypeValidatorImplSP FormatCache::Entry::GetValidator() {
81 return m_validator_sp;
84 void FormatCache::Entry::SetFormat(lldb::TypeFormatImplSP format_sp) {
85 m_format_cached = true;
86 m_format_sp = format_sp;
89 void FormatCache::Entry::SetSummary(lldb::TypeSummaryImplSP summary_sp) {
90 m_summary_cached = true;
91 m_summary_sp = summary_sp;
94 void FormatCache::Entry::SetSynthetic(lldb::SyntheticChildrenSP synthetic_sp) {
95 m_synthetic_cached = true;
96 m_synthetic_sp = synthetic_sp;
99 void FormatCache::Entry::SetValidator(lldb::TypeValidatorImplSP validator_sp) {
100 m_validator_cached = true;
101 m_validator_sp = validator_sp;
104 FormatCache::FormatCache()
106 #ifdef LLDB_CONFIGURATION_DEBUG
108 m_cache_hits(0), m_cache_misses(0)
113 FormatCache::Entry &FormatCache::GetEntry(const ConstString &type) {
114 auto i = m_map.find(type), e = m_map.end();
117 m_map[type] = FormatCache::Entry();
121 bool FormatCache::GetFormat(const ConstString &type,
122 lldb::TypeFormatImplSP &format_sp) {
123 std::lock_guard<std::recursive_mutex> guard(m_mutex);
124 auto entry = GetEntry(type);
125 if (entry.IsFormatCached()) {
126 #ifdef LLDB_CONFIGURATION_DEBUG
129 format_sp = entry.GetFormat();
132 #ifdef LLDB_CONFIGURATION_DEBUG
139 bool FormatCache::GetSummary(const ConstString &type,
140 lldb::TypeSummaryImplSP &summary_sp) {
141 std::lock_guard<std::recursive_mutex> guard(m_mutex);
142 auto entry = GetEntry(type);
143 if (entry.IsSummaryCached()) {
144 #ifdef LLDB_CONFIGURATION_DEBUG
147 summary_sp = entry.GetSummary();
150 #ifdef LLDB_CONFIGURATION_DEBUG
157 bool FormatCache::GetSynthetic(const ConstString &type,
158 lldb::SyntheticChildrenSP &synthetic_sp) {
159 std::lock_guard<std::recursive_mutex> guard(m_mutex);
160 auto entry = GetEntry(type);
161 if (entry.IsSyntheticCached()) {
162 #ifdef LLDB_CONFIGURATION_DEBUG
165 synthetic_sp = entry.GetSynthetic();
168 #ifdef LLDB_CONFIGURATION_DEBUG
171 synthetic_sp.reset();
175 bool FormatCache::GetValidator(const ConstString &type,
176 lldb::TypeValidatorImplSP &validator_sp) {
177 std::lock_guard<std::recursive_mutex> guard(m_mutex);
178 auto entry = GetEntry(type);
179 if (entry.IsValidatorCached()) {
180 #ifdef LLDB_CONFIGURATION_DEBUG
183 validator_sp = entry.GetValidator();
186 #ifdef LLDB_CONFIGURATION_DEBUG
189 validator_sp.reset();
193 void FormatCache::SetFormat(const ConstString &type,
194 lldb::TypeFormatImplSP &format_sp) {
195 std::lock_guard<std::recursive_mutex> guard(m_mutex);
196 GetEntry(type).SetFormat(format_sp);
199 void FormatCache::SetSummary(const ConstString &type,
200 lldb::TypeSummaryImplSP &summary_sp) {
201 std::lock_guard<std::recursive_mutex> guard(m_mutex);
202 GetEntry(type).SetSummary(summary_sp);
205 void FormatCache::SetSynthetic(const ConstString &type,
206 lldb::SyntheticChildrenSP &synthetic_sp) {
207 std::lock_guard<std::recursive_mutex> guard(m_mutex);
208 GetEntry(type).SetSynthetic(synthetic_sp);
211 void FormatCache::SetValidator(const ConstString &type,
212 lldb::TypeValidatorImplSP &validator_sp) {
213 std::lock_guard<std::recursive_mutex> guard(m_mutex);
214 GetEntry(type).SetValidator(validator_sp);
217 void FormatCache::Clear() {
218 std::lock_guard<std::recursive_mutex> guard(m_mutex);