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