blob: 748c6d80fbd272e62c663615f0ab28425809ac31 [file] [log] [blame]
Enrico Granata5548cb52013-01-28 23:47:25 +00001//===-- FormatCache.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// C Includes
11
12// C++ Includes
13
14// Other libraries and framework includes
15
16// Project includes
17#include "lldb/DataFormatters/FormatCache.h"
18
19using namespace lldb;
20using namespace lldb_private;
21
22FormatCache::Entry::Entry () :
Enrico Granata52b4b6c2013-10-17 22:27:19 +000023m_format_cached(false),
Enrico Granata5548cb52013-01-28 23:47:25 +000024m_summary_cached(false),
25m_synthetic_cached(false),
Enrico Granatac5827132014-09-05 20:45:07 +000026m_validator_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000027m_format_sp(),
Daniel Malea30b95a32013-01-30 01:01:11 +000028m_summary_sp(),
Enrico Granatac5827132014-09-05 20:45:07 +000029m_synthetic_sp(),
30m_validator_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000031{}
32
Enrico Granata52b4b6c2013-10-17 22:27:19 +000033FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) :
34m_summary_cached(false),
Daniel Malea0b464d42013-02-06 16:46:40 +000035m_synthetic_cached(false),
Enrico Granatac5827132014-09-05 20:45:07 +000036m_validator_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000037m_summary_sp(),
Enrico Granatac5827132014-09-05 20:45:07 +000038m_synthetic_sp(),
39m_validator_sp()
Enrico Granata52b4b6c2013-10-17 22:27:19 +000040{
41 SetFormat (format_sp);
42}
43
44FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
45m_format_cached(false),
46m_synthetic_cached(false),
Enrico Granatac5827132014-09-05 20:45:07 +000047m_validator_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000048m_format_sp(),
Enrico Granatac5827132014-09-05 20:45:07 +000049m_synthetic_sp(),
50m_validator_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000051{
52 SetSummary (summary_sp);
53}
54
Daniel Malea0b464d42013-02-06 16:46:40 +000055FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
Enrico Granata52b4b6c2013-10-17 22:27:19 +000056m_format_cached(false),
Daniel Malea0b464d42013-02-06 16:46:40 +000057m_summary_cached(false),
Enrico Granatac5827132014-09-05 20:45:07 +000058m_validator_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000059m_format_sp(),
Enrico Granatac5827132014-09-05 20:45:07 +000060m_summary_sp(),
61m_validator_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000062{
63 SetSynthetic (synthetic_sp);
64}
65
Enrico Granatac5827132014-09-05 20:45:07 +000066FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) :
67m_format_cached(false),
68m_summary_cached(false),
69m_synthetic_cached(false),
70m_format_sp(),
71m_summary_sp(),
72m_synthetic_sp()
73{
74 SetValidator (validator_sp);
75}
76
77FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp)
Enrico Granata5548cb52013-01-28 23:47:25 +000078{
Enrico Granata52b4b6c2013-10-17 22:27:19 +000079 SetFormat (format_sp);
Enrico Granata5548cb52013-01-28 23:47:25 +000080 SetSummary (summary_sp);
81 SetSynthetic (synthetic_sp);
Enrico Granatac5827132014-09-05 20:45:07 +000082 SetValidator (validator_sp);
Enrico Granata5548cb52013-01-28 23:47:25 +000083}
84
85bool
Enrico Granata52b4b6c2013-10-17 22:27:19 +000086FormatCache::Entry::IsFormatCached ()
87{
88 return m_format_cached;
89}
90
91bool
Enrico Granata5548cb52013-01-28 23:47:25 +000092FormatCache::Entry::IsSummaryCached ()
93{
94 return m_summary_cached;
95}
96
97bool
98FormatCache::Entry::IsSyntheticCached ()
99{
100 return m_synthetic_cached;
101}
102
Enrico Granatac5827132014-09-05 20:45:07 +0000103bool
104FormatCache::Entry::IsValidatorCached ()
105{
106 return m_validator_cached;
107}
108
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000109lldb::TypeFormatImplSP
110FormatCache::Entry::GetFormat ()
111{
112 return m_format_sp;
113}
114
Enrico Granata5548cb52013-01-28 23:47:25 +0000115lldb::TypeSummaryImplSP
116FormatCache::Entry::GetSummary ()
117{
118 return m_summary_sp;
119}
120
121lldb::SyntheticChildrenSP
122FormatCache::Entry::GetSynthetic ()
123{
124 return m_synthetic_sp;
125}
126
Enrico Granatac5827132014-09-05 20:45:07 +0000127lldb::TypeValidatorImplSP
128FormatCache::Entry::GetValidator ()
129{
130 return m_validator_sp;
131}
132
Enrico Granata5548cb52013-01-28 23:47:25 +0000133void
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000134FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
135{
136 m_format_cached = true;
137 m_format_sp = format_sp;
138}
139
140void
Enrico Granata5548cb52013-01-28 23:47:25 +0000141FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
142{
143 m_summary_cached = true;
144 m_summary_sp = summary_sp;
145}
146
147void
148FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
149{
150 m_synthetic_cached = true;
151 m_synthetic_sp = synthetic_sp;
152}
153
Enrico Granatac5827132014-09-05 20:45:07 +0000154void
155FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp)
156{
157 m_validator_cached = true;
158 m_validator_sp = validator_sp;
159}
160
Enrico Granata5548cb52013-01-28 23:47:25 +0000161FormatCache::FormatCache () :
162m_map(),
163m_mutex (Mutex::eMutexTypeRecursive)
164#ifdef LLDB_CONFIGURATION_DEBUG
165,m_cache_hits(0),m_cache_misses(0)
166#endif
167{
168}
169
170FormatCache::Entry&
171FormatCache::GetEntry (const ConstString& type)
172{
173 auto i = m_map.find(type),
174 e = m_map.end();
175 if (i != e)
176 return i->second;
177 m_map[type] = FormatCache::Entry();
178 return m_map[type];
179}
180
181bool
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000182FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
183{
184 Mutex::Locker lock(m_mutex);
185 auto entry = GetEntry(type);
186 if (entry.IsSummaryCached())
187 {
188#ifdef LLDB_CONFIGURATION_DEBUG
189 m_cache_hits++;
190#endif
191 format_sp = entry.GetFormat();
192 return true;
193 }
194#ifdef LLDB_CONFIGURATION_DEBUG
195 m_cache_misses++;
196#endif
197 format_sp.reset();
198 return false;
199}
200
201bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000202FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
203{
204 Mutex::Locker lock(m_mutex);
205 auto entry = GetEntry(type);
206 if (entry.IsSummaryCached())
207 {
208#ifdef LLDB_CONFIGURATION_DEBUG
209 m_cache_hits++;
210#endif
211 summary_sp = entry.GetSummary();
212 return true;
213 }
214#ifdef LLDB_CONFIGURATION_DEBUG
215 m_cache_misses++;
216#endif
217 summary_sp.reset();
218 return false;
219}
220
221bool
222FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
223{
224 Mutex::Locker lock(m_mutex);
225 auto entry = GetEntry(type);
226 if (entry.IsSyntheticCached())
227 {
228#ifdef LLDB_CONFIGURATION_DEBUG
229 m_cache_hits++;
230#endif
231 synthetic_sp = entry.GetSynthetic();
232 return true;
233 }
234#ifdef LLDB_CONFIGURATION_DEBUG
235 m_cache_misses++;
236#endif
237 synthetic_sp.reset();
238 return false;
239}
240
Enrico Granatac5827132014-09-05 20:45:07 +0000241bool
242FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
243{
244 Mutex::Locker lock(m_mutex);
245 auto entry = GetEntry(type);
246 if (entry.IsValidatorCached())
247 {
248#ifdef LLDB_CONFIGURATION_DEBUG
249 m_cache_hits++;
250#endif
251 validator_sp = entry.GetValidator();
252 return true;
253 }
254#ifdef LLDB_CONFIGURATION_DEBUG
255 m_cache_misses++;
256#endif
257 validator_sp.reset();
258 return false;
259}
260
Enrico Granata5548cb52013-01-28 23:47:25 +0000261void
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000262FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
263{
264 Mutex::Locker lock(m_mutex);
265 GetEntry(type).SetFormat(format_sp);
266}
267
268void
Enrico Granata5548cb52013-01-28 23:47:25 +0000269FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
270{
271 Mutex::Locker lock(m_mutex);
272 GetEntry(type).SetSummary(summary_sp);
273}
274
275void
276FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
277{
278 Mutex::Locker lock(m_mutex);
279 GetEntry(type).SetSynthetic(synthetic_sp);
280}
281
282void
Enrico Granatac5827132014-09-05 20:45:07 +0000283FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
284{
285 Mutex::Locker lock(m_mutex);
286 GetEntry(type).SetValidator(validator_sp);
287}
288
289void
Enrico Granata5548cb52013-01-28 23:47:25 +0000290FormatCache::Clear ()
291{
292 Mutex::Locker lock(m_mutex);
293 m_map.clear();
294}
295