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 
21 #include "lldb/Symbol/Type.h"
22 #include "lldb/lldb-enumerations.h"
23 #include "lldb/lldb-public.h"
24 
25 namespace lldb_private {
26 
28 public:
29  template <typename FormatterType>
31  std::function<typename FormatterType::SharedPointer(
34 
35  template <typename FormatterType>
37  std::vector<HardcodedFormatterFinder<FormatterType>>;
38 
42 };
43 
45 public:
46  FormattersMatchCandidate(ConstString name, bool strip_ptr,
47  bool strip_ref, bool strip_tydef)
48  : m_type_name(name), m_stripped_pointer(strip_ptr),
49  m_stripped_reference(strip_ref), m_stripped_typedef(strip_tydef) {}
50 
51  ~FormattersMatchCandidate() = default;
52 
53  ConstString GetTypeName() const { return m_type_name; }
54 
55  bool DidStripPointer() const { return m_stripped_pointer; }
56 
57  bool DidStripReference() const { return m_stripped_reference; }
58 
59  bool DidStripTypedef() const { return m_stripped_typedef; }
60 
61  template <class Formatter>
62  bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
63  if (!formatter_sp)
64  return false;
65  if (formatter_sp->Cascades() == false && DidStripTypedef())
66  return false;
67  if (formatter_sp->SkipsPointers() && DidStripPointer())
68  return false;
69  if (formatter_sp->SkipsReferences() && DidStripReference())
70  return false;
71  return true;
72  }
73 
74 private:
79 };
80 
81 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
82 typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
83 
85 public:
87 
89 
91 
93 
95 
97 
98 private:
101  std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
104 };
105 
107 public:
109 
110  TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
111  : m_is_regex(is_regex), m_type() {
113  }
114 
115  // if constructing with a given type, is_regex cannot be true since we are
116  // giving an exact type to match
117  TypeNameSpecifierImpl(lldb::TypeSP type) : m_is_regex(false), m_type() {
118  if (type) {
119  m_type.m_type_name = std::string(type->GetName().GetStringRef());
120  m_type.m_compiler_type = type->GetForwardCompilerType();
121  }
122  }
123 
125  if (type.IsValid()) {
126  m_type.m_type_name.assign(type.GetTypeName().GetCString());
127  m_type.m_compiler_type = type;
128  }
129  }
130 
131  const char *GetName() {
132  if (m_type.m_type_name.size())
133  return m_type.m_type_name.c_str();
134  return nullptr;
135  }
136 
139  return m_type.m_compiler_type;
140  return CompilerType();
141  }
142 
143  bool IsRegex() { return m_is_regex; }
144 
145 private:
146  bool m_is_regex = false;
147  // TODO: Replace this with TypeAndOrName.
148  struct TypeOrName {
151  };
153 
155  const TypeNameSpecifierImpl &
156  operator=(const TypeNameSpecifierImpl &) = delete;
157 };
158 
159 } // namespace lldb_private
160 
161 #endif // LLDB_DATAFORMATTERS_FORMATCLASSES_H
lldb_private::FormattersMatchData
Definition: FormatClasses.h:84
lldb_private::FormattersMatchData::m_valobj
ValueObject & m_valobj
Definition: FormatClasses.h:99
lldb-public.h
lldb_private::FormattersMatchCandidate::DidStripTypedef
bool DidStripTypedef() const
Definition: FormatClasses.h:59
lldb_private::TypeNameSpecifierImpl::GetName
const char * GetName()
Definition: FormatClasses.h:131
lldb_private::TypeNameSpecifierImpl::TypeOrName
Definition: FormatClasses.h:148
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:33
lldb_private::HardcodedFormatters::HardcodedFormatFinder
HardcodedFormatterFinders< TypeFormatImpl > HardcodedFormatFinder
Definition: FormatClasses.h:39
lldb_private::TypeNameSpecifierImpl::m_is_regex
bool m_is_regex
Definition: FormatClasses.h:146
lldb_private::FormattersMatchCandidate::IsMatch
bool IsMatch(const std::shared_ptr< Formatter > &formatter_sp) const
Definition: FormatClasses.h:62
lldb_private::FormattersMatchCandidate::DidStripReference
bool DidStripReference() const
Definition: FormatClasses.h:57
lldb_private::TypeNameSpecifierImpl
Definition: FormatClasses.h:106
lldb_private::FormattersMatchData::GetMatchesVector
FormattersMatchVector GetMatchesVector()
Definition: FormatClasses.cpp:30
lldb_private::FormattersMatchCandidate::DidStripPointer
bool DidStripPointer() const
Definition: FormatClasses.h:55
lldb_private::HardcodedFormatters::HardcodedSummaryFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:40
lldb_private::TypeNameSpecifierImpl::GetCompilerType
CompilerType GetCompilerType()
Definition: FormatClasses.h:137
lldb_private::FormattersMatchData::FormattersMatchData
FormattersMatchData(ValueObject &, lldb::DynamicValueType)
Definition: FormatClasses.cpp:20
lldb_private::FormattersMatchCandidate::~FormattersMatchCandidate
~FormattersMatchCandidate()=default
lldb_private::FormattersMatchCandidate::m_stripped_pointer
bool m_stripped_pointer
Definition: FormatClasses.h:76
lldb_private::FormattersMatchVector
std::vector< FormattersMatchCandidate > FormattersMatchVector
Definition: FormatClasses.h:81
lldb_private::FormattersMatchData::GetDynamicValueType
lldb::DynamicValueType GetDynamicValueType()
Definition: FormatClasses.cpp:47
lldb_private::FormattersMatchData::GetTypeForCache
ConstString GetTypeForCache()
Definition: FormatClasses.cpp:39
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
Definition: FormatClasses.h:110
Type.h
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(CompilerType type)
Definition: FormatClasses.h:124
lldb_private::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl(lldb::TypeSP type)
Definition: FormatClasses.h:117
lldb_private::ConstString
Definition: ConstString.h:40
lldb-enumerations.h
lldb_private::FormattersMatchData::GetCandidateLanguages
CandidateLanguagesVector GetCandidateLanguages()
Definition: FormatClasses.cpp:41
lldb_private::FormattersMatchCandidate
Definition: FormatClasses.h:44
lldb::DynamicValueType
DynamicValueType
Definition: lldb-enumerations.h:494
lldb_private::TypeNameSpecifierImpl::TypeOrName::m_compiler_type
CompilerType m_compiler_type
Definition: FormatClasses.h:150
lldb_private::FormattersMatchCandidate::m_stripped_reference
bool m_stripped_reference
Definition: FormatClasses.h:77
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:39
CompilerType.h
lldb_private::CompilerType::IsValid
bool IsValid() const
Definition: CompilerType.h:72
lldb_private::TypeNameSpecifierImpl::IsRegex
bool IsRegex()
Definition: FormatClasses.h:143
lldb_private::FormattersMatchData::m_formatters_match_vector
std::pair< FormattersMatchVector, bool > m_formatters_match_vector
Definition: FormatClasses.h:101
lldb_private::FormattersMatchCandidate::FormattersMatchCandidate
FormattersMatchCandidate(ConstString name, bool strip_ptr, bool strip_ref, bool strip_tydef)
Definition: FormatClasses.h:46
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:149
lldb_private::FormattersMatchCandidate::m_type_name
ConstString m_type_name
Definition: FormatClasses.h:75
TypeSynthetic.h
lldb_private::CompilerType::GetTypeName
ConstString GetTypeName() const
Definition: CompilerType.cpp:277
lldb_private::FormattersMatchData::m_dynamic_value_type
lldb::DynamicValueType m_dynamic_value_type
Definition: FormatClasses.h:100
lldb_private::FormattersMatchCandidate::m_stripped_typedef
bool m_stripped_typedef
Definition: FormatClasses.h:78
TypeFormat.h
lldb_private::ConstString::GetCString
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
lldb_private::FormattersMatchData::m_candidate_languages
CandidateLanguagesVector m_candidate_languages
Definition: FormatClasses.h:103
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
lldb_private::FormattersMatchData::m_type_for_cache
ConstString m_type_for_cache
Definition: FormatClasses.h:102
lldb_private::FormattersMatchCandidate::GetTypeName
ConstString GetTypeName() const
Definition: FormatClasses.h:53
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::TypeNameSpecifierImpl::TypeNameSpecifierImpl
TypeNameSpecifierImpl()
Definition: FormatClasses.h:108
lldb_private::HardcodedFormatters
Definition: FormatClasses.h:27
lldb_private::CandidateLanguagesVector
std::vector< lldb::LanguageType > CandidateLanguagesVector
Definition: FormatClasses.h:82
lldb_private::TypeNameSpecifierImpl::m_type
TypeOrName m_type
Definition: FormatClasses.h:152
lldb_private::HardcodedFormatters::HardcodedFormatterFinders
std::vector< HardcodedFormatterFinder< FormatterType > > HardcodedFormatterFinders
Definition: FormatClasses.h:37
lldb_private::HardcodedFormatters::HardcodedSyntheticFinder
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:41