ClangASTType.h revision 133214fe6ebe3cf7f509047a3d297fca1f4b09ee
10532df02a72a32a6042e961b71989db73d0d0a22Argyrios Kyrtzidis//===-- ClangASTType.h ------------------------------------------*- C++ -*-===// 20532df02a72a32a6042e961b71989db73d0d0a22Argyrios Kyrtzidis// 30532df02a72a32a6042e961b71989db73d0d0a22Argyrios Kyrtzidis// 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 <string> 14#include "lldb/lldb-private.h" 15#include "lldb/Core/ClangForward.h" 16 17namespace lldb_private { 18 19//---------------------------------------------------------------------- 20// A class that can carry around a clang ASTContext and a opaque clang 21// QualType. A clang::QualType can be easily reconstructed from an 22// opaque clang type and often the ASTContext is needed when doing 23// various type related tasks, so this class allows both items to travel 24// in a single very lightweight class that can be used. There are many 25// static equivalents of the member functions that allow the ASTContext 26// and the opaque clang QualType to be specified for ease of use and 27// to avoid code duplication. 28//---------------------------------------------------------------------- 29class ClangASTType 30{ 31public: 32 33 ClangASTType (clang::ASTContext *ast_context, lldb::clang_type_t type) : 34 m_type (type), 35 m_ast (ast_context) 36 { 37 } 38 39 ClangASTType (const ClangASTType &tw) : 40 m_type (tw.m_type), 41 m_ast (tw.m_ast) 42 { 43 } 44 45 ClangASTType () : 46 m_type (0), 47 m_ast (0) 48 { 49 } 50 51 virtual ~ClangASTType(); 52 53 const ClangASTType & 54 operator= (const ClangASTType &atb) 55 { 56 m_type = atb.m_type; 57 m_ast = atb.m_ast; 58 return *this; 59 } 60 61 bool 62 IsValid () const 63 { 64 return m_type != NULL && m_ast != NULL; 65 } 66 67 lldb::clang_type_t 68 GetOpaqueQualType() const 69 { 70 return m_type; 71 } 72 73 clang::ASTContext * 74 GetASTContext() const 75 { 76 return m_ast; 77 } 78 79 ConstString 80 GetConstTypeName (); 81 82 ConstString 83 GetConstQualifiedTypeName (); 84 85 static lldb::BasicType 86 GetBasicTypeEnumeration (const ConstString &name); 87 88 static ClangASTType 89 GetBasicType (clang::ASTContext *ast, lldb::BasicType type); 90 91 static ClangASTType 92 GetBasicType (clang::ASTContext *ast, const ConstString &name); 93 94 static ConstString 95 GetConstTypeName (clang::ASTContext *ast, 96 lldb::clang_type_t clang_type); 97 98 static ConstString 99 GetConstQualifiedTypeName (clang::ASTContext *ast, 100 lldb::clang_type_t clang_type); 101 102 static std::string 103 GetTypeNameForQualType (clang::ASTContext *ast, 104 clang::QualType qual_type); 105 106 static std::string 107 GetTypeNameForOpaqueQualType (clang::ASTContext *ast, 108 lldb::clang_type_t opaque_qual_type); 109 110 uint64_t 111 GetClangTypeByteSize (); 112 113 uint64_t 114 GetClangTypeBitWidth (); 115 116 static uint64_t 117 GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type); 118 119 size_t 120 GetTypeBitAlign (); 121 122 static size_t 123 GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 124 125 lldb::LanguageType 126 GetMinimumLanguage (); 127 128 static lldb::LanguageType 129 GetMinimumLanguage (clang::ASTContext *ctx, 130 lldb::clang_type_t clang_type); 131 132 static lldb::TypeClass 133 GetTypeClass (clang::ASTContext *ast_context, 134 lldb::clang_type_t clang_type); 135 136 void 137 DumpValue (ExecutionContext *exe_ctx, 138 Stream *s, 139 lldb::Format format, 140 const DataExtractor &data, 141 lldb::offset_t data_offset, 142 size_t data_byte_size, 143 uint32_t bitfield_bit_size, 144 uint32_t bitfield_bit_offset, 145 bool show_types, 146 bool show_summary, 147 bool verbose, 148 uint32_t depth); 149 150 static void 151 DumpValue (clang::ASTContext *ast_context, 152 lldb::clang_type_t opaque_clang_qual_type, 153 ExecutionContext *exe_ctx, 154 Stream *s, 155 lldb::Format format, 156 const DataExtractor &data, 157 lldb::offset_t data_offset, 158 size_t data_byte_size, 159 uint32_t bitfield_bit_size, 160 uint32_t bitfield_bit_offset, 161 bool show_types, 162 bool show_summary, 163 bool verbose, 164 uint32_t depth); 165 166 bool 167 DumpTypeValue (Stream *s, 168 lldb::Format format, 169 const DataExtractor &data, 170 lldb::offset_t data_offset, 171 size_t data_byte_size, 172 uint32_t bitfield_bit_size, 173 uint32_t bitfield_bit_offset, 174 ExecutionContextScope *exe_scope); 175 176 177 static bool 178 DumpTypeValue (clang::ASTContext *ast_context, 179 lldb::clang_type_t opaque_clang_qual_type, 180 Stream *s, 181 lldb::Format format, 182 const DataExtractor &data, 183 lldb::offset_t data_offset, 184 size_t data_byte_size, 185 uint32_t bitfield_bit_size, 186 uint32_t bitfield_bit_offset, 187 ExecutionContextScope *exe_scope); 188 189 void 190 DumpSummary (ExecutionContext *exe_ctx, 191 Stream *s, 192 const DataExtractor &data, 193 lldb::offset_t data_offset, 194 size_t data_byte_size); 195 196 197 static void 198 DumpSummary (clang::ASTContext *ast_context, 199 lldb::clang_type_t opaque_clang_qual_type, 200 ExecutionContext *exe_ctx, 201 Stream *s, 202 const DataExtractor &data, 203 lldb::offset_t data_offset, 204 size_t data_byte_size); 205 206 void 207 DumpTypeDescription (); // Dump to stdout 208 209 void 210 DumpTypeDescription (Stream *s); 211 212 static void 213 DumpTypeDescription (clang::ASTContext *ast_context, 214 lldb::clang_type_t opaque_clang_qual_type, 215 Stream *s); 216 217 void DumpTypeCode (Stream *s); 218 219 static void 220 DumpTypeCode (void *type, 221 Stream *s); 222 223 lldb::Encoding 224 GetEncoding (uint64_t &count); 225 226 static lldb::Encoding 227 GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint64_t &count); 228 229 lldb::Format 230 GetFormat (); 231 232 static lldb::Format 233 GetFormat (lldb::clang_type_t opaque_clang_qual_type); 234 235 uint64_t 236 GetTypeByteSize() const; 237 238 static uint64_t 239 GetTypeByteSize(clang::ASTContext *ast_context, 240 lldb::clang_type_t opaque_clang_qual_type); 241 242 bool 243 GetValueAsScalar (const DataExtractor &data, 244 lldb::offset_t data_offset, 245 size_t data_byte_size, 246 Scalar &value); 247 248 static bool 249 GetValueAsScalar (clang::ASTContext *ast_context, 250 lldb::clang_type_t opaque_clang_qual_type, 251 const DataExtractor &data, 252 lldb::offset_t data_offset, 253 size_t data_byte_size, 254 Scalar &value); 255 256 257 bool 258 IsDefined(); 259 260 static bool 261 IsDefined (lldb::clang_type_t opaque_clang_qual_type); 262 263 bool 264 IsConst(); 265 266 static bool 267 IsConst (lldb::clang_type_t opaque_clang_qual_type); 268 269 bool 270 SetValueFromScalar (const Scalar &value, 271 Stream &strm); 272 273 static bool 274 SetValueFromScalar (clang::ASTContext *ast_context, 275 lldb::clang_type_t opaque_clang_qual_type, 276 const Scalar &value, 277 Stream &strm); 278 279 void 280 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type) 281 { 282 m_type = type; 283 m_ast = ast; 284 } 285 286 bool 287 ReadFromMemory (ExecutionContext *exe_ctx, 288 lldb::addr_t addr, 289 AddressType address_type, 290 DataExtractor &data); 291 292 static bool 293 ReadFromMemory (clang::ASTContext *ast_context, 294 lldb::clang_type_t opaque_clang_qual_type, 295 ExecutionContext *exe_ctx, 296 lldb::addr_t addr, 297 AddressType address_type, 298 DataExtractor &data); 299 300 bool 301 WriteToMemory (ExecutionContext *exe_ctx, 302 lldb::addr_t addr, 303 AddressType address_type, 304 StreamString &new_value); 305 306 static bool 307 WriteToMemory (clang::ASTContext *ast_context, 308 lldb::clang_type_t opaque_clang_qual_type, 309 ExecutionContext *exe_ctx, 310 lldb::addr_t addr, 311 AddressType address_type, 312 StreamString &new_value); 313 314 lldb::clang_type_t 315 GetPointeeType (); 316 317 static lldb::clang_type_t 318 GetPointeeType (lldb::clang_type_t opaque_clang_qual_type); 319 320 lldb::clang_type_t 321 GetArrayElementType (uint64_t& stride); 322 323 static lldb::clang_type_t 324 GetArrayElementType (clang::ASTContext* ast, 325 lldb::clang_type_t opaque_clang_qual_type, 326 uint64_t& stride); 327 328 lldb::clang_type_t 329 GetPointerType () const; 330 331 static lldb::clang_type_t 332 GetPointerType (clang::ASTContext *ast_context, 333 lldb::clang_type_t opaque_clang_qual_type); 334 335 static lldb::clang_type_t 336 RemoveFastQualifiers (lldb::clang_type_t); 337 338 static clang::CXXRecordDecl * 339 GetAsCXXRecordDecl (lldb::clang_type_t opaque_clang_qual_type); 340 341 void 342 Clear() 343 { 344 m_type = NULL; 345 m_ast = NULL; 346 } 347 348private: 349 lldb::clang_type_t m_type; 350 clang::ASTContext *m_ast; 351}; 352 353bool operator == (const ClangASTType &lhs, const ClangASTType &rhs); 354bool operator != (const ClangASTType &lhs, const ClangASTType &rhs); 355 356 357} // namespace lldb_private 358 359#endif // #ifndef liblldb_ClangASTType_h_ 360