LLDB mainline
FormatClasses.h
Go to the documentation of this file.
1//===-- FormatClasses.h -----------------------------------------*- C++ -*-===//
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
9#ifndef LLDB_DATAFORMATTERS_FORMATCLASSES_H
10#define LLDB_DATAFORMATTERS_FORMATCLASSES_H
11
12#include <functional>
13#include <memory>
14#include <string>
15#include <vector>
16
22#include "lldb/Symbol/Type.h"
24#include "lldb/lldb-public.h"
25
26namespace lldb_private {
27
29public:
30 template <typename FormatterType>
32 std::function<typename FormatterType::SharedPointer(
34 FormatManager &)>;
35
36 template <typename FormatterType>
38 std::vector<HardcodedFormatterFinder<FormatterType>>;
39
43};
44
46public:
47 // Contains flags to indicate how this candidate was generated (e.g. if
48 // typedefs were stripped, or pointers were skipped). These are later compared
49 // to flags in formatters to confirm a string match.
50 struct Flags {
51 bool stripped_pointer = false;
52 bool stripped_reference = false;
53 bool stripped_typedef = false;
54
55 // Returns a copy of this with the "stripped pointer" flag set.
57 Flags result(*this);
58 result.stripped_pointer = true;
59 return result;
60 }
61
62 // Returns a copy of this with the "stripped reference" flag set.
64 Flags result(*this);
65 result.stripped_reference = true;
66 return result;
67 }
68
69 // Returns a copy of this with the "stripped typedef" flag set.
71 Flags result(*this);
72 result.stripped_typedef = true;
73 return result;
74 }
75 };
76
78 ScriptInterpreter *script_interpreter, TypeImpl type,
79 Flags flags)
80 : m_type_name(name), m_script_interpreter(script_interpreter),
81 m_type(type), m_flags(flags) {}
82
84
86
87 TypeImpl GetType() const { return m_type; }
88
91 }
92
93 bool DidStripPointer() const { return m_flags.stripped_pointer; }
94
96
97 bool DidStripTypedef() const { return m_flags.stripped_typedef; }
98
99 template <class Formatter>
100 bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
101 if (!formatter_sp)
102 return false;
103 if (formatter_sp->Cascades() == false && DidStripTypedef())
104 return false;
105 if (formatter_sp->SkipsPointers() && DidStripPointer())
106 return false;
107 if (formatter_sp->SkipsReferences() && DidStripReference())
108 return false;
109 return true;
110 }
111
112private:
114 // If a formatter provides a matching callback function, we need the script
115 // interpreter and the type object (as an argument to the callback).
119};
120
121typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
122typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
123
125public:
127
129
131
133
135
137
138private:
141 std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
144};
145
147public:
149
150 TypeNameSpecifierImpl(llvm::StringRef name,
151 lldb::FormatterMatchType match_type)
152 : m_match_type(match_type) {
153 m_type.m_type_name = std::string(name);
154 }
155
156 // if constructing with a given type, we consider that a case of exact match.
158 : m_match_type(lldb::eFormatterMatchExact) {
159 if (type) {
160 m_type.m_type_name = std::string(type->GetName().GetStringRef());
161 m_type.m_compiler_type = type->GetForwardCompilerType();
162 }
163 }
164
166 : m_match_type(lldb::eFormatterMatchExact) {
167 if (type.IsValid()) {
168 m_type.m_type_name.assign(type.GetTypeName().GetCString());
169 m_type.m_compiler_type = type;
170 }
171 }
172
173 const char *GetName() {
174 if (m_type.m_type_name.size())
175 return m_type.m_type_name.c_str();
176 return nullptr;
177 }
178
181 return m_type.m_compiler_type;
182 return CompilerType();
183 }
184
186
188
189private:
191 // TODO: Replace this with TypeAndOrName.
192 struct TypeOrName {
193 std::string m_type_name;
195 };
197
201};
202
203} // namespace lldb_private
204
205#endif // LLDB_DATAFORMATTERS_FORMATCLASSES_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
ConstString GetTypeName(bool BaseOnly=false) const
A uniqued constant string class.
Definition: ConstString.h:40
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:214
FormattersMatchCandidate(ConstString name, ScriptInterpreter *script_interpreter, TypeImpl type, Flags flags)
Definition: FormatClasses.h:77
ScriptInterpreter * GetScriptInterpreter() const
Definition: FormatClasses.h:89
bool IsMatch(const std::shared_ptr< Formatter > &formatter_sp) const
CandidateLanguagesVector m_candidate_languages
CandidateLanguagesVector GetCandidateLanguages()
std::pair< FormattersMatchVector, bool > m_formatters_match_vector
lldb::DynamicValueType GetDynamicValueType()
FormattersMatchVector GetMatchesVector()
lldb::DynamicValueType m_dynamic_value_type
std::vector< HardcodedFormatterFinder< FormatterType > > HardcodedFormatterFinders
Definition: FormatClasses.h:38
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:42
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:41
std::function< typename FormatterType::SharedPointer(lldb_private::ValueObject &, lldb::DynamicValueType, FormatManager &)> HardcodedFormatterFinder
Definition: FormatClasses.h:34
HardcodedFormatterFinders< TypeFormatImpl > HardcodedFormatFinder
Definition: FormatClasses.h:40
TypeNameSpecifierImpl(CompilerType type)
const TypeNameSpecifierImpl & operator=(const TypeNameSpecifierImpl &)=delete
lldb::FormatterMatchType GetMatchType()
TypeNameSpecifierImpl(lldb::TypeSP type)
lldb::FormatterMatchType m_match_type
TypeNameSpecifierImpl(const TypeNameSpecifierImpl &)=delete
TypeNameSpecifierImpl(llvm::StringRef name, lldb::FormatterMatchType match_type)
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
std::vector< FormattersMatchCandidate > FormattersMatchVector
std::vector< lldb::LanguageType > CandidateLanguagesVector
Definition: SBAddress.h:15
FormatterMatchType
Type of match to be performed when looking for a formatter for a data type.
@ eFormatterMatchExact
@ eFormatterMatchRegex
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:449