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"
23 #include "lldb/lldb-enumerations.h"
24 #include "lldb/lldb-public.h"
25 
26 namespace lldb_private {
27 
29 public:
30  template <typename FormatterType>
32  std::function<typename FormatterType::SharedPointer(
35 
36  template <typename FormatterType>
38  std::vector<HardcodedFormatterFinder<FormatterType>>;
39 
43 };
44 
46 public:
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 
83  ~FormattersMatchCandidate() = default;
84 
85  ConstString GetTypeName() const { return m_type_name; }
86 
87  TypeImpl GetType() const { return m_type; }
88 
90  return m_script_interpreter;
91  }
92 
93  bool DidStripPointer() const { return m_flags.stripped_pointer; }
94 
95  bool DidStripReference() const { return m_flags.stripped_reference; }
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 
112 private:
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 
121 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
122 typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
123 
125 public:
127 
129 
131 
133 
135 
137 
138 private:
141  std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
144 };
145 
147 public:
148  TypeNameSpecifierImpl() = default;
149 
150  TypeNameSpecifierImpl(llvm::StringRef name,
151  lldb::FormatterMatchType match_type)
152  : m_match_type(match_type) {
154  }
155 
156  // if constructing with a given type, we consider that a case of exact match.
157  TypeNameSpecifierImpl(lldb::TypeSP type)
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 
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 
189 private:
191  // TODO: Replace this with TypeAndOrName.
192  struct TypeOrName {
195  };
197 
199  const TypeNameSpecifierImpl &
200  operator=(const TypeNameSpecifierImpl &) = delete;
201 };
202 
203 } // namespace lldb_private
204 
205 #endif // LLDB_DATAFORMATTERS_FORMATCLASSES_H
lldb_private::FormattersMatchData
Definition: FormatClasses.h:124
lldb_private::FormattersMatchData::m_valobj
ValueObject & m_valobj
Definition: FormatClasses.h:139
lldb_private::FormattersMatchCandidate::FormattersMatchCandidate
FormattersMatchCandidate(ConstString name, ScriptInterpreter *script_interpreter, TypeImpl type, Flags flags)
Definition: FormatClasses.h:77
lldb-public.h
lldb_private::FormattersMatchCandidate::DidStripTypedef
bool DidStripTypedef() const
Definition: FormatClasses.h:97
lldb_private::TypeNameSpecifierImpl::GetName
const char * GetName()
Definition: FormatClasses.h:173
lldb_private::TypeNameSpecifierImpl::TypeOrName
Definition: FormatClasses.h:192
lldb_private::FormatManager
Definition: FormatManager.h:36
lldb_private::HardcodedFormatters::HardcodedFormatterFinder
std::function< typename FormatterType::SharedPointer(lldb_private::ValueObject &, lldb::DynamicValueType, FormatManager &)> HardcodedFormatterFinder
Definition: FormatClasses.h:34
lldb_private::FormattersMatchCandidate::Flags::WithStrippedReference
Flags WithStrippedReference()
Definition: FormatClasses.h:63
lldb_private::HardcodedFormatters::HardcodedFormatFinder
HardcodedFormatterFinders< TypeFormatImpl > HardcodedFormatFinder
Definition: FormatClasses.h:40
lldb_private::CompilerType::GetTypeName
ConstString GetTypeName(bool BaseOnly=false) const
Definition: CompilerType.cpp:314
lldb::FormatterMatchType
FormatterMatchType
Type of match to be performed when looking for a formatter for a data type.
Definition: lldb-enumerations.h:836
lldb_private::FormattersMatchCandidate::IsMatch
bool IsMatch(const std::shared_ptr< Formatter > &formatter_sp) const
Definition: FormatClasses.h:100
lldb_private::FormattersMatchCandidate::Flags::WithStrippedTypedef
Flags WithStrippedTypedef()
Definition: FormatClasses.h:70
lldb_private::FormattersMatchCandidate::Flags::stripped_typedef
bool stripped_typedef
Definition: FormatClasses.h:53
lldb_private::FormattersMatchCandidate::DidStripReference
bool DidStripReference() const
Definition: FormatClasses.h:95
lldb_private::TypeNameSpecifierImpl
Definition: FormatClasses.h:146
lldb_private::FormattersMatchData::GetMatchesVector
FormattersMatchVector GetMatchesVector()
Definition: FormatClasses.cpp:30
lldb_private::FormattersMatchCandidate::m_type
TypeImpl m_type
Definition: FormatClasses.h:117
lldb_private::FormattersMatchCandidate::DidStripPointer
bool DidStripPointer() const
Definition: FormatClasses.h:93
lldb_private::HardcodedFormatters::HardcodedSummaryFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:41
lldb_private::TypeNameSpecifierImpl::GetCompilerType
CompilerType GetCompilerType()
Definition: FormatClasses.h:179
lldb_private::FormattersMatchCandidate::Flags::stripped_pointer
bool stripped_pointer
Definition: FormatClasses.h:51
lldb_private::FormattersMatchData::FormattersMatchData
FormattersMatchData(ValueObject &, lldb::DynamicValueType)
Definition: FormatClasses.cpp:20
lldb_private::FormattersMatchCandidate::~FormattersMatchCandidate
~FormattersMatchCandidate()=default
lldb_private::FormattersMatchVector
std::vector< FormattersMatchCandidate > FormattersMatchVector
Definition: FormatClasses.h:121
lldb_private::FormattersMatchData::GetDynamicValueType
lldb::DynamicValueType GetDynamicValueType()
Definition: FormatClasses.cpp:47
lldb_private::FormattersMatchData::GetTypeForCache
ConstString GetTypeForCache()
Definition: FormatClasses.cpp:39
Type.h
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(CompilerType type)
Definition: FormatClasses.h:165
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(lldb::TypeSP type)
Definition: FormatClasses.h:157
lldb_private::ConstString
Definition: ConstString.h:39
lldb-enumerations.h
lldb_private::FormattersMatchCandidate::m_script_interpreter
ScriptInterpreter * m_script_interpreter
Definition: FormatClasses.h:116
lldb_private::FormattersMatchData::GetCandidateLanguages
CandidateLanguagesVector GetCandidateLanguages()
Definition: FormatClasses.cpp:41
lldb_private::TypeNameSpecifierImpl::GetMatchType
lldb::FormatterMatchType GetMatchType()
Definition: FormatClasses.h:185
lldb_private::FormattersMatchCandidate
Definition: FormatClasses.h:45
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:495
lldb_private::TypeNameSpecifierImpl::TypeOrName::m_compiler_type
CompilerType m_compiler_type
Definition: FormatClasses.h:194
lldb_private::FormattersMatchCandidate::GetType
TypeImpl GetType() const
Definition: FormatClasses.h:87
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::TypeNameSpecifierImpl::m_match_type
lldb::FormatterMatchType m_match_type
Definition: FormatClasses.h:190
lldb::eFormatterMatchExact
@ eFormatterMatchExact
Definition: lldb-enumerations.h:837
lldb_private::FormattersMatchCandidate::GetScriptInterpreter
ScriptInterpreter * GetScriptInterpreter() const
Definition: FormatClasses.h:89
CompilerType.h
lldb_private::CompilerType::IsValid
bool IsValid() const
Definition: CompilerType.h:123
lldb_private::TypeNameSpecifierImpl::IsRegex
bool IsRegex()
Definition: FormatClasses.h:187
lldb_private::FormattersMatchData::m_formatters_match_vector
std::pair< FormattersMatchVector, bool > m_formatters_match_vector
Definition: FormatClasses.h:141
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
TypeSummary.h
lldb_private::TypeNameSpecifierImpl::operator=
const TypeNameSpecifierImpl & operator=(const TypeNameSpecifierImpl &)=delete
lldb_private::TypeNameSpecifierImpl::TypeOrName::m_type_name
std::string m_type_name
Definition: FormatClasses.h:193
lldb_private::FormattersMatchCandidate::m_type_name
ConstString m_type_name
Definition: FormatClasses.h:113
TypeSynthetic.h
lldb_private::FormattersMatchData::m_dynamic_value_type
lldb::DynamicValueType m_dynamic_value_type
Definition: FormatClasses.h:140
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(llvm::StringRef name, lldb::FormatterMatchType match_type)
Definition: FormatClasses.h:150
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl()=default
TypeFormat.h
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:215
lldb_private::ScriptInterpreter
Definition: ScriptInterpreter.h:126
lldb_private::FormattersMatchData::m_candidate_languages
CandidateLanguagesVector m_candidate_languages
Definition: FormatClasses.h:143
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:35
lldb_private::FormattersMatchData::m_type_for_cache
ConstString m_type_for_cache
Definition: FormatClasses.h:142
lldb_private::FormattersMatchCandidate::GetTypeName
ConstString GetTypeName() const
Definition: FormatClasses.h:85
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::TypeImpl
Definition: Type.h:246
lldb_private::HardcodedFormatters
Definition: FormatClasses.h:28
lldb_private::CandidateLanguagesVector
std::vector< lldb::LanguageType > CandidateLanguagesVector
Definition: FormatClasses.h:122
lldb_private::FormattersMatchCandidate::Flags::stripped_reference
bool stripped_reference
Definition: FormatClasses.h:52
lldb_private::FormattersMatchCandidate::Flags
Definition: FormatClasses.h:50
lldb_private::TypeNameSpecifierImpl::m_type
TypeOrName m_type
Definition: FormatClasses.h:196
lldb_private::FormattersMatchCandidate::m_flags
Flags m_flags
Definition: FormatClasses.h:118
lldb_private::HardcodedFormatters::HardcodedFormatterFinders
std::vector< HardcodedFormatterFinder< FormatterType > > HardcodedFormatterFinders
Definition: FormatClasses.h:38
ScriptInterpreter.h
lldb
Definition: SBAddress.h:15
lldb::eFormatterMatchRegex
@ eFormatterMatchRegex
Definition: lldb-enumerations.h:838
lldb_private::FormattersMatchCandidate::Flags::WithStrippedPointer
Flags WithStrippedPointer()
Definition: FormatClasses.h:56
lldb_private::HardcodedFormatters::HardcodedSyntheticFinder
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:42