FormatClasses.h revision 263367
1231673Stheraven//===-- FormatClasses.h -----------------------------------------*- C++ -*-===// 2231673Stheraven// 3231673Stheraven// The LLVM Compiler Infrastructure 4231673Stheraven// 5231673Stheraven// This file is distributed under the University of Illinois Open Source 6231673Stheraven// License. See LICENSE.TXT for details. 7231673Stheraven// 8231673Stheraven//===----------------------------------------------------------------------===// 9231673Stheraven 10231673Stheraven#ifndef lldb_FormatClasses_h_ 11231673Stheraven#define lldb_FormatClasses_h_ 12231673Stheraven 13231673Stheraven// C++ Includes 14231673Stheraven#include <string> 15231673Stheraven#include <vector> 16231673Stheraven 17231673Stheraven// Other libraries and framework includes 18231673Stheraven 19231673Stheraven// Project includes 20231673Stheraven#include "lldb/lldb-public.h" 21231673Stheraven#include "lldb/lldb-enumerations.h" 22231673Stheraven 23231673Stheraven#include "lldb/Symbol/ClangASTType.h" 24231673Stheraven#include "lldb/Symbol/Type.h" 25231673Stheraven 26231673Stheravennamespace lldb_private { 27231673Stheraven 28231673Stheravenclass FormattersMatchCandidate 29231673Stheraven{ 30231673Stheravenpublic: 31231673Stheraven 32231673Stheraven FormattersMatchCandidate (ConstString name, 33231673Stheraven uint32_t reason, 34231673Stheraven bool strip_ptr, 35304862Sache bool strip_ref, 36231673Stheraven bool strip_tydef) : 37231673Stheraven m_type_name(name), 38304862Sache m_reason(reason), 39304862Sache m_stripped_pointer(strip_ptr), 40304862Sache m_stripped_reference(strip_ref), 41304862Sache m_stripped_typedef(strip_tydef) 42231673Stheraven { 43231673Stheraven } 44231673Stheraven 45231673Stheraven ~FormattersMatchCandidate () 46231673Stheraven {} 47231673Stheraven 48231673Stheraven ConstString 49231673Stheraven GetTypeName () const 50231673Stheraven { 51231673Stheraven return m_type_name; 52231673Stheraven } 53231673Stheraven 54231673Stheraven uint32_t 55231673Stheraven GetReason () const 56231673Stheraven { 57231673Stheraven return m_reason; 58 } 59 60 bool 61 DidStripPointer () const 62 { 63 return m_stripped_pointer; 64 } 65 66 bool 67 DidStripReference () const 68 { 69 return m_stripped_reference; 70 } 71 72 bool 73 DidStripTypedef () const 74 { 75 return m_stripped_typedef; 76 } 77 78 template <class Formatter> 79 bool 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 93private: 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 101typedef std::vector<FormattersMatchCandidate> FormattersMatchVector; 102 103class TypeNameSpecifierImpl 104{ 105public: 106 TypeNameSpecifierImpl() : 107 m_is_regex(false), 108 m_type() 109 { 110 } 111 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 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 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* 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 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 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 169 IsRegex() 170 { 171 return m_is_regex; 172 } 173 174private: 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 186private: 187 DISALLOW_COPY_AND_ASSIGN(TypeNameSpecifierImpl); 188}; 189 190} // namespace lldb_private 191 192#endif // lldb_FormatClasses_h_ 193