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 SBType SBType::GetEnumerationIntegerType() {
348   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBType, GetEnumerationIntegerType);
349 
350   if (IsValid()) {
351     return LLDB_RECORD_RESULT(
352         SBType(m_opaque_sp->GetCompilerType(true).GetEnumerationIntegerType()));
353   }
354   return LLDB_RECORD_RESULT(SBType());
355 }
356 
357 lldb::BasicType SBType::GetBasicType() {
358   LLDB_RECORD_METHOD_NO_ARGS(lldb::BasicType, SBType, GetBasicType);
359 
360   if (IsValid())
361     return m_opaque_sp->GetCompilerType(false).GetBasicTypeEnumeration();
362   return eBasicTypeInvalid;
363 }
364 
365 SBType SBType::GetBasicType(lldb::BasicType basic_type) {
366   LLDB_RECORD_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType),
367                      basic_type);
368 
369   if (IsValid() && m_opaque_sp->IsValid())
370     return LLDB_RECORD_RESULT(SBType(
371         m_opaque_sp->GetTypeSystem(false)->GetBasicTypeFromAST(basic_type)));
372   return LLDB_RECORD_RESULT(SBType());
373 }
374 
375 uint32_t SBType::GetNumberOfDirectBaseClasses() {
376   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfDirectBaseClasses);
377 
378   if (IsValid())
379     return m_opaque_sp->GetCompilerType(true).GetNumDirectBaseClasses();
380   return 0;
381 }
382 
383 uint32_t SBType::GetNumberOfVirtualBaseClasses() {
384   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfVirtualBaseClasses);
385 
386   if (IsValid())
387     return m_opaque_sp->GetCompilerType(true).GetNumVirtualBaseClasses();
388   return 0;
389 }
390 
391 uint32_t SBType::GetNumberOfFields() {
392   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfFields);
393 
394   if (IsValid())
395     return m_opaque_sp->GetCompilerType(true).GetNumFields();
396   return 0;
397 }
398 
399 bool SBType::GetDescription(SBStream &description,
400                             lldb::DescriptionLevel description_level) {
401   LLDB_RECORD_METHOD(bool, SBType, GetDescription,
402                      (lldb::SBStream &, lldb::DescriptionLevel), description,
403                      description_level);
404 
405   Stream &strm = description.ref();
406 
407   if (m_opaque_sp) {
408     m_opaque_sp->GetDescription(strm, description_level);
409   } else
410     strm.PutCString("No value");
411 
412   return true;
413 }
414 
415 SBTypeMember SBType::GetDirectBaseClassAtIndex(uint32_t idx) {
416   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
417                      (uint32_t), idx);
418 
419   SBTypeMember sb_type_member;
420   if (IsValid()) {
421     uint32_t bit_offset = 0;
422     CompilerType base_class_type =
423         m_opaque_sp->GetCompilerType(true).GetDirectBaseClassAtIndex(
424             idx, &bit_offset);
425     if (base_class_type.IsValid())
426       sb_type_member.reset(new TypeMemberImpl(
427           TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
428   }
429   return LLDB_RECORD_RESULT(sb_type_member);
430 }
431 
432 SBTypeMember SBType::GetVirtualBaseClassAtIndex(uint32_t idx) {
433   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
434                      (uint32_t), idx);
435 
436   SBTypeMember sb_type_member;
437   if (IsValid()) {
438     uint32_t bit_offset = 0;
439     CompilerType base_class_type =
440         m_opaque_sp->GetCompilerType(true).GetVirtualBaseClassAtIndex(
441             idx, &bit_offset);
442     if (base_class_type.IsValid())
443       sb_type_member.reset(new TypeMemberImpl(
444           TypeImplSP(new TypeImpl(base_class_type)), bit_offset));
445   }
446   return LLDB_RECORD_RESULT(sb_type_member);
447 }
448 
449 SBTypeEnumMemberList SBType::GetEnumMembers() {
450   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeEnumMemberList, SBType,
451                              GetEnumMembers);
452 
453   SBTypeEnumMemberList sb_enum_member_list;
454   if (IsValid()) {
455     CompilerType this_type(m_opaque_sp->GetCompilerType(true));
456     if (this_type.IsValid()) {
457       this_type.ForEachEnumerator([&sb_enum_member_list](
458                                       const CompilerType &integer_type,
459                                       ConstString name,
460                                       const llvm::APSInt &value) -> bool {
461         SBTypeEnumMember enum_member(
462             lldb::TypeEnumMemberImplSP(new TypeEnumMemberImpl(
463                 lldb::TypeImplSP(new TypeImpl(integer_type)), name, value)));
464         sb_enum_member_list.Append(enum_member);
465         return true; // Keep iterating
466       });
467     }
468   }
469   return LLDB_RECORD_RESULT(sb_enum_member_list);
470 }
471 
472 SBTypeMember SBType::GetFieldAtIndex(uint32_t idx) {
473   LLDB_RECORD_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex, (uint32_t),
474                      idx);
475 
476   SBTypeMember sb_type_member;
477   if (IsValid()) {
478     CompilerType this_type(m_opaque_sp->GetCompilerType(false));
479     if (this_type.IsValid()) {
480       uint64_t bit_offset = 0;
481       uint32_t bitfield_bit_size = 0;
482       bool is_bitfield = false;
483       std::string name_sstr;
484       CompilerType field_type(this_type.GetFieldAtIndex(
485           idx, name_sstr, &bit_offset, &bitfield_bit_size, &is_bitfield));
486       if (field_type.IsValid()) {
487         ConstString name;
488         if (!name_sstr.empty())
489           name.SetCString(name_sstr.c_str());
490         sb_type_member.reset(
491             new TypeMemberImpl(TypeImplSP(new TypeImpl(field_type)), bit_offset,
492                                name, bitfield_bit_size, is_bitfield));
493       }
494     }
495   }
496   return LLDB_RECORD_RESULT(sb_type_member);
497 }
498 
499 bool SBType::IsTypeComplete() {
500   LLDB_RECORD_METHOD_NO_ARGS(bool, SBType, IsTypeComplete);
501 
502   if (!IsValid())
503     return false;
504   return m_opaque_sp->GetCompilerType(false).IsCompleteType();
505 }
506 
507 uint32_t SBType::GetTypeFlags() {
508   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetTypeFlags);
509 
510   if (!IsValid())
511     return 0;
512   return m_opaque_sp->GetCompilerType(true).GetTypeInfo();
513 }
514 
515 lldb::SBModule SBType::GetModule() {
516   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule, SBType, GetModule);
517 
518   lldb::SBModule sb_module;
519   if (!IsValid())
520     return LLDB_RECORD_RESULT(sb_module);
521 
522   sb_module.SetSP(m_opaque_sp->GetModule());
523   return LLDB_RECORD_RESULT(sb_module);
524 }
525 
526 const char *SBType::GetName() {
527   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetName);
528 
529   if (!IsValid())
530     return "";
531   return m_opaque_sp->GetName().GetCString();
532 }
533 
534 const char *SBType::GetDisplayTypeName() {
535   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBType, GetDisplayTypeName);
536 
537   if (!IsValid())
538     return "";
539   return m_opaque_sp->GetDisplayTypeName().GetCString();
540 }
541 
542 lldb::TypeClass SBType::GetTypeClass() {
543   LLDB_RECORD_METHOD_NO_ARGS(lldb::TypeClass, SBType, GetTypeClass);
544 
545   if (IsValid())
546     return m_opaque_sp->GetCompilerType(true).GetTypeClass();
547   return lldb::eTypeClassInvalid;
548 }
549 
550 uint32_t SBType::GetNumberOfTemplateArguments() {
551   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBType, GetNumberOfTemplateArguments);
552 
553   if (IsValid())
554     return m_opaque_sp->GetCompilerType(false).GetNumTemplateArguments();
555   return 0;
556 }
557 
558 lldb::SBType SBType::GetTemplateArgumentType(uint32_t idx) {
559   LLDB_RECORD_METHOD(lldb::SBType, SBType, GetTemplateArgumentType, (uint32_t),
560                      idx);
561 
562   if (!IsValid())
563     return LLDB_RECORD_RESULT(SBType());
564 
565   CompilerType type;
566   switch(GetTemplateArgumentKind(idx)) {
567     case eTemplateArgumentKindType:
568       type = m_opaque_sp->GetCompilerType(false).GetTypeTemplateArgument(idx);
569       break;
570     case eTemplateArgumentKindIntegral:
571       type = m_opaque_sp->GetCompilerType(false)
572                  .GetIntegralTemplateArgument(idx)
573                  ->type;
574       break;
575     default:
576       break;
577   }
578   if (type.IsValid())
579     return LLDB_RECORD_RESULT(SBType(type));
580   return LLDB_RECORD_RESULT(SBType());
581 }
582 
583 lldb::TemplateArgumentKind SBType::GetTemplateArgumentKind(uint32_t idx) {
584   LLDB_RECORD_METHOD(lldb::TemplateArgumentKind, SBType,
585                      GetTemplateArgumentKind, (uint32_t), idx);
586 
587   if (IsValid())
588     return m_opaque_sp->GetCompilerType(false).GetTemplateArgumentKind(idx);
589   return eTemplateArgumentKindNull;
590 }
591 
592 SBTypeList::SBTypeList() : m_opaque_up(new TypeListImpl()) {
593   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeList);
594 }
595 
596 SBTypeList::SBTypeList(const SBTypeList &rhs)
597     : m_opaque_up(new TypeListImpl()) {
598   LLDB_RECORD_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &), rhs);
599 
600   for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
601        i < rhs_size; i++)
602     Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
603 }
604 
605 bool SBTypeList::IsValid() {
606   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeList, IsValid);
607   return this->operator bool();
608 }
609 SBTypeList::operator bool() const {
610   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeList, operator bool);
611 
612   return (m_opaque_up != nullptr);
613 }
614 
615 SBTypeList &SBTypeList::operator=(const SBTypeList &rhs) {
616   LLDB_RECORD_METHOD(lldb::SBTypeList &,
617                      SBTypeList, operator=,(const lldb::SBTypeList &), rhs);
618 
619   if (this != &rhs) {
620     m_opaque_up = std::make_unique<TypeListImpl>();
621     for (uint32_t i = 0, rhs_size = const_cast<SBTypeList &>(rhs).GetSize();
622          i < rhs_size; i++)
623       Append(const_cast<SBTypeList &>(rhs).GetTypeAtIndex(i));
624   }
625   return LLDB_RECORD_RESULT(*this);
626 }
627 
628 void SBTypeList::Append(SBType type) {
629   LLDB_RECORD_METHOD(void, SBTypeList, Append, (lldb::SBType), type);
630 
631   if (type.IsValid())
632     m_opaque_up->Append(type.m_opaque_sp);
633 }
634 
635 SBType SBTypeList::GetTypeAtIndex(uint32_t index) {
636   LLDB_RECORD_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t),
637                      index);
638 
639   if (m_opaque_up)
640     return LLDB_RECORD_RESULT(SBType(m_opaque_up->GetTypeAtIndex(index)));
641   return LLDB_RECORD_RESULT(SBType());
642 }
643 
644 uint32_t SBTypeList::GetSize() {
645   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeList, GetSize);
646 
647   return m_opaque_up->GetSize();
648 }
649 
650 SBTypeList::~SBTypeList() = default;
651 
652 SBTypeMember::SBTypeMember() : m_opaque_up() {
653   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMember);
654 }
655 
656 SBTypeMember::~SBTypeMember() = default;
657 
658 SBTypeMember::SBTypeMember(const SBTypeMember &rhs) : m_opaque_up() {
659   LLDB_RECORD_CONSTRUCTOR(SBTypeMember, (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 }
666 
667 lldb::SBTypeMember &SBTypeMember::operator=(const lldb::SBTypeMember &rhs) {
668   LLDB_RECORD_METHOD(lldb::SBTypeMember &,
669                      SBTypeMember, operator=,(const lldb::SBTypeMember &), rhs);
670 
671   if (this != &rhs) {
672     if (rhs.IsValid())
673       m_opaque_up = std::make_unique<TypeMemberImpl>(rhs.ref());
674   }
675   return LLDB_RECORD_RESULT(*this);
676 }
677 
678 bool SBTypeMember::IsValid() const {
679   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, IsValid);
680   return this->operator bool();
681 }
682 SBTypeMember::operator bool() const {
683   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMember, operator bool);
684 
685   return m_opaque_up.get();
686 }
687 
688 const char *SBTypeMember::GetName() {
689   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMember, GetName);
690 
691   if (m_opaque_up)
692     return m_opaque_up->GetName().GetCString();
693   return nullptr;
694 }
695 
696 SBType SBTypeMember::GetType() {
697   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMember, GetType);
698 
699   SBType sb_type;
700   if (m_opaque_up) {
701     sb_type.SetSP(m_opaque_up->GetTypeImpl());
702   }
703   return LLDB_RECORD_RESULT(sb_type);
704 }
705 
706 uint64_t SBTypeMember::GetOffsetInBytes() {
707   LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBytes);
708 
709   if (m_opaque_up)
710     return m_opaque_up->GetBitOffset() / 8u;
711   return 0;
712 }
713 
714 uint64_t SBTypeMember::GetOffsetInBits() {
715   LLDB_RECORD_METHOD_NO_ARGS(uint64_t, SBTypeMember, GetOffsetInBits);
716 
717   if (m_opaque_up)
718     return m_opaque_up->GetBitOffset();
719   return 0;
720 }
721 
722 bool SBTypeMember::IsBitfield() {
723   LLDB_RECORD_METHOD_NO_ARGS(bool, SBTypeMember, IsBitfield);
724 
725   if (m_opaque_up)
726     return m_opaque_up->GetIsBitfield();
727   return false;
728 }
729 
730 uint32_t SBTypeMember::GetBitfieldSizeInBits() {
731   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMember, GetBitfieldSizeInBits);
732 
733   if (m_opaque_up)
734     return m_opaque_up->GetBitfieldBitSize();
735   return 0;
736 }
737 
738 bool SBTypeMember::GetDescription(lldb::SBStream &description,
739                                   lldb::DescriptionLevel description_level) {
740   LLDB_RECORD_METHOD(bool, SBTypeMember, GetDescription,
741                      (lldb::SBStream &, lldb::DescriptionLevel), description,
742                      description_level);
743 
744   Stream &strm = description.ref();
745 
746   if (m_opaque_up) {
747     const uint32_t bit_offset = m_opaque_up->GetBitOffset();
748     const uint32_t byte_offset = bit_offset / 8u;
749     const uint32_t byte_bit_offset = bit_offset % 8u;
750     const char *name = m_opaque_up->GetName().GetCString();
751     if (byte_bit_offset)
752       strm.Printf("+%u + %u bits: (", byte_offset, byte_bit_offset);
753     else
754       strm.Printf("+%u: (", byte_offset);
755 
756     TypeImplSP type_impl_sp(m_opaque_up->GetTypeImpl());
757     if (type_impl_sp)
758       type_impl_sp->GetDescription(strm, description_level);
759 
760     strm.Printf(") %s", name);
761     if (m_opaque_up->GetIsBitfield()) {
762       const uint32_t bitfield_bit_size = m_opaque_up->GetBitfieldBitSize();
763       strm.Printf(" : %u", bitfield_bit_size);
764     }
765   } else {
766     strm.PutCString("No value");
767   }
768   return true;
769 }
770 
771 void SBTypeMember::reset(TypeMemberImpl *type_member_impl) {
772   m_opaque_up.reset(type_member_impl);
773 }
774 
775 TypeMemberImpl &SBTypeMember::ref() {
776   if (m_opaque_up == nullptr)
777     m_opaque_up = std::make_unique<TypeMemberImpl>();
778   return *m_opaque_up;
779 }
780 
781 const TypeMemberImpl &SBTypeMember::ref() const { return *m_opaque_up; }
782 
783 SBTypeMemberFunction::SBTypeMemberFunction() : m_opaque_sp() {
784   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBTypeMemberFunction);
785 }
786 
787 SBTypeMemberFunction::~SBTypeMemberFunction() = default;
788 
789 SBTypeMemberFunction::SBTypeMemberFunction(const SBTypeMemberFunction &rhs)
790     : m_opaque_sp(rhs.m_opaque_sp) {
791   LLDB_RECORD_CONSTRUCTOR(SBTypeMemberFunction,
792                           (const lldb::SBTypeMemberFunction &), rhs);
793 }
794 
795 lldb::SBTypeMemberFunction &SBTypeMemberFunction::
796 operator=(const lldb::SBTypeMemberFunction &rhs) {
797   LLDB_RECORD_METHOD(
798       lldb::SBTypeMemberFunction &,
799       SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &),
800       rhs);
801 
802   if (this != &rhs)
803     m_opaque_sp = rhs.m_opaque_sp;
804   return LLDB_RECORD_RESULT(*this);
805 }
806 
807 bool SBTypeMemberFunction::IsValid() const {
808   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, IsValid);
809   return this->operator bool();
810 }
811 SBTypeMemberFunction::operator bool() const {
812   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBTypeMemberFunction, operator bool);
813 
814   return m_opaque_sp.get();
815 }
816 
817 const char *SBTypeMemberFunction::GetName() {
818   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction, GetName);
819 
820   if (m_opaque_sp)
821     return m_opaque_sp->GetName().GetCString();
822   return nullptr;
823 }
824 
825 const char *SBTypeMemberFunction::GetDemangledName() {
826   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
827                              GetDemangledName);
828 
829   if (m_opaque_sp) {
830     ConstString mangled_str = m_opaque_sp->GetMangledName();
831     if (mangled_str) {
832       Mangled mangled(mangled_str);
833       return mangled.GetDemangledName().GetCString();
834     }
835   }
836   return nullptr;
837 }
838 
839 const char *SBTypeMemberFunction::GetMangledName() {
840   LLDB_RECORD_METHOD_NO_ARGS(const char *, SBTypeMemberFunction,
841                              GetMangledName);
842 
843   if (m_opaque_sp)
844     return m_opaque_sp->GetMangledName().GetCString();
845   return nullptr;
846 }
847 
848 SBType SBTypeMemberFunction::GetType() {
849   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetType);
850 
851   SBType sb_type;
852   if (m_opaque_sp) {
853     sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType())));
854   }
855   return LLDB_RECORD_RESULT(sb_type);
856 }
857 
858 lldb::SBType SBTypeMemberFunction::GetReturnType() {
859   LLDB_RECORD_METHOD_NO_ARGS(lldb::SBType, SBTypeMemberFunction, GetReturnType);
860 
861   SBType sb_type;
862   if (m_opaque_sp) {
863     sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType())));
864   }
865   return LLDB_RECORD_RESULT(sb_type);
866 }
867 
868 uint32_t SBTypeMemberFunction::GetNumberOfArguments() {
869   LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBTypeMemberFunction,
870                              GetNumberOfArguments);
871 
872   if (m_opaque_sp)
873     return m_opaque_sp->GetNumArguments();
874   return 0;
875 }
876 
877 lldb::SBType SBTypeMemberFunction::GetArgumentTypeAtIndex(uint32_t i) {
878   LLDB_RECORD_METHOD(lldb::SBType, SBTypeMemberFunction, GetArgumentTypeAtIndex,
879                      (uint32_t), i);
880 
881   SBType sb_type;
882   if (m_opaque_sp) {
883     sb_type.SetSP(
884         lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i))));
885   }
886   return LLDB_RECORD_RESULT(sb_type);
887 }
888 
889 lldb::MemberFunctionKind SBTypeMemberFunction::GetKind() {
890   LLDB_RECORD_METHOD_NO_ARGS(lldb::MemberFunctionKind, SBTypeMemberFunction,
891                              GetKind);
892 
893   if (m_opaque_sp)
894     return m_opaque_sp->GetKind();
895   return lldb::eMemberFunctionKindUnknown;
896 }
897 
898 bool SBTypeMemberFunction::GetDescription(
899     lldb::SBStream &description, lldb::DescriptionLevel description_level) {
900   LLDB_RECORD_METHOD(bool, SBTypeMemberFunction, GetDescription,
901                      (lldb::SBStream &, lldb::DescriptionLevel), description,
902                      description_level);
903 
904   Stream &strm = description.ref();
905 
906   if (m_opaque_sp)
907     return m_opaque_sp->GetDescription(strm);
908 
909   return false;
910 }
911 
912 void SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) {
913   m_opaque_sp.reset(type_member_impl);
914 }
915 
916 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {
917   if (!m_opaque_sp)
918     m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();
919   return *m_opaque_sp.get();
920 }
921 
922 const TypeMemberFunctionImpl &SBTypeMemberFunction::ref() const {
923   return *m_opaque_sp.get();
924 }
925 
926 namespace lldb_private {
927 namespace repro {
928 
929 template <>
930 void RegisterMethods<SBType>(Registry &R) {
931   LLDB_REGISTER_CONSTRUCTOR(SBType, ());
932   LLDB_REGISTER_CONSTRUCTOR(SBType, (const lldb::SBType &));
933   LLDB_REGISTER_METHOD(bool, SBType, operator==,(lldb::SBType &));
934   LLDB_REGISTER_METHOD(bool, SBType, operator!=,(lldb::SBType &));
935   LLDB_REGISTER_METHOD(lldb::SBType &,
936                        SBType, operator=,(const lldb::SBType &));
937   LLDB_REGISTER_METHOD_CONST(bool, SBType, IsValid, ());
938   LLDB_REGISTER_METHOD_CONST(bool, SBType, operator bool, ());
939   LLDB_REGISTER_METHOD(uint64_t, SBType, GetByteSize, ());
940   LLDB_REGISTER_METHOD(bool, SBType, IsPointerType, ());
941   LLDB_REGISTER_METHOD(bool, SBType, IsArrayType, ());
942   LLDB_REGISTER_METHOD(bool, SBType, IsVectorType, ());
943   LLDB_REGISTER_METHOD(bool, SBType, IsReferenceType, ());
944   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointerType, ());
945   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetPointeeType, ());
946   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetReferenceType, ());
947   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTypedefedType, ());
948   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetDereferencedType, ());
949   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayElementType, ());
950   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetArrayType, (uint64_t));
951   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetVectorElementType, ());
952   LLDB_REGISTER_METHOD(bool, SBType, IsFunctionType, ());
953   LLDB_REGISTER_METHOD(bool, SBType, IsPolymorphicClass, ());
954   LLDB_REGISTER_METHOD(bool, SBType, IsTypedefType, ());
955   LLDB_REGISTER_METHOD(bool, SBType, IsAnonymousType, ());
956   LLDB_REGISTER_METHOD(bool, SBType, IsScopedEnumerationType, ());
957   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetFunctionReturnType, ());
958   LLDB_REGISTER_METHOD(lldb::SBTypeList, SBType, GetFunctionArgumentTypes,
959                        ());
960   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfMemberFunctions, ());
961   LLDB_REGISTER_METHOD(lldb::SBTypeMemberFunction, SBType,
962                        GetMemberFunctionAtIndex, (uint32_t));
963   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetUnqualifiedType, ());
964   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetCanonicalType, ());
965   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetEnumerationIntegerType, ());
966   LLDB_REGISTER_METHOD(lldb::BasicType, SBType, GetBasicType, ());
967   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetBasicType, (lldb::BasicType));
968   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfDirectBaseClasses, ());
969   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfVirtualBaseClasses, ());
970   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfFields, ());
971   LLDB_REGISTER_METHOD(bool, SBType, GetDescription,
972                        (lldb::SBStream &, lldb::DescriptionLevel));
973   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetDirectBaseClassAtIndex,
974                        (uint32_t));
975   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetVirtualBaseClassAtIndex,
976                        (uint32_t));
977   LLDB_REGISTER_METHOD(lldb::SBTypeEnumMemberList, SBType, GetEnumMembers,
978                        ());
979   LLDB_REGISTER_METHOD(lldb::SBTypeMember, SBType, GetFieldAtIndex,
980                        (uint32_t));
981   LLDB_REGISTER_METHOD(bool, SBType, IsTypeComplete, ());
982   LLDB_REGISTER_METHOD(uint32_t, SBType, GetTypeFlags, ());
983   LLDB_REGISTER_METHOD(lldb::SBModule, SBType, GetModule, ());
984   LLDB_REGISTER_METHOD(const char *, SBType, GetName, ());
985   LLDB_REGISTER_METHOD(const char *, SBType, GetDisplayTypeName, ());
986   LLDB_REGISTER_METHOD(lldb::TypeClass, SBType, GetTypeClass, ());
987   LLDB_REGISTER_METHOD(uint32_t, SBType, GetNumberOfTemplateArguments, ());
988   LLDB_REGISTER_METHOD(lldb::SBType, SBType, GetTemplateArgumentType,
989                        (uint32_t));
990   LLDB_REGISTER_METHOD(lldb::TemplateArgumentKind, SBType,
991                        GetTemplateArgumentKind, (uint32_t));
992   LLDB_REGISTER_CONSTRUCTOR(SBTypeList, ());
993   LLDB_REGISTER_CONSTRUCTOR(SBTypeList, (const lldb::SBTypeList &));
994   LLDB_REGISTER_METHOD(bool, SBTypeList, IsValid, ());
995   LLDB_REGISTER_METHOD_CONST(bool, SBTypeList, operator bool, ());
996   LLDB_REGISTER_METHOD(lldb::SBTypeList &,
997                        SBTypeList, operator=,(const lldb::SBTypeList &));
998   LLDB_REGISTER_METHOD(void, SBTypeList, Append, (lldb::SBType));
999   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeList, GetTypeAtIndex, (uint32_t));
1000   LLDB_REGISTER_METHOD(uint32_t, SBTypeList, GetSize, ());
1001   LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, ());
1002   LLDB_REGISTER_CONSTRUCTOR(SBTypeMember, (const lldb::SBTypeMember &));
1003   LLDB_REGISTER_METHOD(lldb::SBTypeMember &,
1004                        SBTypeMember, operator=,(const lldb::SBTypeMember &));
1005   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, IsValid, ());
1006   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMember, operator bool, ());
1007   LLDB_REGISTER_METHOD(const char *, SBTypeMember, GetName, ());
1008   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMember, GetType, ());
1009   LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBytes, ());
1010   LLDB_REGISTER_METHOD(uint64_t, SBTypeMember, GetOffsetInBits, ());
1011   LLDB_REGISTER_METHOD(bool, SBTypeMember, IsBitfield, ());
1012   LLDB_REGISTER_METHOD(uint32_t, SBTypeMember, GetBitfieldSizeInBits, ());
1013   LLDB_REGISTER_METHOD(bool, SBTypeMember, GetDescription,
1014                        (lldb::SBStream &, lldb::DescriptionLevel));
1015   LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction, ());
1016   LLDB_REGISTER_CONSTRUCTOR(SBTypeMemberFunction,
1017                             (const lldb::SBTypeMemberFunction &));
1018   LLDB_REGISTER_METHOD(
1019       lldb::SBTypeMemberFunction &,
1020       SBTypeMemberFunction, operator=,(const lldb::SBTypeMemberFunction &));
1021   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, IsValid, ());
1022   LLDB_REGISTER_METHOD_CONST(bool, SBTypeMemberFunction, operator bool, ());
1023   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetName, ());
1024   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetDemangledName,
1025                        ());
1026   LLDB_REGISTER_METHOD(const char *, SBTypeMemberFunction, GetMangledName,
1027                        ());
1028   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetType, ());
1029   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction, GetReturnType, ());
1030   LLDB_REGISTER_METHOD(uint32_t, SBTypeMemberFunction, GetNumberOfArguments,
1031                        ());
1032   LLDB_REGISTER_METHOD(lldb::SBType, SBTypeMemberFunction,
1033                        GetArgumentTypeAtIndex, (uint32_t));
1034   LLDB_REGISTER_METHOD(lldb::MemberFunctionKind, SBTypeMemberFunction,
1035                        GetKind, ());
1036   LLDB_REGISTER_METHOD(bool, SBTypeMemberFunction, GetDescription,
1037                        (lldb::SBStream &, lldb::DescriptionLevel));
1038 }
1039 
1040 }
1041 }
1042