1 //===-- FormatClasses.h -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_FormatClasses_h_
11 #define lldb_FormatClasses_h_
20 // Other libraries and framework includes
22 #include "lldb/DataFormatters/TypeFormat.h"
23 #include "lldb/DataFormatters/TypeSummary.h"
24 #include "lldb/DataFormatters/TypeSynthetic.h"
25 #include "lldb/DataFormatters/TypeValidator.h"
26 #include "lldb/Symbol/CompilerType.h"
27 #include "lldb/Symbol/Type.h"
28 #include "lldb/lldb-enumerations.h"
29 #include "lldb/lldb-public.h"
31 namespace lldb_private {
33 class HardcodedFormatters {
35 template <typename FormatterType>
36 using HardcodedFormatterFinder =
37 std::function<typename FormatterType::SharedPointer(
38 lldb_private::ValueObject &, lldb::DynamicValueType,
41 template <typename FormatterType>
42 using HardcodedFormatterFinders =
43 std::vector<HardcodedFormatterFinder<FormatterType>>;
45 typedef HardcodedFormatterFinders<TypeFormatImpl> HardcodedFormatFinder;
46 typedef HardcodedFormatterFinders<TypeSummaryImpl> HardcodedSummaryFinder;
47 typedef HardcodedFormatterFinders<SyntheticChildren> HardcodedSyntheticFinder;
48 typedef HardcodedFormatterFinders<TypeValidatorImpl> HardcodedValidatorFinder;
51 class FormattersMatchCandidate {
53 FormattersMatchCandidate(ConstString name, uint32_t reason, bool strip_ptr,
54 bool strip_ref, bool strip_tydef)
55 : m_type_name(name), m_reason(reason), m_stripped_pointer(strip_ptr),
56 m_stripped_reference(strip_ref), m_stripped_typedef(strip_tydef) {}
58 ~FormattersMatchCandidate() = default;
60 ConstString GetTypeName() const { return m_type_name; }
62 uint32_t GetReason() const { return m_reason; }
64 bool DidStripPointer() const { return m_stripped_pointer; }
66 bool DidStripReference() const { return m_stripped_reference; }
68 bool DidStripTypedef() const { return m_stripped_typedef; }
70 template <class Formatter>
71 bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
74 if (formatter_sp->Cascades() == false && DidStripTypedef())
76 if (formatter_sp->SkipsPointers() && DidStripPointer())
78 if (formatter_sp->SkipsReferences() && DidStripReference())
84 ConstString m_type_name;
86 bool m_stripped_pointer;
87 bool m_stripped_reference;
88 bool m_stripped_typedef;
91 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
92 typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
94 class FormattersMatchData {
96 FormattersMatchData(ValueObject &, lldb::DynamicValueType);
98 FormattersMatchVector GetMatchesVector();
100 ConstString GetTypeForCache();
102 CandidateLanguagesVector GetCandidateLanguages();
104 ValueObject &GetValueObject();
106 lldb::DynamicValueType GetDynamicValueType();
109 ValueObject &m_valobj;
110 lldb::DynamicValueType m_dynamic_value_type;
111 std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
112 ConstString m_type_for_cache;
113 CandidateLanguagesVector m_candidate_languages;
116 class TypeNameSpecifierImpl {
118 TypeNameSpecifierImpl() : m_is_regex(false), m_type() {}
120 TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
121 : m_is_regex(is_regex), m_type() {
122 m_type.m_type_name = name;
125 // if constructing with a given type, is_regex cannot be true since we are
126 // giving an exact type to match
127 TypeNameSpecifierImpl(lldb::TypeSP type) : m_is_regex(false), m_type() {
129 m_type.m_type_name = type->GetName().GetStringRef();
130 m_type.m_type_pair.SetType(type);
134 TypeNameSpecifierImpl(CompilerType type) : m_is_regex(false), m_type() {
135 if (type.IsValid()) {
136 m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
137 m_type.m_type_pair.SetType(type);
141 const char *GetName() {
142 if (m_type.m_type_name.size())
143 return m_type.m_type_name.c_str();
147 lldb::TypeSP GetTypeSP() {
148 if (m_type.m_type_pair.IsValid())
149 return m_type.m_type_pair.GetTypeSP();
150 return lldb::TypeSP();
153 CompilerType GetCompilerType() {
154 if (m_type.m_type_pair.IsValid())
155 return m_type.m_type_pair.GetCompilerType();
156 return CompilerType();
159 bool IsRegex() { return m_is_regex; }
163 // this works better than TypeAndOrName because the latter only wraps a TypeSP
164 // whereas TypePair can also be backed by a CompilerType
166 std::string m_type_name;
167 TypePair m_type_pair;
172 DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
175 } // namespace lldb_private
177 #endif // lldb_FormatClasses_h_