]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/DataFormatters/FormatClasses.h
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / include / lldb / DataFormatters / FormatClasses.h
1 //===-- FormatClasses.h -----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef lldb_FormatClasses_h_
11 #define lldb_FormatClasses_h_
12
13 // C Includes
14 // C++ Includes
15 #include <functional>
16 #include <memory>
17 #include <string>
18 #include <vector>
19
20 // Other libraries and framework includes
21 // Project includes
22 #include "lldb/DataFormatters/TypeFormat.h"
23 #include "lldb/DataFormatters/TypeSummary.h"
24 #include "lldb/DataFormatters/TypeSynthetic.h"
25 #include "lldb/DataFormatters/TypeValidator.h"
26 #include "lldb/Symbol/CompilerType.h"
27 #include "lldb/Symbol/Type.h"
28 #include "lldb/lldb-enumerations.h"
29 #include "lldb/lldb-public.h"
30
31 namespace lldb_private {
32
33 class HardcodedFormatters {
34 public:
35   template <typename FormatterType>
36   using HardcodedFormatterFinder =
37       std::function<typename FormatterType::SharedPointer(
38           lldb_private::ValueObject &, lldb::DynamicValueType,
39           FormatManager &)>;
40
41   template <typename FormatterType>
42   using HardcodedFormatterFinders =
43       std::vector<HardcodedFormatterFinder<FormatterType>>;
44
45   typedef HardcodedFormatterFinders<TypeFormatImpl> HardcodedFormatFinder;
46   typedef HardcodedFormatterFinders<TypeSummaryImpl> HardcodedSummaryFinder;
47   typedef HardcodedFormatterFinders<SyntheticChildren> HardcodedSyntheticFinder;
48   typedef HardcodedFormatterFinders<TypeValidatorImpl> HardcodedValidatorFinder;
49 };
50
51 class FormattersMatchCandidate {
52 public:
53   FormattersMatchCandidate(ConstString name, uint32_t reason, bool strip_ptr,
54                            bool strip_ref, bool strip_tydef)
55       : m_type_name(name), m_reason(reason), m_stripped_pointer(strip_ptr),
56         m_stripped_reference(strip_ref), m_stripped_typedef(strip_tydef) {}
57
58   ~FormattersMatchCandidate() = default;
59
60   ConstString GetTypeName() const { return m_type_name; }
61
62   uint32_t GetReason() const { return m_reason; }
63
64   bool DidStripPointer() const { return m_stripped_pointer; }
65
66   bool DidStripReference() const { return m_stripped_reference; }
67
68   bool DidStripTypedef() const { return m_stripped_typedef; }
69
70   template <class Formatter>
71   bool IsMatch(const std::shared_ptr<Formatter> &formatter_sp) const {
72     if (!formatter_sp)
73       return false;
74     if (formatter_sp->Cascades() == false && DidStripTypedef())
75       return false;
76     if (formatter_sp->SkipsPointers() && DidStripPointer())
77       return false;
78     if (formatter_sp->SkipsReferences() && DidStripReference())
79       return false;
80     return true;
81   }
82
83 private:
84   ConstString m_type_name;
85   uint32_t m_reason;
86   bool m_stripped_pointer;
87   bool m_stripped_reference;
88   bool m_stripped_typedef;
89 };
90
91 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
92 typedef std::vector<lldb::LanguageType> CandidateLanguagesVector;
93
94 class FormattersMatchData {
95 public:
96   FormattersMatchData(ValueObject &, lldb::DynamicValueType);
97
98   FormattersMatchVector GetMatchesVector();
99
100   ConstString GetTypeForCache();
101
102   CandidateLanguagesVector GetCandidateLanguages();
103
104   ValueObject &GetValueObject();
105
106   lldb::DynamicValueType GetDynamicValueType();
107
108 private:
109   ValueObject &m_valobj;
110   lldb::DynamicValueType m_dynamic_value_type;
111   std::pair<FormattersMatchVector, bool> m_formatters_match_vector;
112   ConstString m_type_for_cache;
113   CandidateLanguagesVector m_candidate_languages;
114 };
115
116 class TypeNameSpecifierImpl {
117 public:
118   TypeNameSpecifierImpl() : m_is_regex(false), m_type() {}
119
120   TypeNameSpecifierImpl(llvm::StringRef name, bool is_regex)
121       : m_is_regex(is_regex), m_type() {
122     m_type.m_type_name = name;
123   }
124
125   // if constructing with a given type, is_regex cannot be true since we are
126   // giving an exact type to match
127   TypeNameSpecifierImpl(lldb::TypeSP type) : m_is_regex(false), m_type() {
128     if (type) {
129       m_type.m_type_name = type->GetName().GetStringRef();
130       m_type.m_type_pair.SetType(type);
131     }
132   }
133
134   TypeNameSpecifierImpl(CompilerType type) : m_is_regex(false), m_type() {
135     if (type.IsValid()) {
136       m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
137       m_type.m_type_pair.SetType(type);
138     }
139   }
140
141   const char *GetName() {
142     if (m_type.m_type_name.size())
143       return m_type.m_type_name.c_str();
144     return nullptr;
145   }
146
147   lldb::TypeSP GetTypeSP() {
148     if (m_type.m_type_pair.IsValid())
149       return m_type.m_type_pair.GetTypeSP();
150     return lldb::TypeSP();
151   }
152
153   CompilerType GetCompilerType() {
154     if (m_type.m_type_pair.IsValid())
155       return m_type.m_type_pair.GetCompilerType();
156     return CompilerType();
157   }
158
159   bool IsRegex() { return m_is_regex; }
160
161 private:
162   bool m_is_regex;
163   // this works better than TypeAndOrName because the latter only wraps a TypeSP
164   // whereas TypePair can also be backed by a CompilerType
165   struct TypeOrName {
166     std::string m_type_name;
167     TypePair m_type_pair;
168   };
169   TypeOrName m_type;
170
171 private:
172   DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
173 };
174
175 } // namespace lldb_private
176
177 #endif // lldb_FormatClasses_h_