Type.h revision fe6dc6e241c52822710380cec0931351a1d7b2d3
1//===-- Type.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_Type_h_ 11#define liblldb_Type_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Core/ClangForward.h" 15#include "lldb/Core/ConstString.h" 16#include "lldb/Core/UserID.h" 17#include "lldb/Symbol/ClangASTType.h" 18#include "lldb/Symbol/Declaration.h" 19#include <set> 20 21namespace lldb_private { 22 23class SymbolFileType : 24 public STD_ENABLE_SHARED_FROM_THIS(SymbolFileType), 25 public UserID 26 { 27 public: 28 SymbolFileType (SymbolFile &symbol_file, lldb::user_id_t uid) : 29 UserID (uid), 30 m_symbol_file (symbol_file) 31 { 32 } 33 34 ~SymbolFileType () 35 { 36 } 37 38 Type * 39 operator->() 40 { 41 return GetType (); 42 } 43 44 Type * 45 GetType (); 46 47 protected: 48 SymbolFile &m_symbol_file; 49 lldb::TypeSP m_type_sp; 50 }; 51 52class Type : 53 public STD_ENABLE_SHARED_FROM_THIS(Type), 54 public UserID 55{ 56public: 57 typedef enum EncodingDataTypeTag 58 { 59 eEncodingInvalid, 60 eEncodingIsUID, ///< This type is the type whose UID is m_encoding_uid 61 eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added 62 eEncodingIsRestrictUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added 63 eEncodingIsVolatileUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added 64 eEncodingIsTypedefUID, ///< This type is pointer to a type whose UID is m_encoding_uid 65 eEncodingIsPointerUID, ///< This type is pointer to a type whose UID is m_encoding_uid 66 eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type whose UID is m_encoding_uid 67 eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type whose UID is m_encoding_uid 68 eEncodingIsSyntheticUID 69 } EncodingDataType; 70 71 typedef enum ResolveStateTag 72 { 73 eResolveStateUnresolved = 0, 74 eResolveStateForward = 1, 75 eResolveStateLayout = 2, 76 eResolveStateFull = 3 77 } ResolveState; 78 79 Type (lldb::user_id_t uid, 80 SymbolFile* symbol_file, 81 const ConstString &name, 82 uint64_t byte_size, 83 SymbolContextScope *context, 84 lldb::user_id_t encoding_uid, 85 EncodingDataType encoding_uid_type, 86 const Declaration& decl, 87 lldb::clang_type_t clang_qual_type, 88 ResolveState clang_type_resolve_state); 89 90 // This makes an invalid type. Used for functions that return a Type when they 91 // get an error. 92 Type(); 93 94 Type (const Type &rhs); 95 96 const Type& 97 operator= (const Type& rhs); 98 99 void 100 Dump(Stream *s, bool show_context); 101 102 void 103 DumpTypeName(Stream *s); 104 105 106 void 107 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); 108 109 SymbolFile * 110 GetSymbolFile() 111 { 112 return m_symbol_file; 113 } 114 const SymbolFile * 115 GetSymbolFile() const 116 { 117 return m_symbol_file; 118 } 119 120 TypeList* 121 GetTypeList(); 122 123 const ConstString& 124 GetName(); 125 126 uint64_t 127 GetByteSize(); 128 129 uint32_t 130 GetNumChildren (bool omit_empty_base_classes); 131 132 bool 133 IsAggregateType (); 134 135 bool 136 IsValidType () 137 { 138 return m_encoding_uid_type != eEncodingInvalid; 139 } 140 141 bool 142 IsTypedef () 143 { 144 return m_encoding_uid_type == eEncodingIsTypedefUID; 145 } 146 147 lldb::TypeSP 148 GetTypedefType(); 149 150 const ConstString & 151 GetName () const 152 { 153 return m_name; 154 } 155 156 ConstString 157 GetQualifiedName (); 158 159 void 160 DumpValue(ExecutionContext *exe_ctx, 161 Stream *s, 162 const DataExtractor &data, 163 uint32_t data_offset, 164 bool show_type, 165 bool show_summary, 166 bool verbose, 167 lldb::Format format = lldb::eFormatDefault); 168 169 bool 170 DumpValueInMemory(ExecutionContext *exe_ctx, 171 Stream *s, 172 lldb::addr_t address, 173 AddressType address_type, 174 bool show_types, 175 bool show_summary, 176 bool verbose); 177 178 bool 179 ReadFromMemory (ExecutionContext *exe_ctx, 180 lldb::addr_t address, 181 AddressType address_type, 182 DataExtractor &data); 183 184 bool 185 WriteToMemory (ExecutionContext *exe_ctx, 186 lldb::addr_t address, 187 AddressType address_type, 188 DataExtractor &data); 189 190 bool 191 GetIsDeclaration() const; 192 193 void 194 SetIsDeclaration(bool b); 195 196 bool 197 GetIsExternal() const; 198 199 void 200 SetIsExternal(bool b); 201 202 lldb::Format 203 GetFormat (); 204 205 lldb::Encoding 206 GetEncoding (uint64_t &count); 207 208 SymbolContextScope * 209 GetSymbolContextScope() 210 { 211 return m_context; 212 } 213 const SymbolContextScope * 214 GetSymbolContextScope() const 215 { 216 return m_context; 217 } 218 void 219 SetSymbolContextScope(SymbolContextScope *context) 220 { 221 m_context = context; 222 } 223 224 const lldb_private::Declaration & 225 GetDeclaration () const; 226 227 // Get the clang type, and resolve definitions for any 228 // class/struct/union/enum types completely. 229 lldb::clang_type_t 230 GetClangFullType (); 231 232 // Get the clang type, and resolve definitions enough so that the type could 233 // have layout performed. This allows ptrs and refs to class/struct/union/enum 234 // types remain forward declarations. 235 lldb::clang_type_t 236 GetClangLayoutType (); 237 238 // Get the clang type and leave class/struct/union/enum types as forward 239 // declarations if they haven't already been fully defined. 240 lldb::clang_type_t 241 GetClangForwardType (); 242 243 clang::ASTContext * 244 GetClangAST (); 245 246 ClangASTContext & 247 GetClangASTContext (); 248 249 static int 250 Compare(const Type &a, const Type &b); 251 252 // From a fully qualified typename, split the type into the type basename 253 // and the remaining type scope (namespaces/classes). 254 static bool 255 GetTypeScopeAndBasename (const char* &name_cstr, 256 std::string &scope, 257 std::string &basename, 258 lldb::TypeClass &type_class); 259 void 260 SetEncodingType (Type *encoding_type) 261 { 262 m_encoding_type = encoding_type; 263 } 264 265 uint32_t 266 GetEncodingMask (); 267 268 void * 269 CreateClangPointerType (Type *type); 270 271 void * 272 CreateClangTypedefType (Type *typedef_type, Type *base_type); 273 274 // For C++98 references (&) 275 void * 276 CreateClangLValueReferenceType (Type *type); 277 278 // For C++0x references (&&) 279 void * 280 CreateClangRValueReferenceType (Type *type); 281 282 bool 283 IsRealObjCClass(); 284 285 bool 286 IsCompleteObjCClass() 287 { 288 return m_flags.is_complete_objc_class; 289 } 290 291 void 292 SetIsCompleteObjCClass(bool is_complete_objc_class) 293 { 294 m_flags.is_complete_objc_class = is_complete_objc_class; 295 } 296 297protected: 298 ConstString m_name; 299 SymbolFile *m_symbol_file; 300 SymbolContextScope *m_context; // The symbol context in which this type is defined 301 Type *m_encoding_type; 302 lldb::user_id_t m_encoding_uid; 303 EncodingDataType m_encoding_uid_type; 304 uint64_t m_byte_size; 305 Declaration m_decl; 306 lldb::clang_type_t m_clang_type; 307 308 struct Flags { 309 ResolveState clang_type_resolve_state : 2; 310 bool is_complete_objc_class : 1; 311 } m_flags; 312 313 Type * 314 GetEncodingType (); 315 316 bool 317 ResolveClangType (ResolveState clang_type_resolve_state); 318}; 319 320 321/// 322/// Sometimes you can find the name of the type corresponding to an object, but we don't have debug 323/// information for it. If that is the case, you can return one of these objects, and then if it 324/// has a full type, you can use that, but if not at least you can print the name for informational 325/// purposes. 326/// 327 328class TypeAndOrName 329{ 330public: 331 TypeAndOrName (); 332 TypeAndOrName (lldb::TypeSP &type_sp); 333 TypeAndOrName (const char *type_str); 334 TypeAndOrName (const TypeAndOrName &rhs); 335 TypeAndOrName (ConstString &type_const_string); 336 337 TypeAndOrName & 338 operator= (const TypeAndOrName &rhs); 339 340 bool 341 operator==(const TypeAndOrName &other) const; 342 343 bool 344 operator!=(const TypeAndOrName &other) const; 345 346 ConstString GetName () const; 347 348 lldb::TypeSP 349 GetTypeSP () const 350 { 351 return m_type_sp; 352 } 353 354 void 355 SetName (const ConstString &type_name); 356 357 void 358 SetName (const char *type_name_cstr); 359 360 void 361 SetTypeSP (lldb::TypeSP type_sp); 362 363 bool 364 IsEmpty (); 365 366 bool 367 HasName (); 368 369 bool 370 HasTypeSP (); 371 372 void 373 Clear (); 374 375 operator 376 bool () 377 { 378 return !IsEmpty(); 379 } 380 381private: 382 lldb::TypeSP m_type_sp; 383 ConstString m_type_name; 384}; 385 386// the two classes here are used by the public API as a backend to 387// the SBType and SBTypeList classes 388 389class TypeImpl 390{ 391public: 392 393 TypeImpl() : 394 m_clang_ast_type(), 395 m_type_sp() 396 { 397 } 398 399 TypeImpl(const TypeImpl& rhs) : 400 m_clang_ast_type(rhs.m_clang_ast_type), 401 m_type_sp(rhs.m_type_sp) 402 { 403 } 404 405 TypeImpl(const lldb_private::ClangASTType& type); 406 407 TypeImpl(const lldb::TypeSP& type); 408 409 TypeImpl& 410 operator = (const TypeImpl& rhs); 411 412 bool 413 operator == (const TypeImpl& rhs) 414 { 415 return m_clang_ast_type == rhs.m_clang_ast_type && m_type_sp.get() == rhs.m_type_sp.get(); 416 } 417 418 bool 419 operator != (const TypeImpl& rhs) 420 { 421 return m_clang_ast_type != rhs.m_clang_ast_type || m_type_sp.get() != rhs.m_type_sp.get(); 422 } 423 424 bool 425 IsValid() 426 { 427 return m_type_sp.get() != NULL || m_clang_ast_type.IsValid(); 428 } 429 430 const lldb_private::ClangASTType & 431 GetClangASTType() const 432 { 433 return m_clang_ast_type; 434 } 435 436 clang::ASTContext* 437 GetASTContext(); 438 439 lldb::clang_type_t 440 GetOpaqueQualType(); 441 442 lldb::TypeSP 443 GetTypeSP () 444 { 445 return m_type_sp; 446 } 447 448 bool 449 GetDescription (lldb_private::Stream &strm, 450 lldb::DescriptionLevel description_level); 451 452 void 453 SetType (const lldb::TypeSP &type_sp); 454 455private: 456 ClangASTType m_clang_ast_type; 457 lldb::TypeSP m_type_sp; 458}; 459 460class TypeListImpl 461{ 462public: 463 TypeListImpl() : 464 m_content() 465 { 466 } 467 468 void 469 Append (const lldb::TypeImplSP& type) 470 { 471 m_content.push_back(type); 472 } 473 474 lldb::TypeImplSP 475 GetTypeAtIndex(size_t idx) 476 { 477 lldb::TypeImplSP type_sp; 478 if (idx < GetSize()) 479 type_sp = m_content[idx]; 480 return type_sp; 481 } 482 483 size_t 484 GetSize() 485 { 486 return m_content.size(); 487 } 488 489private: 490 std::vector<lldb::TypeImplSP> m_content; 491}; 492 493class TypeMemberImpl 494{ 495public: 496 TypeMemberImpl () : 497 m_type_impl_sp (), 498 m_bit_offset (0), 499 m_name (), 500 m_bitfield_bit_size (0), 501 m_is_bitfield (false) 502 503 { 504 } 505 506 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 507 uint64_t bit_offset, 508 const ConstString &name, 509 uint32_t bitfield_bit_size = 0, 510 bool is_bitfield = false) : 511 m_type_impl_sp (type_impl_sp), 512 m_bit_offset (bit_offset), 513 m_name (name), 514 m_bitfield_bit_size (bitfield_bit_size), 515 m_is_bitfield (is_bitfield) 516 { 517 } 518 519 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 520 uint64_t bit_offset): 521 m_type_impl_sp (type_impl_sp), 522 m_bit_offset (bit_offset), 523 m_name (), 524 m_bitfield_bit_size (0), 525 m_is_bitfield (false) 526 { 527 } 528 529 const lldb::TypeImplSP & 530 GetTypeImpl () 531 { 532 return m_type_impl_sp; 533 } 534 535 const ConstString & 536 GetName () const 537 { 538 return m_name; 539 } 540 541 uint64_t 542 GetBitOffset () const 543 { 544 return m_bit_offset; 545 } 546 547 uint32_t 548 GetBitfieldBitSize () const 549 { 550 return m_bitfield_bit_size; 551 } 552 553 void 554 SetBitfieldBitSize (uint32_t bitfield_bit_size) 555 { 556 m_bitfield_bit_size = bitfield_bit_size; 557 } 558 559 bool 560 GetIsBitfield () const 561 { 562 return m_is_bitfield; 563 } 564 565 void 566 SetIsBitfield (bool is_bitfield) 567 { 568 m_is_bitfield = is_bitfield; 569 } 570 571protected: 572 lldb::TypeImplSP m_type_impl_sp; 573 uint64_t m_bit_offset; 574 ConstString m_name; 575 uint32_t m_bitfield_bit_size; // Bit size for bitfield members only 576 bool m_is_bitfield; 577}; 578 579 580} // namespace lldb_private 581 582#endif // liblldb_Type_h_ 583 584