]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/DataFormatters/FormatCache.cpp
Import LLDB as of upstream SVN r225923 (git 2b588ecd)
[FreeBSD/FreeBSD.git] / source / DataFormatters / FormatCache.cpp
1 //===-- 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 #include "lldb/lldb-python.h"
11
12 // C Includes
13
14 // C++ Includes
15
16 // Other libraries and framework includes
17
18 // Project includes
19 #include "lldb/DataFormatters/FormatCache.h"
20
21 using namespace lldb;
22 using namespace lldb_private;
23
24 FormatCache::Entry::Entry () :
25 m_format_cached(false),
26 m_summary_cached(false),
27 m_synthetic_cached(false),
28 m_validator_cached(false),
29 m_format_sp(),
30 m_summary_sp(),
31 m_synthetic_sp(),
32 m_validator_sp()
33 {}
34
35 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp) :
36 m_summary_cached(false),
37 m_synthetic_cached(false),
38 m_validator_cached(false),
39 m_summary_sp(),
40 m_synthetic_sp(),
41 m_validator_sp()
42 {
43     SetFormat (format_sp);
44 }
45
46 FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
47 m_format_cached(false),
48 m_synthetic_cached(false),
49 m_validator_cached(false),
50 m_format_sp(),
51 m_synthetic_sp(),
52 m_validator_sp()
53 {
54     SetSummary (summary_sp);
55 }
56
57 FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
58 m_format_cached(false),
59 m_summary_cached(false),
60 m_validator_cached(false),
61 m_format_sp(),
62 m_summary_sp(),
63 m_validator_sp()
64 {
65     SetSynthetic (synthetic_sp);
66 }
67
68 FormatCache::Entry::Entry (lldb::TypeValidatorImplSP validator_sp) :
69 m_format_cached(false),
70 m_summary_cached(false),
71 m_synthetic_cached(false),
72 m_format_sp(),
73 m_summary_sp(),
74 m_synthetic_sp()
75 {
76     SetValidator (validator_sp);
77 }
78
79 FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp, lldb::TypeValidatorImplSP validator_sp)
80 {
81     SetFormat (format_sp);
82     SetSummary (summary_sp);
83     SetSynthetic (synthetic_sp);
84     SetValidator (validator_sp);
85 }
86
87 bool
88 FormatCache::Entry::IsFormatCached ()
89 {
90     return m_format_cached;
91 }
92
93 bool
94 FormatCache::Entry::IsSummaryCached ()
95 {
96     return m_summary_cached;
97 }
98
99 bool
100 FormatCache::Entry::IsSyntheticCached ()
101 {
102     return m_synthetic_cached;
103 }
104
105 bool
106 FormatCache::Entry::IsValidatorCached ()
107 {
108     return m_validator_cached;
109 }
110
111 lldb::TypeFormatImplSP
112 FormatCache::Entry::GetFormat ()
113 {
114     return m_format_sp;
115 }
116
117 lldb::TypeSummaryImplSP
118 FormatCache::Entry::GetSummary ()
119 {
120     return m_summary_sp;
121 }
122
123 lldb::SyntheticChildrenSP
124 FormatCache::Entry::GetSynthetic ()
125 {
126     return m_synthetic_sp;
127 }
128
129 lldb::TypeValidatorImplSP
130 FormatCache::Entry::GetValidator ()
131 {
132     return m_validator_sp;
133 }
134
135 void
136 FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
137 {
138     m_format_cached = true;
139     m_format_sp = format_sp;
140 }
141
142 void
143 FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
144 {
145     m_summary_cached = true;
146     m_summary_sp = summary_sp;
147 }
148
149 void
150 FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
151 {
152     m_synthetic_cached = true;
153     m_synthetic_sp = synthetic_sp;
154 }
155
156 void
157 FormatCache::Entry::SetValidator (lldb::TypeValidatorImplSP validator_sp)
158 {
159     m_validator_cached = true;
160     m_validator_sp = validator_sp;
161 }
162
163 FormatCache::FormatCache () :
164 m_map(),
165 m_mutex (Mutex::eMutexTypeRecursive)
166 #ifdef LLDB_CONFIGURATION_DEBUG
167 ,m_cache_hits(0),m_cache_misses(0)
168 #endif
169 {
170 }
171
172 FormatCache::Entry&
173 FormatCache::GetEntry (const ConstString& type)
174 {
175     auto i = m_map.find(type),
176     e = m_map.end();
177     if (i != e)
178         return i->second;
179     m_map[type] = FormatCache::Entry();
180     return m_map[type];
181 }
182
183 bool
184 FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
185 {
186     Mutex::Locker lock(m_mutex);
187     auto entry = GetEntry(type);
188     if (entry.IsSummaryCached())
189     {
190 #ifdef LLDB_CONFIGURATION_DEBUG
191         m_cache_hits++;
192 #endif
193         format_sp = entry.GetFormat();
194         return true;
195     }
196 #ifdef LLDB_CONFIGURATION_DEBUG
197     m_cache_misses++;
198 #endif
199     format_sp.reset();
200     return false;
201 }
202
203 bool
204 FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
205 {
206     Mutex::Locker lock(m_mutex);
207     auto entry = GetEntry(type);
208     if (entry.IsSummaryCached())
209     {
210 #ifdef LLDB_CONFIGURATION_DEBUG
211         m_cache_hits++;
212 #endif
213         summary_sp = entry.GetSummary();
214         return true;
215     }
216 #ifdef LLDB_CONFIGURATION_DEBUG
217     m_cache_misses++;
218 #endif
219     summary_sp.reset();
220     return false;
221 }
222
223 bool
224 FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
225 {
226     Mutex::Locker lock(m_mutex);
227     auto entry = GetEntry(type);
228     if (entry.IsSyntheticCached())
229     {
230 #ifdef LLDB_CONFIGURATION_DEBUG
231         m_cache_hits++;
232 #endif
233         synthetic_sp = entry.GetSynthetic();
234         return true;
235     }
236 #ifdef LLDB_CONFIGURATION_DEBUG
237     m_cache_misses++;
238 #endif
239     synthetic_sp.reset();
240     return false;
241 }
242
243 bool
244 FormatCache::GetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
245 {
246     Mutex::Locker lock(m_mutex);
247     auto entry = GetEntry(type);
248     if (entry.IsValidatorCached())
249     {
250 #ifdef LLDB_CONFIGURATION_DEBUG
251         m_cache_hits++;
252 #endif
253         validator_sp = entry.GetValidator();
254         return true;
255     }
256 #ifdef LLDB_CONFIGURATION_DEBUG
257     m_cache_misses++;
258 #endif
259     validator_sp.reset();
260     return false;
261 }
262
263 void
264 FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
265 {
266     Mutex::Locker lock(m_mutex);
267     GetEntry(type).SetFormat(format_sp);
268 }
269
270 void
271 FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
272 {
273     Mutex::Locker lock(m_mutex);
274     GetEntry(type).SetSummary(summary_sp);
275 }
276
277 void
278 FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
279 {
280     Mutex::Locker lock(m_mutex);
281     GetEntry(type).SetSynthetic(synthetic_sp);
282 }
283
284 void
285 FormatCache::SetValidator (const ConstString& type,lldb::TypeValidatorImplSP& validator_sp)
286 {
287     Mutex::Locker lock(m_mutex);
288     GetEntry(type).SetValidator(validator_sp);
289 }
290
291 void
292 FormatCache::Clear ()
293 {
294     Mutex::Locker lock(m_mutex);
295     m_map.clear();
296 }
297