1 //===-- CompilerType.cpp --------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Symbol/CompilerType.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Symbol/Type.h"
13 #include "lldb/Target/ExecutionContext.h"
14 #include "lldb/Target/Process.h"
15 #include "lldb/Utility/ConstString.h"
16 #include "lldb/Utility/DataBufferHeap.h"
17 #include "lldb/Utility/DataExtractor.h"
18 #include "lldb/Utility/Scalar.h"
19 #include "lldb/Utility/Stream.h"
20 #include "lldb/Utility/StreamString.h"
27 using namespace lldb_private
;
31 bool CompilerType::IsAggregateType() const {
33 if (auto type_system_sp
= GetTypeSystem())
34 return type_system_sp
->IsAggregateType(m_type
);
38 bool CompilerType::IsAnonymousType() const {
40 if (auto type_system_sp
= GetTypeSystem())
41 return type_system_sp
->IsAnonymousType(m_type
);
45 bool CompilerType::IsScopedEnumerationType() const {
47 if (auto type_system_sp
= GetTypeSystem())
48 return type_system_sp
->IsScopedEnumerationType(m_type
);
52 bool CompilerType::IsArrayType(CompilerType
*element_type_ptr
, uint64_t *size
,
53 bool *is_incomplete
) const {
55 if (auto type_system_sp
= GetTypeSystem())
56 return type_system_sp
->IsArrayType(m_type
, element_type_ptr
, size
,
60 element_type_ptr
->Clear();
64 *is_incomplete
= false;
68 bool CompilerType::IsVectorType(CompilerType
*element_type
,
69 uint64_t *size
) const {
71 if (auto type_system_sp
= GetTypeSystem())
72 return type_system_sp
->IsVectorType(m_type
, element_type
, size
);
76 bool CompilerType::IsRuntimeGeneratedType() const {
78 if (auto type_system_sp
= GetTypeSystem())
79 return type_system_sp
->IsRuntimeGeneratedType(m_type
);
83 bool CompilerType::IsCharType() const {
85 if (auto type_system_sp
= GetTypeSystem())
86 return type_system_sp
->IsCharType(m_type
);
90 bool CompilerType::IsCompleteType() const {
92 if (auto type_system_sp
= GetTypeSystem())
93 return type_system_sp
->IsCompleteType(m_type
);
97 bool CompilerType::IsForcefullyCompleted() const {
99 if (auto type_system_sp
= GetTypeSystem())
100 return type_system_sp
->IsForcefullyCompleted(m_type
);
104 bool CompilerType::IsConst() const {
106 if (auto type_system_sp
= GetTypeSystem())
107 return type_system_sp
->IsConst(m_type
);
111 bool CompilerType::IsFunctionType() const {
113 if (auto type_system_sp
= GetTypeSystem())
114 return type_system_sp
->IsFunctionType(m_type
);
118 // Used to detect "Homogeneous Floating-point Aggregates"
120 CompilerType::IsHomogeneousAggregate(CompilerType
*base_type_ptr
) const {
122 if (auto type_system_sp
= GetTypeSystem())
123 return type_system_sp
->IsHomogeneousAggregate(m_type
, base_type_ptr
);
127 size_t CompilerType::GetNumberOfFunctionArguments() const {
129 if (auto type_system_sp
= GetTypeSystem())
130 return type_system_sp
->GetNumberOfFunctionArguments(m_type
);
135 CompilerType::GetFunctionArgumentAtIndex(const size_t index
) const {
137 if (auto type_system_sp
= GetTypeSystem())
138 return type_system_sp
->GetFunctionArgumentAtIndex(m_type
, index
);
139 return CompilerType();
142 bool CompilerType::IsFunctionPointerType() const {
144 if (auto type_system_sp
= GetTypeSystem())
145 return type_system_sp
->IsFunctionPointerType(m_type
);
149 bool CompilerType::IsMemberFunctionPointerType() const {
151 if (auto type_system_sp
= GetTypeSystem())
152 return type_system_sp
->IsMemberFunctionPointerType(m_type
);
156 bool CompilerType::IsBlockPointerType(
157 CompilerType
*function_pointer_type_ptr
) const {
159 if (auto type_system_sp
= GetTypeSystem())
160 return type_system_sp
->IsBlockPointerType(m_type
, function_pointer_type_ptr
);
164 bool CompilerType::IsIntegerType(bool &is_signed
) const {
166 if (auto type_system_sp
= GetTypeSystem())
167 return type_system_sp
->IsIntegerType(m_type
, is_signed
);
171 bool CompilerType::IsEnumerationType(bool &is_signed
) const {
173 if (auto type_system_sp
= GetTypeSystem())
174 return type_system_sp
->IsEnumerationType(m_type
, is_signed
);
178 bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed
) const {
179 return IsIntegerType(is_signed
) || IsEnumerationType(is_signed
);
182 bool CompilerType::IsPointerType(CompilerType
*pointee_type
) const {
184 if (auto type_system_sp
= GetTypeSystem())
185 return type_system_sp
->IsPointerType(m_type
, pointee_type
);
188 pointee_type
->Clear();
192 bool CompilerType::IsPointerOrReferenceType(CompilerType
*pointee_type
) const {
194 if (auto type_system_sp
= GetTypeSystem())
195 return type_system_sp
->IsPointerOrReferenceType(m_type
, pointee_type
);
198 pointee_type
->Clear();
202 bool CompilerType::IsReferenceType(CompilerType
*pointee_type
,
203 bool *is_rvalue
) const {
205 if (auto type_system_sp
= GetTypeSystem())
206 return type_system_sp
->IsReferenceType(m_type
, pointee_type
, is_rvalue
);
209 pointee_type
->Clear();
213 bool CompilerType::ShouldTreatScalarValueAsAddress() const {
215 if (auto type_system_sp
= GetTypeSystem())
216 return type_system_sp
->ShouldTreatScalarValueAsAddress(m_type
);
220 bool CompilerType::IsFloatingPointType(uint32_t &count
,
221 bool &is_complex
) const {
223 if (auto type_system_sp
= GetTypeSystem())
224 return type_system_sp
->IsFloatingPointType(m_type
, count
, is_complex
);
231 bool CompilerType::IsDefined() const {
233 if (auto type_system_sp
= GetTypeSystem())
234 return type_system_sp
->IsDefined(m_type
);
238 bool CompilerType::IsPolymorphicClass() const {
240 if (auto type_system_sp
= GetTypeSystem())
241 return type_system_sp
->IsPolymorphicClass(m_type
);
246 bool CompilerType::IsPossibleDynamicType(CompilerType
*dynamic_pointee_type
,
247 bool check_cplusplus
,
248 bool check_objc
) const {
250 if (auto type_system_sp
= GetTypeSystem())
251 return type_system_sp
->IsPossibleDynamicType(m_type
, dynamic_pointee_type
,
252 check_cplusplus
, check_objc
);
256 bool CompilerType::IsScalarType() const {
258 if (auto type_system_sp
= GetTypeSystem())
259 return type_system_sp
->IsScalarType(m_type
);
263 bool CompilerType::IsTemplateType() const {
265 if (auto type_system_sp
= GetTypeSystem())
266 return type_system_sp
->IsTemplateType(m_type
);
270 bool CompilerType::IsTypedefType() const {
272 if (auto type_system_sp
= GetTypeSystem())
273 return type_system_sp
->IsTypedefType(m_type
);
277 bool CompilerType::IsVoidType() const {
279 if (auto type_system_sp
= GetTypeSystem())
280 return type_system_sp
->IsVoidType(m_type
);
284 bool CompilerType::IsPointerToScalarType() const {
288 return IsPointerType() && GetPointeeType().IsScalarType();
291 bool CompilerType::IsArrayOfScalarType() const {
292 CompilerType element_type
;
293 if (IsArrayType(&element_type
))
294 return element_type
.IsScalarType();
298 bool CompilerType::IsBeingDefined() const {
300 if (auto type_system_sp
= GetTypeSystem())
301 return type_system_sp
->IsBeingDefined(m_type
);
307 bool CompilerType::GetCompleteType() const {
309 if (auto type_system_sp
= GetTypeSystem())
310 return type_system_sp
->GetCompleteType(m_type
);
314 // AST related queries
315 size_t CompilerType::GetPointerByteSize() const {
316 if (auto type_system_sp
= GetTypeSystem())
317 return type_system_sp
->GetPointerByteSize();
321 ConstString
CompilerType::GetTypeName(bool BaseOnly
) const {
323 if (auto type_system_sp
= GetTypeSystem())
324 return type_system_sp
->GetTypeName(m_type
, BaseOnly
);
326 return ConstString("<invalid>");
329 ConstString
CompilerType::GetDisplayTypeName() const {
331 if (auto type_system_sp
= GetTypeSystem())
332 return type_system_sp
->GetDisplayTypeName(m_type
);
333 return ConstString("<invalid>");
336 uint32_t CompilerType::GetTypeInfo(
337 CompilerType
*pointee_or_element_compiler_type
) const {
339 if (auto type_system_sp
= GetTypeSystem())
340 return type_system_sp
->GetTypeInfo(m_type
,
341 pointee_or_element_compiler_type
);
345 lldb::LanguageType
CompilerType::GetMinimumLanguage() {
347 if (auto type_system_sp
= GetTypeSystem())
348 return type_system_sp
->GetMinimumLanguage(m_type
);
349 return lldb::eLanguageTypeC
;
352 lldb::TypeClass
CompilerType::GetTypeClass() const {
354 if (auto type_system_sp
= GetTypeSystem())
355 return type_system_sp
->GetTypeClass(m_type
);
356 return lldb::eTypeClassInvalid
;
359 void CompilerType::SetCompilerType(lldb::TypeSystemWP type_system
,
360 lldb::opaque_compiler_type_t type
) {
361 m_type_system
= type_system
;
365 void CompilerType::SetCompilerType(CompilerType::TypeSystemSPWrapper type_system
,
366 lldb::opaque_compiler_type_t type
) {
367 m_type_system
= type_system
.GetSharedPointer();
371 unsigned CompilerType::GetTypeQualifiers() const {
373 if (auto type_system_sp
= GetTypeSystem())
374 return type_system_sp
->GetTypeQualifiers(m_type
);
378 // Creating related types
381 CompilerType::GetArrayElementType(ExecutionContextScope
*exe_scope
) const {
383 if (auto type_system_sp
= GetTypeSystem())
384 return type_system_sp
->GetArrayElementType(m_type
, exe_scope
);
386 return CompilerType();
389 CompilerType
CompilerType::GetArrayType(uint64_t size
) const {
391 if (auto type_system_sp
= GetTypeSystem())
392 return type_system_sp
->GetArrayType(m_type
, size
);
394 return CompilerType();
397 CompilerType
CompilerType::GetCanonicalType() const {
399 if (auto type_system_sp
= GetTypeSystem())
400 return type_system_sp
->GetCanonicalType(m_type
);
401 return CompilerType();
404 CompilerType
CompilerType::GetFullyUnqualifiedType() const {
406 if (auto type_system_sp
= GetTypeSystem())
407 return type_system_sp
->GetFullyUnqualifiedType(m_type
);
408 return CompilerType();
411 CompilerType
CompilerType::GetEnumerationIntegerType() const {
413 if (auto type_system_sp
= GetTypeSystem())
414 return type_system_sp
->GetEnumerationIntegerType(m_type
);
415 return CompilerType();
418 int CompilerType::GetFunctionArgumentCount() const {
420 if (auto type_system_sp
= GetTypeSystem())
421 return type_system_sp
->GetFunctionArgumentCount(m_type
);
426 CompilerType
CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx
) const {
428 if (auto type_system_sp
= GetTypeSystem())
429 return type_system_sp
->GetFunctionArgumentTypeAtIndex(m_type
, idx
);
431 return CompilerType();
434 CompilerType
CompilerType::GetFunctionReturnType() const {
436 if (auto type_system_sp
= GetTypeSystem())
437 return type_system_sp
->GetFunctionReturnType(m_type
);
439 return CompilerType();
442 size_t CompilerType::GetNumMemberFunctions() const {
444 if (auto type_system_sp
= GetTypeSystem())
445 return type_system_sp
->GetNumMemberFunctions(m_type
);
450 TypeMemberFunctionImpl
CompilerType::GetMemberFunctionAtIndex(size_t idx
) {
452 if (auto type_system_sp
= GetTypeSystem())
453 return type_system_sp
->GetMemberFunctionAtIndex(m_type
, idx
);
455 return TypeMemberFunctionImpl();
458 CompilerType
CompilerType::GetNonReferenceType() const {
460 if (auto type_system_sp
= GetTypeSystem())
461 return type_system_sp
->GetNonReferenceType(m_type
);
462 return CompilerType();
465 CompilerType
CompilerType::GetPointeeType() const {
467 if (auto type_system_sp
= GetTypeSystem())
468 return type_system_sp
->GetPointeeType(m_type
);
470 return CompilerType();
473 CompilerType
CompilerType::GetPointerType() const {
475 if (auto type_system_sp
= GetTypeSystem())
476 return type_system_sp
->GetPointerType(m_type
);
478 return CompilerType();
481 CompilerType
CompilerType::GetLValueReferenceType() const {
483 if (auto type_system_sp
= GetTypeSystem())
484 return type_system_sp
->GetLValueReferenceType(m_type
);
485 return CompilerType();
488 CompilerType
CompilerType::GetRValueReferenceType() const {
490 if (auto type_system_sp
= GetTypeSystem())
491 return type_system_sp
->GetRValueReferenceType(m_type
);
492 return CompilerType();
495 CompilerType
CompilerType::GetAtomicType() const {
497 if (auto type_system_sp
= GetTypeSystem())
498 return type_system_sp
->GetAtomicType(m_type
);
499 return CompilerType();
502 CompilerType
CompilerType::AddConstModifier() const {
504 if (auto type_system_sp
= GetTypeSystem())
505 return type_system_sp
->AddConstModifier(m_type
);
506 return CompilerType();
509 CompilerType
CompilerType::AddVolatileModifier() const {
511 if (auto type_system_sp
= GetTypeSystem())
512 return type_system_sp
->AddVolatileModifier(m_type
);
513 return CompilerType();
516 CompilerType
CompilerType::AddRestrictModifier() const {
518 if (auto type_system_sp
= GetTypeSystem())
519 return type_system_sp
->AddRestrictModifier(m_type
);
520 return CompilerType();
523 CompilerType
CompilerType::CreateTypedef(const char *name
,
524 const CompilerDeclContext
&decl_ctx
,
525 uint32_t payload
) const {
527 if (auto type_system_sp
= GetTypeSystem())
528 return type_system_sp
->CreateTypedef(m_type
, name
, decl_ctx
, payload
);
529 return CompilerType();
532 CompilerType
CompilerType::GetTypedefedType() const {
534 if (auto type_system_sp
= GetTypeSystem())
535 return type_system_sp
->GetTypedefedType(m_type
);
536 return CompilerType();
539 // Create related types using the current type's AST
542 CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type
) const {
544 if (auto type_system_sp
= GetTypeSystem())
545 return type_system_sp
->GetBasicTypeFromAST(basic_type
);
546 return CompilerType();
548 // Exploring the type
550 std::optional
<uint64_t>
551 CompilerType::GetBitSize(ExecutionContextScope
*exe_scope
) const {
553 if (auto type_system_sp
= GetTypeSystem())
554 return type_system_sp
->GetBitSize(m_type
, exe_scope
);
558 std::optional
<uint64_t>
559 CompilerType::GetByteSize(ExecutionContextScope
*exe_scope
) const {
560 if (std::optional
<uint64_t> bit_size
= GetBitSize(exe_scope
))
561 return (*bit_size
+ 7) / 8;
565 std::optional
<size_t>
566 CompilerType::GetTypeBitAlign(ExecutionContextScope
*exe_scope
) const {
568 if (auto type_system_sp
= GetTypeSystem())
569 return type_system_sp
->GetTypeBitAlign(m_type
, exe_scope
);
573 lldb::Encoding
CompilerType::GetEncoding(uint64_t &count
) const {
575 if (auto type_system_sp
= GetTypeSystem())
576 return type_system_sp
->GetEncoding(m_type
, count
);
577 return lldb::eEncodingInvalid
;
580 lldb::Format
CompilerType::GetFormat() const {
582 if (auto type_system_sp
= GetTypeSystem())
583 return type_system_sp
->GetFormat(m_type
);
584 return lldb::eFormatDefault
;
587 uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes
,
588 const ExecutionContext
*exe_ctx
) const {
590 if (auto type_system_sp
= GetTypeSystem())
591 return type_system_sp
->GetNumChildren(m_type
, omit_empty_base_classes
,
596 lldb::BasicType
CompilerType::GetBasicTypeEnumeration() const {
598 if (auto type_system_sp
= GetTypeSystem())
599 return type_system_sp
->GetBasicTypeEnumeration(m_type
);
600 return eBasicTypeInvalid
;
603 void CompilerType::ForEachEnumerator(
604 std::function
<bool(const CompilerType
&integer_type
,
606 const llvm::APSInt
&value
)> const &callback
) const {
608 if (auto type_system_sp
= GetTypeSystem())
609 return type_system_sp
->ForEachEnumerator(m_type
, callback
);
612 uint32_t CompilerType::GetNumFields() const {
614 if (auto type_system_sp
= GetTypeSystem())
615 return type_system_sp
->GetNumFields(m_type
);
619 CompilerType
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 {
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();
630 uint32_t CompilerType::GetNumDirectBaseClasses() const {
632 if (auto type_system_sp
= GetTypeSystem())
633 return type_system_sp
->GetNumDirectBaseClasses(m_type
);
637 uint32_t CompilerType::GetNumVirtualBaseClasses() const {
639 if (auto type_system_sp
= GetTypeSystem())
640 return type_system_sp
->GetNumVirtualBaseClasses(m_type
);
645 CompilerType::GetDirectBaseClassAtIndex(size_t idx
,
646 uint32_t *bit_offset_ptr
) const {
648 if (auto type_system_sp
= GetTypeSystem())
649 return type_system_sp
->GetDirectBaseClassAtIndex(m_type
, idx
,
651 return CompilerType();
655 CompilerType::GetVirtualBaseClassAtIndex(size_t idx
,
656 uint32_t *bit_offset_ptr
) const {
658 if (auto type_system_sp
= GetTypeSystem())
659 return type_system_sp
->GetVirtualBaseClassAtIndex(m_type
, idx
,
661 return CompilerType();
664 uint32_t CompilerType::GetIndexOfFieldWithName(
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
;
683 CompilerType
CompilerType::GetChildCompilerTypeAtIndex(
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 {
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
,
699 return CompilerType();
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.
723 // If we have a clang type that describes "class C", and we wanted to looked
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
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
735 size_t CompilerType::GetIndexOfChildMemberWithName(
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
);
746 size_t CompilerType::GetNumTemplateArguments(bool expand_pack
) const {
748 if (auto type_system_sp
= GetTypeSystem())
749 return type_system_sp
->GetNumTemplateArguments(m_type
, expand_pack
);
755 CompilerType::GetTemplateArgumentKind(size_t idx
, bool expand_pack
) const {
757 if (auto type_system_sp
= GetTypeSystem())
758 return type_system_sp
->GetTemplateArgumentKind(m_type
, idx
, expand_pack
);
759 return eTemplateArgumentKindNull
;
762 CompilerType
CompilerType::GetTypeTemplateArgument(size_t idx
,
763 bool expand_pack
) const {
765 if (auto type_system_sp
= GetTypeSystem())
766 return type_system_sp
->GetTypeTemplateArgument(m_type
, idx
, expand_pack
);
768 return CompilerType();
771 std::optional
<CompilerType::IntegralTemplateArgument
>
772 CompilerType::GetIntegralTemplateArgument(size_t idx
, bool expand_pack
) const {
774 if (auto type_system_sp
= GetTypeSystem())
775 return type_system_sp
->GetIntegralTemplateArgument(m_type
, idx
, expand_pack
);
779 CompilerType
CompilerType::GetTypeForFormatters() const {
781 if (auto type_system_sp
= GetTypeSystem())
782 return type_system_sp
->GetTypeForFormatters(m_type
);
783 return CompilerType();
786 LazyBool
CompilerType::ShouldPrintAsOneLiner(ValueObject
*valobj
) const {
788 if (auto type_system_sp
= GetTypeSystem())
789 return type_system_sp
->ShouldPrintAsOneLiner(m_type
, valobj
);
790 return eLazyBoolCalculate
;
793 bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
795 if (auto type_system_sp
= GetTypeSystem())
796 return type_system_sp
->IsMeaninglessWithoutDynamicResolution(m_type
);
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.
805 CompilerType::GetIndexOfChildWithName(llvm::StringRef name
,
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
);
817 bool CompilerType::DumpTypeValue(Stream
*s
, lldb::Format format
,
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
) {
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
);
831 void CompilerType::DumpTypeDescription(lldb::DescriptionLevel level
) const {
833 if (auto type_system_sp
= GetTypeSystem())
834 type_system_sp
->DumpTypeDescription(m_type
, level
);
837 void CompilerType::DumpTypeDescription(Stream
*s
,
838 lldb::DescriptionLevel level
) const {
840 if (auto type_system_sp
= GetTypeSystem())
841 type_system_sp
->DumpTypeDescription(m_type
, *s
, level
);
845 LLVM_DUMP_METHOD
void CompilerType::dump() const {
847 if (auto type_system_sp
= GetTypeSystem())
848 return type_system_sp
->dump(m_type
);
849 llvm::errs() << "<invalid>\n";
853 bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor
&data
,
854 lldb::offset_t data_byte_offset
,
855 size_t data_byte_size
, Scalar
&value
,
856 ExecutionContextScope
*exe_scope
) const {
860 if (IsAggregateType()) {
861 return false; // Aggregate types don't have scalar values
864 lldb::Encoding encoding
= GetEncoding(count
);
866 if (encoding
== lldb::eEncodingInvalid
|| count
!= 1)
869 std::optional
<uint64_t> byte_size
= GetByteSize(exe_scope
);
872 lldb::offset_t offset
= data_byte_offset
;
874 case lldb::eEncodingInvalid
:
876 case lldb::eEncodingVector
:
878 case lldb::eEncodingUint
:
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
;
884 } else if (*byte_size
<= sizeof(unsigned long)) {
885 value
= (unsigned long)uval64
;
887 } else if (*byte_size
<= sizeof(unsigned long long)) {
888 value
= (unsigned long long)uval64
;
895 case lldb::eEncodingSint
:
896 if (*byte_size
<= sizeof(long long)) {
897 int64_t sval64
= data
.GetMaxS64(&offset
, *byte_size
);
898 if (*byte_size
<= sizeof(int)) {
901 } else if (*byte_size
<= sizeof(long)) {
902 value
= (long)sval64
;
904 } else if (*byte_size
<= sizeof(long long)) {
905 value
= (long long)sval64
;
912 case lldb::eEncodingIEEE754
:
913 if (*byte_size
<= sizeof(long double)) {
916 if (*byte_size
== sizeof(float)) {
917 if (sizeof(float) == sizeof(uint32_t)) {
918 u32
= data
.GetU32(&offset
);
919 value
= *((float *)&u32
);
921 } else if (sizeof(float) == sizeof(uint64_t)) {
922 u64
= data
.GetU64(&offset
);
923 value
= *((float *)&u64
);
926 } else if (*byte_size
== sizeof(double)) {
927 if (sizeof(double) == sizeof(uint32_t)) {
928 u32
= data
.GetU32(&offset
);
929 value
= *((double *)&u32
);
931 } else if (sizeof(double) == sizeof(uint64_t)) {
932 u64
= data
.GetU64(&offset
);
933 value
= *((double *)&u64
);
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
);
941 } else if (sizeof(long double) == sizeof(uint64_t)) {
942 u64
= data
.GetU64(&offset
);
943 value
= *((long double *)&u64
);
954 CompilerType::CompilerType(CompilerType::TypeSystemSPWrapper type_system
,
955 lldb::opaque_compiler_type_t type
)
956 : m_type_system(type_system
.GetSharedPointer()), m_type(type
) {
957 assert(Verify() && "verification failed");
960 CompilerType::CompilerType(lldb::TypeSystemWP type_system
,
961 lldb::opaque_compiler_type_t type
)
962 : m_type_system(type_system
), m_type(type
) {
963 assert(Verify() && "verification failed");
967 bool CompilerType::Verify() const {
970 if (auto type_system_sp
= GetTypeSystem())
971 return type_system_sp
->Verify(m_type
);
976 CompilerType::TypeSystemSPWrapper
CompilerType::GetTypeSystem() const {
977 return {m_type_system
.lock()};
980 bool CompilerType::TypeSystemSPWrapper::operator==(
981 const CompilerType::TypeSystemSPWrapper
&other
) const {
982 if (!m_typesystem_sp
&& !other
.m_typesystem_sp
)
984 if (m_typesystem_sp
&& other
.m_typesystem_sp
)
985 return m_typesystem_sp
.get() == other
.m_typesystem_sp
.get();
989 TypeSystem
*CompilerType::TypeSystemSPWrapper::operator->() const {
990 assert(m_typesystem_sp
);
991 return m_typesystem_sp
.get();
994 bool lldb_private::operator==(const lldb_private::CompilerType
&lhs
,
995 const lldb_private::CompilerType
&rhs
) {
996 return lhs
.GetTypeSystem() == rhs
.GetTypeSystem() &&
997 lhs
.GetOpaqueQualType() == rhs
.GetOpaqueQualType();
1000 bool lldb_private::operator!=(const lldb_private::CompilerType
&lhs
,
1001 const lldb_private::CompilerType
&rhs
) {
1002 return !(lhs
== rhs
);