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->IsFunctionType(m_type);
115 return false;
116}
117
118// Used to detect "Homogeneous Floating-point Aggregates"
119uint32_t
121 if (IsValid())
122 if (auto type_system_sp = GetTypeSystem())
123 return type_system_sp->IsHomogeneousAggregate(m_type, base_type_ptr);
124 return 0;
125}
126
128 if (IsValid())
129 if (auto type_system_sp = GetTypeSystem())
130 return type_system_sp->GetNumberOfFunctionArguments(m_type);
131 return 0;
132}
133
136 if (IsValid())
137 if (auto type_system_sp = GetTypeSystem())
138 return type_system_sp->GetFunctionArgumentAtIndex(m_type, index);
139 return CompilerType();
140}
141
143 if (IsValid())
144 if (auto type_system_sp = GetTypeSystem())
145 return type_system_sp->IsFunctionPointerType(m_type);
146 return false;
147}
148
150 if (IsValid())
151 if (auto type_system_sp = GetTypeSystem())
152 return type_system_sp->IsMemberFunctionPointerType(m_type);
153 return false;
154}
155
157 CompilerType *function_pointer_type_ptr) const {
158 if (IsValid())
159 if (auto type_system_sp = GetTypeSystem())
160 return type_system_sp->IsBlockPointerType(m_type, function_pointer_type_ptr);
161 return false;
162}
163
164bool CompilerType::IsIntegerType(bool &is_signed) const {
165 if (IsValid())
166 if (auto type_system_sp = GetTypeSystem())
167 return type_system_sp->IsIntegerType(m_type, is_signed);
168 return false;
169}
170
171bool CompilerType::IsEnumerationType(bool &is_signed) const {
172 if (IsValid())
173 if (auto type_system_sp = GetTypeSystem())
174 return type_system_sp->IsEnumerationType(m_type, is_signed);
175 return false;
176}
177
178bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
179 return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
180}
181
182bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
183 if (IsValid()) {
184 if (auto type_system_sp = GetTypeSystem())
185 return type_system_sp->IsPointerType(m_type, pointee_type);
186 }
187 if (pointee_type)
188 pointee_type->Clear();
189 return false;
190}
191
193 if (IsValid()) {
194 if (auto type_system_sp = GetTypeSystem())
195 return type_system_sp->IsPointerOrReferenceType(m_type, pointee_type);
196 }
197 if (pointee_type)
198 pointee_type->Clear();
199 return false;
200}
201
203 bool *is_rvalue) const {
204 if (IsValid()) {
205 if (auto type_system_sp = GetTypeSystem())
206 return type_system_sp->IsReferenceType(m_type, pointee_type, is_rvalue);
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->ShouldTreatScalarValueAsAddress(m_type);
217 return false;
218}
219
221 bool &is_complex) const {
222 if (IsValid()) {
223 if (auto type_system_sp = GetTypeSystem())
224 return type_system_sp->IsFloatingPointType(m_type, count, is_complex);
225 }
226 count = 0;
227 is_complex = false;
228 return false;
229}
230
232 if (IsValid())
233 if (auto type_system_sp = GetTypeSystem())
234 return type_system_sp->IsDefined(m_type);
235 return true;
236}
237
239 if (IsValid()) {
240 if (auto type_system_sp = GetTypeSystem())
241 return type_system_sp->IsPolymorphicClass(m_type);
242 }
243 return false;
244}
245
247 bool check_cplusplus,
248 bool check_objc) const {
249 if (IsValid())
250 if (auto type_system_sp = GetTypeSystem())
251 return type_system_sp->IsPossibleDynamicType(m_type, dynamic_pointee_type,
252 check_cplusplus, check_objc);
253 return false;
254}
255
257 if (IsValid())
258 if (auto type_system_sp = GetTypeSystem())
259 return type_system_sp->IsScalarType(m_type);
260 return false;
261}
262
264 if (IsValid())
265 if (auto type_system_sp = GetTypeSystem())
266 return type_system_sp->IsTemplateType(m_type);
267 return false;
268}
269
271 if (IsValid())
272 if (auto type_system_sp = GetTypeSystem())
273 return type_system_sp->IsTypedefType(m_type);
274 return false;
275}
276
278 if (IsValid())
279 if (auto type_system_sp = GetTypeSystem())
280 return type_system_sp->IsVoidType(m_type);
281 return false;
282}
283
285 if (!IsValid())
286 return false;
287
289}
290
292 CompilerType element_type;
293 if (IsArrayType(&element_type))
294 return element_type.IsScalarType();
295 return false;
296}
297
299 if (IsValid())
300 if (auto type_system_sp = GetTypeSystem())
301 return type_system_sp->IsBeingDefined(m_type);
302 return false;
303}
304
305// Type Completion
306
308 if (IsValid())
309 if (auto type_system_sp = GetTypeSystem())
310 return type_system_sp->GetCompleteType(m_type);
311 return false;
312}
313
314// AST related queries
316 if (auto type_system_sp = GetTypeSystem())
317 return type_system_sp->GetPointerByteSize();
318 return 0;
319}
320
322 if (IsValid()) {
323 if (auto type_system_sp = GetTypeSystem())
324 return type_system_sp->GetTypeName(m_type, BaseOnly);
325 }
326 return ConstString("<invalid>");
327}
328
330 if (IsValid())
331 if (auto type_system_sp = GetTypeSystem())
332 return type_system_sp->GetDisplayTypeName(m_type);
333 return ConstString("<invalid>");
334}
335
337 CompilerType *pointee_or_element_compiler_type) const {
338 if (IsValid())
339 if (auto type_system_sp = GetTypeSystem())
340 return type_system_sp->GetTypeInfo(m_type,
341 pointee_or_element_compiler_type);
342 return 0;
343}
344
346 if (IsValid())
347 if (auto type_system_sp = GetTypeSystem())
348 return type_system_sp->GetMinimumLanguage(m_type);
350}
351
352lldb::TypeClass CompilerType::GetTypeClass() const {
353 if (IsValid())
354 if (auto type_system_sp = GetTypeSystem())
355 return type_system_sp->GetTypeClass(m_type);
356 return lldb::eTypeClassInvalid;
357}
358
361 m_type_system = type_system;
362 m_type = type;
363}
364
367 m_type_system = type_system.GetSharedPointer();
368 m_type = type;
369}
370
372 if (IsValid())
373 if (auto type_system_sp = GetTypeSystem())
374 return type_system_sp->GetTypeQualifiers(m_type);
375 return 0;
376}
377
378// Creating related types
379
382 if (IsValid()) {
383 if (auto type_system_sp = GetTypeSystem())
384 return type_system_sp->GetArrayElementType(m_type, exe_scope);
385 }
386 return CompilerType();
387}
388
390 if (IsValid()) {
391 if (auto type_system_sp = GetTypeSystem())
392 return type_system_sp->GetArrayType(m_type, size);
393 }
394 return CompilerType();
395}
396
398 if (IsValid())
399 if (auto type_system_sp = GetTypeSystem())
400 return type_system_sp->GetCanonicalType(m_type);
401 return CompilerType();
402}
403
405 if (IsValid())
406 if (auto type_system_sp = GetTypeSystem())
407 return type_system_sp->GetFullyUnqualifiedType(m_type);
408 return CompilerType();
409}
410
412 if (IsValid())
413 if (auto type_system_sp = GetTypeSystem())
414 return type_system_sp->GetEnumerationIntegerType(m_type);
415 return CompilerType();
416}
417
419 if (IsValid()) {
420 if (auto type_system_sp = GetTypeSystem())
421 return type_system_sp->GetFunctionArgumentCount(m_type);
422 }
423 return -1;
424}
425
427 if (IsValid()) {
428 if (auto type_system_sp = GetTypeSystem())
429 return type_system_sp->GetFunctionArgumentTypeAtIndex(m_type, idx);
430 }
431 return CompilerType();
432}
433
435 if (IsValid()) {
436 if (auto type_system_sp = GetTypeSystem())
437 return type_system_sp->GetFunctionReturnType(m_type);
438 }
439 return CompilerType();
440}
441
443 if (IsValid()) {
444 if (auto type_system_sp = GetTypeSystem())
445 return type_system_sp->GetNumMemberFunctions(m_type);
446 }
447 return 0;
448}
449
451 if (IsValid()) {
452 if (auto type_system_sp = GetTypeSystem())
453 return type_system_sp->GetMemberFunctionAtIndex(m_type, idx);
454 }
455 return TypeMemberFunctionImpl();
456}
457
459 if (IsValid())
460 if (auto type_system_sp = GetTypeSystem())
461 return type_system_sp->GetNonReferenceType(m_type);
462 return CompilerType();
463}
464
466 if (IsValid()) {
467 if (auto type_system_sp = GetTypeSystem())
468 return type_system_sp->GetPointeeType(m_type);
469 }
470 return CompilerType();
471}
472
474 if (IsValid()) {
475 if (auto type_system_sp = GetTypeSystem())
476 return type_system_sp->GetPointerType(m_type);
477 }
478 return CompilerType();
479}
480
482 if (IsValid())
483 if (auto type_system_sp = GetTypeSystem())
484 return type_system_sp->GetLValueReferenceType(m_type);
485 return CompilerType();
486}
487
489 if (IsValid())
490 if (auto type_system_sp = GetTypeSystem())
491 return type_system_sp->GetRValueReferenceType(m_type);
492 return CompilerType();
493}
494
496 if (IsValid())
497 if (auto type_system_sp = GetTypeSystem())
498 return type_system_sp->GetAtomicType(m_type);
499 return CompilerType();
500}
501
503 if (IsValid())
504 if (auto type_system_sp = GetTypeSystem())
505 return type_system_sp->AddConstModifier(m_type);
506 return CompilerType();
507}
508
510 if (IsValid())
511 if (auto type_system_sp = GetTypeSystem())
512 return type_system_sp->AddVolatileModifier(m_type);
513 return CompilerType();
514}
515
517 if (IsValid())
518 if (auto type_system_sp = GetTypeSystem())
519 return type_system_sp->AddRestrictModifier(m_type);
520 return CompilerType();
521}
522
524 const CompilerDeclContext &decl_ctx,
525 uint32_t payload) const {
526 if (IsValid())
527 if (auto type_system_sp = GetTypeSystem())
528 return type_system_sp->CreateTypedef(m_type, name, decl_ctx, payload);
529 return CompilerType();
530}
531
533 if (IsValid())
534 if (auto type_system_sp = GetTypeSystem())
535 return type_system_sp->GetTypedefedType(m_type);
536 return CompilerType();
537}
538
539// Create related types using the current type's AST
540
543 if (IsValid())
544 if (auto type_system_sp = GetTypeSystem())
545 return type_system_sp->GetBasicTypeFromAST(basic_type);
546 return CompilerType();
547}
548// Exploring the type
549
550std::optional<uint64_t>
552 if (IsValid())
553 if (auto type_system_sp = GetTypeSystem())
554 return type_system_sp->GetBitSize(m_type, exe_scope);
555 return {};
556}
557
558std::optional<uint64_t>
560 if (std::optional<uint64_t> bit_size = GetBitSize(exe_scope))
561 return (*bit_size + 7) / 8;
562 return {};
563}
564
565std::optional<size_t>
567 if (IsValid())
568 if (auto type_system_sp = GetTypeSystem())
569 return type_system_sp->GetTypeBitAlign(m_type, exe_scope);
570 return {};
571}
572
574 if (IsValid())
575 if (auto type_system_sp = GetTypeSystem())
576 return type_system_sp->GetEncoding(m_type, count);
578}
579
581 if (IsValid())
582 if (auto type_system_sp = GetTypeSystem())
583 return type_system_sp->GetFormat(m_type);
585}
586
587uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes,
588 const ExecutionContext *exe_ctx) const {
589 if (IsValid())
590 if (auto type_system_sp = GetTypeSystem())
591 return type_system_sp->GetNumChildren(m_type, omit_empty_base_classes,
592 exe_ctx);
593 return 0;
594}
595
597 if (IsValid())
598 if (auto type_system_sp = GetTypeSystem())
599 return type_system_sp->GetBasicTypeEnumeration(m_type);
600 return eBasicTypeInvalid;
601}
602
604 std::function<bool(const CompilerType &integer_type,
605 ConstString name,
606 const llvm::APSInt &value)> const &callback) const {
607 if (IsValid())
608 if (auto type_system_sp = GetTypeSystem())
609 return type_system_sp->ForEachEnumerator(m_type, callback);
610}
611
613 if (IsValid())
614 if (auto type_system_sp = GetTypeSystem())
615 return type_system_sp->GetNumFields(m_type);
616 return 0;
617}
618
619CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
620 uint64_t *bit_offset_ptr,
621 uint32_t *bitfield_bit_size_ptr,
622 bool *is_bitfield_ptr) const {
623 if (IsValid())
624 if (auto type_system_sp = GetTypeSystem())
625 return type_system_sp->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
626 bitfield_bit_size_ptr, is_bitfield_ptr);
627 return CompilerType();
628}
629
631 if (IsValid())
632 if (auto type_system_sp = GetTypeSystem())
633 return type_system_sp->GetNumDirectBaseClasses(m_type);
634 return 0;
635}
636
638 if (IsValid())
639 if (auto type_system_sp = GetTypeSystem())
640 return type_system_sp->GetNumVirtualBaseClasses(m_type);
641 return 0;
642}
643
646 uint32_t *bit_offset_ptr) const {
647 if (IsValid())
648 if (auto type_system_sp = GetTypeSystem())
649 return type_system_sp->GetDirectBaseClassAtIndex(m_type, idx,
650 bit_offset_ptr);
651 return CompilerType();
652}
653
656 uint32_t *bit_offset_ptr) const {
657 if (IsValid())
658 if (auto type_system_sp = GetTypeSystem())
659 return type_system_sp->GetVirtualBaseClassAtIndex(m_type, idx,
660 bit_offset_ptr);
661 return CompilerType();
662}
663
665 const char *name, CompilerType *field_compiler_type_ptr,
666 uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
667 bool *is_bitfield_ptr) const {
668 unsigned count = GetNumFields();
669 std::string field_name;
670 for (unsigned index = 0; index < count; index++) {
671 CompilerType field_compiler_type(
672 GetFieldAtIndex(index, field_name, bit_offset_ptr,
673 bitfield_bit_size_ptr, is_bitfield_ptr));
674 if (strcmp(field_name.c_str(), name) == 0) {
675 if (field_compiler_type_ptr)
676 *field_compiler_type_ptr = field_compiler_type;
677 return index;
678 }
679 }
680 return UINT32_MAX;
681}
682
684 ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
685 bool omit_empty_base_classes, bool ignore_array_bounds,
686 std::string &child_name, uint32_t &child_byte_size,
687 int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
688 uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
689 bool &child_is_deref_of_parent, ValueObject *valobj,
690 uint64_t &language_flags) const {
691 if (IsValid())
692 if (auto type_system_sp = GetTypeSystem())
693 return type_system_sp->GetChildCompilerTypeAtIndex(
694 m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
695 ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
696 child_bitfield_bit_size, child_bitfield_bit_offset,
697 child_is_base_class, child_is_deref_of_parent, valobj,
698 language_flags);
699 return CompilerType();
700}
701
702// Look for a child member (doesn't include base classes, but it does include
703// their members) in the type hierarchy. Returns an index path into
704// "clang_type" on how to reach the appropriate member.
705//
706// class A
707// {
708// public:
709// int m_a;
710// int m_b;
711// };
712//
713// class B
714// {
715// };
716//
717// class C :
718// public B,
719// public A
720// {
721// };
722//
723// If we have a clang type that describes "class C", and we wanted to looked
724// "m_b" in it:
725//
726// With omit_empty_base_classes == false we would get an integer array back
727// with: { 1, 1 } The first index 1 is the child index for "class A" within
728// class C The second index 1 is the child index for "m_b" within class A
729//
730// With omit_empty_base_classes == true we would get an integer array back
731// with: { 0, 1 } The first index 0 is the child index for "class A" within
732// class C (since class B doesn't have any members it doesn't count) The second
733// index 1 is the child index for "m_b" within class A
734
736 llvm::StringRef name, bool omit_empty_base_classes,
737 std::vector<uint32_t> &child_indexes) const {
738 if (IsValid() && !name.empty()) {
739 if (auto type_system_sp = GetTypeSystem())
740 return type_system_sp->GetIndexOfChildMemberWithName(
741 m_type, name, omit_empty_base_classes, child_indexes);
742 }
743 return 0;
744}
745
746size_t CompilerType::GetNumTemplateArguments(bool expand_pack) const {
747 if (IsValid()) {
748 if (auto type_system_sp = GetTypeSystem())
749 return type_system_sp->GetNumTemplateArguments(m_type, expand_pack);
750 }
751 return 0;
752}
753
755CompilerType::GetTemplateArgumentKind(size_t idx, bool expand_pack) const {
756 if (IsValid())
757 if (auto type_system_sp = GetTypeSystem())
758 return type_system_sp->GetTemplateArgumentKind(m_type, idx, expand_pack);
760}
761
763 bool expand_pack) const {
764 if (IsValid()) {
765 if (auto type_system_sp = GetTypeSystem())
766 return type_system_sp->GetTypeTemplateArgument(m_type, idx, expand_pack);
767 }
768 return CompilerType();
769}
770
771std::optional<CompilerType::IntegralTemplateArgument>
772CompilerType::GetIntegralTemplateArgument(size_t idx, bool expand_pack) const {
773 if (IsValid())
774 if (auto type_system_sp = GetTypeSystem())
775 return type_system_sp->GetIntegralTemplateArgument(m_type, idx, expand_pack);
776 return std::nullopt;
777}
778
780 if (IsValid())
781 if (auto type_system_sp = GetTypeSystem())
782 return type_system_sp->GetTypeForFormatters(m_type);
783 return CompilerType();
784}
785
787 if (IsValid())
788 if (auto type_system_sp = GetTypeSystem())
789 return type_system_sp->ShouldPrintAsOneLiner(m_type, valobj);
790 return eLazyBoolCalculate;
791}
792
794 if (IsValid())
795 if (auto type_system_sp = GetTypeSystem())
796 return type_system_sp->IsMeaninglessWithoutDynamicResolution(m_type);
797 return false;
798}
799
800// Get the index of the child of "clang_type" whose name matches. This function
801// doesn't descend into the children, but only looks one level deep and name
802// matches can include base class names.
803
804uint32_t
806 bool omit_empty_base_classes) const {
807 if (IsValid() && !name.empty()) {
808 if (auto type_system_sp = GetTypeSystem())
809 return type_system_sp->GetIndexOfChildWithName(m_type, name,
810 omit_empty_base_classes);
811 }
812 return UINT32_MAX;
813}
814
815// Dumping types
816
818 const DataExtractor &data,
819 lldb::offset_t byte_offset, size_t byte_size,
820 uint32_t bitfield_bit_size,
821 uint32_t bitfield_bit_offset,
822 ExecutionContextScope *exe_scope) {
823 if (IsValid())
824 if (auto type_system_sp = GetTypeSystem())
825 return type_system_sp->DumpTypeValue(
826 m_type, *s, format, data, byte_offset, byte_size, bitfield_bit_size,
827 bitfield_bit_offset, exe_scope);
828 return false;
829}
830
832 if (IsValid())
833 if (auto type_system_sp = GetTypeSystem())
834 type_system_sp->DumpTypeDescription(m_type, level);
835}
836
838 lldb::DescriptionLevel level) const {
839 if (IsValid())
840 if (auto type_system_sp = GetTypeSystem())
841 type_system_sp->DumpTypeDescription(m_type, *s, level);
842}
843
844#ifndef NDEBUG
845LLVM_DUMP_METHOD void CompilerType::dump() const {
846 if (IsValid())
847 if (auto type_system_sp = GetTypeSystem())
848 return type_system_sp->dump(m_type);
849 llvm::errs() << "<invalid>\n";
850}
851#endif
852
854 lldb::offset_t data_byte_offset,
855 size_t data_byte_size, Scalar &value,
856 ExecutionContextScope *exe_scope) const {
857 if (!IsValid())
858 return false;
859
860 if (IsAggregateType()) {
861 return false; // Aggregate types don't have scalar values
862 } else {
863 uint64_t count = 0;
864 lldb::Encoding encoding = GetEncoding(count);
865
866 if (encoding == lldb::eEncodingInvalid || count != 1)
867 return false;
868
869 std::optional<uint64_t> byte_size = GetByteSize(exe_scope);
870 if (!byte_size)
871 return false;
872 lldb::offset_t offset = data_byte_offset;
873 switch (encoding) {
875 break;
877 break;
879 if (*byte_size <= sizeof(unsigned long long)) {
880 uint64_t uval64 = data.GetMaxU64(&offset, *byte_size);
881 if (*byte_size <= sizeof(unsigned int)) {
882 value = (unsigned int)uval64;
883 return true;
884 } else if (*byte_size <= sizeof(unsigned long)) {
885 value = (unsigned long)uval64;
886 return true;
887 } else if (*byte_size <= sizeof(unsigned long long)) {
888 value = (unsigned long long)uval64;
889 return true;
890 } else
891 value.Clear();
892 }
893 break;
894
896 if (*byte_size <= sizeof(long long)) {
897 int64_t sval64 = data.GetMaxS64(&offset, *byte_size);
898 if (*byte_size <= sizeof(int)) {
899 value = (int)sval64;
900 return true;
901 } else if (*byte_size <= sizeof(long)) {
902 value = (long)sval64;
903 return true;
904 } else if (*byte_size <= sizeof(long long)) {
905 value = (long long)sval64;
906 return true;
907 } else
908 value.Clear();
909 }
910 break;
911
913 if (*byte_size <= sizeof(long double)) {
914 uint32_t u32;
915 uint64_t u64;
916 if (*byte_size == sizeof(float)) {
917 if (sizeof(float) == sizeof(uint32_t)) {
918 u32 = data.GetU32(&offset);
919 value = *((float *)&u32);
920 return true;
921 } else if (sizeof(float) == sizeof(uint64_t)) {
922 u64 = data.GetU64(&offset);
923 value = *((float *)&u64);
924 return true;
925 }
926 } else if (*byte_size == sizeof(double)) {
927 if (sizeof(double) == sizeof(uint32_t)) {
928 u32 = data.GetU32(&offset);
929 value = *((double *)&u32);
930 return true;
931 } else if (sizeof(double) == sizeof(uint64_t)) {
932 u64 = data.GetU64(&offset);
933 value = *((double *)&u64);
934 return true;
935 }
936 } else if (*byte_size == sizeof(long double)) {
937 if (sizeof(long double) == sizeof(uint32_t)) {
938 u32 = data.GetU32(&offset);
939 value = *((long double *)&u32);
940 return true;
941 } else if (sizeof(long double) == sizeof(uint64_t)) {
942 u64 = data.GetU64(&offset);
943 value = *((long double *)&u64);
944 return true;
945 }
946 }
947 }
948 break;
949 }
950 }
951 return false;
952}
953
956 : m_type_system(type_system.GetSharedPointer()), m_type(type) {
957 assert(Verify() && "verification failed");
958}
959
962 : m_type_system(type_system), m_type(type) {
963 assert(Verify() && "verification failed");
964}
965
966#ifndef NDEBUG
968 if (!IsValid())
969 return true;
970 if (auto type_system_sp = GetTypeSystem())
971 return type_system_sp->Verify(m_type);
972 return true;
973}
974#endif
975
977 return {m_type_system.lock()};
978}
979
981 const CompilerType::TypeSystemSPWrapper &other) const {
982 if (!m_typesystem_sp && !other.m_typesystem_sp)
983 return true;
984 if (m_typesystem_sp && other.m_typesystem_sp)
985 return m_typesystem_sp.get() == other.m_typesystem_sp.get();
986 return false;
987}
988
990 assert(m_typesystem_sp);
991 return m_typesystem_sp.get();
992}
993
995 const lldb_private::CompilerType &rhs) {
996 return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
998}
999
1001 const lldb_private::CompilerType &rhs) {
1002 return !(lhs == rhs);
1003}
Represents a generic declaration context in a program.
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
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...
bool IsEnumerationType(bool &is_signed) const
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...
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.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
lldb::TypeClass GetTypeClass() const
lldb::opaque_compiler_type_t GetOpaqueQualType() const
Definition: CompilerType.h:227
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...
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:466
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
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
uint32_t GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) 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.
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.
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.
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 ...
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
CompilerType GetEnumerationIntegerType() const
lldb::opaque_compiler_type_t m_type
Definition: CompilerType.h:467
bool IsForcefullyCompleted() 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
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:83
#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:1022
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1016
Definition: SBAddress.h:15
void * opaque_compiler_type_t
Definition: lldb-types.h:87
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeInvalid
Format
Display format definitions.
uint64_t offset_t
Definition: lldb-types.h:83
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:455