blob: 3721f182f91e78316e7b2a1a80a414cc918ad923 [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
Matt Kopec676a4872013-02-21 23:55:31 +000010#include "lldb/lldb-python.h"
11
Enrico Granata5548cb52013-01-28 23:47:25 +000012// C Includes
13
14// C++ Includes
15
16// Other libraries and framework includes
17
18// Project includes
19#include "lldb/DataFormatters/FormatCache.h"
20
21using namespace lldb;
22using namespace lldb_private;
23
24FormatCache::Entry::Entry () :
Enrico Granata52b4b6c2013-10-17 22:27:19 +000025m_format_cached(false),
Enrico Granata5548cb52013-01-28 23:47:25 +000026m_summary_cached(false),
27m_synthetic_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000028m_format_sp(),
Daniel Malea30b95a32013-01-30 01:01:11 +000029m_summary_sp(),
30m_synthetic_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 Granata52b4b6c2013-10-17 22:27:19 +000036m_summary_sp(),
37m_synthetic_sp()
38{
39 SetFormat (format_sp);
40}
41
42FormatCache::Entry::Entry (lldb::TypeSummaryImplSP summary_sp) :
43m_format_cached(false),
44m_synthetic_cached(false),
45m_format_sp(),
Daniel Malea0b464d42013-02-06 16:46:40 +000046m_synthetic_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000047{
48 SetSummary (summary_sp);
49}
50
Daniel Malea0b464d42013-02-06 16:46:40 +000051FormatCache::Entry::Entry (lldb::SyntheticChildrenSP synthetic_sp) :
Enrico Granata52b4b6c2013-10-17 22:27:19 +000052m_format_cached(false),
Daniel Malea0b464d42013-02-06 16:46:40 +000053m_summary_cached(false),
Enrico Granata52b4b6c2013-10-17 22:27:19 +000054m_format_sp(),
Daniel Malea0b464d42013-02-06 16:46:40 +000055m_summary_sp()
Enrico Granata5548cb52013-01-28 23:47:25 +000056{
57 SetSynthetic (synthetic_sp);
58}
59
Enrico Granata52b4b6c2013-10-17 22:27:19 +000060FormatCache::Entry::Entry (lldb::TypeFormatImplSP format_sp, lldb::TypeSummaryImplSP summary_sp, lldb::SyntheticChildrenSP synthetic_sp)
Enrico Granata5548cb52013-01-28 23:47:25 +000061{
Enrico Granata52b4b6c2013-10-17 22:27:19 +000062 SetFormat (format_sp);
Enrico Granata5548cb52013-01-28 23:47:25 +000063 SetSummary (summary_sp);
64 SetSynthetic (synthetic_sp);
65}
66
67bool
Enrico Granata52b4b6c2013-10-17 22:27:19 +000068FormatCache::Entry::IsFormatCached ()
69{
70 return m_format_cached;
71}
72
73bool
Enrico Granata5548cb52013-01-28 23:47:25 +000074FormatCache::Entry::IsSummaryCached ()
75{
76 return m_summary_cached;
77}
78
79bool
80FormatCache::Entry::IsSyntheticCached ()
81{
82 return m_synthetic_cached;
83}
84
Enrico Granata52b4b6c2013-10-17 22:27:19 +000085lldb::TypeFormatImplSP
86FormatCache::Entry::GetFormat ()
87{
88 return m_format_sp;
89}
90
Enrico Granata5548cb52013-01-28 23:47:25 +000091lldb::TypeSummaryImplSP
92FormatCache::Entry::GetSummary ()
93{
94 return m_summary_sp;
95}
96
97lldb::SyntheticChildrenSP
98FormatCache::Entry::GetSynthetic ()
99{
100 return m_synthetic_sp;
101}
102
103void
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000104FormatCache::Entry::SetFormat (lldb::TypeFormatImplSP format_sp)
105{
106 m_format_cached = true;
107 m_format_sp = format_sp;
108}
109
110void
Enrico Granata5548cb52013-01-28 23:47:25 +0000111FormatCache::Entry::SetSummary (lldb::TypeSummaryImplSP summary_sp)
112{
113 m_summary_cached = true;
114 m_summary_sp = summary_sp;
115}
116
117void
118FormatCache::Entry::SetSynthetic (lldb::SyntheticChildrenSP synthetic_sp)
119{
120 m_synthetic_cached = true;
121 m_synthetic_sp = synthetic_sp;
122}
123
124FormatCache::FormatCache () :
125m_map(),
126m_mutex (Mutex::eMutexTypeRecursive)
127#ifdef LLDB_CONFIGURATION_DEBUG
128,m_cache_hits(0),m_cache_misses(0)
129#endif
130{
131}
132
133FormatCache::Entry&
134FormatCache::GetEntry (const ConstString& type)
135{
136 auto i = m_map.find(type),
137 e = m_map.end();
138 if (i != e)
139 return i->second;
140 m_map[type] = FormatCache::Entry();
141 return m_map[type];
142}
143
144bool
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000145FormatCache::GetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
146{
147 Mutex::Locker lock(m_mutex);
148 auto entry = GetEntry(type);
149 if (entry.IsSummaryCached())
150 {
151#ifdef LLDB_CONFIGURATION_DEBUG
152 m_cache_hits++;
153#endif
154 format_sp = entry.GetFormat();
155 return true;
156 }
157#ifdef LLDB_CONFIGURATION_DEBUG
158 m_cache_misses++;
159#endif
160 format_sp.reset();
161 return false;
162}
163
164bool
Enrico Granata5548cb52013-01-28 23:47:25 +0000165FormatCache::GetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
166{
167 Mutex::Locker lock(m_mutex);
168 auto entry = GetEntry(type);
169 if (entry.IsSummaryCached())
170 {
171#ifdef LLDB_CONFIGURATION_DEBUG
172 m_cache_hits++;
173#endif
174 summary_sp = entry.GetSummary();
175 return true;
176 }
177#ifdef LLDB_CONFIGURATION_DEBUG
178 m_cache_misses++;
179#endif
180 summary_sp.reset();
181 return false;
182}
183
184bool
185FormatCache::GetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
186{
187 Mutex::Locker lock(m_mutex);
188 auto entry = GetEntry(type);
189 if (entry.IsSyntheticCached())
190 {
191#ifdef LLDB_CONFIGURATION_DEBUG
192 m_cache_hits++;
193#endif
194 synthetic_sp = entry.GetSynthetic();
195 return true;
196 }
197#ifdef LLDB_CONFIGURATION_DEBUG
198 m_cache_misses++;
199#endif
200 synthetic_sp.reset();
201 return false;
202}
203
204void
Enrico Granata52b4b6c2013-10-17 22:27:19 +0000205FormatCache::SetFormat (const ConstString& type,lldb::TypeFormatImplSP& format_sp)
206{
207 Mutex::Locker lock(m_mutex);
208 GetEntry(type).SetFormat(format_sp);
209}
210
211void
Enrico Granata5548cb52013-01-28 23:47:25 +0000212FormatCache::SetSummary (const ConstString& type,lldb::TypeSummaryImplSP& summary_sp)
213{
214 Mutex::Locker lock(m_mutex);
215 GetEntry(type).SetSummary(summary_sp);
216}
217
218void
219FormatCache::SetSynthetic (const ConstString& type,lldb::SyntheticChildrenSP& synthetic_sp)
220{
221 Mutex::Locker lock(m_mutex);
222 GetEntry(type).SetSynthetic(synthetic_sp);
223}
224
225void
226FormatCache::Clear ()
227{
228 Mutex::Locker lock(m_mutex);
229 m_map.clear();
230}
231