1 //===-- FormatCache.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
14 // Other libraries and framework includes
17 #include "lldb/DataFormatters/FormatCache.h"
20 using namespace lldb_private;
22 FormatCache::Entry::Entry () :
23 m_format_cached(false),
24 m_summary_cached(false),
25 m_synthetic_cached(false),
26 m_validator_cached(false),
33 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) :
34 m_summary_cached(false),
35 m_synthetic_cached(false),
36 m_validator_cached(false),
41 SetFormat (format_sp);
44 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
45 m_format_cached(false),
46 m_synthetic_cached(false),
47 m_validator_cached(false),
52 SetSummary (summary_sp);
55 FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
56 m_format_cached(false),
57 m_summary_cached(false),
58 m_validator_cached(false),
63 SetSynthetic (synthetic_sp);
66 FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) :
67 m_format_cached(false),
68 m_summary_cached(false),
69 m_synthetic_cached(false),
74 SetValidator (validator_sp);
77 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp)
79 SetFormat (format_sp);
80 SetSummary (summary_sp);
81 SetSynthetic (synthetic_sp);
82 SetValidator (validator_sp);
86 FormatCache::Entry::IsFormatCached ()
88 return m_format_cached;
92 FormatCache::Entry::IsSummaryCached ()
94 return m_summary_cached;
98 FormatCache::Entry::IsSyntheticCached ()
100 return m_synthetic_cached;
104 FormatCache::Entry::IsValidatorCached ()
106 return m_validator_cached;
109 lldb::TypeFormatImplSP
110 FormatCache::Entry::GetFormat ()
115 lldb::TypeSummaryImplSP
116 FormatCache::Entry::GetSummary ()
121 lldb::SyntheticChildrenSP
122 FormatCache::Entry::GetSynthetic ()
124 return m_synthetic_sp;
127 lldb::TypeValidatorImplSP
128 FormatCache::Entry::GetValidator ()
130 return m_validator_sp;
134 FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
136 m_format_cached = true;
137 m_format_sp = format_sp;
141 FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
143 m_summary_cached = true;
144 m_summary_sp = summary_sp;
148 FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
150 m_synthetic_cached = true;
151 m_synthetic_sp = synthetic_sp;
155 FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp)
157 m_validator_cached = true;
158 m_validator_sp = validator_sp;
161 FormatCache::FormatCache () :
163 m_mutex (Mutex::eMutexTypeRecursive)
164 #ifdef LLDB_CONFIGURATION_DEBUG
165 ,m_cache_hits(0),m_cache_misses(0)
171 FormatCache::GetEntry (const ConstString& type)
173 auto i = m_map.find(type),
177 m_map[type] = FormatCache::Entry();
182 FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
184 Mutex::Locker lock(m_mutex);
185 auto entry = GetEntry(type);
186 if (entry.IsSummaryCached())
188 #ifdef LLDB_CONFIGURATION_DEBUG
191 format_sp = entry.GetFormat();
194 #ifdef LLDB_CONFIGURATION_DEBUG
202 FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
204 Mutex::Locker lock(m_mutex);
205 auto entry = GetEntry(type);
206 if (entry.IsSummaryCached())
208 #ifdef LLDB_CONFIGURATION_DEBUG
211 summary_sp = entry.GetSummary();
214 #ifdef LLDB_CONFIGURATION_DEBUG
222 FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
224 Mutex::Locker lock(m_mutex);
225 auto entry = GetEntry(type);
226 if (entry.IsSyntheticCached())
228 #ifdef LLDB_CONFIGURATION_DEBUG
231 synthetic_sp = entry.GetSynthetic();
234 #ifdef LLDB_CONFIGURATION_DEBUG
237 synthetic_sp.reset();
242 FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
244 Mutex::Locker lock(m_mutex);
245 auto entry = GetEntry(type);
246 if (entry.IsValidatorCached())
248 #ifdef LLDB_CONFIGURATION_DEBUG
251 validator_sp = entry.GetValidator();
254 #ifdef LLDB_CONFIGURATION_DEBUG
257 validator_sp.reset();
262 FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
264 Mutex::Locker lock(m_mutex);
265 GetEntry(type).SetFormat(format_sp);
269 FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
271 Mutex::Locker lock(m_mutex);
272 GetEntry(type).SetSummary(summary_sp);
276 FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
278 Mutex::Locker lock(m_mutex);
279 GetEntry(type).SetSynthetic(synthetic_sp);
283 FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
285 Mutex::Locker lock(m_mutex);
286 GetEntry(type).SetValidator(validator_sp);
290 FormatCache::Clear ()
292 Mutex::Locker lock(m_mutex);