ClangASTType.h revision b6a4c565732b3a7b546ba2aa0e7aec3a4bb359a4
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 <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 static ClangASTType 80 GetCanonicalType (clang::ASTContext *ast, lldb::clang_type_t clang_type); 81 82 ClangASTType 83 GetCanonicalType () 84 { 85 return GetCanonicalType (GetASTContext(), GetOpaqueQualType()); 86 } 87 88 ConstString 89 GetConstTypeName (); 90 91 ConstString 92 GetConstQualifiedTypeName (); 93 94 static lldb::BasicType 95 GetBasicTypeEnumeration (const ConstString &name); 96 97 static ClangASTType 98 GetBasicType (clang::ASTContext *ast, lldb::BasicType type); 99 100 static ClangASTType 101 GetBasicType (clang::ASTContext *ast, const ConstString &name); 102 103 static ConstString 104 GetConstTypeName (clang::ASTContext *ast, 105 lldb::clang_type_t clang_type); 106 107 static ConstString 108 GetConstQualifiedTypeName (clang::ASTContext *ast, 109 lldb::clang_type_t clang_type); 110 111 static std::string 112 GetTypeNameForQualType (clang::ASTContext *ast, 113 clang::QualType qual_type); 114 115 static std::string 116 GetTypeNameForOpaqueQualType (clang::ASTContext *ast, 117 lldb::clang_type_t opaque_qual_type); 118 119 uint64_t 120 GetClangTypeByteSize (); 121 122 static uint64_t 123 GetClangTypeByteSize (clang::ASTContext *ast_context, 124 lldb::clang_type_t clang_type); 125 126 uint64_t 127 GetClangTypeBitWidth (); 128 129 static uint64_t 130 GetClangTypeBitWidth (clang::ASTContext *ast_context, lldb::clang_type_t opaque_clang_qual_type); 131 132 size_t 133 GetTypeBitAlign (); 134 135 static size_t 136 GetTypeBitAlign (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 137 138 lldb::LanguageType 139 GetMinimumLanguage (); 140 141 static lldb::LanguageType 142 GetMinimumLanguage (clang::ASTContext *ctx, 143 lldb::clang_type_t clang_type); 144 145 static lldb::TypeClass 146 GetTypeClass (clang::ASTContext *ast_context, 147 lldb::clang_type_t clang_type); 148 149 lldb::TypeClass 150 GetTypeClass () const 151 { 152 return GetTypeClass (GetASTContext(), GetOpaqueQualType()); 153 } 154 155 ClangASTType 156 GetFullyUnqualifiedType (); 157 158 static ClangASTType 159 GetFullyUnqualifiedType (clang::ASTContext *ast_context, lldb::clang_type_t clang_type); 160 161 void 162 DumpValue (ExecutionContext *exe_ctx, 163 Stream *s, 164 lldb::Format format, 165 const DataExtractor &data, 166 lldb::offset_t data_offset, 167 size_t data_byte_size, 168 uint32_t bitfield_bit_size, 169 uint32_t bitfield_bit_offset, 170 bool show_types, 171 bool show_summary, 172 bool verbose, 173 uint32_t depth); 174 175 static void 176 DumpValue (clang::ASTContext *ast_context, 177 lldb::clang_type_t opaque_clang_qual_type, 178 ExecutionContext *exe_ctx, 179 Stream *s, 180 lldb::Format format, 181 const DataExtractor &data, 182 lldb::offset_t data_offset, 183 size_t data_byte_size, 184 uint32_t bitfield_bit_size, 185 uint32_t bitfield_bit_offset, 186 bool show_types, 187 bool show_summary, 188 bool verbose, 189 uint32_t depth); 190 191 bool 192 DumpTypeValue (Stream *s, 193 lldb::Format format, 194 const DataExtractor &data, 195 lldb::offset_t data_offset, 196 size_t data_byte_size, 197 uint32_t bitfield_bit_size, 198 uint32_t bitfield_bit_offset, 199 ExecutionContextScope *exe_scope); 200 201 202 static bool 203 DumpTypeValue (clang::ASTContext *ast_context, 204 lldb::clang_type_t opaque_clang_qual_type, 205 Stream *s, 206 lldb::Format format, 207 const DataExtractor &data, 208 lldb::offset_t data_offset, 209 size_t data_byte_size, 210 uint32_t bitfield_bit_size, 211 uint32_t bitfield_bit_offset, 212 ExecutionContextScope *exe_scope); 213 214 void 215 DumpSummary (ExecutionContext *exe_ctx, 216 Stream *s, 217 const DataExtractor &data, 218 lldb::offset_t data_offset, 219 size_t data_byte_size); 220 221 222 static void 223 DumpSummary (clang::ASTContext *ast_context, 224 lldb::clang_type_t opaque_clang_qual_type, 225 ExecutionContext *exe_ctx, 226 Stream *s, 227 const DataExtractor &data, 228 lldb::offset_t data_offset, 229 size_t data_byte_size); 230 231 void 232 DumpTypeDescription (); // Dump to stdout 233 234 void 235 DumpTypeDescription (Stream *s); 236 237 static void 238 DumpTypeDescription (clang::ASTContext *ast_context, 239 lldb::clang_type_t opaque_clang_qual_type, 240 Stream *s); 241 242 lldb::Encoding 243 GetEncoding (uint64_t &count); 244 245 static lldb::Encoding 246 GetEncoding (lldb::clang_type_t opaque_clang_qual_type, uint64_t &count); 247 248 lldb::Format 249 GetFormat (); 250 251 static lldb::Format 252 GetFormat (lldb::clang_type_t opaque_clang_qual_type); 253 254 uint64_t 255 GetTypeByteSize() const; 256 257 static uint64_t 258 GetTypeByteSize(clang::ASTContext *ast_context, 259 lldb::clang_type_t opaque_clang_qual_type); 260 261 bool 262 GetValueAsScalar (const DataExtractor &data, 263 lldb::offset_t data_offset, 264 size_t data_byte_size, 265 Scalar &value); 266 267 static bool 268 GetValueAsScalar (clang::ASTContext *ast_context, 269 lldb::clang_type_t opaque_clang_qual_type, 270 const DataExtractor &data, 271 lldb::offset_t data_offset, 272 size_t data_byte_size, 273 Scalar &value); 274 275 276 bool 277 IsDefined(); 278 279 static bool 280 IsDefined (lldb::clang_type_t opaque_clang_qual_type); 281 282 bool 283 IsConst(); 284 285 static bool 286 IsConst (lldb::clang_type_t opaque_clang_qual_type); 287 288 bool 289 SetValueFromScalar (const Scalar &value, 290 Stream &strm); 291 292 static bool 293 SetValueFromScalar (clang::ASTContext *ast_context, 294 lldb::clang_type_t opaque_clang_qual_type, 295 const Scalar &value, 296 Stream &strm); 297 298 void 299 SetClangType (clang::ASTContext *ast, lldb::clang_type_t type) 300 { 301 m_type = type; 302 m_ast = ast; 303 } 304 305 bool 306 ReadFromMemory (ExecutionContext *exe_ctx, 307 lldb::addr_t addr, 308 AddressType address_type, 309 DataExtractor &data); 310 311 static bool 312 ReadFromMemory (clang::ASTContext *ast_context, 313 lldb::clang_type_t opaque_clang_qual_type, 314 ExecutionContext *exe_ctx, 315 lldb::addr_t addr, 316 AddressType address_type, 317 DataExtractor &data); 318 319 bool 320 WriteToMemory (ExecutionContext *exe_ctx, 321 lldb::addr_t addr, 322 AddressType address_type, 323 StreamString &new_value); 324 325 static bool 326 WriteToMemory (clang::ASTContext *ast_context, 327 lldb::clang_type_t opaque_clang_qual_type, 328 ExecutionContext *exe_ctx, 329 lldb::addr_t addr, 330 AddressType address_type, 331 StreamString &new_value); 332 333 lldb::clang_type_t 334 GetPointeeType () const; 335 336 static lldb::clang_type_t 337 GetPointeeType (lldb::clang_type_t opaque_clang_qual_type); 338 339 lldb::clang_type_t 340 GetArrayElementType (uint64_t& stride); 341 342 static lldb::clang_type_t 343 GetArrayElementType (clang::ASTContext* ast, 344 lldb::clang_type_t opaque_clang_qual_type, 345 uint64_t& stride); 346 347 lldb::clang_type_t 348 GetPointerType () const; 349 350 static lldb::clang_type_t 351 GetPointerType (clang::ASTContext *ast_context, 352 lldb::clang_type_t opaque_clang_qual_type); 353 354 static lldb::clang_type_t 355 RemoveFastQualifiers (lldb::clang_type_t); 356 357 static clang::CXXRecordDecl * 358 GetAsCXXRecordDecl (lldb::clang_type_t opaque_clang_qual_type); 359 360 void 361 Clear() 362 { 363 m_type = NULL; 364 m_ast = NULL; 365 } 366 367private: 368 lldb::clang_type_t m_type; 369 clang::ASTContext *m_ast; 370}; 371 372bool operator == (const ClangASTType &lhs, const ClangASTType &rhs); 373bool operator != (const ClangASTType &lhs, const ClangASTType &rhs); 374 375 376} // namespace lldb_private 377 378#endif // #ifndef liblldb_ClangASTType_h_ 379