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, uint32_t ptr_stripped_depth = 0)
80 : m_type_name(name), m_script_interpreter(script_interpreter),
81 m_type(type), m_flags(flags), m_ptr_stripped_depth(ptr_stripped_depth) {
82 }
83
85
87
88 TypeImpl GetType() const { return m_type; }
89
93
94 bool DidStripPointer() const { return m_flags.stripped_pointer; }
95
96 bool DidStripReference() const { return m_flags.stripped_reference; }
97
98 bool DidStripTypedef() const { return m_flags.stripped_typedef; }
99
100 uint32_t GetPtrStrippedDepth() const { return m_ptr_stripped_depth; }
101
102 template <class Formatter>
103 bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
104 if (!formatter_sp)
105 return false;
106 if (formatter_sp->Cascades() == false && DidStripTypedef())
107 return false;
108 if (formatter_sp->SkipsPointers() && DidStripPointer())
109 return false;
110 if (formatter_sp->GetPtrMatchDepth() < GetPtrStrippedDepth())
111 return false;
112 if (formatter_sp->SkipsReferences() && DidStripReference())
113 return false;
114 return true;
115 }
116
117private:
119 // If a formatter provides a matching callback function, we need the script
120 // interpreter and the type object (as an argument to the callback).
125};
126
127typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
128typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
129
151
153public:
155
156 TypeNameSpecifierImpl(llvm::StringRef name,
157 lldb::FormatterMatchType match_type)
158 : m_match_type(match_type) {
159 m_type.m_type_name = std::string(name);
160 }
161
162 // if constructing with a given type, we consider that a case of exact match.
164 : m_match_type(lldb::eFormatterMatchExact) {
165 if (type) {
166 m_type.m_type_name = std::string(type->GetName().GetStringRef());
167 m_type.m_compiler_type = type->GetForwardCompilerType();
168 }
169 }
170
172 : m_match_type(lldb::eFormatterMatchExact) {
173 if (type.IsValid()) {
174 m_type.m_type_name.assign(type.GetTypeName().GetCString());
175 m_type.m_compiler_type = type;
176 }
177 }
178
179 const char *GetName() {
180 if (m_type.m_type_name.size())
181 return m_type.m_type_name.c_str();
182 return nullptr;
183 }
184
186 if (m_type.m_compiler_type.IsValid())
187 return m_type.m_compiler_type;
188 return CompilerType();
189 }
190
192
194
195private:
197 // TODO: Replace this with TypeAndOrName.
203
207};
208
209} // namespace lldb_private
210
211#endif // LLDB_DATAFORMATTERS_FORMATCLASSES_H
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
ScriptInterpreter * GetScriptInterpreter() const
bool IsMatch(const std::shared_ptr< Formatter > &formatter_sp) const
FormattersMatchCandidate(ConstString name, ScriptInterpreter *script_interpreter, TypeImpl type, Flags flags, uint32_t ptr_stripped_depth=0)
CandidateLanguagesVector m_candidate_languages
CandidateLanguagesVector GetCandidateLanguages()
std::pair< FormattersMatchVector, bool > m_formatters_match_vector
lldb::DynamicValueType GetDynamicValueType()
FormattersMatchVector GetMatchesVector()
FormattersMatchData(ValueObject &, lldb::DynamicValueType)
lldb::DynamicValueType m_dynamic_value_type
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
std::function< typename FormatterType::SharedPointer( lldb_private::ValueObject &, lldb::DynamicValueType, FormatManager &)> HardcodedFormatterFinder
HardcodedFormatterFinders< TypeFormatImpl > HardcodedFormatFinder
std::vector< HardcodedFormatterFinder< FormatterType > > HardcodedFormatterFinders
const TypeNameSpecifierImpl & operator=(const TypeNameSpecifierImpl &)=delete
lldb::FormatterMatchType GetMatchType()
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.
std::vector< FormattersMatchCandidate > FormattersMatchVector
std::vector< lldb::LanguageType > CandidateLanguagesVector
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