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 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
16 // Other libraries and framework includes
19 #include "lldb/DataFormatters/FormatCache.h"
22 using namespace lldb_private;
24 FormatCache::Entry::Entry () :
25 m_format_cached(false),
26 m_summary_cached(false),
27 m_synthetic_cached(false),
28 m_validator_cached(false),
35 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) :
36 m_summary_cached(false),
37 m_synthetic_cached(false),
38 m_validator_cached(false),
43 SetFormat (format_sp);
46 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
47 m_format_cached(false),
48 m_synthetic_cached(false),
49 m_validator_cached(false),
54 SetSummary (summary_sp);
57 FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
58 m_format_cached(false),
59 m_summary_cached(false),
60 m_validator_cached(false),
65 SetSynthetic (synthetic_sp);
68 FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) :
69 m_format_cached(false),
70 m_summary_cached(false),
71 m_synthetic_cached(false),
76 SetValidator (validator_sp);
79 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp)
81 SetFormat (format_sp);
82 SetSummary (summary_sp);
83 SetSynthetic (synthetic_sp);
84 SetValidator (validator_sp);
88 FormatCache::Entry::IsFormatCached ()
90 return m_format_cached;
94 FormatCache::Entry::IsSummaryCached ()
96 return m_summary_cached;
100 FormatCache::Entry::IsSyntheticCached ()
102 return m_synthetic_cached;
106 FormatCache::Entry::IsValidatorCached ()
108 return m_validator_cached;
111 lldb::TypeFormatImplSP
112 FormatCache::Entry::GetFormat ()
117 lldb::TypeSummaryImplSP
118 FormatCache::Entry::GetSummary ()
123 lldb::SyntheticChildrenSP
124 FormatCache::Entry::GetSynthetic ()
126 return m_synthetic_sp;
129 lldb::TypeValidatorImplSP
130 FormatCache::Entry::GetValidator ()
132 return m_validator_sp;
136 FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
138 m_format_cached = true;
139 m_format_sp = format_sp;
143 FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
145 m_summary_cached = true;
146 m_summary_sp = summary_sp;
150 FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
152 m_synthetic_cached = true;
153 m_synthetic_sp = synthetic_sp;
157 FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp)
159 m_validator_cached = true;
160 m_validator_sp = validator_sp;
163 FormatCache::FormatCache () :
165 m_mutex (Mutex::eMutexTypeRecursive)
166 #ifdef LLDB_CONFIGURATION_DEBUG
167 ,m_cache_hits(0),m_cache_misses(0)
173 FormatCache::GetEntry (const ConstString& type)
175 auto i = m_map.find(type),
179 m_map[type] = FormatCache::Entry();
184 FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
186 Mutex::Locker lock(m_mutex);
187 auto entry = GetEntry(type);
188 if (entry.IsSummaryCached())
190 #ifdef LLDB_CONFIGURATION_DEBUG
193 format_sp = entry.GetFormat();
196 #ifdef LLDB_CONFIGURATION_DEBUG
204 FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
206 Mutex::Locker lock(m_mutex);
207 auto entry = GetEntry(type);
208 if (entry.IsSummaryCached())
210 #ifdef LLDB_CONFIGURATION_DEBUG
213 summary_sp = entry.GetSummary();
216 #ifdef LLDB_CONFIGURATION_DEBUG
224 FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
226 Mutex::Locker lock(m_mutex);
227 auto entry = GetEntry(type);
228 if (entry.IsSyntheticCached())
230 #ifdef LLDB_CONFIGURATION_DEBUG
233 synthetic_sp = entry.GetSynthetic();
236 #ifdef LLDB_CONFIGURATION_DEBUG
239 synthetic_sp.reset();
244 FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
246 Mutex::Locker lock(m_mutex);
247 auto entry = GetEntry(type);
248 if (entry.IsValidatorCached())
250 #ifdef LLDB_CONFIGURATION_DEBUG
253 validator_sp = entry.GetValidator();
256 #ifdef LLDB_CONFIGURATION_DEBUG
259 validator_sp.reset();
264 FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
266 Mutex::Locker lock(m_mutex);
267 GetEntry(type).SetFormat(format_sp);
271 FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
273 Mutex::Locker lock(m_mutex);
274 GetEntry(type).SetSummary(summary_sp);
278 FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
280 Mutex::Locker lock(m_mutex);
281 GetEntry(type).SetSynthetic(synthetic_sp);
285 FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
287 Mutex::Locker lock(m_mutex);
288 GetEntry(type).SetValidator(validator_sp);
292 FormatCache::Clear ()
294 Mutex::Locker lock(m_mutex);