1//===-- SBType.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
9#include "lldb/API/SBType.h"
10#include "lldb/API/SBDefines.h"
11#include "lldb/API/SBModule.h"
12#include "lldb/API/SBStream.h"
13#include "lldb/API/SBTypeEnumMember.h"
14#include "lldb/Core/Mangled.h"
15#include "lldb/Symbol/CompilerType.h"
16#include "lldb/Symbol/Type.h"
17#include "lldb/Symbol/TypeSystem.h"
18#include "lldb/Utility/ConstString.h"
19#include "lldb/Utility/Instrumentation.h"
20#include "lldb/Utility/Stream.h"
21
22#include "llvm/ADT/APSInt.h"
23
24#include <memory>
25#include <optional>
26
27using namespace lldb;
28using namespace lldb_private;
29
30SBType::SBType() { LLDB_INSTRUMENT_VA(this); }
31
32SBType::SBType(const CompilerType &type) : m_opaque_sp(new TypeImpl(type)) {}
33
34SBType::SBType(const lldb::TypeSP &type_sp)
35 : m_opaque_sp(new TypeImpl(type_sp)) {}
36
37SBType::SBType(const lldb::TypeImplSP &type_impl_sp)
38 : m_opaque_sp(type_impl_sp) {}
39
40SBType::SBType(const SBType &rhs) {
41 LLDB_INSTRUMENT_VA(this, rhs);
42
43 if (this != &rhs) {
44 m_opaque_sp = rhs.m_opaque_sp;
45 }
46}
47
48// SBType::SBType (TypeImpl* impl) :
49// m_opaque_up(impl)
50//{}
51//
52bool SBType::operator==(SBType &rhs) {
53 LLDB_INSTRUMENT_VA(this, rhs);
54
55 if (!IsValid())
56 return !rhs.IsValid();
57
58 if (!rhs.IsValid())
59 return false;
60
61 return *m_opaque_sp.get() == *rhs.m_opaque_sp.get();
62}
63
64bool SBType::operator!=(SBType &rhs) {
65 LLDB_INSTRUMENT_VA(this, rhs);
66
67 if (!IsValid())
68 return rhs.IsValid();
69
70 if (!rhs.IsValid())
71 return true;
72
73 return *m_opaque_sp.get() != *rhs.m_opaque_sp.get();
74}
75
76lldb::TypeImplSP SBType::GetSP() { return m_opaque_sp; }
77
78void SBType::SetSP(const lldb::TypeImplSP &type_impl_sp) {
79 m_opaque_sp = type_impl_sp;
80}
81
82SBType &SBType::operator=(const SBType &rhs) {
83 LLDB_INSTRUMENT_VA(this, rhs);
84
85 if (this != &rhs) {
86 m_opaque_sp = rhs.m_opaque_sp;
87 }
88 return *this;
89}
90
91SBType::~SBType() = default;
92
93TypeImpl &SBType::ref() {
94 if (m_opaque_sp.get() == nullptr)
95 m_opaque_sp = std::make_shared<TypeImpl>();
96 return *m_opaque_sp;
97}
98
99const TypeImpl &SBType::ref() const {
100 // "const SBAddress &addr" should already have checked "addr.IsValid()" prior
101 // to calling this function. In case you didn't we will assert and die to let
102 // you know.
103 assert(m_opaque_sp.get());
104 return *m_opaque_sp;
105}
106
107bool SBType::IsValid() const {
108 LLDB_INSTRUMENT_VA(this);
109 return this->operator bool();
110}
111SBType::operator bool() const {
112 LLDB_INSTRUMENT_VA(this);
113
114 if (m_opaque_sp.get() == nullptr)
115 return false;
116
117 return m_opaque_sp->IsValid();
118}
119
120uint64_t SBType::GetByteSize() {
121 LLDB_INSTRUMENT_VA(this);
122
123 if (IsValid())
124 if (std::optional<uint64_t> size =
125 m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetByteSize(exe_scope: nullptr))
126 return *size;
127 return 0;
128}
129
130bool SBType::IsPointerType() {
131 LLDB_INSTRUMENT_VA(this);
132
133 if (!IsValid())
134 return false;
135 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsPointerType();
136}
137
138bool SBType::IsArrayType() {
139 LLDB_INSTRUMENT_VA(this);
140
141 if (!IsValid())
142 return false;
143 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsArrayType(element_type: nullptr, size: nullptr,
144 is_incomplete: nullptr);
145}
146
147bool SBType::IsVectorType() {
148 LLDB_INSTRUMENT_VA(this);
149
150 if (!IsValid())
151 return false;
152 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsVectorType(element_type: nullptr, size: nullptr);
153}
154
155bool SBType::IsReferenceType() {
156 LLDB_INSTRUMENT_VA(this);
157
158 if (!IsValid())
159 return false;
160 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsReferenceType();
161}
162
163SBType SBType::GetPointerType() {
164 LLDB_INSTRUMENT_VA(this);
165
166 if (!IsValid())
167 return SBType();
168
169 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType())));
170}
171
172SBType SBType::GetPointeeType() {
173 LLDB_INSTRUMENT_VA(this);
174
175 if (!IsValid())
176 return SBType();
177 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType())));
178}
179
180SBType SBType::GetReferenceType() {
181 LLDB_INSTRUMENT_VA(this);
182
183 if (!IsValid())
184 return SBType();
185 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType())));
186}
187
188SBType SBType::GetTypedefedType() {
189 LLDB_INSTRUMENT_VA(this);
190
191 if (!IsValid())
192 return SBType();
193 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType())));
194}
195
196SBType SBType::GetDereferencedType() {
197 LLDB_INSTRUMENT_VA(this);
198
199 if (!IsValid())
200 return SBType();
201 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType())));
202}
203
204SBType SBType::GetArrayElementType() {
205 LLDB_INSTRUMENT_VA(this);
206
207 if (!IsValid())
208 return SBType();
209 return SBType(TypeImplSP(new TypeImpl(
210 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetArrayElementType(exe_scope: nullptr))));
211}
212
213SBType SBType::GetArrayType(uint64_t size) {
214 LLDB_INSTRUMENT_VA(this, size);
215
216 if (!IsValid())
217 return SBType();
218 return SBType(TypeImplSP(
219 new TypeImpl(m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetArrayType(size))));
220}
221
222SBType SBType::GetVectorElementType() {
223 LLDB_INSTRUMENT_VA(this);
224
225 SBType type_sb;
226 if (IsValid()) {
227 CompilerType vector_element_type;
228 if (m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsVectorType(element_type: &vector_element_type,
229 size: nullptr))
230 type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type)));
231 }
232 return type_sb;
233}
234
235bool SBType::IsFunctionType() {
236 LLDB_INSTRUMENT_VA(this);
237
238 if (!IsValid())
239 return false;
240 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsFunctionType();
241}
242
243bool SBType::IsPolymorphicClass() {
244 LLDB_INSTRUMENT_VA(this);
245
246 if (!IsValid())
247 return false;
248 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsPolymorphicClass();
249}
250
251bool SBType::IsTypedefType() {
252 LLDB_INSTRUMENT_VA(this);
253
254 if (!IsValid())
255 return false;
256 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsTypedefType();
257}
258
259bool SBType::IsAnonymousType() {
260 LLDB_INSTRUMENT_VA(this);
261
262 if (!IsValid())
263 return false;
264 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsAnonymousType();
265}
266
267bool SBType::IsScopedEnumerationType() {
268 LLDB_INSTRUMENT_VA(this);
269
270 if (!IsValid())
271 return false;
272 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsScopedEnumerationType();
273}
274
275bool SBType::IsAggregateType() {
276 LLDB_INSTRUMENT_VA(this);
277
278 if (!IsValid())
279 return false;
280 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).IsAggregateType();
281}
282
283lldb::SBType SBType::GetFunctionReturnType() {
284 LLDB_INSTRUMENT_VA(this);
285
286 if (IsValid()) {
287 CompilerType return_type(
288 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetFunctionReturnType());
289 if (return_type.IsValid())
290 return SBType(return_type);
291 }
292 return lldb::SBType();
293}
294
295lldb::SBTypeList SBType::GetFunctionArgumentTypes() {
296 LLDB_INSTRUMENT_VA(this);
297
298 SBTypeList sb_type_list;
299 if (IsValid()) {
300 CompilerType func_type(m_opaque_sp->GetCompilerType(prefer_dynamic: true));
301 size_t count = func_type.GetNumberOfFunctionArguments();
302 for (size_t i = 0; i < count; i++) {
303 sb_type_list.Append(type: SBType(func_type.GetFunctionArgumentAtIndex(index: i)));
304 }
305 }
306 return sb_type_list;
307}
308
309uint32_t SBType::GetNumberOfMemberFunctions() {
310 LLDB_INSTRUMENT_VA(this);
311
312 if (IsValid()) {
313 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumMemberFunctions();
314 }
315 return 0;
316}
317
318lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) {
319 LLDB_INSTRUMENT_VA(this, idx);
320
321 SBTypeMemberFunction sb_func_type;
322 if (IsValid())
323 sb_func_type.reset(new TypeMemberFunctionImpl(
324 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetMemberFunctionAtIndex(idx)));
325 return sb_func_type;
326}
327
328lldb::SBType SBType::GetUnqualifiedType() {
329 LLDB_INSTRUMENT_VA(this);
330
331 if (!IsValid())
332 return SBType();
333 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetUnqualifiedType())));
334}
335
336lldb::SBType SBType::GetCanonicalType() {
337 LLDB_INSTRUMENT_VA(this);
338
339 if (IsValid())
340 return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType())));
341 return SBType();
342}
343
344SBType SBType::GetEnumerationIntegerType() {
345 LLDB_INSTRUMENT_VA(this);
346
347 if (IsValid()) {
348 return SBType(
349 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetEnumerationIntegerType());
350 }
351 return SBType();
352}
353
354lldb::BasicType SBType::GetBasicType() {
355 LLDB_INSTRUMENT_VA(this);
356
357 if (IsValid())
358 return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetBasicTypeEnumeration();
359 return eBasicTypeInvalid;
360}
361
362SBType SBType::GetBasicType(lldb::BasicType basic_type) {
363 LLDB_INSTRUMENT_VA(this, basic_type);
364
365 if (IsValid() && m_opaque_sp->IsValid())
366 if (auto ts = m_opaque_sp->GetTypeSystem(prefer_dynamic: false))
367 return SBType(ts->GetBasicTypeFromAST(basic_type));
368 return SBType();
369}
370
371uint32_t SBType::GetNumberOfDirectBaseClasses() {
372 LLDB_INSTRUMENT_VA(this);
373
374 if (IsValid())
375 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumDirectBaseClasses();
376 return 0;
377}
378
379uint32_t SBType::GetNumberOfVirtualBaseClasses() {
380 LLDB_INSTRUMENT_VA(this);
381
382 if (IsValid())
383 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumVirtualBaseClasses();
384 return 0;
385}
386
387uint32_t SBType::GetNumberOfFields() {
388 LLDB_INSTRUMENT_VA(this);
389
390 if (IsValid())
391 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetNumFields();
392 return 0;
393}
394
395bool SBType::GetDescription(SBStream &description,
396 lldb::DescriptionLevel description_level) {
397 LLDB_INSTRUMENT_VA(this, description, description_level);
398
399 Stream &strm = description.ref();
400
401 if (m_opaque_sp) {
402 m_opaque_sp->GetDescription(strm, description_level);
403 } else
404 strm.PutCString(cstr: "No value");
405
406 return true;
407}
408
409SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) {
410 LLDB_INSTRUMENT_VA(this, idx);
411
412 SBTypeMember sb_type_member;
413 if (IsValid()) {
414 uint32_t bit_offset = 0;
415 CompilerType base_class_type =
416 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetDirectBaseClassAtIndex(
417 idx, bit_offset_ptr: &bit_offset);
418 if (base_class_type.IsValid())
419 sb_type_member.reset(new TypeMemberImpl(
420 TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
421 }
422 return sb_type_member;
423}
424
425SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) {
426 LLDB_INSTRUMENT_VA(this, idx);
427
428 SBTypeMember sb_type_member;
429 if (IsValid()) {
430 uint32_t bit_offset = 0;
431 CompilerType base_class_type =
432 m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetVirtualBaseClassAtIndex(
433 idx, bit_offset_ptr: &bit_offset);
434 if (base_class_type.IsValid())
435 sb_type_member.reset(new TypeMemberImpl(
436 TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
437 }
438 return sb_type_member;
439}
440
441SBTypeEnumMemberList SBType::GetEnumMembers() {
442 LLDB_INSTRUMENT_VA(this);
443
444 SBTypeEnumMemberList sb_enum_member_list;
445 if (IsValid()) {
446 CompilerType this_type(m_opaque_sp->GetCompilerType(prefer_dynamic: true));
447 if (this_type.IsValid()) {
448 this_type.ForEachEnumerator(callback: [&sb_enum_member_list](
449 const CompilerType &integer_type,
450 ConstString name,
451 const llvm::APSInt &value) -> bool {
452 SBTypeEnumMember enum_member(
453 lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl(
454 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value)));
455 sb_enum_member_list.Append(entry: enum_member);
456 return true; // Keep iterating
457 });
458 }
459 }
460 return sb_enum_member_list;
461}
462
463SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) {
464 LLDB_INSTRUMENT_VA(this, idx);
465
466 SBTypeMember sb_type_member;
467 if (IsValid()) {
468 CompilerType this_type(m_opaque_sp->GetCompilerType(prefer_dynamic: false));
469 if (this_type.IsValid()) {
470 uint64_t bit_offset = 0;
471 uint32_t bitfield_bit_size = 0;
472 bool is_bitfield = false;
473 std::string name_sstr;
474 CompilerType field_type(this_type.GetFieldAtIndex(
475 idx, name&: name_sstr, bit_offset_ptr: &bit_offset, bitfield_bit_size_ptr: &bitfield_bit_size, is_bitfield_ptr: &is_bitfield));
476 if (field_type.IsValid()) {
477 ConstString name;
478 if (!name_sstr.empty())
479 name.SetCString(name_sstr.c_str());
480 sb_type_member.reset(
481 new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset,
482 name, bitfield_bit_size, is_bitfield));
483 }
484 }
485 }
486 return sb_type_member;
487}
488
489bool SBType::IsTypeComplete() {
490 LLDB_INSTRUMENT_VA(this);
491
492 if (!IsValid())
493 return false;
494 CompilerType compiler_type = m_opaque_sp->GetCompilerType(prefer_dynamic: false);
495 // Only return true if we have a complete type and it wasn't forcefully
496 // completed.
497 if (compiler_type.IsCompleteType())
498 return !compiler_type.IsForcefullyCompleted();
499 return false;
500}
501
502uint32_t SBType::GetTypeFlags() {
503 LLDB_INSTRUMENT_VA(this);
504
505 if (!IsValid())
506 return 0;
507 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetTypeInfo();
508}
509
510lldb::SBModule SBType::GetModule() {
511 LLDB_INSTRUMENT_VA(this);
512
513 lldb::SBModule sb_module;
514 if (!IsValid())
515 return sb_module;
516
517 sb_module.SetSP(m_opaque_sp->GetModule());
518 return sb_module;
519}
520
521const char *SBType::GetName() {
522 LLDB_INSTRUMENT_VA(this);
523
524 if (!IsValid())
525 return "";
526 return m_opaque_sp->GetName().GetCString();
527}
528
529const char *SBType::GetDisplayTypeName() {
530 LLDB_INSTRUMENT_VA(this);
531
532 if (!IsValid())
533 return "";
534 return m_opaque_sp->GetDisplayTypeName().GetCString();
535}
536
537lldb::TypeClass SBType::GetTypeClass() {
538 LLDB_INSTRUMENT_VA(this);
539
540 if (IsValid())
541 return m_opaque_sp->GetCompilerType(prefer_dynamic: true).GetTypeClass();
542 return lldb::eTypeClassInvalid;
543}
544
545uint32_t SBType::GetNumberOfTemplateArguments() {
546 LLDB_INSTRUMENT_VA(this);
547
548 if (IsValid())
549 return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetNumTemplateArguments(
550 /*expand_pack=*/true);
551 return 0;
552}
553
554lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) {
555 LLDB_INSTRUMENT_VA(this, idx);
556
557 if (!IsValid())
558 return SBType();
559
560 CompilerType type;
561 const bool expand_pack = true;
562 switch(GetTemplateArgumentKind(idx)) {
563 case eTemplateArgumentKindType:
564 type = m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetTypeTemplateArgument(
565 idx, expand_pack);
566 break;
567 case eTemplateArgumentKindIntegral:
568 type = m_opaque_sp->GetCompilerType(prefer_dynamic: false)
569 .GetIntegralTemplateArgument(idx, expand_pack)
570 ->type;
571 break;
572 default:
573 break;
574 }
575 if (type.IsValid())
576 return SBType(type);
577 return SBType();
578}
579
580lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {
581 LLDB_INSTRUMENT_VA(this, idx);
582
583 if (IsValid())
584 return m_opaque_sp->GetCompilerType(prefer_dynamic: false).GetTemplateArgumentKind(
585 idx, /*expand_pack=*/true);
586 return eTemplateArgumentKindNull;
587}
588
589SBType SBType::FindDirectNestedType(const char *name) {
590 LLDB_INSTRUMENT_VA(this, name);
591
592 if (!IsValid())
593 return SBType();
594 return SBType(m_opaque_sp->FindDirectNestedType(name));
595}
596
597SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
598 LLDB_INSTRUMENT_VA(this);
599}
600
601SBTypeList::SBTypeList(const SBTypeList &rhs)
602 : m_opaque_up(new TypeListImpl()) {
603 LLDB_INSTRUMENT_VA(this, rhs);
604
605 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
606 i < rhs_size; i++)
607 Append(type: const_cast<SBTypeList &>(rhs).GetTypeAtIndex(index: i));
608}
609
610bool SBTypeList::IsValid() {
611 LLDB_INSTRUMENT_VA(this);
612 return this->operator bool();
613}
614SBTypeList::operator bool() const {
615 LLDB_INSTRUMENT_VA(this);
616
617 return (m_opaque_up != nullptr);
618}
619
620SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) {
621 LLDB_INSTRUMENT_VA(this, rhs);
622
623 if (this != &rhs) {
624 m_opaque_up = std::make_unique<TypeListImpl>();
625 for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
626 i < rhs_size; i++)
627 Append(type: const_cast<SBTypeList &>(rhs).GetTypeAtIndex(index: i));
628 }
629 return *this;
630}
631
632void SBTypeList::Append(SBType type) {
633 LLDB_INSTRUMENT_VA(this, type);
634
635 if (type.IsValid())
636 m_opaque_up->Append(type: type.m_opaque_sp);
637}
638
639SBType SBTypeList::GetTypeAtIndex(uint32_t index) {
640 LLDB_INSTRUMENT_VA(this, index);
641
642 if (m_opaque_up)
643 return SBType(m_opaque_up->GetTypeAtIndex(idx: index));
644 return SBType();
645}
646
647uint32_t SBTypeList::GetSize() {
648 LLDB_INSTRUMENT_VA(this);
649
650 return m_opaque_up->GetSize();
651}
652
653SBTypeList::~SBTypeList() = default;
654
655SBTypeMember::SBTypeMember() { LLDB_INSTRUMENT_VA(this); }
656
657SBTypeMember::~SBTypeMember() = default;
658
659SBTypeMember::SBTypeMember(const SBTypeMember &rhs) {
660 LLDB_INSTRUMENT_VA(this, rhs);
661
662 if (this != &rhs) {
663 if (rhs.IsValid())
664 m_opaque_up = std::make_unique<TypeMemberImpl>(args: rhs.ref());
665 }
666}
667
668lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) {
669 LLDB_INSTRUMENT_VA(this, rhs);
670
671 if (this != &rhs) {
672 if (rhs.IsValid())
673 m_opaque_up = std::make_unique<TypeMemberImpl>(args: rhs.ref());
674 }
675 return *this;
676}
677
678bool SBTypeMember::IsValid() const {
679 LLDB_INSTRUMENT_VA(this);
680 return this->operator bool();
681}
682SBTypeMember::operator bool() const {
683 LLDB_INSTRUMENT_VA(this);
684
685 return m_opaque_up.get();
686}
687
688const char *SBTypeMember::GetName() {
689 LLDB_INSTRUMENT_VA(this);
690
691 if (m_opaque_up)
692 return m_opaque_up->GetName().GetCString();
693 return nullptr;
694}
695
696SBType SBTypeMember::GetType() {
697 LLDB_INSTRUMENT_VA(this);
698
699 SBType sb_type;
700 if (m_opaque_up) {
701 sb_type.SetSP(m_opaque_up->GetTypeImpl());
702 }
703 return sb_type;
704}
705
706uint64_t SBTypeMember::GetOffsetInBytes() {
707 LLDB_INSTRUMENT_VA(this);
708
709 if (m_opaque_up)
710 return m_opaque_up->GetBitOffset() / 8u;
711 return 0;
712}
713
714uint64_t SBTypeMember::GetOffsetInBits() {
715 LLDB_INSTRUMENT_VA(this);
716
717 if (m_opaque_up)
718 return m_opaque_up->GetBitOffset();
719 return 0;
720}
721
722bool SBTypeMember::IsBitfield() {
723 LLDB_INSTRUMENT_VA(this);
724
725 if (m_opaque_up)
726 return m_opaque_up->GetIsBitfield();
727 return false;
728}
729
730uint32_t SBTypeMember::GetBitfieldSizeInBits() {
731 LLDB_INSTRUMENT_VA(this);
732
733 if (m_opaque_up)
734 return m_opaque_up->GetBitfieldBitSize();
735 return 0;
736}
737
738bool SBTypeMember::GetDescription(lldb::SBStream &description,
739 lldb::DescriptionLevel description_level) {
740 LLDB_INSTRUMENT_VA(this, description, description_level);
741
742 Stream &strm = description.ref();
743
744 if (m_opaque_up) {
745 const uint32_t bit_offset = m_opaque_up->GetBitOffset();
746 const uint32_t byte_offset = bit_offset / 8u;
747 const uint32_t byte_bit_offset = bit_offset % 8u;
748 const char *name = m_opaque_up->GetName().GetCString();
749 if (byte_bit_offset)
750 strm.Printf(format: "+%u + %u bits: (", byte_offset, byte_bit_offset);
751 else
752 strm.Printf(format: "+%u: (", byte_offset);
753
754 TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl());
755 if (type_impl_sp)
756 type_impl_sp->GetDescription(strm, description_level);
757
758 strm.Printf(format: ") %s", name);
759 if (m_opaque_up->GetIsBitfield()) {
760 const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize();
761 strm.Printf(format: " : %u", bitfield_bit_size);
762 }
763 } else {
764 strm.PutCString(cstr: "No value");
765 }
766 return true;
767}
768
769void SBTypeMember::reset(TypeMemberImpl *type_member_impl) {
770 m_opaque_up.reset(p: type_member_impl);
771}
772
773TypeMemberImpl &SBTypeMember::ref() {
774 if (m_opaque_up == nullptr)
775 m_opaque_up = std::make_unique<TypeMemberImpl>();
776 return *m_opaque_up;
777}
778
779const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; }
780
781SBTypeMemberFunction::SBTypeMemberFunction() { LLDB_INSTRUMENT_VA(this); }
782
783SBTypeMemberFunction::~SBTypeMemberFunction() = default;
784
785SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs)
786 : m_opaque_sp(rhs.m_opaque_sp) {
787 LLDB_INSTRUMENT_VA(this, rhs);
788}
789
790lldb::SBTypeMemberFunction &SBTypeMemberFunction::
791operator=(const lldb::SBTypeMemberFunction &rhs) {
792 LLDB_INSTRUMENT_VA(this, rhs);
793
794 if (this != &rhs)
795 m_opaque_sp = rhs.m_opaque_sp;
796 return *this;
797}
798
799bool SBTypeMemberFunction::IsValid() const {
800 LLDB_INSTRUMENT_VA(this);
801 return this->operator bool();
802}
803SBTypeMemberFunction::operator bool() const {
804 LLDB_INSTRUMENT_VA(this);
805
806 return m_opaque_sp.get();
807}
808
809const char *SBTypeMemberFunction::GetName() {
810 LLDB_INSTRUMENT_VA(this);
811
812 if (m_opaque_sp)
813 return m_opaque_sp->GetName().GetCString();
814 return nullptr;
815}
816
817const char *SBTypeMemberFunction::GetDemangledName() {
818 LLDB_INSTRUMENT_VA(this);
819
820 if (!m_opaque_sp)
821 return nullptr;
822
823 ConstString mangled_str = m_opaque_sp->GetMangledName();
824 if (!mangled_str)
825 return nullptr;
826
827 Mangled mangled(mangled_str);
828 return mangled.GetDemangledName().GetCString();
829}
830
831const char *SBTypeMemberFunction::GetMangledName() {
832 LLDB_INSTRUMENT_VA(this);
833
834 if (m_opaque_sp)
835 return m_opaque_sp->GetMangledName().GetCString();
836 return nullptr;
837}
838
839SBType SBTypeMemberFunction::GetType() {
840 LLDB_INSTRUMENT_VA(this);
841
842 SBType sb_type;
843 if (m_opaque_sp) {
844 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType())));
845 }
846 return sb_type;
847}
848
849lldb::SBType SBTypeMemberFunction::GetReturnType() {
850 LLDB_INSTRUMENT_VA(this);
851
852 SBType sb_type;
853 if (m_opaque_sp) {
854 sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType())));
855 }
856 return sb_type;
857}
858
859uint32_t SBTypeMemberFunction::GetNumberOfArguments() {
860 LLDB_INSTRUMENT_VA(this);
861
862 if (m_opaque_sp)
863 return m_opaque_sp->GetNumArguments();
864 return 0;
865}
866
867lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) {
868 LLDB_INSTRUMENT_VA(this, i);
869
870 SBType sb_type;
871 if (m_opaque_sp) {
872 sb_type.SetSP(
873 lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(idx: i))));
874 }
875 return sb_type;
876}
877
878lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() {
879 LLDB_INSTRUMENT_VA(this);
880
881 if (m_opaque_sp)
882 return m_opaque_sp->GetKind();
883 return lldb::eMemberFunctionKindUnknown;
884}
885
886bool SBTypeMemberFunction::GetDescription(
887 lldb::SBStream &description, lldb::DescriptionLevel description_level) {
888 LLDB_INSTRUMENT_VA(this, description, description_level);
889
890 Stream &strm = description.ref();
891
892 if (m_opaque_sp)
893 return m_opaque_sp->GetDescription(stream&: strm);
894
895 return false;
896}
897
898void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) {
899 m_opaque_sp.reset(p: type_member_impl);
900}
901
902TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {
903 if (!m_opaque_sp)
904 m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();
905 return *m_opaque_sp.get();
906}
907
908const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const {
909 return *m_opaque_sp.get();
910}
911

source code of lldb/source/API/SBType.cpp