LLDB mainline
CompilerType.cpp
Go to the documentation of this file.
1//===-- CompilerType.cpp --------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include "lldb/Core/Debugger.h"
12#include "lldb/Symbol/Type.h"
14#include "lldb/Target/Process.h"
18#include "lldb/Utility/Scalar.h"
19#include "lldb/Utility/Stream.h"
21
22#include <iterator>
23#include <mutex>
24#include <optional>
25
26using namespace lldb;
27using namespace lldb_private;
28
29// Tests
30
32 if (IsValid())
33 if (auto type_system_sp = GetTypeSystem())
34 return type_system_sp->IsAggregateType(m_type);
35 return false;
36}
37
39 if (IsValid())
40 if (auto type_system_sp = GetTypeSystem())
41 return type_system_sp->IsAnonymousType(m_type);
42 return false;
43}
44
46 if (IsValid())
47 if (auto type_system_sp = GetTypeSystem())
48 return type_system_sp->IsScopedEnumerationType(m_type);
49 return false;
50}
51
52bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
53 bool *is_incomplete) const {
54 if (IsValid())
55 if (auto type_system_sp = GetTypeSystem())
56 return type_system_sp->IsArrayType(m_type, element_type_ptr, size,
57 is_incomplete);
58
59 if (element_type_ptr)
60 element_type_ptr->Clear();
61 if (size)
62 *size = 0;
63 if (is_incomplete)
64 *is_incomplete = false;
65 return false;
66}
67
69 uint64_t *size) const {
70 if (IsValid())
71 if (auto type_system_sp = GetTypeSystem())
72 return type_system_sp->IsVectorType(m_type, element_type, size);
73 return false;
74}
75
77 if (IsValid())
78 if (auto type_system_sp = GetTypeSystem())
79 return type_system_sp->IsRuntimeGeneratedType(m_type);
80 return false;
81}
82
84 if (IsValid())
85 if (auto type_system_sp = GetTypeSystem())
86 return type_system_sp->IsCharType(m_type);
87 return false;
88}
89
91 if (IsValid())
92 if (auto type_system_sp = GetTypeSystem())
93 return type_system_sp->IsCompleteType(m_type);
94 return false;
95}
96
98 if (IsValid())
99 if (auto type_system_sp = GetTypeSystem())
100 return type_system_sp->IsForcefullyCompleted(m_type);
101 return false;
102}
103
105 if (IsValid())
106 if (auto type_system_sp = GetTypeSystem())
107 return type_system_sp->IsConst(m_type);
108 return false;
109}
110
112 if (IsValid())
113 if (auto type_system_sp = GetTypeSystem())
114 return type_system_sp->GetPtrAuthKey(m_type);
115 return 0;
116}
117
119 if (IsValid())
120 if (auto type_system_sp = GetTypeSystem())
121 return type_system_sp->GetPtrAuthDiscriminator(m_type);
122 return 0;
123}
124
126 if (IsValid())
127 if (auto type_system_sp = GetTypeSystem())
128 return type_system_sp->GetPtrAuthAddressDiversity(m_type);
129 return false;
130}
131
133 if (IsValid())
134 if (auto type_system_sp = GetTypeSystem())
135 return type_system_sp->IsFunctionType(m_type);
136 return false;
137}
138
139// Used to detect "Homogeneous Floating-point Aggregates"
140uint32_t
142 if (IsValid())
143 if (auto type_system_sp = GetTypeSystem())
144 return type_system_sp->IsHomogeneousAggregate(m_type, base_type_ptr);
145 return 0;
146}
147
149 if (IsValid())
150 if (auto type_system_sp = GetTypeSystem())
151 return type_system_sp->GetNumberOfFunctionArguments(m_type);
152 return 0;
153}
154
157 if (IsValid())
158 if (auto type_system_sp = GetTypeSystem())
159 return type_system_sp->GetFunctionArgumentAtIndex(m_type, index);
160 return CompilerType();
161}
162
164 if (IsValid())
165 if (auto type_system_sp = GetTypeSystem())
166 return type_system_sp->IsFunctionPointerType(m_type);
167 return false;
168}
169
171 if (IsValid())
172 if (auto type_system_sp = GetTypeSystem())
173 return type_system_sp->IsMemberFunctionPointerType(m_type);
174 return false;
175}
176
178 CompilerType *function_pointer_type_ptr) const {
179 if (IsValid())
180 if (auto type_system_sp = GetTypeSystem())
181 return type_system_sp->IsBlockPointerType(m_type, function_pointer_type_ptr);
182 return false;
183}
184
185bool CompilerType::IsIntegerType(bool &is_signed) const {
186 if (IsValid())
187 if (auto type_system_sp = GetTypeSystem())
188 return type_system_sp->IsIntegerType(m_type, is_signed);
189 return false;
190}
191
192bool CompilerType::IsEnumerationType(bool &is_signed) const {
193 if (IsValid())
194 if (auto type_system_sp = GetTypeSystem())
195 return type_system_sp->IsEnumerationType(m_type, is_signed);
196 return false;
197}
198
199bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
200 return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
201}
202
203bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
204 if (IsValid()) {
205 if (auto type_system_sp = GetTypeSystem())
206 return type_system_sp->IsPointerType(m_type, pointee_type);
207 }
208 if (pointee_type)
209 pointee_type->Clear();
210 return false;
211}
212
214 if (IsValid()) {
215 if (auto type_system_sp = GetTypeSystem())
216 return type_system_sp->IsPointerOrReferenceType(m_type, pointee_type);
217 }
218 if (pointee_type)
219 pointee_type->Clear();
220 return false;
221}
222
224 bool *is_rvalue) const {
225 if (IsValid()) {
226 if (auto type_system_sp = GetTypeSystem())
227 return type_system_sp->IsReferenceType(m_type, pointee_type, is_rvalue);
228 }
229 if (pointee_type)
230 pointee_type->Clear();
231 return false;
232}
233
235 if (IsValid())
236 if (auto type_system_sp = GetTypeSystem())
237 return type_system_sp->ShouldTreatScalarValueAsAddress(m_type);
238 return false;
239}
240
242 bool &is_complex) const {
243 if (IsValid()) {
244 if (auto type_system_sp = GetTypeSystem())
245 return type_system_sp->IsFloatingPointType(m_type, count, is_complex);
246 }
247 count = 0;
248 is_complex = false;
249 return false;
250}
251
253 if (IsValid())
254 if (auto type_system_sp = GetTypeSystem())
255 return type_system_sp->IsDefined(m_type);
256 return true;
257}
258
260 if (IsValid()) {
261 if (auto type_system_sp = GetTypeSystem())
262 return type_system_sp->IsPolymorphicClass(m_type);
263 }
264 return false;
265}
266
268 bool check_cplusplus,
269 bool check_objc) const {
270 if (IsValid())
271 if (auto type_system_sp = GetTypeSystem())
272 return type_system_sp->IsPossibleDynamicType(m_type, dynamic_pointee_type,
273 check_cplusplus, check_objc);
274 return false;
275}
276
278 if (IsValid())
279 if (auto type_system_sp = GetTypeSystem())
280 return type_system_sp->IsScalarType(m_type);
281 return false;
282}
283
285 if (IsValid())
286 if (auto type_system_sp = GetTypeSystem())
287 return type_system_sp->IsTemplateType(m_type);
288 return false;
289}
290
292 if (IsValid())
293 if (auto type_system_sp = GetTypeSystem())
294 return type_system_sp->IsTypedefType(m_type);
295 return false;
296}
297
299 if (IsValid())
300 if (auto type_system_sp = GetTypeSystem())
301 return type_system_sp->IsVoidType(m_type);
302 return false;
303}
304
306 if (!IsValid())
307 return false;
308
310}
311
313 CompilerType element_type;
314 if (IsArrayType(&element_type))
315 return element_type.IsScalarType();
316 return false;
317}
318
320 if (IsValid())
321 if (auto type_system_sp = GetTypeSystem())
322 return type_system_sp->IsBeingDefined(m_type);
323 return false;
324}
325
327 bool is_signed = false; // May be reset by the call below.
328 return IsIntegerType(is_signed);
329}
330
332 uint32_t count = 0;
333 bool is_complex = false;
334 return IsFloatingPointType(count, is_complex);
335}
336
338 bool is_signed = false; // May be reset by the call below.
339 return IsEnumerationType(is_signed);
340}
341
344}
345
348}
349
351 return GetTypeInfo() & lldb::eTypeIsSigned;
352}
353
357}
358
361}
362
364 if (IsValid())
365 return GetEnumerationIntegerType().GetTypeInfo() & lldb::eTypeIsSigned;
366
367 return false;
368}
369
372}
373
375 // Unscoped enums are always considered as promotable, even if their
376 // underlying type does not need to be promoted (e.g. "int").
378 return true;
379
392 return true;
393
394 default:
395 return false;
396 }
397
398 llvm_unreachable("All cases handled above.");
399}
400
402 if (!IsValid())
403 return false;
404
405 return IsPointerType() &&
407}
408
410 if (!IsValid())
411 return false;
412
413 return GetCanonicalType().GetTypeClass() &
414 (lldb::eTypeClassClass | lldb::eTypeClassStruct |
415 lldb::eTypeClassUnion);
416}
417
419 CompilerType *virtual_base,
420 bool carry_virtual) const {
421 if (CompareTypes(target_base))
422 return carry_virtual;
423
424 if (!carry_virtual) {
425 uint32_t num_virtual_bases = GetNumVirtualBaseClasses();
426 for (uint32_t i = 0; i < num_virtual_bases; ++i) {
427 uint32_t bit_offset;
428 auto base = GetVirtualBaseClassAtIndex(i, &bit_offset);
429 if (base.IsVirtualBase(target_base, virtual_base,
430 /*carry_virtual*/ true)) {
431 if (virtual_base)
432 *virtual_base = base;
433
434 return true;
435 }
436 }
437 }
438
439 uint32_t num_direct_bases = GetNumDirectBaseClasses();
440 for (uint32_t i = 0; i < num_direct_bases; ++i) {
441 uint32_t bit_offset;
442 auto base = GetDirectBaseClassAtIndex(i, &bit_offset);
443 if (base.IsVirtualBase(target_base, virtual_base, carry_virtual))
444 return true;
445 }
446
447 return false;
448}
449
453}
454
458}
459
461 auto name = GetTypeName();
462 auto canonical_name = GetCanonicalType().GetTypeName();
463 if (name.IsEmpty() || canonical_name.IsEmpty())
464 return "''"; // Should not happen, unless the input is broken somehow.
465
466 if (name == canonical_name)
467 return llvm::formatv("'{0}'", name);
468
469 return llvm::formatv("'{0}' (canonically referred to as '{1}')", name,
470 canonical_name);
471}
472
474 if (*this == rhs)
475 return true;
476
478 const ConstString rhs_name = rhs.GetFullyUnqualifiedType().GetTypeName();
479 return name == rhs_name;
480}
481
483 switch (GetTypeClass()) {
484 case lldb::eTypeClassClass:
485 return "class";
486 case lldb::eTypeClassEnumeration:
487 return "enum";
488 case lldb::eTypeClassStruct:
489 return "struct";
490 case lldb::eTypeClassUnion:
491 return "union";
492 default:
493 return "unknown";
494 }
495 llvm_unreachable("All cases are covered by code above.");
496}
497
499 uint32_t ret = 0;
500 uint32_t num_direct_bases = GetNumDirectBaseClasses();
501
502 for (uint32_t i = 0; i < num_direct_bases; ++i) {
503 uint32_t bit_offset;
504 CompilerType base_type = GetDirectBaseClassAtIndex(i, &bit_offset);
505 if (base_type.GetNumFields() > 0 ||
506 base_type.GetNumberOfNonEmptyBaseClasses() > 0)
507 ret += 1;
508 }
509 return ret;
510}
511
512// Type Completion
513
515 if (IsValid())
516 if (auto type_system_sp = GetTypeSystem())
517 return type_system_sp->GetCompleteType(m_type);
518 return false;
519}
520
521// AST related queries
523 if (auto type_system_sp = GetTypeSystem())
524 return type_system_sp->GetPointerByteSize();
525 return 0;
526}
527
529 if (IsValid()) {
530 if (auto type_system_sp = GetTypeSystem())
531 return type_system_sp->GetTypeName(m_type, BaseOnly);
532 }
533 return ConstString("<invalid>");
534}
535
537 if (IsValid())
538 if (auto type_system_sp = GetTypeSystem())
539 return type_system_sp->GetDisplayTypeName(m_type);
540 return ConstString("<invalid>");
541}
542
544 CompilerType *pointee_or_element_compiler_type) const {
545 if (IsValid())
546 if (auto type_system_sp = GetTypeSystem())
547 return type_system_sp->GetTypeInfo(m_type,
548 pointee_or_element_compiler_type);
549 return 0;
550}
551
553 if (IsValid())
554 if (auto type_system_sp = GetTypeSystem())
555 return type_system_sp->GetMinimumLanguage(m_type);
557}
558
559lldb::TypeClass CompilerType::GetTypeClass() const {
560 if (IsValid())
561 if (auto type_system_sp = GetTypeSystem())
562 return type_system_sp->GetTypeClass(m_type);
563 return lldb::eTypeClassInvalid;
564}
565
568 m_type_system = type_system;
569 m_type = type;
570}
571
574 m_type_system = type_system.GetSharedPointer();
575 m_type = type;
576}
577
579 if (IsValid())
580 if (auto type_system_sp = GetTypeSystem())
581 return type_system_sp->GetTypeQualifiers(m_type);
582 return 0;
583}
584
585// Creating related types
586
589 if (IsValid()) {
590 if (auto type_system_sp = GetTypeSystem())
591 return type_system_sp->GetArrayElementType(m_type, exe_scope);
592 }
593 return CompilerType();
594}
595
597 if (IsValid()) {
598 if (auto type_system_sp = GetTypeSystem())
599 return type_system_sp->GetArrayType(m_type, size);
600 }
601 return CompilerType();
602}
603
605 if (IsValid())
606 if (auto type_system_sp = GetTypeSystem())
607 return type_system_sp->GetCanonicalType(m_type);
608 return CompilerType();
609}
610
612 if (IsValid())
613 if (auto type_system_sp = GetTypeSystem())
614 return type_system_sp->GetFullyUnqualifiedType(m_type);
615 return CompilerType();
616}
617
619 if (IsValid())
620 if (auto type_system_sp = GetTypeSystem())
621 return type_system_sp->GetEnumerationIntegerType(m_type);
622 return CompilerType();
623}
624
626 if (IsValid()) {
627 if (auto type_system_sp = GetTypeSystem())
628 return type_system_sp->GetFunctionArgumentCount(m_type);
629 }
630 return -1;
631}
632
634 if (IsValid()) {
635 if (auto type_system_sp = GetTypeSystem())
636 return type_system_sp->GetFunctionArgumentTypeAtIndex(m_type, idx);
637 }
638 return CompilerType();
639}
640
642 if (IsValid()) {
643 if (auto type_system_sp = GetTypeSystem())
644 return type_system_sp->GetFunctionReturnType(m_type);
645 }
646 return CompilerType();
647}
648
650 if (IsValid()) {
651 if (auto type_system_sp = GetTypeSystem())
652 return type_system_sp->GetNumMemberFunctions(m_type);
653 }
654 return 0;
655}
656
658 if (IsValid()) {
659 if (auto type_system_sp = GetTypeSystem())
660 return type_system_sp->GetMemberFunctionAtIndex(m_type, idx);
661 }
662 return TypeMemberFunctionImpl();
663}
664
666 if (IsValid())
667 if (auto type_system_sp = GetTypeSystem())
668 return type_system_sp->GetNonReferenceType(m_type);
669 return CompilerType();
670}
671
673 if (IsValid()) {
674 if (auto type_system_sp = GetTypeSystem())
675 return type_system_sp->GetPointeeType(m_type);
676 }
677 return CompilerType();
678}
679
681 if (IsValid()) {
682 if (auto type_system_sp = GetTypeSystem())
683 return type_system_sp->GetPointerType(m_type);
684 }
685 return CompilerType();
686}
687
689 if (IsValid())
690 if (auto type_system_sp = GetTypeSystem())
691 return type_system_sp->AddPtrAuthModifier(m_type, payload);
692 return CompilerType();
693}
694
696 if (IsValid())
697 if (auto type_system_sp = GetTypeSystem())
698 return type_system_sp->GetLValueReferenceType(m_type);
699 return CompilerType();
700}
701
703 if (IsValid())
704 if (auto type_system_sp = GetTypeSystem())
705 return type_system_sp->GetRValueReferenceType(m_type);
706 return CompilerType();
707}
708
710 if (IsValid())
711 if (auto type_system_sp = GetTypeSystem())
712 return type_system_sp->GetAtomicType(m_type);
713 return CompilerType();
714}
715
717 if (IsValid())
718 if (auto type_system_sp = GetTypeSystem())
719 return type_system_sp->AddConstModifier(m_type);
720 return CompilerType();
721}
722
724 if (IsValid())
725 if (auto type_system_sp = GetTypeSystem())
726 return type_system_sp->AddVolatileModifier(m_type);
727 return CompilerType();
728}
729
731 if (IsValid())
732 if (auto type_system_sp = GetTypeSystem())
733 return type_system_sp->AddRestrictModifier(m_type);
734 return CompilerType();
735}
736
738 const CompilerDeclContext &decl_ctx,
739 uint32_t payload) const {
740 if (IsValid())
741 if (auto type_system_sp = GetTypeSystem())
742 return type_system_sp->CreateTypedef(m_type, name, decl_ctx, payload);
743 return CompilerType();
744}
745
747 if (IsValid())
748 if (auto type_system_sp = GetTypeSystem())
749 return type_system_sp->GetTypedefedType(m_type);
750 return CompilerType();
751}
752
753// Create related types using the current type's AST
754
757 if (IsValid())
758 if (auto type_system_sp = GetTypeSystem())
759 return type_system_sp->GetBasicTypeFromAST(basic_type);
760 return CompilerType();
761}
762// Exploring the type
763
764std::optional<uint64_t>
766 if (IsValid())
767 if (auto type_system_sp = GetTypeSystem())
768 return type_system_sp->GetBitSize(m_type, exe_scope);
769 return {};
770}
771
772std::optional<uint64_t>
774 if (std::optional<uint64_t> bit_size = GetBitSize(exe_scope))
775 return (*bit_size + 7) / 8;
776 return {};
777}
778
779std::optional<size_t>
781 if (IsValid())
782 if (auto type_system_sp = GetTypeSystem())
783 return type_system_sp->GetTypeBitAlign(m_type, exe_scope);
784 return {};
785}
786
788 if (IsValid())
789 if (auto type_system_sp = GetTypeSystem())
790 return type_system_sp->GetEncoding(m_type, count);
792}
793
795 if (IsValid())
796 if (auto type_system_sp = GetTypeSystem())
797 return type_system_sp->GetFormat(m_type);
799}
800
801llvm::Expected<uint32_t>
802CompilerType::GetNumChildren(bool omit_empty_base_classes,
803 const ExecutionContext *exe_ctx) const {
804 if (IsValid())
805 if (auto type_system_sp = GetTypeSystem())
806 return type_system_sp->GetNumChildren(m_type, omit_empty_base_classes,
807 exe_ctx);
808 return llvm::make_error<llvm::StringError>("invalid type",
809 llvm::inconvertibleErrorCode());
810}
811
813 if (IsValid())
814 if (auto type_system_sp = GetTypeSystem())
815 return type_system_sp->GetBasicTypeEnumeration(m_type);
816 return eBasicTypeInvalid;
817}
818
820 std::function<bool(const CompilerType &integer_type,
821 ConstString name,
822 const llvm::APSInt &value)> const &callback) const {
823 if (IsValid())
824 if (auto type_system_sp = GetTypeSystem())
825 return type_system_sp->ForEachEnumerator(m_type, callback);
826}
827
829 if (IsValid())
830 if (auto type_system_sp = GetTypeSystem())
831 return type_system_sp->GetNumFields(m_type);
832 return 0;
833}
834
835CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
836 uint64_t *bit_offset_ptr,
837 uint32_t *bitfield_bit_size_ptr,
838 bool *is_bitfield_ptr) const {
839 if (IsValid())
840 if (auto type_system_sp = GetTypeSystem())
841 return type_system_sp->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
842 bitfield_bit_size_ptr, is_bitfield_ptr);
843 return CompilerType();
844}
845
847 if (IsValid())
848 if (auto type_system_sp = GetTypeSystem())
849 return type_system_sp->GetNumDirectBaseClasses(m_type);
850 return 0;
851}
852
854 if (IsValid())
855 if (auto type_system_sp = GetTypeSystem())
856 return type_system_sp->GetNumVirtualBaseClasses(m_type);
857 return 0;
858}
859
862 uint32_t *bit_offset_ptr) const {
863 if (IsValid())
864 if (auto type_system_sp = GetTypeSystem())
865 return type_system_sp->GetDirectBaseClassAtIndex(m_type, idx,
866 bit_offset_ptr);
867 return CompilerType();
868}
869
872 uint32_t *bit_offset_ptr) const {
873 if (IsValid())
874 if (auto type_system_sp = GetTypeSystem())
875 return type_system_sp->GetVirtualBaseClassAtIndex(m_type, idx,
876 bit_offset_ptr);
877 return CompilerType();
878}
879
881 if (IsValid())
883 return CompilerDecl();
884}
885
887 const char *name, CompilerType *field_compiler_type_ptr,
888 uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
889 bool *is_bitfield_ptr) const {
890 unsigned count = GetNumFields();
891 std::string field_name;
892 for (unsigned index = 0; index < count; index++) {
893 CompilerType field_compiler_type(
894 GetFieldAtIndex(index, field_name, bit_offset_ptr,
895 bitfield_bit_size_ptr, is_bitfield_ptr));
896 if (strcmp(field_name.c_str(), name) == 0) {
897 if (field_compiler_type_ptr)
898 *field_compiler_type_ptr = field_compiler_type;
899 return index;
900 }
901 }
902 return UINT32_MAX;
903}
904
906 ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
907 bool omit_empty_base_classes, bool ignore_array_bounds,
908 std::string &child_name, uint32_t &child_byte_size,
909 int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
910 uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
911 bool &child_is_deref_of_parent, ValueObject *valobj,
912 uint64_t &language_flags) const {
913 if (IsValid())
914 if (auto type_system_sp = GetTypeSystem())
915 return type_system_sp->GetChildCompilerTypeAtIndex(
916 m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
917 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
918 child_bitfield_bit_size, child_bitfield_bit_offset,
919 child_is_base_class, child_is_deref_of_parent, valobj,
920 language_flags);
921 return CompilerType();
922}
923
924// Look for a child member (doesn't include base classes, but it does include
925// their members) in the type hierarchy. Returns an index path into
926// "clang_type" on how to reach the appropriate member.
927//
928// class A
929// {
930// public:
931// int m_a;
932// int m_b;
933// };
934//
935// class B
936// {
937// };
938//
939// class C :
940// public B,
941// public A
942// {
943// };
944//
945// If we have a clang type that describes "class C", and we wanted to looked
946// "m_b" in it:
947//
948// With omit_empty_base_classes == false we would get an integer array back
949// with: { 1, 1 } The first index 1 is the child index for "class A" within
950// class C The second index 1 is the child index for "m_b" within class A
951//
952// With omit_empty_base_classes == true we would get an integer array back
953// with: { 0, 1 } The first index 0 is the child index for "class A" within
954// class C (since class B doesn't have any members it doesn't count) The second
955// index 1 is the child index for "m_b" within class A
956
958 llvm::StringRef name, bool omit_empty_base_classes,
959 std::vector<uint32_t> &child_indexes) const {
960 if (IsValid() && !name.empty()) {
961 if (auto type_system_sp = GetTypeSystem())
962 return type_system_sp->GetIndexOfChildMemberWithName(
963 m_type, name, omit_empty_base_classes, child_indexes);
964 }
965 return 0;
966}
967
969CompilerType::GetDirectNestedTypeWithName(llvm::StringRef name) const {
970 if (IsValid() && !name.empty()) {
971 if (auto type_system_sp = GetTypeSystem())
972 return type_system_sp->GetDirectNestedTypeWithName(m_type, name);
973 }
974 return CompilerType();
975}
976
977size_t CompilerType::GetNumTemplateArguments(bool expand_pack) const {
978 if (IsValid()) {
979 if (auto type_system_sp = GetTypeSystem())
980 return type_system_sp->GetNumTemplateArguments(m_type, expand_pack);
981 }
982 return 0;
983}
984
986CompilerType::GetTemplateArgumentKind(size_t idx, bool expand_pack) const {
987 if (IsValid())
988 if (auto type_system_sp = GetTypeSystem())
989 return type_system_sp->GetTemplateArgumentKind(m_type, idx, expand_pack);
991}
992
994 bool expand_pack) const {
995 if (IsValid()) {
996 if (auto type_system_sp = GetTypeSystem())
997 return type_system_sp->GetTypeTemplateArgument(m_type, idx, expand_pack);
998 }
999 return CompilerType();
1000}
1001
1002std::optional<CompilerType::IntegralTemplateArgument>
1003CompilerType::GetIntegralTemplateArgument(size_t idx, bool expand_pack) const {
1004 if (IsValid())
1005 if (auto type_system_sp = GetTypeSystem())
1006 return type_system_sp->GetIntegralTemplateArgument(m_type, idx, expand_pack);
1007 return std::nullopt;
1008}
1009
1011 if (IsValid())
1012 if (auto type_system_sp = GetTypeSystem())
1013 return type_system_sp->GetTypeForFormatters(m_type);
1014 return CompilerType();
1015}
1016
1018 if (IsValid())
1019 if (auto type_system_sp = GetTypeSystem())
1020 return type_system_sp->ShouldPrintAsOneLiner(m_type, valobj);
1021 return eLazyBoolCalculate;
1022}
1023
1025 if (IsValid())
1026 if (auto type_system_sp = GetTypeSystem())
1027 return type_system_sp->IsMeaninglessWithoutDynamicResolution(m_type);
1028 return false;
1029}
1030
1031// Get the index of the child of "clang_type" whose name matches. This function
1032// doesn't descend into the children, but only looks one level deep and name
1033// matches can include base class names.
1034
1035uint32_t
1037 bool omit_empty_base_classes) const {
1038 if (IsValid() && !name.empty()) {
1039 if (auto type_system_sp = GetTypeSystem())
1040 return type_system_sp->GetIndexOfChildWithName(m_type, name,
1041 omit_empty_base_classes);
1042 }
1043 return UINT32_MAX;
1044}
1045
1046// Dumping types
1047
1049 const DataExtractor &data,
1050 lldb::offset_t byte_offset, size_t byte_size,
1051 uint32_t bitfield_bit_size,
1052 uint32_t bitfield_bit_offset,
1053 ExecutionContextScope *exe_scope) {
1054 if (IsValid())
1055 if (auto type_system_sp = GetTypeSystem())
1056 return type_system_sp->DumpTypeValue(
1057 m_type, *s, format, data, byte_offset, byte_size, bitfield_bit_size,
1058 bitfield_bit_offset, exe_scope);
1059 return false;
1060}
1061
1063 if (IsValid())
1064 if (auto type_system_sp = GetTypeSystem())
1065 type_system_sp->DumpTypeDescription(m_type, level);
1066}
1067
1069 lldb::DescriptionLevel level) const {
1070 if (IsValid())
1071 if (auto type_system_sp = GetTypeSystem())
1072 type_system_sp->DumpTypeDescription(m_type, *s, level);
1073}
1074
1075#ifndef NDEBUG
1076LLVM_DUMP_METHOD void CompilerType::dump() const {
1077 if (IsValid())
1078 if (auto type_system_sp = GetTypeSystem())
1079 return type_system_sp->dump(m_type);
1080 llvm::errs() << "<invalid>\n";
1081}
1082#endif
1083
1085 lldb::offset_t data_byte_offset,
1086 size_t data_byte_size, Scalar &value,
1087 ExecutionContextScope *exe_scope) const {
1088 if (!IsValid())
1089 return false;
1090
1091 if (IsAggregateType()) {
1092 return false; // Aggregate types don't have scalar values
1093 } else {
1094 uint64_t count = 0;
1095 lldb::Encoding encoding = GetEncoding(count);
1096
1097 if (encoding == lldb::eEncodingInvalid || count != 1)
1098 return false;
1099
1100 std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
1101 if (!byte_size)
1102 return false;
1103 lldb::offset_t offset = data_byte_offset;
1104 switch (encoding) {
1106 break;
1108 break;
1110 if (*byte_size <= sizeof(unsigned long long)) {
1111 uint64_t uval64 = data.GetMaxU64(&offset, *byte_size);
1112 if (*byte_size <= sizeof(unsigned int)) {
1113 value = (unsigned int)uval64;
1114 return true;
1115 } else if (*byte_size <= sizeof(unsigned long)) {
1116 value = (unsigned long)uval64;
1117 return true;
1118 } else if (*byte_size <= sizeof(unsigned long long)) {
1119 value = (unsigned long long)uval64;
1120 return true;
1121 } else
1122 value.Clear();
1123 }
1124 break;
1125
1127 if (*byte_size <= sizeof(long long)) {
1128 int64_t sval64 = data.GetMaxS64(&offset, *byte_size);
1129 if (*byte_size <= sizeof(int)) {
1130 value = (int)sval64;
1131 return true;
1132 } else if (*byte_size <= sizeof(long)) {
1133 value = (long)sval64;
1134 return true;
1135 } else if (*byte_size <= sizeof(long long)) {
1136 value = (long long)sval64;
1137 return true;
1138 } else
1139 value.Clear();
1140 }
1141 break;
1142
1144 if (*byte_size <= sizeof(long double)) {
1145 uint32_t u32;
1146 uint64_t u64;
1147 if (*byte_size == sizeof(float)) {
1148 if (sizeof(float) == sizeof(uint32_t)) {
1149 u32 = data.GetU32(&offset);
1150 value = *((float *)&u32);
1151 return true;
1152 } else if (sizeof(float) == sizeof(uint64_t)) {
1153 u64 = data.GetU64(&offset);
1154 value = *((float *)&u64);
1155 return true;
1156 }
1157 } else if (*byte_size == sizeof(double)) {
1158 if (sizeof(double) == sizeof(uint32_t)) {
1159 u32 = data.GetU32(&offset);
1160 value = *((double *)&u32);
1161 return true;
1162 } else if (sizeof(double) == sizeof(uint64_t)) {
1163 u64 = data.GetU64(&offset);
1164 value = *((double *)&u64);
1165 return true;
1166 }
1167 } else if (*byte_size == sizeof(long double)) {
1168 if (sizeof(long double) == sizeof(uint32_t)) {
1169 u32 = data.GetU32(&offset);
1170 value = *((long double *)&u32);
1171 return true;
1172 } else if (sizeof(long double) == sizeof(uint64_t)) {
1173 u64 = data.GetU64(&offset);
1174 value = *((long double *)&u64);
1175 return true;
1176 }
1177 }
1178 }
1179 break;
1180 }
1181 }
1182 return false;
1183}
1184
1187 : m_type_system(type_system.GetSharedPointer()), m_type(type) {
1188 assert(Verify() && "verification failed");
1189}
1190
1193 : m_type_system(type_system), m_type(type) {
1194 assert(Verify() && "verification failed");
1195}
1196
1197#ifndef NDEBUG
1199 if (!IsValid())
1200 return true;
1201 if (auto type_system_sp = GetTypeSystem())
1202 return type_system_sp->Verify(m_type);
1203 return true;
1204}
1205#endif
1206
1208 return {m_type_system.lock()};
1209}
1210
1212 const CompilerType::TypeSystemSPWrapper &other) const {
1213 if (!m_typesystem_sp && !other.m_typesystem_sp)
1214 return true;
1215 if (m_typesystem_sp && other.m_typesystem_sp)
1216 return m_typesystem_sp.get() == other.m_typesystem_sp.get();
1217 return false;
1218}
1219
1221 assert(m_typesystem_sp);
1222 return m_typesystem_sp.get();
1223}
1224
1226 const lldb_private::CompilerType &rhs) {
1227 return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
1228 lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
1229}
1230
1232 const lldb_private::CompilerType &rhs) {
1233 return !(lhs == rhs);
1234}
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
This is a minimal wrapper of a TypeSystem shared pointer as returned by CompilerType which conventien...
Definition: CompilerType.h:49
lldb::TypeSystemSP GetSharedPointer() const
Definition: CompilerType.h:85
bool operator==(const TypeSystemSPWrapper &other) const
TypeSystem * operator->() const
Only to be used in a one-off situations like if (typesystem && typesystem->method()) Do not store thi...
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
uint32_t GetNumberOfNonEmptyBaseClasses()
Go through the base classes and count non-empty ones.
CompilerType GetTypeForFormatters() const
CompilerType GetTypeTemplateArgument(size_t idx, bool expand_pack=false) const
lldb::LanguageType GetMinimumLanguage()
bool GetValueAsScalar(const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, Scalar &value, ExecutionContextScope *exe_scope) const
bool Verify() const
If the type is valid, ask the TypeSystem to verify the integrity of the type to catch CompilerTypes t...
lldb::BasicType GetBasicTypeEnumeration() const
std::optional< IntegralTemplateArgument > GetIntegralTemplateArgument(size_t idx, bool expand_pack=false) const
Returns the value of the template argument and its type.
TypeSystemSPWrapper GetTypeSystem() const
Accessors.
CompilerType GetArrayType(uint64_t size) const
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
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
bool IsPossibleDynamicType(CompilerType *target_type, bool check_cplusplus, bool check_objc) const
void SetCompilerType(lldb::TypeSystemWP type_system, lldb::opaque_compiler_type_t type)
std::optional< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
CompilerType AddConstModifier() const
Return a new CompilerType adds a const modifier to this type if this type is valid and the type syste...
lldb::Encoding GetEncoding(uint64_t &count) const
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
ConstString GetDisplayTypeName() const
CompilerType GetVirtualBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
size_t GetNumMemberFunctions() const
CompilerType GetFunctionArgumentTypeAtIndex(size_t idx) const
uint32_t IsHomogeneousAggregate(CompilerType *base_type_ptr) const
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
CompilerType GetRValueReferenceType() const
Return a new CompilerType that is a R value reference to this type if this type is valid and the type...
bool IsIntegerOrUnscopedEnumerationType() const
size_t GetIndexOfChildMemberWithName(llvm::StringRef name, bool omit_empty_base_classes, std::vector< uint32_t > &child_indexes) const
Lookup a child member given a name.
bool IsScalarOrUnscopedEnumerationType() const
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
bool IsContextuallyConvertibleToBool() const
This may only be defined in TypeSystemClang.
CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const
lldb::TypeClass GetTypeClass() const
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:287
size_t GetNumTemplateArguments(bool expand_pack=false) const
Return the number of template arguments the type has.
CompilerType AddVolatileModifier() const
Return a new CompilerType adds a volatile modifier to this type if this type is valid and the type sy...
bool IsVirtualBase(CompilerType target_base, CompilerType *virtual_base, bool carry_virtual=false) const
Checks whether target_base is a virtual base of type (direct or indirect).
CompilerType AddRestrictModifier() const
Return a new CompilerType adds a restrict modifier to this type if this type is valid and the type sy...
lldb::TypeSystemWP m_type_system
Definition: CompilerType.h:537
CompilerType GetDirectNestedTypeWithName(llvm::StringRef name) const
bool GetPtrAuthAddressDiversity() const
uint32_t GetNumVirtualBaseClasses() const
size_t GetPointerByteSize() const
AST related queries.
CompilerType GetFunctionArgumentAtIndex(const size_t index) const
void ForEachEnumerator(std::function< bool(const CompilerType &integer_type, ConstString name, const llvm::APSInt &value)> const &callback) const
If this type is an enumeration, iterate through all of its enumerators using a callback.
bool IsFloatingPointType(uint32_t &count, bool &is_complex) const
LLVM_DUMP_METHOD void dump() const
Dumping types.
CompilerType GetLValueReferenceType() const
Return a new CompilerType that is a L value reference to this type if this type is valid and the type...
uint32_t GetNumFields() const
bool IsPromotableIntegerType() const
size_t GetNumberOfFunctionArguments() const
bool IsIntegerOrEnumerationType(bool &is_signed) const
bool IsScopedEnumerationType() const
bool ShouldTreatScalarValueAsAddress() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
uint32_t GetNumDirectBaseClasses() const
bool IsMeaninglessWithoutDynamicResolution() const
bool IsBlockPointerType(CompilerType *function_pointer_type_ptr=nullptr) const
ConstString GetTypeName(bool BaseOnly=false) const
uint32_t GetIndexOfChildWithName(llvm::StringRef name, bool omit_empty_base_classes) const
Lookup a child given a name.
bool IsEnumerationIntegerTypeSigned() const
CompilerType GetTypedefedType() const
If the current object represents a typedef type, get the underlying type.
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
bool DumpTypeValue(Stream *s, lldb::Format format, const DataExtractor &data, lldb::offset_t data_offset, size_t data_byte_size, uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope)
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope) const
Creating related types.
bool IsInteger() const
This is used when you don't care about the signedness of the integer.
lldb::Format GetFormat() const
CompilerType GetFullyUnqualifiedType() const
unsigned GetTypeQualifiers() const
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
std::optional< size_t > GetTypeBitAlign(ExecutionContextScope *exe_scope) const
bool IsFunctionPointerType() const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
bool IsIntegerType(bool &is_signed) const
bool GetCompleteType() const
Type Completion.
bool IsUnscopedEnumerationType() const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
int GetFunctionArgumentCount() const
Returns -1 if this isn't a function of if the function doesn't have a prototype Returns a value >= 0 ...
unsigned GetPtrAuthDiscriminator() const
std::optional< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
uint32_t GetIndexOfFieldWithName(const char *name, CompilerType *field_compiler_type=nullptr, uint64_t *bit_offset_ptr=nullptr, uint32_t *bitfield_bit_size_ptr=nullptr, bool *is_bitfield_ptr=nullptr) const
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
CompilerType GetEnumerationIntegerType() const
lldb::opaque_compiler_type_t m_type
Definition: CompilerType.h:538
bool CompareTypes(CompilerType rhs) const
bool IsForcefullyCompleted() const
bool IsEnumerationType() const
This is used when you don't care about the signedness of the enum.
unsigned GetPtrAuthKey() const
CompilerType CreateTypedef(const char *name, const CompilerDeclContext &decl_ctx, uint32_t payload) const
Create a typedef to this type using "name" as the name of the typedef this type is valid and the type...
CompilerType GetFunctionReturnType() const
bool IsVectorType(CompilerType *element_type=nullptr, uint64_t *size=nullptr) const
bool IsMemberFunctionPointerType() const
CompilerType GetAtomicType() const
Return a new CompilerType that is the atomic type of this type.
CompilerType GetCanonicalType() const
void DumpTypeDescription(lldb::DescriptionLevel level=lldb::eDescriptionLevelFull) const
Dump to stdout.
bool IsRuntimeGeneratedType() const
lldb::TemplateArgumentKind GetTemplateArgumentKind(size_t idx, bool expand_pack=false) const
LazyBool ShouldPrintAsOneLiner(ValueObject *valobj) const
TypeMemberFunctionImpl GetMemberFunctionAtIndex(size_t idx)
bool IsPointerOrReferenceType(CompilerType *pointee_type=nullptr) const
bool IsPointerToScalarType() const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
CompilerType AddPtrAuthModifier(uint32_t payload) const
Return a new CompilerType adds a ptrauth modifier from the given 32-bit opaque payload to this type i...
A uniqued constant string class.
Definition: ConstString.h:40
An data extractor class.
Definition: DataExtractor.h:48
int64_t GetMaxS64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an signed integer of size byte_size from *offset_ptr.
uint64_t GetU64(lldb::offset_t *offset_ptr) const
Extract a uint64_t value from *offset_ptr.
uint32_t GetU32(lldb::offset_t *offset_ptr) const
Extract a uint32_t value from *offset_ptr.
uint64_t GetMaxU64(lldb::offset_t *offset_ptr, size_t byte_size) const
Extract an unsigned integer of size byte_size from *offset_ptr.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
Interface for representing a type system.
Definition: TypeSystem.h:70
virtual CompilerDecl GetStaticFieldWithName(lldb::opaque_compiler_type_t type, llvm::StringRef name)
Definition: TypeSystem.h:357
#define UINT32_MAX
Definition: lldb-defines.h:19
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1029
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1023
Definition: SBAddress.h:15
void * opaque_compiler_type_t
Definition: lldb-types.h:89
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedShort
@ eBasicTypeSignedChar
@ eBasicTypeNullPtr
@ eBasicTypeUnsignedWChar
@ eBasicTypeInvalid
@ eBasicTypeSignedWChar
@ eBasicTypeChar16
@ eBasicTypeUnsignedChar
@ eBasicTypeChar32
Format
Display format definitions.
uint64_t offset_t
Definition: lldb-types.h:85
LanguageType
Programming language type.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eTemplateArgumentKindNull
Encoding
Register encoding definitions.
@ eEncodingIEEE754
float
@ eEncodingVector
vector registers
@ eEncodingUint
unsigned integer
@ eEncodingInvalid
@ eEncodingSint
signed integer
std::weak_ptr< lldb_private::TypeSystem > TypeSystemWP
Definition: lldb-forward.h:459