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),
33 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) :
34 m_summary_cached(false),
35 m_synthetic_cached(false),
39 SetFormat (format_sp);
42 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
43 m_format_cached(false),
44 m_synthetic_cached(false),
48 SetSummary (summary_sp);
51 FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
52 m_format_cached(false),
53 m_summary_cached(false),
57 SetSynthetic (synthetic_sp);
60 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp)
62 SetFormat (format_sp);
63 SetSummary (summary_sp);
64 SetSynthetic (synthetic_sp);
68 FormatCache::Entry::IsFormatCached ()
70 return m_format_cached;
74 FormatCache::Entry::IsSummaryCached ()
76 return m_summary_cached;
80 FormatCache::Entry::IsSyntheticCached ()
82 return m_synthetic_cached;
85 lldb::TypeFormatImplSP
86 FormatCache::Entry::GetFormat ()
91 lldb::TypeSummaryImplSP
92 FormatCache::Entry::GetSummary ()
97 lldb::SyntheticChildrenSP
98 FormatCache::Entry::GetSynthetic ()
100 return m_synthetic_sp;
104 FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
106 m_format_cached = true;
107 m_format_sp = format_sp;
111 FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
113 m_summary_cached = true;
114 m_summary_sp = summary_sp;
118 FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
120 m_synthetic_cached = true;
121 m_synthetic_sp = synthetic_sp;
124 FormatCache::FormatCache () :
126 m_mutex (Mutex::eMutexTypeRecursive)
127 #ifdef LLDB_CONFIGURATION_DEBUG
128 ,m_cache_hits(0),m_cache_misses(0)
134 FormatCache::GetEntry (const ConstString& type)
136 auto i = m_map.find(type),
140 m_map[type] = FormatCache::Entry();
145 FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
147 Mutex::Locker lock(m_mutex);
148 auto entry = GetEntry(type);
149 if (entry.IsSummaryCached())
151 #ifdef LLDB_CONFIGURATION_DEBUG
154 format_sp = entry.GetFormat();
157 #ifdef LLDB_CONFIGURATION_DEBUG
165 FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
167 Mutex::Locker lock(m_mutex);
168 auto entry = GetEntry(type);
169 if (entry.IsSummaryCached())
171 #ifdef LLDB_CONFIGURATION_DEBUG
174 summary_sp = entry.GetSummary();
177 #ifdef LLDB_CONFIGURATION_DEBUG
185 FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
187 Mutex::Locker lock(m_mutex);
188 auto entry = GetEntry(type);
189 if (entry.IsSyntheticCached())
191 #ifdef LLDB_CONFIGURATION_DEBUG
194 synthetic_sp = entry.GetSynthetic();
197 #ifdef LLDB_CONFIGURATION_DEBUG
200 synthetic_sp.reset();
205 FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
207 Mutex::Locker lock(m_mutex);
208 GetEntry(type).SetFormat(format_sp);
212 FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
214 Mutex::Locker lock(m_mutex);
215 GetEntry(type).SetSummary(summary_sp);
219 FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
221 Mutex::Locker lock(m_mutex);
222 GetEntry(type).SetSynthetic(synthetic_sp);
226 FormatCache::Clear ()
228 Mutex::Locker lock(m_mutex);