LLDB  mainline
LanguageCategory.cpp
Go to the documentation of this file.
1 //===-- LanguageCategory.cpp ----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
16 #include "lldb/Target/Language.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 LanguageCategory::LanguageCategory(lldb::LanguageType lang_type)
22  : m_category_sp(), m_hardcoded_formats(), m_hardcoded_summaries(),
23  m_hardcoded_synthetics(), m_format_cache(), m_enabled(false) {
24  if (Language *language_plugin = Language::FindPlugin(lang_type)) {
25  m_category_sp = language_plugin->GetFormatters();
26  m_hardcoded_formats = language_plugin->GetHardcodedFormats();
27  m_hardcoded_summaries = language_plugin->GetHardcodedSummaries();
28  m_hardcoded_synthetics = language_plugin->GetHardcodedSynthetics();
29  }
30  Enable();
31 }
32 
33 template<typename ImplSP>
35  ImplSP &retval_sp) {
36  if (!m_category_sp)
37  return false;
38 
39  if (!IsEnabled())
40  return false;
41 
42  if (match_data.GetTypeForCache()) {
43  if (m_format_cache.Get(match_data.GetTypeForCache(), retval_sp))
44  return (bool)retval_sp;
45  }
46 
47  ValueObject &valobj(match_data.GetValueObject());
48  bool result = m_category_sp->Get(valobj.GetObjectRuntimeLanguage(),
49  match_data.GetMatchesVector(), retval_sp);
50  if (match_data.GetTypeForCache() &&
51  (!retval_sp || !retval_sp->NonCacheable())) {
52  m_format_cache.Set(match_data.GetTypeForCache(), retval_sp);
53  }
54  return result;
55 }
56 
57 namespace lldb_private {
58 
59 /// Explicit instantiations for the three types.
60 /// \{
61 template bool
62 LanguageCategory::Get<lldb::TypeFormatImplSP>(FormattersMatchData &,
63  lldb::TypeFormatImplSP &);
64 template bool
65 LanguageCategory::Get<lldb::TypeSummaryImplSP>(FormattersMatchData &,
66  lldb::TypeSummaryImplSP &);
67 template bool
68 LanguageCategory::Get<lldb::SyntheticChildrenSP>(FormattersMatchData &,
69  lldb::SyntheticChildrenSP &);
70 /// \}
71 
72 template <>
73 auto &LanguageCategory::GetHardcodedFinder<lldb::TypeFormatImplSP>() {
74  return m_hardcoded_formats;
75 }
76 
77 template <>
78 auto &LanguageCategory::GetHardcodedFinder<lldb::TypeSummaryImplSP>() {
79  return m_hardcoded_summaries;
80 }
81 
82 template <>
83 auto &LanguageCategory::GetHardcodedFinder<lldb::SyntheticChildrenSP>() {
84  return m_hardcoded_synthetics;
85 }
86 
87 } // namespace lldb_private
88 
89 template <typename ImplSP>
91  FormattersMatchData &match_data,
92  ImplSP &retval_sp) {
93  if (!IsEnabled())
94  return false;
95 
96  ValueObject &valobj(match_data.GetValueObject());
97  lldb::DynamicValueType use_dynamic(match_data.GetDynamicValueType());
98 
99  for (auto &candidate : GetHardcodedFinder<ImplSP>()) {
100  if (auto result = candidate(valobj, use_dynamic, fmt_mgr)) {
101  retval_sp = result;
102  break;
103  }
104  }
105  return (bool)retval_sp;
106 }
107 
108 /// Explicit instantiations for the three types.
109 /// \{
110 template bool LanguageCategory::GetHardcoded<lldb::TypeFormatImplSP>(
111  FormatManager &, FormattersMatchData &, lldb::TypeFormatImplSP &);
112 template bool LanguageCategory::GetHardcoded<lldb::TypeSummaryImplSP>(
113  FormatManager &, FormattersMatchData &, lldb::TypeSummaryImplSP &);
114 template bool LanguageCategory::GetHardcoded<lldb::SyntheticChildrenSP>(
115  FormatManager &, FormattersMatchData &, lldb::SyntheticChildrenSP &);
116 /// \}
117 
118 lldb::TypeCategoryImplSP LanguageCategory::GetCategory() const {
119  return m_category_sp;
120 }
121 
123 
125  if (m_category_sp)
127  m_enabled = true;
128 }
129 
131  if (m_category_sp)
132  m_category_sp->Disable();
133  m_enabled = false;
134 }
135 
lldb_private::FormattersMatchData
Definition: FormatClasses.h:84
lldb_private::FormatCache::Set
void Set(ConstString type, lldb::TypeFormatImplSP &format_sp)
Definition: FormatCache.cpp:102
lldb_private::LanguageCategory::Enable
void Enable()
Definition: LanguageCategory.cpp:124
lldb_private::FormatManager
Definition: FormatManager.h:36
FormatManager.h
lldb_private::LanguageCategory::Get
bool Get(FormattersMatchData &match_data, ImplSP &format_sp)
Definition: LanguageCategory.cpp:34
lldb_private::LanguageCategory::m_hardcoded_synthetics
HardcodedFormatters::HardcodedSyntheticFinder m_hardcoded_synthetics
Definition: LanguageCategory.h:48
lldb_private::FormatCache
Definition: FormatCache.h:20
lldb_private::FormatCache::Get
bool Get(ConstString type, ImplSP &format_impl_sp)
Definition: FormatCache.cpp:77
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::LanguageCategory::IsEnabled
bool IsEnabled()
Definition: LanguageCategory.cpp:136
Language.h
lldb_private::LanguageCategory::m_enabled
bool m_enabled
Definition: LanguageCategory.h:55
lldb_private::FormattersMatchData::GetMatchesVector
FormattersMatchVector GetMatchesVector()
Definition: FormatClasses.cpp:30
lldb_private::LanguageCategory::GetHardcoded
bool GetHardcoded(FormatManager &fmt_mgr, FormattersMatchData &match_data, ImplSP &format_sp)
Definition: LanguageCategory.cpp:90
lldb_private::LanguageCategory::m_hardcoded_summaries
HardcodedFormatters::HardcodedSummaryFinder m_hardcoded_summaries
Definition: LanguageCategory.h:47
lldb_private::FormattersMatchData::GetDynamicValueType
lldb::DynamicValueType GetDynamicValueType()
Definition: FormatClasses.cpp:47
lldb_private::FormattersMatchData::GetTypeForCache
ConstString GetTypeForCache()
Definition: FormatClasses.cpp:39
lldb_private::LanguageCategory::GetFormatCache
FormatCache & GetFormatCache()
Definition: LanguageCategory.cpp:122
lldb_private::LanguageCategory::m_hardcoded_formats
HardcodedFormatters::HardcodedFormatFinder m_hardcoded_formats
Definition: LanguageCategory.h:46
lldb_private::TypeCategoryMap::Default
static const Position Default
Definition: TypeCategoryMap.h:40
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:494
lldb_private::Language::FindPlugin
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:53
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::LanguageCategory::m_category_sp
lldb::TypeCategoryImplSP m_category_sp
Definition: LanguageCategory.h:44
TypeSummary.h
LanguageCategory.h
lldb_private::LanguageCategory::Disable
void Disable()
Definition: LanguageCategory.cpp:130
TypeSynthetic.h
lldb_private::Language
Definition: Language.h:29
TypeFormat.h
TypeCategory.h
lldb_private::FormattersMatchData::GetValueObject
ValueObject & GetValueObject()
Definition: FormatClasses.cpp:45
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::LanguageCategory::m_format_cache
lldb_private::FormatCache m_format_cache
Definition: LanguageCategory.h:53
lldb
Definition: SBAddress.h:15
lldb_private::LanguageCategory::GetCategory
lldb::TypeCategoryImplSP GetCategory() const
Definition: LanguageCategory.cpp:118
lldb_private::ValueObject::GetObjectRuntimeLanguage
virtual lldb::LanguageType GetObjectRuntimeLanguage()
Definition: ValueObject.h:373