xref: /trueos/contrib/llvm/tools/lldb/include/lldb/DataFormatters/FormatClasses.h (revision de2662087f68970c151b26a2997516c216039b26)
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 #include <string>
15 #include <vector>
16 
17 // Other libraries and framework includes
18 
19 // Project includes
20 #include "lldb/lldb-public.h"
21 #include "lldb/lldb-enumerations.h"
22 
23 #include "lldb/Symbol/ClangASTType.h"
24 #include "lldb/Symbol/Type.h"
25 
26 namespace lldb_private {
27 
28 class FormattersMatchCandidate
29 {
30 public:
31 
FormattersMatchCandidate(ConstString name,uint32_t reason,bool strip_ptr,bool strip_ref,bool strip_tydef)32     FormattersMatchCandidate (ConstString name,
33                               uint32_t reason,
34                               bool strip_ptr,
35                               bool strip_ref,
36                               bool strip_tydef) :
37     m_type_name(name),
38     m_reason(reason),
39     m_stripped_pointer(strip_ptr),
40     m_stripped_reference(strip_ref),
41     m_stripped_typedef(strip_tydef)
42     {
43     }
44 
~FormattersMatchCandidate()45     ~FormattersMatchCandidate ()
46     {}
47 
48     ConstString
GetTypeName()49     GetTypeName () const
50     {
51         return m_type_name;
52     }
53 
54     uint32_t
GetReason()55     GetReason () const
56     {
57         return m_reason;
58     }
59 
60     bool
DidStripPointer()61     DidStripPointer () const
62     {
63         return m_stripped_pointer;
64     }
65 
66     bool
DidStripReference()67     DidStripReference () const
68     {
69         return m_stripped_reference;
70     }
71 
72     bool
DidStripTypedef()73     DidStripTypedef () const
74     {
75         return m_stripped_typedef;
76     }
77 
78     template <class Formatter>
79     bool
IsMatch(const std::shared_ptr<Formatter> & formatter_sp)80     IsMatch (const std::shared_ptr<Formatter>& formatter_sp) const
81     {
82         if (!formatter_sp)
83             return false;
84         if (formatter_sp->Cascades() == false && DidStripTypedef())
85             return false;
86         if (formatter_sp->SkipsPointers() && DidStripPointer())
87             return false;
88         if (formatter_sp->SkipsReferences() && DidStripReference())
89             return false;
90         return true;
91     }
92 
93 private:
94     ConstString m_type_name;
95     uint32_t m_reason;
96     bool m_stripped_pointer;
97     bool m_stripped_reference;
98     bool m_stripped_typedef;
99 };
100 
101 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
102 
103 class TypeNameSpecifierImpl
104 {
105 public:
TypeNameSpecifierImpl()106     TypeNameSpecifierImpl() :
107     m_is_regex(false),
108     m_type()
109     {
110     }
111 
TypeNameSpecifierImpl(const char * name,bool is_regex)112     TypeNameSpecifierImpl (const char* name, bool is_regex) :
113     m_is_regex(is_regex),
114     m_type()
115     {
116         if (name)
117             m_type.m_type_name.assign(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
TypeNameSpecifierImpl(lldb::TypeSP type)122     TypeNameSpecifierImpl (lldb::TypeSP type) :
123     m_is_regex(false),
124     m_type()
125     {
126         if (type)
127         {
128             m_type.m_type_name.assign(type->GetName().GetCString());
129             m_type.m_type_pair.SetType(type);
130         }
131     }
132 
TypeNameSpecifierImpl(ClangASTType type)133     TypeNameSpecifierImpl (ClangASTType type) :
134     m_is_regex(false),
135     m_type()
136     {
137         if (type.IsValid())
138         {
139             m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
140             m_type.m_type_pair.SetType(type);
141         }
142     }
143 
144     const char*
GetName()145     GetName()
146     {
147         if (m_type.m_type_name.size())
148             return m_type.m_type_name.c_str();
149         return NULL;
150     }
151 
152     lldb::TypeSP
GetTypeSP()153     GetTypeSP ()
154     {
155         if (m_type.m_type_pair.IsValid())
156             return m_type.m_type_pair.GetTypeSP();
157         return lldb::TypeSP();
158     }
159 
160     ClangASTType
GetClangASTType()161     GetClangASTType ()
162     {
163         if (m_type.m_type_pair.IsValid())
164             return m_type.m_type_pair.GetClangASTType();
165         return ClangASTType();
166     }
167 
168     bool
IsRegex()169     IsRegex()
170     {
171         return m_is_regex;
172     }
173 
174 private:
175     bool m_is_regex;
176     // this works better than TypeAndOrName because the latter only wraps a TypeSP
177     // whereas TypePair can also be backed by a ClangASTType
178     struct TypeOrName
179     {
180         std::string m_type_name;
181         TypePair m_type_pair;
182     };
183     TypeOrName m_type;
184 
185 
186 private:
187     DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
188 };
189 
190 } // namespace lldb_private
191 
192 #endif	// lldb_FormatClasses_h_
193