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 "SBReproducerPrivate.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBModule.h"
13 #include "lldb/API/SBStream.h"
14 #include "lldb/API/SBTypeEnumMember.h"
15 #include "lldb/Core/Mangled.h"
16 #include "lldb/Symbol/CompilerType.h"
17 #include "lldb/Symbol/Type.h"
18 #include "lldb/Symbol/TypeSystem.h"
19 #include "lldb/Utility/ConstString.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() : m_opaque_sp() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBType); }
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) : m_opaque_sp() {
42   LLDB_RECORD_CONSTRUCTOR(SBType, (const lldb::SBType &), 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_RECORD_METHOD(bool, SBType, operator==,(lldb::SBType &), 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_RECORD_METHOD(bool, SBType, operator!=,(lldb::SBType &), 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_RECORD_METHOD(lldb::SBType &, SBType, operator=,(const lldb::SBType &),
85                      rhs);
86 
87   if (this != &rhs) {
88     m_opaque_sp = rhs.m_opaque_sp;
89   }
90   return LLDB_RECORD_RESULT(*this);
91 }
92 
93 SBType::~SBType() = default;
94 
95 TypeImpl &SBType::ref() {
96   if (m_opaque_sp.get() == nullptr)
97     m_opaque_sp = std::make_shared<TypeImpl>();
98   return *m_opaque_sp;
99 }
100 
101 const TypeImpl &SBType::ref() const {
102   // "const SBAddress &addr" should already have checked "addr.IsValid()" prior
103   // to calling this function. In case you didn't we will assert and die to let
104   // you know.
105   assert(m_opaque_sp.get());
106   return *m_opaque_sp;
107 }
108 
109 bool SBType::IsValid() const {
110   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, IsValid);
111   return this->operator bool();
112 }
113 SBType::operator bool() const {
114   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBType, operator bool);
115 
116   if (m_opaque_sp.get() == nullptr)
117     return false;
118 
119   return m_opaque_sp->IsValid();
120 }
121 
122 uint64_t SBType::GetByteSize() {
123   LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBType, GetByteSize);
124 
125   if (IsValid())
126     if (llvm::Optional<uint64_t> size =
127             m_opaque_sp->GetCompilerType(false).GetByteSize(nullptr))
128       return *size;
129   return 0;
130 }
131 
132 bool SBType::IsPointerType() {
133   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPointerType);
134 
135   if (!IsValid())
136     return false;
137   return m_opaque_sp->GetCompilerType(true).IsPointerType();
138 }
139 
140 bool SBType::IsArrayType() {
141   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsArrayType);
142 
143   if (!IsValid())
144     return false;
145   return m_opaque_sp->GetCompilerType(true).IsArrayType(nullptr, nullptr,
146                                                         nullptr);
147 }
148 
149 bool SBType::IsVectorType() {
150   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsVectorType);
151 
152   if (!IsValid())
153     return false;
154   return m_opaque_sp->GetCompilerType(true).IsVectorType(nullptr, nullptr);
155 }
156 
157 bool SBType::IsReferenceType() {
158   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsReferenceType);
159 
160   if (!IsValid())
161     return false;
162   return m_opaque_sp->GetCompilerType(true).IsReferenceType();
163 }
164 
165 SBType SBType::GetPointerType() {
166   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointerType);
167 
168   if (!IsValid())
169     return LLDB_RECORD_RESULT(SBType());
170 
171   return LLDB_RECORD_RESULT(
172       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointerType()))));
173 }
174 
175 SBType SBType::GetPointeeType() {
176   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetPointeeType);
177 
178   if (!IsValid())
179     return LLDB_RECORD_RESULT(SBType());
180   return LLDB_RECORD_RESULT(
181       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetPointeeType()))));
182 }
183 
184 SBType SBType::GetReferenceType() {
185   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetReferenceType);
186 
187   if (!IsValid())
188     return LLDB_RECORD_RESULT(SBType());
189   return LLDB_RECORD_RESULT(
190       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetReferenceType()))));
191 }
192 
193 SBType SBType::GetTypedefedType() {
194   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetTypedefedType);
195 
196   if (!IsValid())
197     return LLDB_RECORD_RESULT(SBType());
198   return LLDB_RECORD_RESULT(
199       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetTypedefedType()))));
200 }
201 
202 SBType SBType::GetDereferencedType() {
203   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetDereferencedType);
204 
205   if (!IsValid())
206     return LLDB_RECORD_RESULT(SBType());
207   return LLDB_RECORD_RESULT(
208       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType()))));
209 }
210 
211 SBType SBType::GetArrayElementType() {
212   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetArrayElementType);
213 
214   if (!IsValid())
215     return LLDB_RECORD_RESULT(SBType());
216   return LLDB_RECORD_RESULT(SBType(TypeImplSP(new TypeImpl(
217       m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)))));
218 }
219 
220 SBType SBType::GetArrayType(uint64_t size) {
221   LLDB_RECORD_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t), size);
222 
223   if (!IsValid())
224     return LLDB_RECORD_RESULT(SBType());
225   return LLDB_RECORD_RESULT(SBType(TypeImplSP(
226       new TypeImpl(m_opaque_sp->GetCompilerType(true).GetArrayType(size)))));
227 }
228 
229 SBType SBType::GetVectorElementType() {
230   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetVectorElementType);
231 
232   SBType type_sb;
233   if (IsValid()) {
234     CompilerType vector_element_type;
235     if (m_opaque_sp->GetCompilerType(true).IsVectorType(&vector_element_type,
236                                                         nullptr))
237       type_sb.SetSP(TypeImplSP(new TypeImpl(vector_element_type)));
238   }
239   return LLDB_RECORD_RESULT(type_sb);
240 }
241 
242 bool SBType::IsFunctionType() {
243   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsFunctionType);
244 
245   if (!IsValid())
246     return false;
247   return m_opaque_sp->GetCompilerType(true).IsFunctionType();
248 }
249 
250 bool SBType::IsPolymorphicClass() {
251   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsPolymorphicClass);
252 
253   if (!IsValid())
254     return false;
255   return m_opaque_sp->GetCompilerType(true).IsPolymorphicClass();
256 }
257 
258 bool SBType::IsTypedefType() {
259   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypedefType);
260 
261   if (!IsValid())
262     return false;
263   return m_opaque_sp->GetCompilerType(true).IsTypedefType();
264 }
265 
266 bool SBType::IsAnonymousType() {
267   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsAnonymousType);
268 
269   if (!IsValid())
270     return false;
271   return m_opaque_sp->GetCompilerType(true).IsAnonymousType();
272 }
273 
274 bool SBType::IsScopedEnumerationType() {
275   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsScopedEnumerationType);
276 
277   if (!IsValid())
278     return false;
279   return m_opaque_sp->GetCompilerType(true).IsScopedEnumerationType();
280 }
281 
282 lldb::SBType SBType::GetFunctionReturnType() {
283   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetFunctionReturnType);
284 
285   if (IsValid()) {
286     CompilerType return_type(
287         m_opaque_sp->GetCompilerType(true).GetFunctionReturnType());
288     if (return_type.IsValid())
289       return LLDB_RECORD_RESULT(SBType(return_type));
290   }
291   return LLDB_RECORD_RESULT(lldb::SBType());
292 }
293 
294 lldb::SBTypeList SBType::GetFunctionArgumentTypes() {
295   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeList, SBType,
296                              GetFunctionArgumentTypes);
297 
298   SBTypeList sb_type_list;
299   if (IsValid()) {
300     CompilerType func_type(m_opaque_sp->GetCompilerType(true));
301     size_t count = func_type.GetNumberOfFunctionArguments();
302     for (size_t i = 0; i < count; i++) {
303       sb_type_list.Append(SBType(func_type.GetFunctionArgumentAtIndex(i)));
304     }
305   }
306   return LLDB_RECORD_RESULT(sb_type_list);
307 }
308 
309 uint32_t SBType::GetNumberOfMemberFunctions() {
310   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfMemberFunctions);
311 
312   if (IsValid()) {
313     return m_opaque_sp->GetCompilerType(true).GetNumMemberFunctions();
314   }
315   return 0;
316 }
317 
318 lldb::SBTypeMemberFunction SBType::GetMemberFunctionAtIndex(uint32_t idx) {
319   LLDB_RECORD_METHOD(lldb::SBTypeMemberFunction, SBType,
320                      GetMemberFunctionAtIndex, (uint32_t), idx);
321 
322   SBTypeMemberFunction sb_func_type;
323   if (IsValid())
324     sb_func_type.reset(new TypeMemberFunctionImpl(
325         m_opaque_sp->GetCompilerType(true).GetMemberFunctionAtIndex(idx)));
326   return LLDB_RECORD_RESULT(sb_func_type);
327 }
328 
329 lldb::SBType SBType::GetUnqualifiedType() {
330   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetUnqualifiedType);
331 
332   if (!IsValid())
333     return LLDB_RECORD_RESULT(SBType());
334   return LLDB_RECORD_RESULT(
335       SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetUnqualifiedType()))));
336 }
337 
338 lldb::SBType SBType::GetCanonicalType() {
339   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetCanonicalType);
340 
341   if (IsValid())
342     return LLDB_RECORD_RESULT(
343         SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetCanonicalType()))));
344   return LLDB_RECORD_RESULT(SBType());
345 }
346 
347 lldb::BasicType SBType::GetBasicType() {
348   LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType);
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_RECORD_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType),
357                      basic_type);
358 
359   if (IsValid() && m_opaque_sp->IsValid())
360     return LLDB_RECORD_RESULT(SBType(
361         m_opaque_sp->GetTypeSystem(false)->GetBasicTypeFromAST(basic_type)));
362   return LLDB_RECORD_RESULT(SBType());
363 }
364 
365 uint32_t SBType::GetNumberOfDirectBaseClasses() {
366   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfDirectBaseClasses);
367 
368   if (IsValid())
369     return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses();
370   return 0;
371 }
372 
373 uint32_t SBType::GetNumberOfVirtualBaseClasses() {
374   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfVirtualBaseClasses);
375 
376   if (IsValid())
377     return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses();
378   return 0;
379 }
380 
381 uint32_t SBType::GetNumberOfFields() {
382   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfFields);
383 
384   if (IsValid())
385     return m_opaque_sp->GetCompilerType(true).GetNumFields();
386   return 0;
387 }
388 
389 bool SBType::GetDescription(SBStream &description,
390                             lldb::DescriptionLevel description_level) {
391   LLDB_RECORD_METHOD(bool, SBType, GetDescription,
392                      (lldb::SBStream &, lldb::DescriptionLevel), description,
393                      description_level);
394 
395   Stream &strm = description.ref();
396 
397   if (m_opaque_sp) {
398     m_opaque_sp->GetDescription(strm, description_level);
399   } else
400     strm.PutCString("No value");
401 
402   return true;
403 }
404 
405 SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) {
406   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
407                      (uint32_t), idx);
408 
409   SBTypeMember sb_type_member;
410   if (IsValid()) {
411     uint32_t bit_offset = 0;
412     CompilerType base_class_type =
413         m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex(
414             idx, &bit_offset);
415     if (base_class_type.IsValid())
416       sb_type_member.reset(new TypeMemberImpl(
417           TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
418   }
419   return LLDB_RECORD_RESULT(sb_type_member);
420 }
421 
422 SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) {
423   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
424                      (uint32_t), idx);
425 
426   SBTypeMember sb_type_member;
427   if (IsValid()) {
428     uint32_t bit_offset = 0;
429     CompilerType base_class_type =
430         m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex(
431             idx, &bit_offset);
432     if (base_class_type.IsValid())
433       sb_type_member.reset(new TypeMemberImpl(
434           TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
435   }
436   return LLDB_RECORD_RESULT(sb_type_member);
437 }
438 
439 SBTypeEnumMemberList SBType::GetEnumMembers() {
440   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeEnumMemberList, SBType,
441                              GetEnumMembers);
442 
443   SBTypeEnumMemberList sb_enum_member_list;
444   if (IsValid()) {
445     CompilerType this_type(m_opaque_sp->GetCompilerType(true));
446     if (this_type.IsValid()) {
447       this_type.ForEachEnumerator([&sb_enum_member_list](
448                                       const CompilerType &integer_type,
449                                       ConstString name,
450                                       const llvm::APSInt &value) -> bool {
451         SBTypeEnumMember enum_member(
452             lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl(
453                 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value)));
454         sb_enum_member_list.Append(enum_member);
455         return true; // Keep iterating
456       });
457     }
458   }
459   return LLDB_RECORD_RESULT(sb_enum_member_list);
460 }
461 
462 SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) {
463   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, (uint32_t),
464                      idx);
465 
466   SBTypeMember sb_type_member;
467   if (IsValid()) {
468     CompilerType this_type(m_opaque_sp->GetCompilerType(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_sstr, &bit_offset, &bitfield_bit_size, &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 LLDB_RECORD_RESULT(sb_type_member);
487 }
488 
489 bool SBType::IsTypeComplete() {
490   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypeComplete);
491 
492   if (!IsValid())
493     return false;
494   return m_opaque_sp->GetCompilerType(false).IsCompleteType();
495 }
496 
497 uint32_t SBType::GetTypeFlags() {
498   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetTypeFlags);
499 
500   if (!IsValid())
501     return 0;
502   return m_opaque_sp->GetCompilerType(true).GetTypeInfo();
503 }
504 
505 lldb::SBModule SBType::GetModule() {
506   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule);
507 
508   lldb::SBModule sb_module;
509   if (!IsValid())
510     return LLDB_RECORD_RESULT(sb_module);
511 
512   sb_module.SetSP(m_opaque_sp->GetModule());
513   return LLDB_RECORD_RESULT(sb_module);
514 }
515 
516 const char *SBType::GetName() {
517   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName);
518 
519   if (!IsValid())
520     return "";
521   return m_opaque_sp->GetName().GetCString();
522 }
523 
524 const char *SBType::GetDisplayTypeName() {
525   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetDisplayTypeName);
526 
527   if (!IsValid())
528     return "";
529   return m_opaque_sp->GetDisplayTypeName().GetCString();
530 }
531 
532 lldb::TypeClass SBType::GetTypeClass() {
533   LLDB_RECORD_METHOD_NO_ARGS(lldb::TypeClass, SBType, GetTypeClass);
534 
535   if (IsValid())
536     return m_opaque_sp->GetCompilerType(true).GetTypeClass();
537   return lldb::eTypeClassInvalid;
538 }
539 
540 uint32_t SBType::GetNumberOfTemplateArguments() {
541   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfTemplateArguments);
542 
543   if (IsValid())
544     return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments();
545   return 0;
546 }
547 
548 lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) {
549   LLDB_RECORD_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, (uint32_t),
550                      idx);
551 
552   if (!IsValid())
553     return LLDB_RECORD_RESULT(SBType());
554 
555   CompilerType type;
556   switch(GetTemplateArgumentKind(idx)) {
557     case eTemplateArgumentKindType:
558       type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx);
559       break;
560     case eTemplateArgumentKindIntegral:
561       type = m_opaque_sp->GetCompilerType(false)
562                  .GetIntegralTemplateArgument(idx)
563                  ->type;
564       break;
565     default:
566       break;
567   }
568   if (type.IsValid())
569     return LLDB_RECORD_RESULT(SBType(type));
570   return LLDB_RECORD_RESULT(SBType());
571 }
572 
573 lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {
574   LLDB_RECORD_METHOD(lldb::TemplateArgumentKind, SBType,
575                      GetTemplateArgumentKind, (uint32_t), idx);
576 
577   if (IsValid())
578     return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx);
579   return eTemplateArgumentKindNull;
580 }
581 
582 SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
583   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeList);
584 }
585 
586 SBTypeList::SBTypeList(const SBTypeList &rhs)
587     : m_opaque_up(new TypeListImpl()) {
588   LLDB_RECORD_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &), rhs);
589 
590   for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
591        i < rhs_size; i++)
592     Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
593 }
594 
595 bool SBTypeList::IsValid() {
596   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeList, IsValid);
597   return this->operator bool();
598 }
599 SBTypeList::operator bool() const {
600   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeList, operator bool);
601 
602   return (m_opaque_up != nullptr);
603 }
604 
605 SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) {
606   LLDB_RECORD_METHOD(lldb::SBTypeList &,
607                      SBTypeList, operator=,(const lldb::SBTypeList &), rhs);
608 
609   if (this != &rhs) {
610     m_opaque_up = std::make_unique<TypeListImpl>();
611     for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
612          i < rhs_size; i++)
613       Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
614   }
615   return LLDB_RECORD_RESULT(*this);
616 }
617 
618 void SBTypeList::Append(SBType type) {
619   LLDB_RECORD_METHOD(void, SBTypeList, Append, (lldb::SBType), type);
620 
621   if (type.IsValid())
622     m_opaque_up->Append(type.m_opaque_sp);
623 }
624 
625 SBType SBTypeList::GetTypeAtIndex(uint32_t index) {
626   LLDB_RECORD_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t),
627                      index);
628 
629   if (m_opaque_up)
630     return LLDB_RECORD_RESULT(SBType(m_opaque_up->GetTypeAtIndex(index)));
631   return LLDB_RECORD_RESULT(SBType());
632 }
633 
634 uint32_t SBTypeList::GetSize() {
635   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeList, GetSize);
636 
637   return m_opaque_up->GetSize();
638 }
639 
640 SBTypeList::~SBTypeList() = default;
641 
642 SBTypeMember::SBTypeMember() : m_opaque_up() {
643   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMember);
644 }
645 
646 SBTypeMember::~SBTypeMember() = default;
647 
648 SBTypeMember::SBTypeMember(const SBTypeMember &rhs) : m_opaque_up() {
649   LLDB_RECORD_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &), rhs);
650 
651   if (this != &rhs) {
652     if (rhs.IsValid())
653       m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());
654   }
655 }
656 
657 lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) {
658   LLDB_RECORD_METHOD(lldb::SBTypeMember &,
659                      SBTypeMember, operator=,(const lldb::SBTypeMember &), rhs);
660 
661   if (this != &rhs) {
662     if (rhs.IsValid())
663       m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());
664   }
665   return LLDB_RECORD_RESULT(*this);
666 }
667 
668 bool SBTypeMember::IsValid() const {
669   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, IsValid);
670   return this->operator bool();
671 }
672 SBTypeMember::operator bool() const {
673   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, operator bool);
674 
675   return m_opaque_up.get();
676 }
677 
678 const char *SBTypeMember::GetName() {
679   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMember, GetName);
680 
681   if (m_opaque_up)
682     return m_opaque_up->GetName().GetCString();
683   return nullptr;
684 }
685 
686 SBType SBTypeMember::GetType() {
687   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMember, GetType);
688 
689   SBType sb_type;
690   if (m_opaque_up) {
691     sb_type.SetSP(m_opaque_up->GetTypeImpl());
692   }
693   return LLDB_RECORD_RESULT(sb_type);
694 }
695 
696 uint64_t SBTypeMember::GetOffsetInBytes() {
697   LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBytes);
698 
699   if (m_opaque_up)
700     return m_opaque_up->GetBitOffset() / 8u;
701   return 0;
702 }
703 
704 uint64_t SBTypeMember::GetOffsetInBits() {
705   LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBits);
706 
707   if (m_opaque_up)
708     return m_opaque_up->GetBitOffset();
709   return 0;
710 }
711 
712 bool SBTypeMember::IsBitfield() {
713   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeMember, IsBitfield);
714 
715   if (m_opaque_up)
716     return m_opaque_up->GetIsBitfield();
717   return false;
718 }
719 
720 uint32_t SBTypeMember::GetBitfieldSizeInBits() {
721   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMember, GetBitfieldSizeInBits);
722 
723   if (m_opaque_up)
724     return m_opaque_up->GetBitfieldBitSize();
725   return 0;
726 }
727 
728 bool SBTypeMember::GetDescription(lldb::SBStream &description,
729                                   lldb::DescriptionLevel description_level) {
730   LLDB_RECORD_METHOD(bool, SBTypeMember, GetDescription,
731                      (lldb::SBStream &, lldb::DescriptionLevel), description,
732                      description_level);
733 
734   Stream &strm = description.ref();
735 
736   if (m_opaque_up) {
737     const uint32_t bit_offset = m_opaque_up->GetBitOffset();
738     const uint32_t byte_offset = bit_offset / 8u;
739     const uint32_t byte_bit_offset = bit_offset % 8u;
740     const char *name = m_opaque_up->GetName().GetCString();
741     if (byte_bit_offset)
742       strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset);
743     else
744       strm.Printf("+%u: (", byte_offset);
745 
746     TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl());
747     if (type_impl_sp)
748       type_impl_sp->GetDescription(strm, description_level);
749 
750     strm.Printf(") %s", name);
751     if (m_opaque_up->GetIsBitfield()) {
752       const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize();
753       strm.Printf(" : %u", bitfield_bit_size);
754     }
755   } else {
756     strm.PutCString("No value");
757   }
758   return true;
759 }
760 
761 void SBTypeMember::reset(TypeMemberImpl *type_member_impl) {
762   m_opaque_up.reset(type_member_impl);
763 }
764 
765 TypeMemberImpl &SBTypeMember::ref() {
766   if (m_opaque_up == nullptr)
767     m_opaque_up = std::make_unique<TypeMemberImpl>();
768   return *m_opaque_up;
769 }
770 
771 const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; }
772 
773 SBTypeMemberFunction::SBTypeMemberFunction() : m_opaque_sp() {
774   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMemberFunction);
775 }
776 
777 SBTypeMemberFunction::~SBTypeMemberFunction() = default;
778 
779 SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs)
780     : m_opaque_sp(rhs.m_opaque_sp) {
781   LLDB_RECORD_CONSTRUCTOR(SBTypeMemberFunction,
782                           (const lldb::SBTypeMemberFunction &), rhs);
783 }
784 
785 lldb::SBTypeMemberFunction &SBTypeMemberFunction::
786 operator=(const lldb::SBTypeMemberFunction &rhs) {
787   LLDB_RECORD_METHOD(
788       lldb::SBTypeMemberFunction &,
789       SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &),
790       rhs);
791 
792   if (this != &rhs)
793     m_opaque_sp = rhs.m_opaque_sp;
794   return LLDB_RECORD_RESULT(*this);
795 }
796 
797 bool SBTypeMemberFunction::IsValid() const {
798   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, IsValid);
799   return this->operator bool();
800 }
801 SBTypeMemberFunction::operator bool() const {
802   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, operator bool);
803 
804   return m_opaque_sp.get();
805 }
806 
807 const char *SBTypeMemberFunction::GetName() {
808   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, GetName);
809 
810   if (m_opaque_sp)
811     return m_opaque_sp->GetName().GetCString();
812   return nullptr;
813 }
814 
815 const char *SBTypeMemberFunction::GetDemangledName() {
816   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
817                              GetDemangledName);
818 
819   if (m_opaque_sp) {
820     ConstString mangled_str = m_opaque_sp->GetMangledName();
821     if (mangled_str) {
822       Mangled mangled(mangled_str);
823       return mangled.GetDemangledName().GetCString();
824     }
825   }
826   return nullptr;
827 }
828 
829 const char *SBTypeMemberFunction::GetMangledName() {
830   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
831                              GetMangledName);
832 
833   if (m_opaque_sp)
834     return m_opaque_sp->GetMangledName().GetCString();
835   return nullptr;
836 }
837 
838 SBType SBTypeMemberFunction::GetType() {
839   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetType);
840 
841   SBType sb_type;
842   if (m_opaque_sp) {
843     sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType())));
844   }
845   return LLDB_RECORD_RESULT(sb_type);
846 }
847 
848 lldb::SBType SBTypeMemberFunction::GetReturnType() {
849   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetReturnType);
850 
851   SBType sb_type;
852   if (m_opaque_sp) {
853     sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType())));
854   }
855   return LLDB_RECORD_RESULT(sb_type);
856 }
857 
858 uint32_t SBTypeMemberFunction::GetNumberOfArguments() {
859   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMemberFunction,
860                              GetNumberOfArguments);
861 
862   if (m_opaque_sp)
863     return m_opaque_sp->GetNumArguments();
864   return 0;
865 }
866 
867 lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) {
868   LLDB_RECORD_METHOD(lldb::SBType, SBTypeMemberFunction, GetArgumentTypeAtIndex,
869                      (uint32_t), i);
870 
871   SBType sb_type;
872   if (m_opaque_sp) {
873     sb_type.SetSP(
874         lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i))));
875   }
876   return LLDB_RECORD_RESULT(sb_type);
877 }
878 
879 lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() {
880   LLDB_RECORD_METHOD_NO_ARGS(lldb::MemberFunctionKind, SBTypeMemberFunction,
881                              GetKind);
882 
883   if (m_opaque_sp)
884     return m_opaque_sp->GetKind();
885   return lldb::eMemberFunctionKindUnknown;
886 }
887 
888 bool SBTypeMemberFunction::GetDescription(
889     lldb::SBStream &description, lldb::DescriptionLevel description_level) {
890   LLDB_RECORD_METHOD(bool, SBTypeMemberFunction, GetDescription,
891                      (lldb::SBStream &, lldb::DescriptionLevel), description,
892                      description_level);
893 
894   Stream &strm = description.ref();
895 
896   if (m_opaque_sp)
897     return m_opaque_sp->GetDescription(strm);
898 
899   return false;
900 }
901 
902 void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) {
903   m_opaque_sp.reset(type_member_impl);
904 }
905 
906 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {
907   if (!m_opaque_sp)
908     m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();
909   return *m_opaque_sp.get();
910 }
911 
912 const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const {
913   return *m_opaque_sp.get();
914 }
915 
916 namespace lldb_private {
917 namespace repro {
918 
919 template <>
920 void RegisterMethods<SBType>(Registry &R) {
921   LLDB_REGISTER_CONSTRUCTOR(SBType, ());
922   LLDB_REGISTER_CONSTRUCTOR(SBType, (const lldb::SBType &));
923   LLDB_REGISTER_METHOD(bool, SBType, operator==,(lldb::SBType &));
924   LLDB_REGISTER_METHOD(bool, SBType, operator!=,(lldb::SBType &));
925   LLDB_REGISTER_METHOD(lldb::SBType &,
926                        SBType, operator=,(const lldb::SBType &));
927   LLDB_REGISTER_METHOD_CONST(bool, SBType, IsValid, ());
928   LLDB_REGISTER_METHOD_CONST(bool, SBType, operator bool, ());
929   LLDB_REGISTER_METHOD(uint64_t, SBType, GetByteSize, ());
930   LLDB_REGISTER_METHOD(bool, SBType, IsPointerType, ());
931   LLDB_REGISTER_METHOD(bool, SBType, IsArrayType, ());
932   LLDB_REGISTER_METHOD(bool, SBType, IsVectorType, ());
933   LLDB_REGISTER_METHOD(bool, SBType, IsReferenceType, ());
934   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointerType, ());
935   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointeeType, ());
936   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetReferenceType, ());
937   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTypedefedType, ());
938   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetDereferencedType, ());
939   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayElementType, ());
940   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t));
941   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetVectorElementType, ());
942   LLDB_REGISTER_METHOD(bool, SBType, IsFunctionType, ());
943   LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ());
944   LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ());
945   LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ());
946   LLDB_REGISTER_METHOD(bool, SBType, IsScopedEnumerationType, ());
947   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ());
948   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes,
949                        ());
950   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfMemberFunctions, ());
951   LLDB_REGISTER_METHOD(lldb::SBTypeMemberFunction, SBType,
952                        GetMemberFunctionAtIndex, (uint32_t));
953   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ());
954   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ());
955   LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ());
956   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType));
957   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ());
958   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfVirtualBaseClasses, ());
959   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfFields, ());
960   LLDB_REGISTER_METHOD(bool, SBType, GetDescription,
961                        (lldb::SBStream &, lldb::DescriptionLevel));
962   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
963                        (uint32_t));
964   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
965                        (uint32_t));
966   LLDB_REGISTER_METHOD(lldb::SBTypeEnumMemberList, SBType, GetEnumMembers,
967                        ());
968   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex,
969                        (uint32_t));
970   LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ());
971   LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ());
972   LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ());
973   LLDB_REGISTER_METHOD(const char *, SBType, GetName, ());
974   LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ());
975   LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ());
976   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfTemplateArguments, ());
977   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTemplateArgumentType,
978                        (uint32_t));
979   LLDB_REGISTER_METHOD(lldb::TemplateArgumentKind, SBType,
980                        GetTemplateArgumentKind, (uint32_t));
981   LLDB_REGISTER_CONSTRUCTOR(SBTypeList, ());
982   LLDB_REGISTER_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &));
983   LLDB_REGISTER_METHOD(bool, SBTypeList, IsValid, ());
984   LLDB_REGISTER_METHOD_CONST(bool, SBTypeList, operator bool, ());
985   LLDB_REGISTER_METHOD(lldb::SBTypeList &,
986                        SBTypeList, operator=,(const lldb::SBTypeList &));
987   LLDB_REGISTER_METHOD(void, SBTypeList, Append, (lldb::SBType));
988   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t));
989   LLDB_REGISTER_METHOD(uint32_t, SBTypeList, GetSize, ());
990   LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, ());
991   LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &));
992   LLDB_REGISTER_METHOD(lldb::SBTypeMember &,
993                        SBTypeMember, operator=,(const lldb::SBTypeMember &));
994   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, IsValid, ());
995   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, operator bool, ());
996   LLDB_REGISTER_METHOD(const char *, SBTypeMember, GetName, ());
997   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMember, GetType, ());
998   LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBytes, ());
999   LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBits, ());
1000   LLDB_REGISTER_METHOD(bool, SBTypeMember, IsBitfield, ());
1001   LLDB_REGISTER_METHOD(uint32_t, SBTypeMember, GetBitfieldSizeInBits, ());
1002   LLDB_REGISTER_METHOD(bool, SBTypeMember, GetDescription,
1003                        (lldb::SBStream &, lldb::DescriptionLevel));
1004   LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction, ());
1005   LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction,
1006                             (const lldb::SBTypeMemberFunction &));
1007   LLDB_REGISTER_METHOD(
1008       lldb::SBTypeMemberFunction &,
1009       SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &));
1010   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, IsValid, ());
1011   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, operator bool, ());
1012   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetName, ());
1013   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetDemangledName,
1014                        ());
1015   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetMangledName,
1016                        ());
1017   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetType, ());
1018   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetReturnType, ());
1019   LLDB_REGISTER_METHOD(uint32_t, SBTypeMemberFunction, GetNumberOfArguments,
1020                        ());
1021   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction,
1022                        GetArgumentTypeAtIndex, (uint32_t));
1023   LLDB_REGISTER_METHOD(lldb::MemberFunctionKind, SBTypeMemberFunction,
1024                        GetKind, ());
1025   LLDB_REGISTER_METHOD(bool, SBTypeMemberFunction, GetDescription,
1026                        (lldb::SBStream &, lldb::DescriptionLevel));
1027 }
1028 
1029 }
1030 }
1031