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_FormatClasses_h_
10 #define lldb_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 
44 };
45 
47 public:
48  FormattersMatchCandidate(ConstString name, uint32_t reason, bool strip_ptr,
49  bool strip_ref, bool strip_tydef)
50  : m_type_name(name), m_reason(reason), m_stripped_pointer(strip_ptr),
51  m_stripped_reference(strip_ref), m_stripped_typedef(strip_tydef) {}
52 
53  ~FormattersMatchCandidate() = default;
54 
55  ConstString GetTypeName() const { return m_type_name; }
56 
57  uint32_t GetReason() const { return m_reason; }
58 
59  bool DidStripPointer() const { return m_stripped_pointer; }
60 
61  bool DidStripReference() const { return m_stripped_reference; }
62 
63  bool DidStripTypedef() const { return m_stripped_typedef; }
64 
65  template <class Formatter>
66  bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
67  if (!formatter_sp)
68  return false;
69  if (formatter_sp->Cascades() == false && DidStripTypedef())
70  return false;
71  if (formatter_sp->SkipsPointers() && DidStripPointer())
72  return false;
73  if (formatter_sp->SkipsReferences() && DidStripReference())
74  return false;
75  return true;
76  }
77 
78 private:
79  ConstString m_type_name;
80  uint32_t m_reason;
81  bool m_stripped_pointer;
82  bool m_stripped_reference;
83  bool m_stripped_typedef;
84 };
85 
86 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
87 typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
88 
90 public:
92 
93  FormattersMatchVector GetMatchesVector();
94 
95  ConstString GetTypeForCache();
96 
97  CandidateLanguagesVector GetCandidateLanguages();
98 
99  ValueObject &GetValueObject();
100 
101  lldb::DynamicValueType GetDynamicValueType();
102 
103 private:
104  ValueObject &m_valobj;
105  lldb::DynamicValueType m_dynamic_value_type;
106  std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
107  ConstString m_type_for_cache;
108  CandidateLanguagesVector m_candidate_languages;
109 };
110 
112 public:
113  TypeNameSpecifierImpl() : m_is_regex(false), m_type() {}
114 
115  TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
116  : m_is_regex(is_regex), m_type() {
117  m_type.m_type_name = name;
118  }
119 
120  // if constructing with a given type, is_regex cannot be true since we are
121  // giving an exact type to match
122  TypeNameSpecifierImpl(lldb::TypeSP type) : m_is_regex(false), m_type() {
123  if (type) {
124  m_type.m_type_name = type->GetName().GetStringRef();
125  m_type.m_compiler_type = type->GetForwardCompilerType();
126  }
127  }
128 
129  TypeNameSpecifierImpl(CompilerType type) : m_is_regex(false), m_type() {
130  if (type.IsValid()) {
131  m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
132  m_type.m_compiler_type = type;
133  }
134  }
135 
136  const char *GetName() {
137  if (m_type.m_type_name.size())
138  return m_type.m_type_name.c_str();
139  return nullptr;
140  }
141 
143  if (m_type.m_compiler_type.IsValid())
144  return m_type.m_compiler_type;
145  return CompilerType();
146  }
147 
148  bool IsRegex() { return m_is_regex; }
149 
150 private:
151  bool m_is_regex;
152  // TODO: Replace this with TypeAndOrName.
153  struct TypeOrName {
154  std::string m_type_name;
155  CompilerType m_compiler_type;
156  };
157  TypeOrName m_type;
158 
159 private:
160  DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
161 };
162 
163 } // namespace lldb_private
164 
165 #endif // lldb_FormatClasses_h_
std::vector< lldb::LanguageType > CandidateLanguagesVector
Definition: FormatClasses.h:87
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:42
std::vector< FormattersMatchCandidate > FormattersMatchVector
Definition: FormatClasses.h:86
HardcodedFormatterFinders< TypeFormatImpl > HardcodedFormatFinder
Definition: FormatClasses.h:40
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:41
std::function< typename FormatterType::SharedPointer(lldb_private::ValueObject &, lldb::DynamicValueType, FormatManager &)> HardcodedFormatterFinder
Definition: FormatClasses.h:34
bool IsMatch(const std::shared_ptr< Formatter > &formatter_sp) const
Definition: FormatClasses.h:66
std::vector< HardcodedFormatterFinder< FormatterType > > HardcodedFormatterFinders
Definition: FormatClasses.h:38
A uniqued constant string class.
Definition: ConstString.h:38
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:247
TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
FormattersMatchCandidate(ConstString name, uint32_t reason, bool strip_ptr, bool strip_ref, bool strip_tydef)
Definition: FormatClasses.h:48
HardcodedFormatterFinders< TypeValidatorImpl > HardcodedValidatorFinder
Definition: FormatClasses.h:43
ConstString GetConstTypeName() const
TypeNameSpecifierImpl(CompilerType type)
TypeNameSpecifierImpl(lldb::TypeSP type)