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 20 #include "llvm/ADT/APSInt.h" 21 22 #include <set> 23 24 namespace lldb_private { 25 26 class SymbolFileType : 27 public std::enable_shared_from_this<SymbolFileType>, 28 public UserID 29 { 30 public: SymbolFileType(SymbolFile & symbol_file,lldb::user_id_t uid)31 SymbolFileType (SymbolFile &symbol_file, lldb::user_id_t uid) : 32 UserID (uid), 33 m_symbol_file (symbol_file) 34 { 35 } 36 ~SymbolFileType()37 ~SymbolFileType () 38 { 39 } 40 41 Type * 42 operator->() 43 { 44 return GetType (); 45 } 46 47 Type * 48 GetType (); 49 50 protected: 51 SymbolFile &m_symbol_file; 52 lldb::TypeSP m_type_sp; 53 }; 54 55 class Type : 56 public std::enable_shared_from_this<Type>, 57 public UserID 58 { 59 public: 60 typedef enum EncodingDataTypeTag 61 { 62 eEncodingInvalid, 63 eEncodingIsUID, ///< This type is the type whose UID is m_encoding_uid 64 eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added 65 eEncodingIsRestrictUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added 66 eEncodingIsVolatileUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added 67 eEncodingIsTypedefUID, ///< This type is pointer to a type whose UID is m_encoding_uid 68 eEncodingIsPointerUID, ///< This type is pointer to a type whose UID is m_encoding_uid 69 eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type whose UID is m_encoding_uid 70 eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type whose UID is m_encoding_uid 71 eEncodingIsSyntheticUID 72 } EncodingDataType; 73 74 // We must force the underlying type of the enum to be unsigned here. Not all compilers 75 // behave the same with regards to the default underlying type of an enum, but because 76 // this enum is used in an enum bitfield and integer comparisons are done with the value 77 // we need to guarantee that it's always unsigned so that, for example, eResolveStateFull 78 // doesn't compare less than eResolveStateUnresolved when used in a 2-bit bitfield. 79 typedef enum ResolveStateTag : unsigned 80 { 81 eResolveStateUnresolved = 0, 82 eResolveStateForward = 1, 83 eResolveStateLayout = 2, 84 eResolveStateFull = 3 85 } ResolveState; 86 87 Type (lldb::user_id_t uid, 88 SymbolFile* symbol_file, 89 const ConstString &name, 90 uint64_t byte_size, 91 SymbolContextScope *context, 92 lldb::user_id_t encoding_uid, 93 EncodingDataType encoding_uid_type, 94 const Declaration& decl, 95 const ClangASTType &clang_qual_type, 96 ResolveState clang_type_resolve_state); 97 98 // This makes an invalid type. Used for functions that return a Type when they 99 // get an error. 100 Type(); 101 102 Type (const Type &rhs); 103 104 const Type& 105 operator= (const Type& rhs); 106 107 void 108 Dump(Stream *s, bool show_context); 109 110 void 111 DumpTypeName(Stream *s); 112 113 // Since Type instances only keep a "SymbolFile *" internally, other classes 114 // like TypeImpl need make sure the module is still around before playing with 115 // Type instances. They can store a weak pointer to the Module; 116 lldb::ModuleSP 117 GetModule(); 118 119 void 120 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); 121 122 SymbolFile * GetSymbolFile()123 GetSymbolFile() 124 { 125 return m_symbol_file; 126 } 127 const SymbolFile * GetSymbolFile()128 GetSymbolFile() const 129 { 130 return m_symbol_file; 131 } 132 133 TypeList* 134 GetTypeList(); 135 136 const ConstString& 137 GetName(); 138 139 uint64_t 140 GetByteSize(); 141 142 uint32_t 143 GetNumChildren (bool omit_empty_base_classes); 144 145 bool 146 IsAggregateType (); 147 148 bool IsValidType()149 IsValidType () 150 { 151 return m_encoding_uid_type != eEncodingInvalid; 152 } 153 154 bool IsTypedef()155 IsTypedef () 156 { 157 return m_encoding_uid_type == eEncodingIsTypedefUID; 158 } 159 160 lldb::TypeSP 161 GetTypedefType(); 162 163 const ConstString & GetName()164 GetName () const 165 { 166 return m_name; 167 } 168 169 ConstString 170 GetQualifiedName (); 171 172 void 173 DumpValue(ExecutionContext *exe_ctx, 174 Stream *s, 175 const DataExtractor &data, 176 uint32_t data_offset, 177 bool show_type, 178 bool show_summary, 179 bool verbose, 180 lldb::Format format = lldb::eFormatDefault); 181 182 bool 183 DumpValueInMemory(ExecutionContext *exe_ctx, 184 Stream *s, 185 lldb::addr_t address, 186 AddressType address_type, 187 bool show_types, 188 bool show_summary, 189 bool verbose); 190 191 bool 192 ReadFromMemory (ExecutionContext *exe_ctx, 193 lldb::addr_t address, 194 AddressType address_type, 195 DataExtractor &data); 196 197 bool 198 WriteToMemory (ExecutionContext *exe_ctx, 199 lldb::addr_t address, 200 AddressType address_type, 201 DataExtractor &data); 202 203 bool 204 GetIsDeclaration() const; 205 206 void 207 SetIsDeclaration(bool b); 208 209 bool 210 GetIsExternal() const; 211 212 void 213 SetIsExternal(bool b); 214 215 lldb::Format 216 GetFormat (); 217 218 lldb::Encoding 219 GetEncoding (uint64_t &count); 220 221 SymbolContextScope * GetSymbolContextScope()222 GetSymbolContextScope() 223 { 224 return m_context; 225 } 226 const SymbolContextScope * GetSymbolContextScope()227 GetSymbolContextScope() const 228 { 229 return m_context; 230 } 231 void SetSymbolContextScope(SymbolContextScope * context)232 SetSymbolContextScope(SymbolContextScope *context) 233 { 234 m_context = context; 235 } 236 237 const lldb_private::Declaration & 238 GetDeclaration () const; 239 240 // Get the clang type, and resolve definitions for any 241 // class/struct/union/enum types completely. 242 ClangASTType 243 GetClangFullType (); 244 245 // Get the clang type, and resolve definitions enough so that the type could 246 // have layout performed. This allows ptrs and refs to class/struct/union/enum 247 // types remain forward declarations. 248 ClangASTType 249 GetClangLayoutType (); 250 251 // Get the clang type and leave class/struct/union/enum types as forward 252 // declarations if they haven't already been fully defined. 253 ClangASTType 254 GetClangForwardType (); 255 256 ClangASTContext & 257 GetClangASTContext (); 258 259 static int 260 Compare(const Type &a, const Type &b); 261 262 // From a fully qualified typename, split the type into the type basename 263 // and the remaining type scope (namespaces/classes). 264 static bool 265 GetTypeScopeAndBasename (const char* &name_cstr, 266 std::string &scope, 267 std::string &basename, 268 lldb::TypeClass &type_class); 269 void SetEncodingType(Type * encoding_type)270 SetEncodingType (Type *encoding_type) 271 { 272 m_encoding_type = encoding_type; 273 } 274 275 uint32_t 276 GetEncodingMask (); 277 278 ClangASTType 279 CreateClangTypedefType (Type *typedef_type, Type *base_type); 280 281 bool 282 IsRealObjCClass(); 283 284 bool IsCompleteObjCClass()285 IsCompleteObjCClass() 286 { 287 return m_flags.is_complete_objc_class; 288 } 289 290 void SetIsCompleteObjCClass(bool is_complete_objc_class)291 SetIsCompleteObjCClass(bool is_complete_objc_class) 292 { 293 m_flags.is_complete_objc_class = is_complete_objc_class; 294 } 295 296 protected: 297 ConstString m_name; 298 SymbolFile *m_symbol_file; 299 SymbolContextScope *m_context; // The symbol context in which this type is defined 300 Type *m_encoding_type; 301 lldb::user_id_t m_encoding_uid; 302 EncodingDataType m_encoding_uid_type; 303 uint64_t m_byte_size; 304 Declaration m_decl; 305 ClangASTType m_clang_type; 306 307 struct Flags { 308 #ifdef __GNUC__ 309 // using unsigned type here to work around a very noisy gcc warning 310 unsigned clang_type_resolve_state : 2; 311 #else 312 ResolveState clang_type_resolve_state : 2; 313 #endif 314 bool is_complete_objc_class : 1; 315 } m_flags; 316 317 Type * 318 GetEncodingType (); 319 320 bool 321 ResolveClangType (ResolveState clang_type_resolve_state); 322 }; 323 324 // these classes are used to back the SBType* objects 325 326 class TypePair 327 { 328 public: TypePair()329 TypePair () : 330 clang_type(), 331 type_sp() 332 { 333 } 334 TypePair(ClangASTType type)335 TypePair (ClangASTType type) : 336 clang_type(type), 337 type_sp() 338 { 339 } 340 TypePair(lldb::TypeSP type)341 TypePair (lldb::TypeSP type) : 342 clang_type(), 343 type_sp(type) 344 { 345 clang_type = type_sp->GetClangForwardType(); 346 } 347 348 bool IsValid()349 IsValid () const 350 { 351 return clang_type.IsValid() || (type_sp.get() != nullptr); 352 } 353 354 explicit operator bool () const 355 { 356 return IsValid(); 357 } 358 359 bool 360 operator == (const TypePair& rhs) const 361 { 362 return clang_type == rhs.clang_type && 363 type_sp.get() == rhs.type_sp.get(); 364 } 365 366 bool 367 operator != (const TypePair& rhs) const 368 { 369 return clang_type != rhs.clang_type || 370 type_sp.get() != rhs.type_sp.get(); 371 } 372 373 void Clear()374 Clear () 375 { 376 clang_type.Clear(); 377 type_sp.reset(); 378 } 379 380 ConstString GetName()381 GetName () const 382 { 383 if (type_sp) 384 return type_sp->GetName(); 385 if (clang_type) 386 return clang_type.GetTypeName(); 387 return ConstString (); 388 } 389 390 ConstString GetDisplayTypeName()391 GetDisplayTypeName () const 392 { 393 if (type_sp) 394 return type_sp->GetClangForwardType().GetDisplayTypeName(); 395 if (clang_type) 396 return clang_type.GetDisplayTypeName(); 397 return ConstString(); 398 } 399 400 void SetType(ClangASTType type)401 SetType (ClangASTType type) 402 { 403 type_sp.reset(); 404 clang_type = type; 405 } 406 407 void SetType(lldb::TypeSP type)408 SetType (lldb::TypeSP type) 409 { 410 type_sp = type; 411 clang_type = type_sp->GetClangForwardType(); 412 } 413 414 lldb::TypeSP GetTypeSP()415 GetTypeSP () const 416 { 417 return type_sp; 418 } 419 420 ClangASTType GetClangASTType()421 GetClangASTType () const 422 { 423 return clang_type; 424 } 425 426 ClangASTType GetPointerType()427 GetPointerType () const 428 { 429 if (type_sp) 430 return type_sp->GetClangLayoutType().GetPointerType(); 431 return clang_type.GetPointerType(); 432 } 433 434 ClangASTType GetPointeeType()435 GetPointeeType () const 436 { 437 if (type_sp) 438 return type_sp->GetClangFullType().GetPointeeType(); 439 return clang_type.GetPointeeType(); 440 } 441 442 ClangASTType GetReferenceType()443 GetReferenceType () const 444 { 445 if (type_sp) 446 return type_sp->GetClangLayoutType().GetLValueReferenceType(); 447 return clang_type.GetLValueReferenceType(); 448 } 449 450 ClangASTType GetTypedefedType()451 GetTypedefedType () const 452 { 453 if (type_sp) 454 return type_sp->GetClangFullType().GetTypedefedType(); 455 return clang_type.GetTypedefedType(); 456 } 457 458 ClangASTType GetDereferencedType()459 GetDereferencedType () const 460 { 461 if (type_sp) 462 return type_sp->GetClangFullType().GetNonReferenceType(); 463 return clang_type.GetNonReferenceType(); 464 } 465 466 ClangASTType GetUnqualifiedType()467 GetUnqualifiedType () const 468 { 469 if (type_sp) 470 return type_sp->GetClangLayoutType().GetFullyUnqualifiedType(); 471 return clang_type.GetFullyUnqualifiedType(); 472 } 473 474 ClangASTType GetCanonicalType()475 GetCanonicalType () const 476 { 477 if (type_sp) 478 return type_sp->GetClangFullType().GetCanonicalType(); 479 return clang_type.GetCanonicalType(); 480 } 481 482 clang::ASTContext * GetClangASTContext()483 GetClangASTContext () const 484 { 485 return clang_type.GetASTContext(); 486 } 487 488 lldb::ModuleSP GetModule()489 GetModule () const 490 { 491 if (type_sp) 492 return type_sp->GetModule(); 493 return lldb::ModuleSP(); 494 } 495 protected: 496 ClangASTType clang_type; 497 lldb::TypeSP type_sp; 498 }; 499 500 class TypeImpl 501 { 502 public: 503 504 TypeImpl(); 505 ~TypeImpl()506 ~TypeImpl () {} 507 508 TypeImpl(const TypeImpl& rhs); 509 510 TypeImpl (const lldb::TypeSP &type_sp); 511 512 TypeImpl (const ClangASTType &clang_type); 513 514 TypeImpl (const lldb::TypeSP &type_sp, const ClangASTType &dynamic); 515 516 TypeImpl (const ClangASTType &clang_type, const ClangASTType &dynamic); 517 518 TypeImpl (const TypePair &pair, const ClangASTType &dynamic); 519 520 void 521 SetType (const lldb::TypeSP &type_sp); 522 523 void 524 SetType (const ClangASTType &clang_type); 525 526 void 527 SetType (const lldb::TypeSP &type_sp, const ClangASTType &dynamic); 528 529 void 530 SetType (const ClangASTType &clang_type, const ClangASTType &dynamic); 531 532 void 533 SetType (const TypePair &pair, const ClangASTType &dynamic); 534 535 TypeImpl& 536 operator = (const TypeImpl& rhs); 537 538 bool 539 operator == (const TypeImpl& rhs) const; 540 541 bool 542 operator != (const TypeImpl& rhs) const; 543 544 bool 545 IsValid() const; 546 547 explicit operator bool () const; 548 549 void Clear(); 550 551 ConstString 552 GetName () const; 553 554 ConstString 555 GetDisplayTypeName () const; 556 557 TypeImpl 558 GetPointerType () const; 559 560 TypeImpl 561 GetPointeeType () const; 562 563 TypeImpl 564 GetReferenceType () const; 565 566 TypeImpl 567 GetTypedefedType () const; 568 569 TypeImpl 570 GetDereferencedType () const; 571 572 TypeImpl 573 GetUnqualifiedType() const; 574 575 TypeImpl 576 GetCanonicalType() const; 577 578 ClangASTType 579 GetClangASTType (bool prefer_dynamic); 580 581 clang::ASTContext * 582 GetClangASTContext (bool prefer_dynamic); 583 584 bool 585 GetDescription (lldb_private::Stream &strm, 586 lldb::DescriptionLevel description_level); 587 588 private: 589 590 bool 591 CheckModule (lldb::ModuleSP &module_sp) const; 592 593 lldb::ModuleWP m_module_wp; 594 TypePair m_static_type; 595 ClangASTType m_dynamic_type; 596 }; 597 598 class TypeListImpl 599 { 600 public: TypeListImpl()601 TypeListImpl() : 602 m_content() 603 { 604 } 605 606 void Append(const lldb::TypeImplSP & type)607 Append (const lldb::TypeImplSP& type) 608 { 609 m_content.push_back(type); 610 } 611 612 class AppendVisitor 613 { 614 public: AppendVisitor(TypeListImpl & type_list)615 AppendVisitor(TypeListImpl &type_list) : 616 m_type_list(type_list) 617 { 618 } 619 620 void operator()621 operator() (const lldb::TypeImplSP& type) 622 { 623 m_type_list.Append(type); 624 } 625 626 private: 627 TypeListImpl &m_type_list; 628 }; 629 630 void 631 Append (const lldb_private::TypeList &type_list); 632 633 lldb::TypeImplSP GetTypeAtIndex(size_t idx)634 GetTypeAtIndex(size_t idx) 635 { 636 lldb::TypeImplSP type_sp; 637 if (idx < GetSize()) 638 type_sp = m_content[idx]; 639 return type_sp; 640 } 641 642 size_t GetSize()643 GetSize() 644 { 645 return m_content.size(); 646 } 647 648 private: 649 std::vector<lldb::TypeImplSP> m_content; 650 }; 651 652 class TypeMemberImpl 653 { 654 public: TypeMemberImpl()655 TypeMemberImpl () : 656 m_type_impl_sp (), 657 m_bit_offset (0), 658 m_name (), 659 m_bitfield_bit_size (0), 660 m_is_bitfield (false) 661 662 { 663 } 664 665 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 666 uint64_t bit_offset, 667 const ConstString &name, 668 uint32_t bitfield_bit_size = 0, 669 bool is_bitfield = false) : m_type_impl_sp(type_impl_sp)670 m_type_impl_sp (type_impl_sp), 671 m_bit_offset (bit_offset), 672 m_name (name), 673 m_bitfield_bit_size (bitfield_bit_size), 674 m_is_bitfield (is_bitfield) 675 { 676 } 677 TypeMemberImpl(const lldb::TypeImplSP & type_impl_sp,uint64_t bit_offset)678 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 679 uint64_t bit_offset): 680 m_type_impl_sp (type_impl_sp), 681 m_bit_offset (bit_offset), 682 m_name (), 683 m_bitfield_bit_size (0), 684 m_is_bitfield (false) 685 { 686 if (m_type_impl_sp) 687 m_name = m_type_impl_sp->GetName(); 688 } 689 690 const lldb::TypeImplSP & GetTypeImpl()691 GetTypeImpl () 692 { 693 return m_type_impl_sp; 694 } 695 696 const ConstString & GetName()697 GetName () const 698 { 699 return m_name; 700 } 701 702 uint64_t GetBitOffset()703 GetBitOffset () const 704 { 705 return m_bit_offset; 706 } 707 708 uint32_t GetBitfieldBitSize()709 GetBitfieldBitSize () const 710 { 711 return m_bitfield_bit_size; 712 } 713 714 void SetBitfieldBitSize(uint32_t bitfield_bit_size)715 SetBitfieldBitSize (uint32_t bitfield_bit_size) 716 { 717 m_bitfield_bit_size = bitfield_bit_size; 718 } 719 720 bool GetIsBitfield()721 GetIsBitfield () const 722 { 723 return m_is_bitfield; 724 } 725 726 void SetIsBitfield(bool is_bitfield)727 SetIsBitfield (bool is_bitfield) 728 { 729 m_is_bitfield = is_bitfield; 730 } 731 732 protected: 733 lldb::TypeImplSP m_type_impl_sp; 734 uint64_t m_bit_offset; 735 ConstString m_name; 736 uint32_t m_bitfield_bit_size; // Bit size for bitfield members only 737 bool m_is_bitfield; 738 }; 739 740 741 /// 742 /// Sometimes you can find the name of the type corresponding to an object, but we don't have debug 743 /// information for it. If that is the case, you can return one of these objects, and then if it 744 /// has a full type, you can use that, but if not at least you can print the name for informational 745 /// purposes. 746 /// 747 748 class TypeAndOrName 749 { 750 public: 751 TypeAndOrName (); 752 TypeAndOrName (lldb::TypeSP &type_sp); 753 TypeAndOrName (const ClangASTType &clang_type); 754 TypeAndOrName (const char *type_str); 755 TypeAndOrName (const TypeAndOrName &rhs); 756 TypeAndOrName (ConstString &type_const_string); 757 758 TypeAndOrName & 759 operator= (const TypeAndOrName &rhs); 760 761 bool 762 operator==(const TypeAndOrName &other) const; 763 764 bool 765 operator!=(const TypeAndOrName &other) const; 766 767 ConstString GetName () const; 768 769 lldb::TypeSP GetTypeSP()770 GetTypeSP () const 771 { 772 return m_type_pair.GetTypeSP(); 773 } 774 775 ClangASTType GetClangASTType()776 GetClangASTType () const 777 { 778 return m_type_pair.GetClangASTType(); 779 } 780 781 void 782 SetName (const ConstString &type_name); 783 784 void 785 SetName (const char *type_name_cstr); 786 787 void 788 SetTypeSP (lldb::TypeSP type_sp); 789 790 void 791 SetClangASTType (ClangASTType clang_type); 792 793 bool 794 IsEmpty () const; 795 796 bool 797 HasName () const; 798 799 bool 800 HasTypeSP () const; 801 802 bool 803 HasClangASTType () const; 804 805 bool HasType()806 HasType () const 807 { 808 return HasTypeSP() || HasClangASTType(); 809 } 810 811 void 812 Clear (); 813 814 explicit operator bool () 815 { 816 return !IsEmpty(); 817 } 818 819 private: 820 TypePair m_type_pair; 821 ConstString m_type_name; 822 }; 823 824 class TypeMemberFunctionImpl 825 { 826 public: TypeMemberFunctionImpl()827 TypeMemberFunctionImpl() : 828 m_type(), 829 m_objc_method_decl(nullptr), 830 m_name(), 831 m_kind(lldb::eMemberFunctionKindUnknown) 832 { 833 } 834 TypeMemberFunctionImpl(const ClangASTType & type,const std::string & name,const lldb::MemberFunctionKind & kind)835 TypeMemberFunctionImpl (const ClangASTType& type, 836 const std::string& name, 837 const lldb::MemberFunctionKind& kind) : 838 m_type(type), 839 m_objc_method_decl(nullptr), 840 m_name(name), 841 m_kind(kind) 842 { 843 } 844 TypeMemberFunctionImpl(clang::ObjCMethodDecl * method,const std::string & name,const lldb::MemberFunctionKind & kind)845 TypeMemberFunctionImpl (clang::ObjCMethodDecl *method, 846 const std::string& name, 847 const lldb::MemberFunctionKind& kind) : 848 m_type(), 849 m_objc_method_decl(method), 850 m_name(name), 851 m_kind(kind) 852 { 853 } 854 TypeMemberFunctionImpl(const TypeMemberFunctionImpl & rhs)855 TypeMemberFunctionImpl (const TypeMemberFunctionImpl& rhs) : 856 m_type(rhs.m_type), 857 m_objc_method_decl(rhs.m_objc_method_decl), 858 m_name(rhs.m_name), 859 m_kind(rhs.m_kind) 860 { 861 } 862 863 TypeMemberFunctionImpl& 864 operator = (const TypeMemberFunctionImpl& rhs); 865 866 bool 867 IsValid (); 868 869 ConstString 870 GetName () const; 871 872 ClangASTType 873 GetType () const; 874 875 ClangASTType 876 GetReturnType () const; 877 878 size_t 879 GetNumArguments () const; 880 881 ClangASTType 882 GetArgumentAtIndex (size_t idx) const; 883 884 lldb::MemberFunctionKind 885 GetKind () const; 886 887 bool 888 GetDescription (Stream& stream); 889 890 protected: 891 std::string 892 GetPrintableTypeName (); 893 894 private: 895 ClangASTType m_type; 896 clang::ObjCMethodDecl *m_objc_method_decl; 897 ConstString m_name; 898 lldb::MemberFunctionKind m_kind; 899 }; 900 901 class TypeEnumMemberImpl 902 { 903 public: TypeEnumMemberImpl()904 TypeEnumMemberImpl () : 905 m_integer_type_sp(), 906 m_name("<invalid>"), 907 m_value(), 908 m_valid(false) 909 { 910 } 911 912 TypeEnumMemberImpl (const clang::EnumConstantDecl* enum_member_decl, 913 const lldb_private::ClangASTType& integer_type); 914 TypeEnumMemberImpl(const TypeEnumMemberImpl & rhs)915 TypeEnumMemberImpl (const TypeEnumMemberImpl& rhs) : 916 m_integer_type_sp(rhs.m_integer_type_sp), 917 m_name(rhs.m_name), 918 m_value(rhs.m_value), 919 m_valid(rhs.m_valid) 920 { 921 } 922 923 TypeEnumMemberImpl& 924 operator = (const TypeEnumMemberImpl& rhs); 925 926 bool IsValid()927 IsValid () 928 { 929 return m_valid; 930 } 931 932 const ConstString & GetName()933 GetName () const 934 { 935 return m_name; 936 } 937 938 const lldb::TypeImplSP & GetIntegerType()939 GetIntegerType () const 940 { 941 return m_integer_type_sp; 942 } 943 944 uint64_t GetValueAsUnsigned()945 GetValueAsUnsigned () const 946 { 947 return *m_value.getRawData(); 948 } 949 950 int64_t GetValueAsSigned()951 GetValueAsSigned () const 952 { 953 return (int64_t) *m_value.getRawData(); 954 } 955 956 protected: 957 lldb::TypeImplSP m_integer_type_sp; 958 ConstString m_name; 959 llvm::APSInt m_value; 960 bool m_valid; 961 }; 962 963 class TypeEnumMemberListImpl 964 { 965 public: TypeEnumMemberListImpl()966 TypeEnumMemberListImpl() : 967 m_content() 968 { 969 } 970 971 void Append(const lldb::TypeEnumMemberImplSP & type)972 Append (const lldb::TypeEnumMemberImplSP& type) 973 { 974 m_content.push_back(type); 975 } 976 977 void 978 Append (const lldb_private::TypeEnumMemberListImpl& type_list); 979 980 lldb::TypeEnumMemberImplSP GetTypeEnumMemberAtIndex(size_t idx)981 GetTypeEnumMemberAtIndex(size_t idx) 982 { 983 lldb::TypeEnumMemberImplSP enum_member; 984 if (idx < GetSize()) 985 enum_member = m_content[idx]; 986 return enum_member; 987 } 988 989 size_t GetSize()990 GetSize() 991 { 992 return m_content.size(); 993 } 994 995 private: 996 std::vector<lldb::TypeEnumMemberImplSP> m_content; 997 }; 998 999 } // namespace lldb_private 1000 1001 #endif // liblldb_Type_h_ 1002 1003