1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
|
//===-- CompilerType.cpp --------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lldb/Symbol/CompilerType.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Symbol/Type.h"
#include "lldb/Target/ExecutionContext.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/ConstString.h"
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/Stream.h"
#include "lldb/Utility/StreamString.h"
#include <iterator>
#include <mutex>
#include <optional>
using namespace lldb;
using namespace lldb_private;
// Tests
bool CompilerType::IsAggregateType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsAggregateType(m_type);
return false;
}
bool CompilerType::IsAnonymousType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsAnonymousType(m_type);
return false;
}
bool CompilerType::IsScopedEnumerationType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsScopedEnumerationType(m_type);
return false;
}
bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
bool *is_incomplete) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsArrayType(m_type, element_type_ptr, size,
is_incomplete);
if (element_type_ptr)
element_type_ptr->Clear();
if (size)
*size = 0;
if (is_incomplete)
*is_incomplete = false;
return false;
}
bool CompilerType::IsVectorType(CompilerType *element_type,
uint64_t *size) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsVectorType(m_type, element_type, size);
return false;
}
bool CompilerType::IsRuntimeGeneratedType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsRuntimeGeneratedType(m_type);
return false;
}
bool CompilerType::IsCharType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsCharType(m_type);
return false;
}
bool CompilerType::IsCompleteType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsCompleteType(m_type);
return false;
}
bool CompilerType::IsForcefullyCompleted() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsForcefullyCompleted(m_type);
return false;
}
bool CompilerType::IsConst() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsConst(m_type);
return false;
}
bool CompilerType::IsCStringType(uint32_t &length) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsCStringType(m_type, length);
return false;
}
bool CompilerType::IsFunctionType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsFunctionType(m_type);
return false;
}
// Used to detect "Homogeneous Floating-point Aggregates"
uint32_t
CompilerType::IsHomogeneousAggregate(CompilerType *base_type_ptr) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsHomogeneousAggregate(m_type, base_type_ptr);
return 0;
}
size_t CompilerType::GetNumberOfFunctionArguments() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumberOfFunctionArguments(m_type);
return 0;
}
CompilerType
CompilerType::GetFunctionArgumentAtIndex(const size_t index) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFunctionArgumentAtIndex(m_type, index);
return CompilerType();
}
bool CompilerType::IsFunctionPointerType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsFunctionPointerType(m_type);
return false;
}
bool CompilerType::IsMemberFunctionPointerType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsMemberFunctionPointerType(m_type);
return false;
}
bool CompilerType::IsBlockPointerType(
CompilerType *function_pointer_type_ptr) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsBlockPointerType(m_type, function_pointer_type_ptr);
return false;
}
bool CompilerType::IsIntegerType(bool &is_signed) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsIntegerType(m_type, is_signed);
return false;
}
bool CompilerType::IsEnumerationType(bool &is_signed) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsEnumerationType(m_type, is_signed);
return false;
}
bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
}
bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsPointerType(m_type, pointee_type);
}
if (pointee_type)
pointee_type->Clear();
return false;
}
bool CompilerType::IsPointerOrReferenceType(CompilerType *pointee_type) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsPointerOrReferenceType(m_type, pointee_type);
}
if (pointee_type)
pointee_type->Clear();
return false;
}
bool CompilerType::IsReferenceType(CompilerType *pointee_type,
bool *is_rvalue) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsReferenceType(m_type, pointee_type, is_rvalue);
}
if (pointee_type)
pointee_type->Clear();
return false;
}
bool CompilerType::ShouldTreatScalarValueAsAddress() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->ShouldTreatScalarValueAsAddress(m_type);
return false;
}
bool CompilerType::IsFloatingPointType(uint32_t &count,
bool &is_complex) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsFloatingPointType(m_type, count, is_complex);
}
count = 0;
is_complex = false;
return false;
}
bool CompilerType::IsDefined() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsDefined(m_type);
return true;
}
bool CompilerType::IsPolymorphicClass() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsPolymorphicClass(m_type);
}
return false;
}
bool CompilerType::IsPossibleDynamicType(CompilerType *dynamic_pointee_type,
bool check_cplusplus,
bool check_objc) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsPossibleDynamicType(m_type, dynamic_pointee_type,
check_cplusplus, check_objc);
return false;
}
bool CompilerType::IsScalarType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsScalarType(m_type);
return false;
}
bool CompilerType::IsTemplateType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsTemplateType(m_type);
return false;
}
bool CompilerType::IsTypedefType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsTypedefType(m_type);
return false;
}
bool CompilerType::IsVoidType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsVoidType(m_type);
return false;
}
bool CompilerType::IsPointerToScalarType() const {
if (!IsValid())
return false;
return IsPointerType() && GetPointeeType().IsScalarType();
}
bool CompilerType::IsArrayOfScalarType() const {
CompilerType element_type;
if (IsArrayType(&element_type))
return element_type.IsScalarType();
return false;
}
bool CompilerType::IsBeingDefined() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsBeingDefined(m_type);
return false;
}
// Type Completion
bool CompilerType::GetCompleteType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetCompleteType(m_type);
return false;
}
// AST related queries
size_t CompilerType::GetPointerByteSize() const {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetPointerByteSize();
return 0;
}
ConstString CompilerType::GetTypeName(bool BaseOnly) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeName(m_type, BaseOnly);
}
return ConstString("<invalid>");
}
ConstString
CompilerType::GetDisplayTypeName(const SymbolContext *sc) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetDisplayTypeName(m_type, sc);
return ConstString("<invalid>");
}
ConstString CompilerType::GetMangledTypeName() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetMangledTypeName(m_type);
}
return ConstString();
}
uint32_t CompilerType::GetTypeInfo(
CompilerType *pointee_or_element_compiler_type) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeInfo(m_type,
pointee_or_element_compiler_type);
return 0;
}
lldb::LanguageType CompilerType::GetMinimumLanguage() {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetMinimumLanguage(m_type);
return lldb::eLanguageTypeC;
}
lldb::TypeClass CompilerType::GetTypeClass() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeClass(m_type);
return lldb::eTypeClassInvalid;
}
void CompilerType::SetCompilerType(lldb::TypeSystemWP type_system,
lldb::opaque_compiler_type_t type) {
m_type_system = type_system;
m_type = type;
}
void CompilerType::SetCompilerType(CompilerType::TypeSystemSPWrapper type_system,
lldb::opaque_compiler_type_t type) {
m_type_system = type_system.GetSharedPointer();
m_type = type;
}
unsigned CompilerType::GetTypeQualifiers() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeQualifiers(m_type);
return 0;
}
// Creating related types
CompilerType
CompilerType::GetArrayElementType(ExecutionContextScope *exe_scope) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetArrayElementType(m_type, exe_scope);
}
return CompilerType();
}
CompilerType CompilerType::GetArrayType(uint64_t size) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetArrayType(m_type, size);
}
return CompilerType();
}
CompilerType CompilerType::GetCanonicalType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetCanonicalType(m_type);
return CompilerType();
}
CompilerType CompilerType::GetFullyUnqualifiedType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFullyUnqualifiedType(m_type);
return CompilerType();
}
CompilerType CompilerType::GetEnumerationIntegerType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetEnumerationIntegerType(m_type);
return CompilerType();
}
int CompilerType::GetFunctionArgumentCount() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFunctionArgumentCount(m_type);
}
return -1;
}
CompilerType CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFunctionArgumentTypeAtIndex(m_type, idx);
}
return CompilerType();
}
CompilerType CompilerType::GetFunctionReturnType() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFunctionReturnType(m_type);
}
return CompilerType();
}
size_t CompilerType::GetNumMemberFunctions() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumMemberFunctions(m_type);
}
return 0;
}
TypeMemberFunctionImpl CompilerType::GetMemberFunctionAtIndex(size_t idx) {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetMemberFunctionAtIndex(m_type, idx);
}
return TypeMemberFunctionImpl();
}
CompilerType CompilerType::GetNonReferenceType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNonReferenceType(m_type);
return CompilerType();
}
CompilerType CompilerType::GetPointeeType() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetPointeeType(m_type);
}
return CompilerType();
}
CompilerType CompilerType::GetPointerType() const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetPointerType(m_type);
}
return CompilerType();
}
CompilerType CompilerType::GetLValueReferenceType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetLValueReferenceType(m_type);
return CompilerType();
}
CompilerType CompilerType::GetRValueReferenceType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetRValueReferenceType(m_type);
return CompilerType();
}
CompilerType CompilerType::GetAtomicType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetAtomicType(m_type);
return CompilerType();
}
CompilerType CompilerType::AddConstModifier() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->AddConstModifier(m_type);
return CompilerType();
}
CompilerType CompilerType::AddVolatileModifier() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->AddVolatileModifier(m_type);
return CompilerType();
}
CompilerType CompilerType::AddRestrictModifier() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->AddRestrictModifier(m_type);
return CompilerType();
}
CompilerType CompilerType::CreateTypedef(const char *name,
const CompilerDeclContext &decl_ctx,
uint32_t payload) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->CreateTypedef(m_type, name, decl_ctx, payload);
return CompilerType();
}
CompilerType CompilerType::GetTypedefedType() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypedefedType(m_type);
return CompilerType();
}
// Create related types using the current type's AST
CompilerType
CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetBasicTypeFromAST(basic_type);
return CompilerType();
}
// Exploring the type
std::optional<uint64_t>
CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetBitSize(m_type, exe_scope);
return {};
}
std::optional<uint64_t>
CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const {
if (std::optional<uint64_t> bit_size = GetBitSize(exe_scope))
return (*bit_size + 7) / 8;
return {};
}
std::optional<uint64_t>
CompilerType::GetByteStride(ExecutionContextScope *exe_scope) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetByteStride(m_type, exe_scope);
return {};
}
std::optional<size_t>
CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeBitAlign(m_type, exe_scope);
return {};
}
lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetEncoding(m_type, count);
return lldb::eEncodingInvalid;
}
lldb::Format CompilerType::GetFormat() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFormat(m_type);
return lldb::eFormatDefault;
}
llvm::Expected<uint32_t>
CompilerType::GetNumChildren(bool omit_empty_base_classes,
const ExecutionContext *exe_ctx) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumChildren(m_type, omit_empty_base_classes,
exe_ctx);
return llvm::createStringError("invalid type");
}
lldb::BasicType CompilerType::GetBasicTypeEnumeration() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetBasicTypeEnumeration(m_type);
return eBasicTypeInvalid;
}
void CompilerType::ForEachEnumerator(
std::function<bool(const CompilerType &integer_type,
ConstString name,
const llvm::APSInt &value)> const &callback) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->ForEachEnumerator(m_type, callback);
}
uint32_t CompilerType::GetNumFields(ExecutionContext *exe_ctx) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumFields(m_type, exe_ctx);
return 0;
}
CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
uint64_t *bit_offset_ptr,
uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
bitfield_bit_size_ptr, is_bitfield_ptr);
return CompilerType();
}
uint32_t CompilerType::GetNumDirectBaseClasses() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumDirectBaseClasses(m_type);
return 0;
}
uint32_t CompilerType::GetNumVirtualBaseClasses() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumVirtualBaseClasses(m_type);
return 0;
}
CompilerType
CompilerType::GetDirectBaseClassAtIndex(size_t idx,
uint32_t *bit_offset_ptr) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetDirectBaseClassAtIndex(m_type, idx,
bit_offset_ptr);
return CompilerType();
}
CompilerType
CompilerType::GetVirtualBaseClassAtIndex(size_t idx,
uint32_t *bit_offset_ptr) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetVirtualBaseClassAtIndex(m_type, idx,
bit_offset_ptr);
return CompilerType();
}
uint32_t CompilerType::GetIndexOfFieldWithName(
const char *name, CompilerType *field_compiler_type_ptr,
uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) const {
unsigned count = GetNumFields();
std::string field_name;
for (unsigned index = 0; index < count; index++) {
CompilerType field_compiler_type(
GetFieldAtIndex(index, field_name, bit_offset_ptr,
bitfield_bit_size_ptr, is_bitfield_ptr));
if (strcmp(field_name.c_str(), name) == 0) {
if (field_compiler_type_ptr)
*field_compiler_type_ptr = field_compiler_type;
return index;
}
}
return UINT32_MAX;
}
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
bool omit_empty_base_classes, bool ignore_array_bounds,
std::string &child_name, uint32_t &child_byte_size,
int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
bool &child_is_deref_of_parent, ValueObject *valobj,
uint64_t &language_flags) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetChildCompilerTypeAtIndex(
m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
child_bitfield_bit_size, child_bitfield_bit_offset,
child_is_base_class, child_is_deref_of_parent, valobj,
language_flags);
return CompilerType();
}
// Look for a child member (doesn't include base classes, but it does include
// their members) in the type hierarchy. Returns an index path into
// "clang_type" on how to reach the appropriate member.
//
// class A
// {
// public:
// int m_a;
// int m_b;
// };
//
// class B
// {
// };
//
// class C :
// public B,
// public A
// {
// };
//
// If we have a clang type that describes "class C", and we wanted to looked
// "m_b" in it:
//
// With omit_empty_base_classes == false we would get an integer array back
// with: { 1, 1 } The first index 1 is the child index for "class A" within
// class C The second index 1 is the child index for "m_b" within class A
//
// With omit_empty_base_classes == true we would get an integer array back
// with: { 0, 1 } The first index 0 is the child index for "class A" within
// class C (since class B doesn't have any members it doesn't count) The second
// index 1 is the child index for "m_b" within class A
size_t CompilerType::GetIndexOfChildMemberWithName(
llvm::StringRef name, ExecutionContext *exe_ctx,
bool omit_empty_base_classes,
std::vector<uint32_t> &child_indexes) const {
if (IsValid() && !name.empty()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetIndexOfChildMemberWithName(
m_type, name, exe_ctx, omit_empty_base_classes, child_indexes);
}
return 0;
}
size_t CompilerType::GetNumTemplateArguments(bool expand_pack) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetNumTemplateArguments(m_type, expand_pack);
}
return 0;
}
TemplateArgumentKind
CompilerType::GetTemplateArgumentKind(size_t idx, bool expand_pack) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTemplateArgumentKind(m_type, idx, expand_pack);
return eTemplateArgumentKindNull;
}
CompilerType CompilerType::GetTypeTemplateArgument(size_t idx,
bool expand_pack) const {
if (IsValid()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeTemplateArgument(m_type, idx, expand_pack);
}
return CompilerType();
}
std::optional<CompilerType::IntegralTemplateArgument>
CompilerType::GetIntegralTemplateArgument(size_t idx, bool expand_pack) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetIntegralTemplateArgument(m_type, idx, expand_pack);
return std::nullopt;
}
CompilerType CompilerType::GetTypeForFormatters() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetTypeForFormatters(m_type);
return CompilerType();
}
LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->ShouldPrintAsOneLiner(m_type, valobj);
return eLazyBoolCalculate;
}
bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->IsMeaninglessWithoutDynamicResolution(m_type);
return false;
}
// Get the index of the child of "clang_type" whose name matches. This function
// doesn't descend into the children, but only looks one level deep and name
// matches can include base class names.
uint32_t
CompilerType::GetIndexOfChildWithName(llvm::StringRef name,
ExecutionContext *exe_ctx,
bool omit_empty_base_classes) const {
if (IsValid() && !name.empty()) {
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->GetIndexOfChildWithName(m_type, name, exe_ctx,
omit_empty_base_classes);
}
return UINT32_MAX;
}
// Dumping types
void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
lldb::Format format, const DataExtractor &data,
lldb::offset_t data_byte_offset,
size_t data_byte_size, uint32_t bitfield_bit_size,
uint32_t bitfield_bit_offset, bool show_types,
bool show_summary, bool verbose, uint32_t depth) {
if (!IsValid())
if (auto type_system_sp = GetTypeSystem())
type_system_sp->DumpValue(m_type, exe_ctx, *s, format, data,
data_byte_offset, data_byte_size,
bitfield_bit_size, bitfield_bit_offset,
show_types, show_summary, verbose, depth);
}
bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
const DataExtractor &data,
lldb::offset_t byte_offset, size_t byte_size,
uint32_t bitfield_bit_size,
uint32_t bitfield_bit_offset,
ExecutionContextScope *exe_scope,
bool is_base_class) {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->DumpTypeValue(
m_type, *s, format, data, byte_offset, byte_size, bitfield_bit_size,
bitfield_bit_offset, exe_scope, is_base_class);
return false;
}
void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
const DataExtractor &data,
lldb::offset_t data_byte_offset,
size_t data_byte_size) {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
type_system_sp->DumpSummary(m_type, exe_ctx, *s, data, data_byte_offset,
data_byte_size);
}
void CompilerType::DumpTypeDescription(lldb::DescriptionLevel level,
ExecutionContextScope *exe_scope) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
type_system_sp->DumpTypeDescription(m_type, level, exe_scope);
}
void CompilerType::DumpTypeDescription(Stream *s, lldb::DescriptionLevel level,
ExecutionContextScope *exe_scope) const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
type_system_sp->DumpTypeDescription(m_type, *s, level, exe_scope);
}
#ifndef NDEBUG
LLVM_DUMP_METHOD void CompilerType::dump() const {
if (IsValid())
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->dump(m_type);
llvm::errs() << "<invalid>\n";
}
#endif
bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
lldb::offset_t data_byte_offset,
size_t data_byte_size, Scalar &value,
ExecutionContextScope *exe_scope) const {
if (!IsValid())
return false;
if (0 == (GetTypeInfo() & eTypeHasValue)) {
return false; // Aggregate types don't have scalar values
} else {
uint64_t count = 0;
lldb::Encoding encoding = GetEncoding(count);
if (encoding == lldb::eEncodingInvalid || count != 1)
return false;
std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
if (!byte_size)
return false;
lldb::offset_t offset = data_byte_offset;
switch (encoding) {
case lldb::eEncodingInvalid:
break;
case lldb::eEncodingVector:
break;
case lldb::eEncodingUint:
if (*byte_size <= sizeof(unsigned long long)) {
uint64_t uval64 = data.GetMaxU64(&offset, *byte_size);
if (*byte_size <= sizeof(unsigned int)) {
value = (unsigned int)uval64;
return true;
} else if (*byte_size <= sizeof(unsigned long)) {
value = (unsigned long)uval64;
return true;
} else if (*byte_size <= sizeof(unsigned long long)) {
value = (unsigned long long)uval64;
return true;
} else
value.Clear();
}
break;
case lldb::eEncodingSint:
if (*byte_size <= sizeof(long long)) {
int64_t sval64 = data.GetMaxS64(&offset, *byte_size);
if (*byte_size <= sizeof(int)) {
value = (int)sval64;
return true;
} else if (*byte_size <= sizeof(long)) {
value = (long)sval64;
return true;
} else if (*byte_size <= sizeof(long long)) {
value = (long long)sval64;
return true;
} else
value.Clear();
}
break;
case lldb::eEncodingIEEE754:
if (*byte_size <= sizeof(long double)) {
uint32_t u32;
uint64_t u64;
if (*byte_size == sizeof(float)) {
if (sizeof(float) == sizeof(uint32_t)) {
u32 = data.GetU32(&offset);
value = *((float *)&u32);
return true;
} else if (sizeof(float) == sizeof(uint64_t)) {
u64 = data.GetU64(&offset);
value = *((float *)&u64);
return true;
}
} else if (*byte_size == sizeof(double)) {
if (sizeof(double) == sizeof(uint32_t)) {
u32 = data.GetU32(&offset);
value = *((double *)&u32);
return true;
} else if (sizeof(double) == sizeof(uint64_t)) {
u64 = data.GetU64(&offset);
value = *((double *)&u64);
return true;
}
} else if (*byte_size == sizeof(long double)) {
if (sizeof(long double) == sizeof(uint32_t)) {
u32 = data.GetU32(&offset);
value = *((long double *)&u32);
return true;
} else if (sizeof(long double) == sizeof(uint64_t)) {
u64 = data.GetU64(&offset);
value = *((long double *)&u64);
return true;
}
}
}
break;
}
}
return false;
}
#ifndef NDEBUG
bool CompilerType::Verify() const {
if (!IsValid())
return true;
if (auto type_system_sp = GetTypeSystem())
return type_system_sp->Verify(m_type);
return true;
}
#endif
CompilerType::TypeSystemSPWrapper CompilerType::GetTypeSystem() const {
return {m_type_system.lock()};
}
bool CompilerType::TypeSystemSPWrapper::operator==(
const CompilerType::TypeSystemSPWrapper &other) const {
if (!m_typesystem_sp && !other.m_typesystem_sp)
return true;
if (m_typesystem_sp && other.m_typesystem_sp)
return m_typesystem_sp.get() == other.m_typesystem_sp.get();
return false;
}
TypeSystem *CompilerType::TypeSystemSPWrapper::operator->() const {
assert(m_typesystem_sp);
return m_typesystem_sp.get();
}
bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
const lldb_private::CompilerType &rhs) {
return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
}
bool lldb_private::operator!=(const lldb_private::CompilerType &lhs,
const lldb_private::CompilerType &rhs) {
return !(lhs == rhs);
}
|