1 //===-- FormatClasses.h -----------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_FormatClasses_h_
11 #define lldb_FormatClasses_h_
17 // Other libraries and framework includes
20 #include "lldb/lldb-public.h"
21 #include "lldb/lldb-enumerations.h"
23 #include "lldb/Symbol/ClangASTType.h"
24 #include "lldb/Symbol/Type.h"
26 namespace lldb_private {
28 class FormattersMatchCandidate
32 FormattersMatchCandidate (ConstString name,
39 m_stripped_pointer(strip_ptr),
40 m_stripped_reference(strip_ref),
41 m_stripped_typedef(strip_tydef)
45 ~FormattersMatchCandidate ()
61 DidStripPointer () const
63 return m_stripped_pointer;
67 DidStripReference () const
69 return m_stripped_reference;
73 DidStripTypedef () const
75 return m_stripped_typedef;
78 template <class Formatter>
80 IsMatch (const std::shared_ptr<Formatter>& formatter_sp) const
84 if (formatter_sp->Cascades() == false && DidStripTypedef())
86 if (formatter_sp->SkipsPointers() && DidStripPointer())
88 if (formatter_sp->SkipsReferences() && DidStripReference())
94 ConstString m_type_name;
96 bool m_stripped_pointer;
97 bool m_stripped_reference;
98 bool m_stripped_typedef;
101 typedef std::vector<FormattersMatchCandidate> FormattersMatchVector;
103 class TypeNameSpecifierImpl
106 TypeNameSpecifierImpl() :
112 TypeNameSpecifierImpl (const char* name, bool is_regex) :
113 m_is_regex(is_regex),
117 m_type.m_type_name.assign(name);
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) :
128 m_type.m_type_name.assign(type->GetName().GetCString());
129 m_type.m_type_pair.SetType(type);
133 TypeNameSpecifierImpl (ClangASTType type) :
139 m_type.m_type_name.assign(type.GetConstTypeName().GetCString());
140 m_type.m_type_pair.SetType(type);
147 if (m_type.m_type_name.size())
148 return m_type.m_type_name.c_str();
155 if (m_type.m_type_pair.IsValid())
156 return m_type.m_type_pair.GetTypeSP();
157 return lldb::TypeSP();
163 if (m_type.m_type_pair.IsValid())
164 return m_type.m_type_pair.GetClangASTType();
165 return ClangASTType();
176 // this works better than TypeAndOrName because the latter only wraps a TypeSP
177 // whereas TypePair can also be backed by a ClangASTType
180 std::string m_type_name;
181 TypePair m_type_pair;
187 DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl);
190 } // namespace lldb_private
192 #endif // lldb_FormatClasses_h_