]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/DataFormatters/LanguageCategory.cpp
Merge ^/head r303250 through r308226.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / DataFormatters / LanguageCategory.cpp
1 //===-- LanguageCategory.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/DataFormatters/LanguageCategory.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/DataFormatters/FormatManager.h"
17 #include "lldb/DataFormatters/TypeCategory.h"
18 #include "lldb/DataFormatters/TypeFormat.h"
19 #include "lldb/DataFormatters/TypeSummary.h"
20 #include "lldb/DataFormatters/TypeSynthetic.h"
21 #include "lldb/DataFormatters/TypeValidator.h"
22 #include "lldb/Target/Language.h"
23
24 using namespace lldb;
25 using namespace lldb_private;
26
27 LanguageCategory::LanguageCategory (lldb::LanguageType lang_type) :
28     m_category_sp(),
29     m_hardcoded_formats(),
30     m_hardcoded_summaries(),
31     m_hardcoded_synthetics(),
32     m_hardcoded_validators(),
33     m_format_cache(),
34     m_enabled(false)
35 {
36     if (Language* language_plugin = Language::FindPlugin(lang_type))
37     {
38         m_category_sp = language_plugin->GetFormatters();
39         m_hardcoded_formats = language_plugin->GetHardcodedFormats();
40         m_hardcoded_summaries = language_plugin->GetHardcodedSummaries();
41         m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics();
42         m_hardcoded_validators = language_plugin->GetHardcodedValidators();
43     }
44     Enable();
45 }
46
47 bool
48 LanguageCategory::Get (FormattersMatchData& match_data,
49                        lldb::TypeFormatImplSP& format_sp)
50 {
51     if (!m_category_sp)
52         return false;
53     
54     if (!IsEnabled())
55         return false;
56
57     if (match_data.GetTypeForCache())
58     {
59         if (m_format_cache.GetFormat(match_data.GetTypeForCache(), format_sp))
60             return format_sp.get() != nullptr;
61     }
62
63     ValueObject& valobj(match_data.GetValueObject());
64     bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
65     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
66     {
67         m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp);
68     }
69     return result;
70 }
71
72 bool
73 LanguageCategory::Get (FormattersMatchData& match_data,
74                        lldb::TypeSummaryImplSP& format_sp)
75 {
76     if (!m_category_sp)
77         return false;
78     
79     if (!IsEnabled())
80         return false;
81
82     if (match_data.GetTypeForCache())
83     {
84         if (m_format_cache.GetSummary(match_data.GetTypeForCache(), format_sp))
85             return format_sp.get() != nullptr;
86     }
87     
88     ValueObject& valobj(match_data.GetValueObject());
89     bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
90     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
91     {
92         m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp);
93     }
94     return result;
95 }
96
97 bool
98 LanguageCategory::Get (FormattersMatchData& match_data,
99                        lldb::SyntheticChildrenSP& format_sp)
100 {
101     if (!m_category_sp)
102         return false;
103     
104     if (!IsEnabled())
105         return false;
106
107     if (match_data.GetTypeForCache())
108     {
109         if (m_format_cache.GetSynthetic(match_data.GetTypeForCache(), format_sp))
110             return format_sp.get() != nullptr;
111     }
112     
113     ValueObject& valobj(match_data.GetValueObject());
114     bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
115     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
116     {
117         m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp);
118     }
119     return result;
120 }
121
122 bool
123 LanguageCategory::Get (FormattersMatchData& match_data,
124                        lldb::TypeValidatorImplSP& format_sp)
125 {
126     if (!m_category_sp)
127         return false;
128
129     if (!IsEnabled())
130         return false;
131
132     if (match_data.GetTypeForCache())
133     {
134         if (m_format_cache.GetValidator(match_data.GetTypeForCache(), format_sp))
135             return format_sp.get() != nullptr;
136     }
137     
138     ValueObject& valobj(match_data.GetValueObject());
139     bool result = m_category_sp->Get(valobj, match_data.GetMatchesVector(), format_sp);
140     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
141     {
142         m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp);
143     }
144     return result;
145 }
146
147 bool
148 LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
149                                 FormattersMatchData& match_data,
150                                 lldb::TypeFormatImplSP& format_sp)
151 {
152     if (!IsEnabled())
153         return false;
154
155     ValueObject& valobj(match_data.GetValueObject());
156     lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
157     
158     for (auto& candidate : m_hardcoded_formats)
159     {
160         if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
161             break;
162     }
163     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
164     {
165         m_format_cache.SetFormat(match_data.GetTypeForCache(), format_sp);
166     }
167     return format_sp.get() != nullptr;
168 }
169
170 bool
171 LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
172                                 FormattersMatchData& match_data,
173                                 lldb::TypeSummaryImplSP& format_sp)
174 {
175     if (!IsEnabled())
176         return false;
177     
178     ValueObject& valobj(match_data.GetValueObject());
179     lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
180
181     for (auto& candidate : m_hardcoded_summaries)
182     {
183         if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
184             break;
185     }
186     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
187     {
188         m_format_cache.SetSummary(match_data.GetTypeForCache(), format_sp);
189     }
190     return format_sp.get() != nullptr;
191 }
192
193 bool
194 LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
195                                 FormattersMatchData& match_data,
196                                 lldb::SyntheticChildrenSP& format_sp)
197 {
198     if (!IsEnabled())
199         return false;
200
201     ValueObject& valobj(match_data.GetValueObject());
202     lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
203     
204     for (auto& candidate : m_hardcoded_synthetics)
205     {
206         if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
207             break;
208     }
209     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
210     {
211         m_format_cache.SetSynthetic(match_data.GetTypeForCache(), format_sp);
212     }
213     return format_sp.get() != nullptr;
214 }
215
216 bool
217 LanguageCategory::GetHardcoded (FormatManager& fmt_mgr,
218                                 FormattersMatchData& match_data,
219                                 lldb::TypeValidatorImplSP& format_sp)
220 {
221     if (!IsEnabled())
222         return false;
223
224     ValueObject& valobj(match_data.GetValueObject());
225     lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
226     
227     for (auto& candidate : m_hardcoded_validators)
228     {
229         if ((format_sp = candidate(valobj, use_dynamic, fmt_mgr)))
230             break;
231     }
232     if (match_data.GetTypeForCache() && (!format_sp || !format_sp->NonCacheable()))
233     {
234         m_format_cache.SetValidator(match_data.GetTypeForCache(), format_sp);
235     }
236     return format_sp.get() != nullptr;
237 }
238
239 lldb::TypeCategoryImplSP
240 LanguageCategory::GetCategory () const
241 {
242     return m_category_sp;
243 }
244
245 FormatCache&
246 LanguageCategory::GetFormatCache ()
247 {
248     return m_format_cache;
249 }
250
251 void
252 LanguageCategory::Enable ()
253 {
254     if (m_category_sp)
255         m_category_sp->Enable(true, TypeCategoryMap::Default);
256     m_enabled = true;
257 }
258
259 void
260 LanguageCategory::Disable ()
261 {
262     if (m_category_sp)
263         m_category_sp->Disable();
264     m_enabled = false;
265 }
266
267 bool
268 LanguageCategory::IsEnabled ()
269 {
270     return m_enabled;
271 }