ClangASTType.h revision 3aa7da5cb3327792415de44405e0896c6bdc305b
1//===-- ClangASTType.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 liblldb_ClangASTType_h_ 11#define liblldb_ClangASTType_h_ 12 13#include "lldb/lldb-include.h" 14#include "lldb/Core/ClangForward.h" 15 16namespace lldb_private { 17 18//---------------------------------------------------------------------- 19// A class that can carry around a clang ASTContext and a opaque clang 20// QualType. A clang::QualType can be easily reconstructed from an 21// opaque clang type and often the ASTContext is needed when doing 22// various type related tasks, so this class allows both items to travel 23// in a single very lightweight class that can be used. There are many 24// static equivalents of the member functions that allow the ASTContext 25// and the opaque clang QualType to be specified for ease of use and 26// to avoid code duplication. 27//---------------------------------------------------------------------- 28class ClangASTType 29{ 30protected: 31 ClangASTType (lldb::clang_type_t type, clang::ASTContext *ast_context) : 32 m_type (type), 33 m_ast (ast_context) 34 { 35 } 36 37 ClangASTType (const ClangASTType &tw) : 38 m_type (tw.m_type), 39 m_ast (tw.m_ast) 40 { 41 } 42 43 ClangASTType () : 44 m_type (0), 45 m_ast (0) 46 { 47 } 48 49 ~ClangASTType(); 50 51 const ClangASTType & 52 operator= (const ClangASTType &atb) 53 { 54 m_type = atb.m_type; 55 m_ast = atb.m_ast; 56 return *this; 57 } 58 59public: 60 lldb::clang_type_t 61 GetOpaqueQualType() const 62 { 63 return m_type; 64 } 65 66 clang::ASTContext * 67 GetASTContext() const 68 { 69 return m_ast; 70 } 71 72 ConstString 73 GetClangTypeName (); 74 75 static ConstString 76 GetClangTypeName (lldb::clang_type_t clang_type); 77 78 uint64_t 79 GetClangTypeBitWidth (); 80 81 static uint64_t 82 GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type); 83 84 size_t 85 GetTypeBitAlign (); 86 87 static size_t 88 GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 89 90 void 91 DumpValue (ExecutionContext *exe_ctx, 92 Stream *s, 93 lldb::Format format, 94 const DataExtractor &data, 95 uint32_t data_offset, 96 size_t data_byte_size, 97 uint32_t bitfield_bit_size, 98 uint32_t bitfield_bit_offset, 99 bool show_types, 100 bool show_summary, 101 bool verbose, 102 uint32_t depth); 103 104 static void 105 DumpValue (clang::ASTContext *ast_context, 106 lldb::clang_type_t opaque_clang_qual_type, 107 ExecutionContext *exe_ctx, 108 Stream *s, 109 lldb::Format format, 110 const DataExtractor &data, 111 uint32_t data_offset, 112 size_t data_byte_size, 113 uint32_t bitfield_bit_size, 114 uint32_t bitfield_bit_offset, 115 bool show_types, 116 bool show_summary, 117 bool verbose, 118 uint32_t depth); 119 120 bool 121 DumpTypeValue (Stream *s, 122 lldb::Format format, 123 const DataExtractor &data, 124 uint32_t data_offset, 125 size_t data_byte_size, 126 uint32_t bitfield_bit_size, 127 uint32_t bitfield_bit_offset); 128 129 130 static bool 131 DumpTypeValue (clang::ASTContext *ast_context, 132 lldb::clang_type_t opaque_clang_qual_type, 133 Stream *s, 134 lldb::Format format, 135 const DataExtractor &data, 136 uint32_t data_offset, 137 size_t data_byte_size, 138 uint32_t bitfield_bit_size, 139 uint32_t bitfield_bit_offset); 140 141 void 142 DumpSummary (ExecutionContext *exe_ctx, 143 Stream *s, 144 const DataExtractor &data, 145 uint32_t data_offset, 146 size_t data_byte_size); 147 148 149 static void 150 DumpSummary (clang::ASTContext *ast_context, 151 lldb::clang_type_t opaque_clang_qual_type, 152 ExecutionContext *exe_ctx, 153 Stream *s, 154 const DataExtractor &data, 155 uint32_t data_offset, 156 size_t data_byte_size); 157 158 void 159 DumpTypeDescription (Stream *s); 160 161 static void 162 DumpTypeDescription (clang::ASTContext *ast_context, 163 lldb::clang_type_t opaque_clang_qual_type, 164 Stream *s); 165 166 void DumpTypeCode (Stream *s); 167 168 static void 169 DumpTypeCode (void *type, 170 Stream *s); 171 172 lldb::Encoding 173 GetEncoding (uint32_t &count); 174 175 static lldb::Encoding 176 GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint32_t &count); 177 178 lldb::Format 179 GetFormat (); 180 181 static lldb::Format 182 GetFormat (lldb::clang_type_t opaque_clang_qual_type); 183 184 bool 185 GetValueAsScalar (const DataExtractor &data, 186 uint32_t data_offset, 187 size_t data_byte_size, 188 Scalar &value); 189 190 static bool 191 GetValueAsScalar (clang::ASTContext *ast_context, 192 lldb::clang_type_t opaque_clang_qual_type, 193 const DataExtractor &data, 194 uint32_t data_offset, 195 size_t data_byte_size, 196 Scalar &value); 197 198 199 bool 200 IsDefined(); 201 202 static bool 203 IsDefined (lldb::clang_type_t opaque_clang_qual_type); 204 205 bool 206 IsConst(); 207 208 static bool 209 IsConst (lldb::clang_type_t opaque_clang_qual_type); 210 211 bool 212 SetValueFromScalar (const Scalar &value, 213 Stream &strm); 214 215 static bool 216 SetValueFromScalar (clang::ASTContext *ast_context, 217 lldb::clang_type_t opaque_clang_qual_type, 218 const Scalar &value, 219 Stream &strm); 220 221 bool 222 ReadFromMemory (ExecutionContext *exe_ctx, 223 lldb::addr_t addr, 224 lldb::AddressType address_type, 225 DataExtractor &data); 226 227 static bool 228 ReadFromMemory (clang::ASTContext *ast_context, 229 lldb::clang_type_t opaque_clang_qual_type, 230 ExecutionContext *exe_ctx, 231 lldb::addr_t addr, 232 lldb::AddressType address_type, 233 DataExtractor &data); 234 235 bool 236 WriteToMemory (ExecutionContext *exe_ctx, 237 lldb::addr_t addr, 238 lldb::AddressType address_type, 239 StreamString &new_value); 240 241 static bool 242 WriteToMemory (clang::ASTContext *ast_context, 243 lldb::clang_type_t opaque_clang_qual_type, 244 ExecutionContext *exe_ctx, 245 lldb::addr_t addr, 246 lldb::AddressType address_type, 247 StreamString &new_value); 248 249 lldb::clang_type_t 250 GetPointeeType (); 251 252 static lldb::clang_type_t 253 GetPointeeType (lldb::clang_type_t opaque_clang_qual_type); 254 255 static lldb::clang_type_t 256 RemoveFastQualifiers (lldb::clang_type_t); 257 258private: 259 void *m_type; 260 clang::ASTContext *m_ast; 261}; 262 263 264} // namespace lldb_private 265 266#endif // #ifndef liblldb_ClangASTType_h_ 267