180814287SRaphael Isemann //===-- CompilerType.cpp --------------------------------------------------===//
2a1e5dc86SGreg Clayton //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a1e5dc86SGreg Clayton //
7a1e5dc86SGreg Clayton //===----------------------------------------------------------------------===//
8a1e5dc86SGreg Clayton 
9a1e5dc86SGreg Clayton #include "lldb/Symbol/CompilerType.h"
10a1e5dc86SGreg Clayton 
11a1e5dc86SGreg Clayton #include "lldb/Core/Debugger.h"
12a1e5dc86SGreg Clayton #include "lldb/Core/StreamFile.h"
13a1e5dc86SGreg Clayton #include "lldb/Symbol/Type.h"
14a1e5dc86SGreg Clayton #include "lldb/Target/ExecutionContext.h"
15a1e5dc86SGreg Clayton #include "lldb/Target/Process.h"
16bf9a7730SZachary Turner #include "lldb/Utility/ConstString.h"
17666cc0b2SZachary Turner #include "lldb/Utility/DataBufferHeap.h"
18666cc0b2SZachary Turner #include "lldb/Utility/DataExtractor.h"
19d821c997SPavel Labath #include "lldb/Utility/Scalar.h"
20bf9a7730SZachary Turner #include "lldb/Utility/Stream.h"
21bf9a7730SZachary Turner #include "lldb/Utility/StreamString.h"
22a1e5dc86SGreg Clayton 
23a1e5dc86SGreg Clayton #include <iterator>
24a1e5dc86SGreg Clayton #include <mutex>
25a1e5dc86SGreg Clayton 
26a1e5dc86SGreg Clayton using namespace lldb;
27a1e5dc86SGreg Clayton using namespace lldb_private;
28a1e5dc86SGreg Clayton 
29a1e5dc86SGreg Clayton // Tests
30a1e5dc86SGreg Clayton 
IsAggregateType() const31b9c1b51eSKate Stone bool CompilerType::IsAggregateType() const {
32a1e5dc86SGreg Clayton   if (IsValid())
33a1e5dc86SGreg Clayton     return m_type_system->IsAggregateType(m_type);
34a1e5dc86SGreg Clayton   return false;
35a1e5dc86SGreg Clayton }
36a1e5dc86SGreg Clayton 
IsAnonymousType() const37b9c1b51eSKate Stone bool CompilerType::IsAnonymousType() const {
387123e2b5SEnrico Granata   if (IsValid())
397123e2b5SEnrico Granata     return m_type_system->IsAnonymousType(m_type);
407123e2b5SEnrico Granata   return false;
417123e2b5SEnrico Granata }
427123e2b5SEnrico Granata 
IsScopedEnumerationType() const43e17a00fcSAndy Yankovsky bool CompilerType::IsScopedEnumerationType() const {
44e17a00fcSAndy Yankovsky   if (IsValid())
45e17a00fcSAndy Yankovsky     return m_type_system->IsScopedEnumerationType(m_type);
46e17a00fcSAndy Yankovsky   return false;
47e17a00fcSAndy Yankovsky }
48e17a00fcSAndy Yankovsky 
IsArrayType(CompilerType * element_type_ptr,uint64_t * size,bool * is_incomplete) const49b9c1b51eSKate Stone bool CompilerType::IsArrayType(CompilerType *element_type_ptr, uint64_t *size,
50b9c1b51eSKate Stone                                bool *is_incomplete) const {
51a1e5dc86SGreg Clayton   if (IsValid())
52b9c1b51eSKate Stone     return m_type_system->IsArrayType(m_type, element_type_ptr, size,
53b9c1b51eSKate Stone                                       is_incomplete);
54a1e5dc86SGreg Clayton 
55a1e5dc86SGreg Clayton   if (element_type_ptr)
56a1e5dc86SGreg Clayton     element_type_ptr->Clear();
57a1e5dc86SGreg Clayton   if (size)
58a1e5dc86SGreg Clayton     *size = 0;
59a1e5dc86SGreg Clayton   if (is_incomplete)
60a1e5dc86SGreg Clayton     *is_incomplete = false;
61778e7ab5SBruce Mitchener   return false;
62a1e5dc86SGreg Clayton }
63a1e5dc86SGreg Clayton 
IsVectorType(CompilerType * element_type,uint64_t * size) const64b9c1b51eSKate Stone bool CompilerType::IsVectorType(CompilerType *element_type,
65b9c1b51eSKate Stone                                 uint64_t *size) const {
66a1e5dc86SGreg Clayton   if (IsValid())
67a1e5dc86SGreg Clayton     return m_type_system->IsVectorType(m_type, element_type, size);
68a1e5dc86SGreg Clayton   return false;
69a1e5dc86SGreg Clayton }
70a1e5dc86SGreg Clayton 
IsRuntimeGeneratedType() const71b9c1b51eSKate Stone bool CompilerType::IsRuntimeGeneratedType() const {
72a1e5dc86SGreg Clayton   if (IsValid())
73a1e5dc86SGreg Clayton     return m_type_system->IsRuntimeGeneratedType(m_type);
74a1e5dc86SGreg Clayton   return false;
75a1e5dc86SGreg Clayton }
76a1e5dc86SGreg Clayton 
IsCharType() const77b9c1b51eSKate Stone bool CompilerType::IsCharType() const {
78a1e5dc86SGreg Clayton   if (IsValid())
79a1e5dc86SGreg Clayton     return m_type_system->IsCharType(m_type);
80a1e5dc86SGreg Clayton   return false;
81a1e5dc86SGreg Clayton }
82a1e5dc86SGreg Clayton 
IsCompleteType() const83b9c1b51eSKate Stone bool CompilerType::IsCompleteType() const {
84a1e5dc86SGreg Clayton   if (IsValid())
85a1e5dc86SGreg Clayton     return m_type_system->IsCompleteType(m_type);
86a1e5dc86SGreg Clayton   return false;
87a1e5dc86SGreg Clayton }
88a1e5dc86SGreg Clayton 
IsConst() const89b9c1b51eSKate Stone bool CompilerType::IsConst() const {
90a1e5dc86SGreg Clayton   if (IsValid())
91a1e5dc86SGreg Clayton     return m_type_system->IsConst(m_type);
92a1e5dc86SGreg Clayton   return false;
93a1e5dc86SGreg Clayton }
94a1e5dc86SGreg Clayton 
IsCStringType(uint32_t & length) const95b9c1b51eSKate Stone bool CompilerType::IsCStringType(uint32_t &length) const {
96a1e5dc86SGreg Clayton   if (IsValid())
97a1e5dc86SGreg Clayton     return m_type_system->IsCStringType(m_type, length);
98a1e5dc86SGreg Clayton   return false;
99a1e5dc86SGreg Clayton }
100a1e5dc86SGreg Clayton 
IsFunctionType() const101012fd0b1SDave Lee bool CompilerType::IsFunctionType() const {
102a1e5dc86SGreg Clayton   if (IsValid())
103012fd0b1SDave Lee     return m_type_system->IsFunctionType(m_type);
104a1e5dc86SGreg Clayton   return false;
105a1e5dc86SGreg Clayton }
106a1e5dc86SGreg Clayton 
107a1e5dc86SGreg Clayton // Used to detect "Homogeneous Floating-point Aggregates"
108a1e5dc86SGreg Clayton uint32_t
IsHomogeneousAggregate(CompilerType * base_type_ptr) const109b9c1b51eSKate Stone CompilerType::IsHomogeneousAggregate(CompilerType *base_type_ptr) const {
110a1e5dc86SGreg Clayton   if (IsValid())
111a1e5dc86SGreg Clayton     return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr);
112a1e5dc86SGreg Clayton   return 0;
113a1e5dc86SGreg Clayton }
114a1e5dc86SGreg Clayton 
GetNumberOfFunctionArguments() const115b9c1b51eSKate Stone size_t CompilerType::GetNumberOfFunctionArguments() const {
116a1e5dc86SGreg Clayton   if (IsValid())
117a1e5dc86SGreg Clayton     return m_type_system->GetNumberOfFunctionArguments(m_type);
118a1e5dc86SGreg Clayton   return 0;
119a1e5dc86SGreg Clayton }
120a1e5dc86SGreg Clayton 
121a1e5dc86SGreg Clayton CompilerType
GetFunctionArgumentAtIndex(const size_t index) const122b9c1b51eSKate Stone CompilerType::GetFunctionArgumentAtIndex(const size_t index) const {
123a1e5dc86SGreg Clayton   if (IsValid())
124a1e5dc86SGreg Clayton     return m_type_system->GetFunctionArgumentAtIndex(m_type, index);
125a1e5dc86SGreg Clayton   return CompilerType();
126a1e5dc86SGreg Clayton }
127a1e5dc86SGreg Clayton 
IsFunctionPointerType() const128b9c1b51eSKate Stone bool CompilerType::IsFunctionPointerType() const {
129a1e5dc86SGreg Clayton   if (IsValid())
130a1e5dc86SGreg Clayton     return m_type_system->IsFunctionPointerType(m_type);
131a1e5dc86SGreg Clayton   return false;
132c530ba98SSean Callanan }
133a1e5dc86SGreg Clayton 
IsBlockPointerType(CompilerType * function_pointer_type_ptr) const134b9c1b51eSKate Stone bool CompilerType::IsBlockPointerType(
135b9c1b51eSKate Stone     CompilerType *function_pointer_type_ptr) const {
136c530ba98SSean Callanan   if (IsValid())
137c530ba98SSean Callanan     return m_type_system->IsBlockPointerType(m_type, function_pointer_type_ptr);
13809ad8c8fSJonas Devlieghere   return false;
139a1e5dc86SGreg Clayton }
140a1e5dc86SGreg Clayton 
IsIntegerType(bool & is_signed) const141b9c1b51eSKate Stone bool CompilerType::IsIntegerType(bool &is_signed) const {
142a1e5dc86SGreg Clayton   if (IsValid())
143a1e5dc86SGreg Clayton     return m_type_system->IsIntegerType(m_type, is_signed);
144a1e5dc86SGreg Clayton   return false;
145a1e5dc86SGreg Clayton }
146a1e5dc86SGreg Clayton 
IsEnumerationType(bool & is_signed) const147b9c1b51eSKate Stone bool CompilerType::IsEnumerationType(bool &is_signed) const {
148d7f71addSGreg Clayton   if (IsValid())
149d7f71addSGreg Clayton     return m_type_system->IsEnumerationType(m_type, is_signed);
150d7f71addSGreg Clayton   return false;
151d7f71addSGreg Clayton }
152d7f71addSGreg Clayton 
IsIntegerOrEnumerationType(bool & is_signed) const153b9c1b51eSKate Stone bool CompilerType::IsIntegerOrEnumerationType(bool &is_signed) const {
154d7f71addSGreg Clayton   return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
155d7f71addSGreg Clayton }
156d7f71addSGreg Clayton 
IsPointerType(CompilerType * pointee_type) const157b9c1b51eSKate Stone bool CompilerType::IsPointerType(CompilerType *pointee_type) const {
158b9c1b51eSKate Stone   if (IsValid()) {
159a1e5dc86SGreg Clayton     return m_type_system->IsPointerType(m_type, pointee_type);
160a1e5dc86SGreg Clayton   }
161a1e5dc86SGreg Clayton   if (pointee_type)
162a1e5dc86SGreg Clayton     pointee_type->Clear();
163a1e5dc86SGreg Clayton   return false;
164a1e5dc86SGreg Clayton }
165a1e5dc86SGreg Clayton 
IsPointerOrReferenceType(CompilerType * pointee_type) const166b9c1b51eSKate Stone bool CompilerType::IsPointerOrReferenceType(CompilerType *pointee_type) const {
167b9c1b51eSKate Stone   if (IsValid()) {
168a1e5dc86SGreg Clayton     return m_type_system->IsPointerOrReferenceType(m_type, pointee_type);
169a1e5dc86SGreg Clayton   }
170a1e5dc86SGreg Clayton   if (pointee_type)
171a1e5dc86SGreg Clayton     pointee_type->Clear();
172a1e5dc86SGreg Clayton   return false;
173a1e5dc86SGreg Clayton }
174a1e5dc86SGreg Clayton 
IsReferenceType(CompilerType * pointee_type,bool * is_rvalue) const175b9c1b51eSKate Stone bool CompilerType::IsReferenceType(CompilerType *pointee_type,
176b9c1b51eSKate Stone                                    bool *is_rvalue) const {
177b9c1b51eSKate Stone   if (IsValid()) {
178a1e5dc86SGreg Clayton     return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue);
179a1e5dc86SGreg Clayton   }
180a1e5dc86SGreg Clayton   if (pointee_type)
181a1e5dc86SGreg Clayton     pointee_type->Clear();
182a1e5dc86SGreg Clayton   return false;
183a1e5dc86SGreg Clayton }
184a1e5dc86SGreg Clayton 
ShouldTreatScalarValueAsAddress() const185b9c1b51eSKate Stone bool CompilerType::ShouldTreatScalarValueAsAddress() const {
18699448c63SEnrico Granata   if (IsValid())
18799448c63SEnrico Granata     return m_type_system->ShouldTreatScalarValueAsAddress(m_type);
18899448c63SEnrico Granata   return false;
18999448c63SEnrico Granata }
19099448c63SEnrico Granata 
IsFloatingPointType(uint32_t & count,bool & is_complex) const191b9c1b51eSKate Stone bool CompilerType::IsFloatingPointType(uint32_t &count,
192b9c1b51eSKate Stone                                        bool &is_complex) const {
193b9c1b51eSKate Stone   if (IsValid()) {
194a1e5dc86SGreg Clayton     return m_type_system->IsFloatingPointType(m_type, count, is_complex);
195a1e5dc86SGreg Clayton   }
196a1e5dc86SGreg Clayton   count = 0;
197a1e5dc86SGreg Clayton   is_complex = false;
198a1e5dc86SGreg Clayton   return false;
199a1e5dc86SGreg Clayton }
200a1e5dc86SGreg Clayton 
IsDefined() const201b9c1b51eSKate Stone bool CompilerType::IsDefined() const {
202a1e5dc86SGreg Clayton   if (IsValid())
203a1e5dc86SGreg Clayton     return m_type_system->IsDefined(m_type);
204a1e5dc86SGreg Clayton   return true;
205a1e5dc86SGreg Clayton }
206a1e5dc86SGreg Clayton 
IsPolymorphicClass() const207b9c1b51eSKate Stone bool CompilerType::IsPolymorphicClass() const {
208b9c1b51eSKate Stone   if (IsValid()) {
209a1e5dc86SGreg Clayton     return m_type_system->IsPolymorphicClass(m_type);
210a1e5dc86SGreg Clayton   }
211a1e5dc86SGreg Clayton   return false;
212a1e5dc86SGreg Clayton }
213a1e5dc86SGreg Clayton 
IsPossibleDynamicType(CompilerType * dynamic_pointee_type,bool check_cplusplus,bool check_objc) const214b9c1b51eSKate Stone bool CompilerType::IsPossibleDynamicType(CompilerType *dynamic_pointee_type,
215a1e5dc86SGreg Clayton                                          bool check_cplusplus,
216b9c1b51eSKate Stone                                          bool check_objc) const {
217a1e5dc86SGreg Clayton   if (IsValid())
218b9c1b51eSKate Stone     return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type,
219b9c1b51eSKate Stone                                                 check_cplusplus, check_objc);
220a1e5dc86SGreg Clayton   return false;
221a1e5dc86SGreg Clayton }
222a1e5dc86SGreg Clayton 
IsScalarType() const223b9c1b51eSKate Stone bool CompilerType::IsScalarType() const {
224a1e5dc86SGreg Clayton   if (!IsValid())
225a1e5dc86SGreg Clayton     return false;
226a1e5dc86SGreg Clayton 
227a1e5dc86SGreg Clayton   return m_type_system->IsScalarType(m_type);
228a1e5dc86SGreg Clayton }
229a1e5dc86SGreg Clayton 
IsTypedefType() const230b9c1b51eSKate Stone bool CompilerType::IsTypedefType() const {
231a1e5dc86SGreg Clayton   if (!IsValid())
232a1e5dc86SGreg Clayton     return false;
233a1e5dc86SGreg Clayton   return m_type_system->IsTypedefType(m_type);
234a1e5dc86SGreg Clayton }
235a1e5dc86SGreg Clayton 
IsVoidType() const236b9c1b51eSKate Stone bool CompilerType::IsVoidType() const {
237a1e5dc86SGreg Clayton   if (!IsValid())
238a1e5dc86SGreg Clayton     return false;
239a1e5dc86SGreg Clayton   return m_type_system->IsVoidType(m_type);
240a1e5dc86SGreg Clayton }
241a1e5dc86SGreg Clayton 
IsPointerToScalarType() const242b9c1b51eSKate Stone bool CompilerType::IsPointerToScalarType() const {
243a1e5dc86SGreg Clayton   if (!IsValid())
244a1e5dc86SGreg Clayton     return false;
245a1e5dc86SGreg Clayton 
246a1e5dc86SGreg Clayton   return IsPointerType() && GetPointeeType().IsScalarType();
247a1e5dc86SGreg Clayton }
248a1e5dc86SGreg Clayton 
IsArrayOfScalarType() const249b9c1b51eSKate Stone bool CompilerType::IsArrayOfScalarType() const {
250a1e5dc86SGreg Clayton   CompilerType element_type;
25103310c1eSRaphael Isemann   if (IsArrayType(&element_type))
252a1e5dc86SGreg Clayton     return element_type.IsScalarType();
253a1e5dc86SGreg Clayton   return false;
254a1e5dc86SGreg Clayton }
255a1e5dc86SGreg Clayton 
IsBeingDefined() const256b9c1b51eSKate Stone bool CompilerType::IsBeingDefined() const {
257a1e5dc86SGreg Clayton   if (!IsValid())
258a1e5dc86SGreg Clayton     return false;
259a1e5dc86SGreg Clayton   return m_type_system->IsBeingDefined(m_type);
260a1e5dc86SGreg Clayton }
261a1e5dc86SGreg Clayton 
262a1e5dc86SGreg Clayton // Type Completion
263a1e5dc86SGreg Clayton 
GetCompleteType() const264b9c1b51eSKate Stone bool CompilerType::GetCompleteType() const {
265a1e5dc86SGreg Clayton   if (!IsValid())
266a1e5dc86SGreg Clayton     return false;
267a1e5dc86SGreg Clayton   return m_type_system->GetCompleteType(m_type);
268a1e5dc86SGreg Clayton }
269a1e5dc86SGreg Clayton 
270a1e5dc86SGreg Clayton // AST related queries
GetPointerByteSize() const271b9c1b51eSKate Stone size_t CompilerType::GetPointerByteSize() const {
272a1e5dc86SGreg Clayton   if (m_type_system)
273a1e5dc86SGreg Clayton     return m_type_system->GetPointerByteSize();
274a1e5dc86SGreg Clayton   return 0;
275a1e5dc86SGreg Clayton }
276a1e5dc86SGreg Clayton 
GetTypeName() const277b9c1b51eSKate Stone ConstString CompilerType::GetTypeName() const {
278b9c1b51eSKate Stone   if (IsValid()) {
279a1e5dc86SGreg Clayton     return m_type_system->GetTypeName(m_type);
280a1e5dc86SGreg Clayton   }
281a1e5dc86SGreg Clayton   return ConstString("<invalid>");
282a1e5dc86SGreg Clayton }
283a1e5dc86SGreg Clayton 
GetDisplayTypeName() const2844617fb0bSRaphael Isemann ConstString CompilerType::GetDisplayTypeName() const {
2854617fb0bSRaphael Isemann   if (IsValid())
2864617fb0bSRaphael Isemann     return m_type_system->GetDisplayTypeName(m_type);
2874617fb0bSRaphael Isemann   return ConstString("<invalid>");
2884617fb0bSRaphael Isemann }
289a1e5dc86SGreg Clayton 
GetTypeInfo(CompilerType * pointee_or_element_compiler_type) const290b9c1b51eSKate Stone uint32_t CompilerType::GetTypeInfo(
291b9c1b51eSKate Stone     CompilerType *pointee_or_element_compiler_type) const {
292a1e5dc86SGreg Clayton   if (!IsValid())
293a1e5dc86SGreg Clayton     return 0;
294a1e5dc86SGreg Clayton 
2953ad353f3SBruce Mitchener   return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type);
296a1e5dc86SGreg Clayton }
297a1e5dc86SGreg Clayton 
GetMinimumLanguage()298b9c1b51eSKate Stone lldb::LanguageType CompilerType::GetMinimumLanguage() {
299a1e5dc86SGreg Clayton   if (!IsValid())
300a1e5dc86SGreg Clayton     return lldb::eLanguageTypeC;
301a1e5dc86SGreg Clayton 
302a1e5dc86SGreg Clayton   return m_type_system->GetMinimumLanguage(m_type);
303a1e5dc86SGreg Clayton }
304a1e5dc86SGreg Clayton 
GetTypeClass() const305b9c1b51eSKate Stone lldb::TypeClass CompilerType::GetTypeClass() const {
306a1e5dc86SGreg Clayton   if (!IsValid())
307a1e5dc86SGreg Clayton     return lldb::eTypeClassInvalid;
308a1e5dc86SGreg Clayton 
309a1e5dc86SGreg Clayton   return m_type_system->GetTypeClass(m_type);
310a1e5dc86SGreg Clayton }
311a1e5dc86SGreg Clayton 
SetCompilerType(TypeSystem * type_system,lldb::opaque_compiler_type_t type)312b9c1b51eSKate Stone void CompilerType::SetCompilerType(TypeSystem *type_system,
313b9c1b51eSKate Stone                                    lldb::opaque_compiler_type_t type) {
314a1e5dc86SGreg Clayton   m_type_system = type_system;
315a1e5dc86SGreg Clayton   m_type = type;
316a1e5dc86SGreg Clayton }
317a1e5dc86SGreg Clayton 
GetTypeQualifiers() const318b9c1b51eSKate Stone unsigned CompilerType::GetTypeQualifiers() const {
319a1e5dc86SGreg Clayton   if (IsValid())
320a1e5dc86SGreg Clayton     return m_type_system->GetTypeQualifiers(m_type);
321a1e5dc86SGreg Clayton   return 0;
322a1e5dc86SGreg Clayton }
323a1e5dc86SGreg Clayton 
324a1e5dc86SGreg Clayton // Creating related types
325a1e5dc86SGreg Clayton 
3265913f259SRaphael Isemann CompilerType
GetArrayElementType(ExecutionContextScope * exe_scope) const3275913f259SRaphael Isemann CompilerType::GetArrayElementType(ExecutionContextScope *exe_scope) const {
328b9c1b51eSKate Stone   if (IsValid()) {
3295913f259SRaphael Isemann     return m_type_system->GetArrayElementType(m_type, exe_scope);
330639392feSEnrico Granata   }
331639392feSEnrico Granata   return CompilerType();
332639392feSEnrico Granata }
333a1e5dc86SGreg Clayton 
GetArrayType(uint64_t size) const334b9c1b51eSKate Stone CompilerType CompilerType::GetArrayType(uint64_t size) const {
335b9c1b51eSKate Stone   if (IsValid()) {
336639392feSEnrico Granata     return m_type_system->GetArrayType(m_type, size);
337a1e5dc86SGreg Clayton   }
338a1e5dc86SGreg Clayton   return CompilerType();
339a1e5dc86SGreg Clayton }
340a1e5dc86SGreg Clayton 
GetCanonicalType() const341b9c1b51eSKate Stone CompilerType CompilerType::GetCanonicalType() const {
342a1e5dc86SGreg Clayton   if (IsValid())
343a1e5dc86SGreg Clayton     return m_type_system->GetCanonicalType(m_type);
344a1e5dc86SGreg Clayton   return CompilerType();
345a1e5dc86SGreg Clayton }
346a1e5dc86SGreg Clayton 
GetFullyUnqualifiedType() const347b9c1b51eSKate Stone CompilerType CompilerType::GetFullyUnqualifiedType() const {
348a1e5dc86SGreg Clayton   if (IsValid())
349a1e5dc86SGreg Clayton     return m_type_system->GetFullyUnqualifiedType(m_type);
350a1e5dc86SGreg Clayton   return CompilerType();
351a1e5dc86SGreg Clayton }
352a1e5dc86SGreg Clayton 
GetEnumerationIntegerType() const3531432ae57SAndy Yankovsky CompilerType CompilerType::GetEnumerationIntegerType() const {
3541432ae57SAndy Yankovsky   if (IsValid())
3551432ae57SAndy Yankovsky     return m_type_system->GetEnumerationIntegerType(m_type);
3561432ae57SAndy Yankovsky   return CompilerType();
3571432ae57SAndy Yankovsky }
3581432ae57SAndy Yankovsky 
GetFunctionArgumentCount() const359b9c1b51eSKate Stone int CompilerType::GetFunctionArgumentCount() const {
360b9c1b51eSKate Stone   if (IsValid()) {
361a1e5dc86SGreg Clayton     return m_type_system->GetFunctionArgumentCount(m_type);
362a1e5dc86SGreg Clayton   }
363a1e5dc86SGreg Clayton   return -1;
364a1e5dc86SGreg Clayton }
365a1e5dc86SGreg Clayton 
GetFunctionArgumentTypeAtIndex(size_t idx) const366b9c1b51eSKate Stone CompilerType CompilerType::GetFunctionArgumentTypeAtIndex(size_t idx) const {
367b9c1b51eSKate Stone   if (IsValid()) {
368a1e5dc86SGreg Clayton     return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx);
369a1e5dc86SGreg Clayton   }
370a1e5dc86SGreg Clayton   return CompilerType();
371a1e5dc86SGreg Clayton }
372a1e5dc86SGreg Clayton 
GetFunctionReturnType() const373b9c1b51eSKate Stone CompilerType CompilerType::GetFunctionReturnType() const {
374b9c1b51eSKate Stone   if (IsValid()) {
375a1e5dc86SGreg Clayton     return m_type_system->GetFunctionReturnType(m_type);
376a1e5dc86SGreg Clayton   }
377a1e5dc86SGreg Clayton   return CompilerType();
378a1e5dc86SGreg Clayton }
379a1e5dc86SGreg Clayton 
GetNumMemberFunctions() const380b9c1b51eSKate Stone size_t CompilerType::GetNumMemberFunctions() const {
381b9c1b51eSKate Stone   if (IsValid()) {
382a1e5dc86SGreg Clayton     return m_type_system->GetNumMemberFunctions(m_type);
383a1e5dc86SGreg Clayton   }
384a1e5dc86SGreg Clayton   return 0;
385a1e5dc86SGreg Clayton }
386a1e5dc86SGreg Clayton 
GetMemberFunctionAtIndex(size_t idx)387b9c1b51eSKate Stone TypeMemberFunctionImpl CompilerType::GetMemberFunctionAtIndex(size_t idx) {
388b9c1b51eSKate Stone   if (IsValid()) {
389a1e5dc86SGreg Clayton     return m_type_system->GetMemberFunctionAtIndex(m_type, idx);
390a1e5dc86SGreg Clayton   }
391a1e5dc86SGreg Clayton   return TypeMemberFunctionImpl();
392a1e5dc86SGreg Clayton }
393a1e5dc86SGreg Clayton 
GetNonReferenceType() const394b9c1b51eSKate Stone CompilerType CompilerType::GetNonReferenceType() const {
395a1e5dc86SGreg Clayton   if (IsValid())
396a1e5dc86SGreg Clayton     return m_type_system->GetNonReferenceType(m_type);
397a1e5dc86SGreg Clayton   return CompilerType();
398a1e5dc86SGreg Clayton }
399a1e5dc86SGreg Clayton 
GetPointeeType() const400b9c1b51eSKate Stone CompilerType CompilerType::GetPointeeType() const {
401b9c1b51eSKate Stone   if (IsValid()) {
402a1e5dc86SGreg Clayton     return m_type_system->GetPointeeType(m_type);
403a1e5dc86SGreg Clayton   }
404a1e5dc86SGreg Clayton   return CompilerType();
405a1e5dc86SGreg Clayton }
406a1e5dc86SGreg Clayton 
GetPointerType() const407b9c1b51eSKate Stone CompilerType CompilerType::GetPointerType() const {
408b9c1b51eSKate Stone   if (IsValid()) {
409a1e5dc86SGreg Clayton     return m_type_system->GetPointerType(m_type);
410a1e5dc86SGreg Clayton   }
411a1e5dc86SGreg Clayton   return CompilerType();
412a1e5dc86SGreg Clayton }
413a1e5dc86SGreg Clayton 
GetLValueReferenceType() const414b9c1b51eSKate Stone CompilerType CompilerType::GetLValueReferenceType() const {
41556939cb3SGreg Clayton   if (IsValid())
41656939cb3SGreg Clayton     return m_type_system->GetLValueReferenceType(m_type);
41756939cb3SGreg Clayton   else
41856939cb3SGreg Clayton     return CompilerType();
41956939cb3SGreg Clayton }
42056939cb3SGreg Clayton 
GetRValueReferenceType() const421b9c1b51eSKate Stone CompilerType CompilerType::GetRValueReferenceType() const {
42256939cb3SGreg Clayton   if (IsValid())
42356939cb3SGreg Clayton     return m_type_system->GetRValueReferenceType(m_type);
42456939cb3SGreg Clayton   else
42556939cb3SGreg Clayton     return CompilerType();
42656939cb3SGreg Clayton }
42756939cb3SGreg Clayton 
GetAtomicType() const428d0fb7a47SRaphael Isemann CompilerType CompilerType::GetAtomicType() const {
429d0fb7a47SRaphael Isemann   if (IsValid())
430d0fb7a47SRaphael Isemann     return m_type_system->GetAtomicType(m_type);
431d0fb7a47SRaphael Isemann   return CompilerType();
432d0fb7a47SRaphael Isemann }
433d0fb7a47SRaphael Isemann 
AddConstModifier() const434b9c1b51eSKate Stone CompilerType CompilerType::AddConstModifier() const {
43556939cb3SGreg Clayton   if (IsValid())
43656939cb3SGreg Clayton     return m_type_system->AddConstModifier(m_type);
43756939cb3SGreg Clayton   else
43856939cb3SGreg Clayton     return CompilerType();
43956939cb3SGreg Clayton }
44056939cb3SGreg Clayton 
AddVolatileModifier() const441b9c1b51eSKate Stone CompilerType CompilerType::AddVolatileModifier() const {
44256939cb3SGreg Clayton   if (IsValid())
44356939cb3SGreg Clayton     return m_type_system->AddVolatileModifier(m_type);
44456939cb3SGreg Clayton   else
44556939cb3SGreg Clayton     return CompilerType();
44656939cb3SGreg Clayton }
44756939cb3SGreg Clayton 
AddRestrictModifier() const448b9c1b51eSKate Stone CompilerType CompilerType::AddRestrictModifier() const {
44956939cb3SGreg Clayton   if (IsValid())
45056939cb3SGreg Clayton     return m_type_system->AddRestrictModifier(m_type);
45156939cb3SGreg Clayton   else
45256939cb3SGreg Clayton     return CompilerType();
45356939cb3SGreg Clayton }
45456939cb3SGreg Clayton 
CreateTypedef(const char * name,const CompilerDeclContext & decl_ctx,uint32_t payload) const455143d507cSAdrian Prantl CompilerType CompilerType::CreateTypedef(const char *name,
456143d507cSAdrian Prantl                                          const CompilerDeclContext &decl_ctx,
457143d507cSAdrian Prantl                                          uint32_t payload) const {
45856939cb3SGreg Clayton   if (IsValid())
459143d507cSAdrian Prantl     return m_type_system->CreateTypedef(m_type, name, decl_ctx, payload);
46056939cb3SGreg Clayton   else
46156939cb3SGreg Clayton     return CompilerType();
46256939cb3SGreg Clayton }
46356939cb3SGreg Clayton 
GetTypedefedType() const464b9c1b51eSKate Stone CompilerType CompilerType::GetTypedefedType() const {
465a1e5dc86SGreg Clayton   if (IsValid())
466a1e5dc86SGreg Clayton     return m_type_system->GetTypedefedType(m_type);
46756939cb3SGreg Clayton   else
468a1e5dc86SGreg Clayton     return CompilerType();
469a1e5dc86SGreg Clayton }
470a1e5dc86SGreg Clayton 
471a1e5dc86SGreg Clayton // Create related types using the current type's AST
472a1e5dc86SGreg Clayton 
473a1e5dc86SGreg Clayton CompilerType
GetBasicTypeFromAST(lldb::BasicType basic_type) const474b9c1b51eSKate Stone CompilerType::GetBasicTypeFromAST(lldb::BasicType basic_type) const {
475a1e5dc86SGreg Clayton   if (IsValid())
47699558cc4SGreg Clayton     return m_type_system->GetBasicTypeFromAST(basic_type);
477a1e5dc86SGreg Clayton   return CompilerType();
478a1e5dc86SGreg Clayton }
479a1e5dc86SGreg Clayton // Exploring the type
480a1e5dc86SGreg Clayton 
481d963a7c3SAdrian Prantl llvm::Optional<uint64_t>
GetBitSize(ExecutionContextScope * exe_scope) const482d963a7c3SAdrian Prantl CompilerType::GetBitSize(ExecutionContextScope *exe_scope) const {
483d963a7c3SAdrian Prantl   if (IsValid())
484a1e5dc86SGreg Clayton     return m_type_system->GetBitSize(m_type, exe_scope);
485d963a7c3SAdrian Prantl   return {};
486a1e5dc86SGreg Clayton }
487a1e5dc86SGreg Clayton 
488d963a7c3SAdrian Prantl llvm::Optional<uint64_t>
GetByteSize(ExecutionContextScope * exe_scope) const489d963a7c3SAdrian Prantl CompilerType::GetByteSize(ExecutionContextScope *exe_scope) const {
490d6a9bbf6SAdrian Prantl   if (llvm::Optional<uint64_t> bit_size = GetBitSize(exe_scope))
491d963a7c3SAdrian Prantl     return (*bit_size + 7) / 8;
492d963a7c3SAdrian Prantl   return {};
493a1e5dc86SGreg Clayton }
494a1e5dc86SGreg Clayton 
GetTypeBitAlign(ExecutionContextScope * exe_scope) const4957f9bbe05SDavide Italiano llvm::Optional<size_t> CompilerType::GetTypeBitAlign(ExecutionContextScope *exe_scope) const {
496a1e5dc86SGreg Clayton   if (IsValid())
4977f9bbe05SDavide Italiano     return m_type_system->GetTypeBitAlign(m_type, exe_scope);
49836f13e49SDavide Italiano   return {};
499a1e5dc86SGreg Clayton }
500a1e5dc86SGreg Clayton 
GetEncoding(uint64_t & count) const501b9c1b51eSKate Stone lldb::Encoding CompilerType::GetEncoding(uint64_t &count) const {
502a1e5dc86SGreg Clayton   if (!IsValid())
503a1e5dc86SGreg Clayton     return lldb::eEncodingInvalid;
504a1e5dc86SGreg Clayton 
505a1e5dc86SGreg Clayton   return m_type_system->GetEncoding(m_type, count);
506a1e5dc86SGreg Clayton }
507a1e5dc86SGreg Clayton 
GetFormat() const508b9c1b51eSKate Stone lldb::Format CompilerType::GetFormat() const {
509a1e5dc86SGreg Clayton   if (!IsValid())
510a1e5dc86SGreg Clayton     return lldb::eFormatDefault;
511a1e5dc86SGreg Clayton 
512a1e5dc86SGreg Clayton   return m_type_system->GetFormat(m_type);
513a1e5dc86SGreg Clayton }
514a1e5dc86SGreg Clayton 
GetNumChildren(bool omit_empty_base_classes,const ExecutionContext * exe_ctx) const515eca07c59SAdrian Prantl uint32_t CompilerType::GetNumChildren(bool omit_empty_base_classes,
516eca07c59SAdrian Prantl                                       const ExecutionContext *exe_ctx) const {
517a1e5dc86SGreg Clayton   if (!IsValid())
518a1e5dc86SGreg Clayton     return 0;
519eca07c59SAdrian Prantl   return m_type_system->GetNumChildren(m_type, omit_empty_base_classes,
520eca07c59SAdrian Prantl                                        exe_ctx);
521a1e5dc86SGreg Clayton }
522a1e5dc86SGreg Clayton 
GetBasicTypeEnumeration() const523b9c1b51eSKate Stone lldb::BasicType CompilerType::GetBasicTypeEnumeration() const {
524a1e5dc86SGreg Clayton   if (IsValid())
525a1e5dc86SGreg Clayton     return m_type_system->GetBasicTypeEnumeration(m_type);
526a1e5dc86SGreg Clayton   return eBasicTypeInvalid;
527a1e5dc86SGreg Clayton }
528a1e5dc86SGreg Clayton 
ForEachEnumerator(std::function<bool (const CompilerType & integer_type,ConstString name,const llvm::APSInt & value)> const & callback) const529b9c1b51eSKate Stone void CompilerType::ForEachEnumerator(
530b9c1b51eSKate Stone     std::function<bool(const CompilerType &integer_type,
5310e4c4821SAdrian Prantl                        ConstString name,
532b9c1b51eSKate Stone                        const llvm::APSInt &value)> const &callback) const {
53399558cc4SGreg Clayton   if (IsValid())
53499558cc4SGreg Clayton     return m_type_system->ForEachEnumerator(m_type, callback);
53599558cc4SGreg Clayton }
536a1e5dc86SGreg Clayton 
GetNumFields() const537b9c1b51eSKate Stone uint32_t CompilerType::GetNumFields() const {
538a1e5dc86SGreg Clayton   if (!IsValid())
539a1e5dc86SGreg Clayton     return 0;
540a1e5dc86SGreg Clayton   return m_type_system->GetNumFields(m_type);
541a1e5dc86SGreg Clayton }
542a1e5dc86SGreg Clayton 
GetFieldAtIndex(size_t idx,std::string & name,uint64_t * bit_offset_ptr,uint32_t * bitfield_bit_size_ptr,bool * is_bitfield_ptr) const543b9c1b51eSKate Stone CompilerType CompilerType::GetFieldAtIndex(size_t idx, std::string &name,
544a1e5dc86SGreg Clayton                                            uint64_t *bit_offset_ptr,
545a1e5dc86SGreg Clayton                                            uint32_t *bitfield_bit_size_ptr,
546b9c1b51eSKate Stone                                            bool *is_bitfield_ptr) const {
547a1e5dc86SGreg Clayton   if (!IsValid())
548a1e5dc86SGreg Clayton     return CompilerType();
549b9c1b51eSKate Stone   return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr,
550b9c1b51eSKate Stone                                         bitfield_bit_size_ptr, is_bitfield_ptr);
551a1e5dc86SGreg Clayton }
552a1e5dc86SGreg Clayton 
GetNumDirectBaseClasses() const553b9c1b51eSKate Stone uint32_t CompilerType::GetNumDirectBaseClasses() const {
55499558cc4SGreg Clayton   if (IsValid())
55599558cc4SGreg Clayton     return m_type_system->GetNumDirectBaseClasses(m_type);
55699558cc4SGreg Clayton   return 0;
55799558cc4SGreg Clayton }
55899558cc4SGreg Clayton 
GetNumVirtualBaseClasses() const559b9c1b51eSKate Stone uint32_t CompilerType::GetNumVirtualBaseClasses() const {
56099558cc4SGreg Clayton   if (IsValid())
56199558cc4SGreg Clayton     return m_type_system->GetNumVirtualBaseClasses(m_type);
56299558cc4SGreg Clayton   return 0;
56399558cc4SGreg Clayton }
56499558cc4SGreg Clayton 
56599558cc4SGreg Clayton CompilerType
GetDirectBaseClassAtIndex(size_t idx,uint32_t * bit_offset_ptr) const566b9c1b51eSKate Stone CompilerType::GetDirectBaseClassAtIndex(size_t idx,
567b9c1b51eSKate Stone                                         uint32_t *bit_offset_ptr) const {
56899558cc4SGreg Clayton   if (IsValid())
569b9c1b51eSKate Stone     return m_type_system->GetDirectBaseClassAtIndex(m_type, idx,
570b9c1b51eSKate Stone                                                     bit_offset_ptr);
57199558cc4SGreg Clayton   return CompilerType();
57299558cc4SGreg Clayton }
57399558cc4SGreg Clayton 
57499558cc4SGreg Clayton CompilerType
GetVirtualBaseClassAtIndex(size_t idx,uint32_t * bit_offset_ptr) const575b9c1b51eSKate Stone CompilerType::GetVirtualBaseClassAtIndex(size_t idx,
576b9c1b51eSKate Stone                                          uint32_t *bit_offset_ptr) const {
57799558cc4SGreg Clayton   if (IsValid())
578b9c1b51eSKate Stone     return m_type_system->GetVirtualBaseClassAtIndex(m_type, idx,
579b9c1b51eSKate Stone                                                      bit_offset_ptr);
58099558cc4SGreg Clayton   return CompilerType();
58199558cc4SGreg Clayton }
58299558cc4SGreg Clayton 
GetIndexOfFieldWithName(const char * name,CompilerType * field_compiler_type_ptr,uint64_t * bit_offset_ptr,uint32_t * bitfield_bit_size_ptr,bool * is_bitfield_ptr) const583b9c1b51eSKate Stone uint32_t CompilerType::GetIndexOfFieldWithName(
584b9c1b51eSKate Stone     const char *name, CompilerType *field_compiler_type_ptr,
585b9c1b51eSKate Stone     uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
586b9c1b51eSKate Stone     bool *is_bitfield_ptr) const {
587a1e5dc86SGreg Clayton   unsigned count = GetNumFields();
588a1e5dc86SGreg Clayton   std::string field_name;
589b9c1b51eSKate Stone   for (unsigned index = 0; index < count; index++) {
590b9c1b51eSKate Stone     CompilerType field_compiler_type(
591b9c1b51eSKate Stone         GetFieldAtIndex(index, field_name, bit_offset_ptr,
592b9c1b51eSKate Stone                         bitfield_bit_size_ptr, is_bitfield_ptr));
593b9c1b51eSKate Stone     if (strcmp(field_name.c_str(), name) == 0) {
5943ad353f3SBruce Mitchener       if (field_compiler_type_ptr)
5953ad353f3SBruce Mitchener         *field_compiler_type_ptr = field_compiler_type;
596a1e5dc86SGreg Clayton       return index;
597a1e5dc86SGreg Clayton     }
598a1e5dc86SGreg Clayton   }
599a1e5dc86SGreg Clayton   return UINT32_MAX;
600a1e5dc86SGreg Clayton }
601a1e5dc86SGreg Clayton 
GetChildCompilerTypeAtIndex(ExecutionContext * exe_ctx,size_t idx,bool transparent_pointers,bool omit_empty_base_classes,bool ignore_array_bounds,std::string & child_name,uint32_t & child_byte_size,int32_t & child_byte_offset,uint32_t & child_bitfield_bit_size,uint32_t & child_bitfield_bit_offset,bool & child_is_base_class,bool & child_is_deref_of_parent,ValueObject * valobj,uint64_t & language_flags) const602b9c1b51eSKate Stone CompilerType CompilerType::GetChildCompilerTypeAtIndex(
603b9c1b51eSKate Stone     ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
604b9c1b51eSKate Stone     bool omit_empty_base_classes, bool ignore_array_bounds,
605b9c1b51eSKate Stone     std::string &child_name, uint32_t &child_byte_size,
606b9c1b51eSKate Stone     int32_t &child_byte_offset, uint32_t &child_bitfield_bit_size,
607b9c1b51eSKate Stone     uint32_t &child_bitfield_bit_offset, bool &child_is_base_class,
608b9c1b51eSKate Stone     bool &child_is_deref_of_parent, ValueObject *valobj,
609b9c1b51eSKate Stone     uint64_t &language_flags) const {
610a1e5dc86SGreg Clayton   if (!IsValid())
611a1e5dc86SGreg Clayton     return CompilerType();
612b9c1b51eSKate Stone   return m_type_system->GetChildCompilerTypeAtIndex(
613b9c1b51eSKate Stone       m_type, exe_ctx, idx, transparent_pointers, omit_empty_base_classes,
614b9c1b51eSKate Stone       ignore_array_bounds, child_name, child_byte_size, child_byte_offset,
615b9c1b51eSKate Stone       child_bitfield_bit_size, child_bitfield_bit_offset, child_is_base_class,
616b9c1b51eSKate Stone       child_is_deref_of_parent, valobj, language_flags);
617a1e5dc86SGreg Clayton }
618a1e5dc86SGreg Clayton 
619a1e5dc86SGreg Clayton // Look for a child member (doesn't include base classes, but it does include
62005097246SAdrian Prantl // their members) in the type hierarchy. Returns an index path into
62105097246SAdrian Prantl // "clang_type" on how to reach the appropriate member.
622a1e5dc86SGreg Clayton //
623a1e5dc86SGreg Clayton //    class A
624a1e5dc86SGreg Clayton //    {
625a1e5dc86SGreg Clayton //    public:
626a1e5dc86SGreg Clayton //        int m_a;
627a1e5dc86SGreg Clayton //        int m_b;
628a1e5dc86SGreg Clayton //    };
629a1e5dc86SGreg Clayton //
630a1e5dc86SGreg Clayton //    class B
631a1e5dc86SGreg Clayton //    {
632a1e5dc86SGreg Clayton //    };
633a1e5dc86SGreg Clayton //
634a1e5dc86SGreg Clayton //    class C :
635a1e5dc86SGreg Clayton //        public B,
636a1e5dc86SGreg Clayton //        public A
637a1e5dc86SGreg Clayton //    {
638a1e5dc86SGreg Clayton //    };
639a1e5dc86SGreg Clayton //
640a1e5dc86SGreg Clayton // If we have a clang type that describes "class C", and we wanted to looked
641a1e5dc86SGreg Clayton // "m_b" in it:
642a1e5dc86SGreg Clayton //
643b9c1b51eSKate Stone // With omit_empty_base_classes == false we would get an integer array back
64405097246SAdrian Prantl // with: { 1,  1 } The first index 1 is the child index for "class A" within
64505097246SAdrian Prantl // class C The second index 1 is the child index for "m_b" within class A
646a1e5dc86SGreg Clayton //
64705097246SAdrian Prantl // With omit_empty_base_classes == true we would get an integer array back
64805097246SAdrian Prantl // with: { 0,  1 } The first index 0 is the child index for "class A" within
64905097246SAdrian Prantl // class C (since class B doesn't have any members it doesn't count) The second
65005097246SAdrian Prantl // index 1 is the child index for "m_b" within class A
651a1e5dc86SGreg Clayton 
GetIndexOfChildMemberWithName(const char * name,bool omit_empty_base_classes,std::vector<uint32_t> & child_indexes) const652b9c1b51eSKate Stone size_t CompilerType::GetIndexOfChildMemberWithName(
653b9c1b51eSKate Stone     const char *name, bool omit_empty_base_classes,
654b9c1b51eSKate Stone     std::vector<uint32_t> &child_indexes) const {
655b9c1b51eSKate Stone   if (IsValid() && name && name[0]) {
656b9c1b51eSKate Stone     return m_type_system->GetIndexOfChildMemberWithName(
657b9c1b51eSKate Stone         m_type, name, omit_empty_base_classes, child_indexes);
658a1e5dc86SGreg Clayton   }
659a1e5dc86SGreg Clayton   return 0;
660a1e5dc86SGreg Clayton }
661a1e5dc86SGreg Clayton 
GetNumTemplateArguments(bool expand_pack) const662*2d5c43adSJonas Devlieghere size_t CompilerType::GetNumTemplateArguments(bool expand_pack) const {
663b9c1b51eSKate Stone   if (IsValid()) {
664*2d5c43adSJonas Devlieghere     return m_type_system->GetNumTemplateArguments(m_type, expand_pack);
66553f2a4afSEnrico Granata   }
66653f2a4afSEnrico Granata   return 0;
66753f2a4afSEnrico Granata }
66853f2a4afSEnrico Granata 
669*2d5c43adSJonas Devlieghere TemplateArgumentKind
GetTemplateArgumentKind(size_t idx,bool expand_pack) const670*2d5c43adSJonas Devlieghere CompilerType::GetTemplateArgumentKind(size_t idx, bool expand_pack) const {
671769b21eaSPavel Labath   if (IsValid())
672*2d5c43adSJonas Devlieghere     return m_type_system->GetTemplateArgumentKind(m_type, idx, expand_pack);
673769b21eaSPavel Labath   return eTemplateArgumentKindNull;
674769b21eaSPavel Labath }
675769b21eaSPavel Labath 
GetTypeTemplateArgument(size_t idx,bool expand_pack) const676*2d5c43adSJonas Devlieghere CompilerType CompilerType::GetTypeTemplateArgument(size_t idx,
677*2d5c43adSJonas Devlieghere                                                    bool expand_pack) const {
678b9c1b51eSKate Stone   if (IsValid()) {
679*2d5c43adSJonas Devlieghere     return m_type_system->GetTypeTemplateArgument(m_type, idx, expand_pack);
68053f2a4afSEnrico Granata   }
68153f2a4afSEnrico Granata   return CompilerType();
68253f2a4afSEnrico Granata }
68353f2a4afSEnrico Granata 
684f59056ffSPavel Labath llvm::Optional<CompilerType::IntegralTemplateArgument>
GetIntegralTemplateArgument(size_t idx,bool expand_pack) const685*2d5c43adSJonas Devlieghere CompilerType::GetIntegralTemplateArgument(size_t idx, bool expand_pack) const {
686769b21eaSPavel Labath   if (IsValid())
687*2d5c43adSJonas Devlieghere     return m_type_system->GetIntegralTemplateArgument(m_type, idx, expand_pack);
688f59056ffSPavel Labath   return llvm::None;
689769b21eaSPavel Labath }
690769b21eaSPavel Labath 
GetTypeForFormatters() const691b9c1b51eSKate Stone CompilerType CompilerType::GetTypeForFormatters() const {
692c6bf2e2dSEnrico Granata   if (IsValid())
693c6bf2e2dSEnrico Granata     return m_type_system->GetTypeForFormatters(m_type);
694c6bf2e2dSEnrico Granata   return CompilerType();
695c6bf2e2dSEnrico Granata }
696a1e5dc86SGreg Clayton 
ShouldPrintAsOneLiner(ValueObject * valobj) const697b9c1b51eSKate Stone LazyBool CompilerType::ShouldPrintAsOneLiner(ValueObject *valobj) const {
6989c63f99aSEnrico Granata   if (IsValid())
6996500061eSEnrico Granata     return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
7009c63f99aSEnrico Granata   return eLazyBoolCalculate;
7019c63f99aSEnrico Granata }
7029c63f99aSEnrico Granata 
IsMeaninglessWithoutDynamicResolution() const70378f05d35SDavide Italiano bool CompilerType::IsMeaninglessWithoutDynamicResolution() const {
70478f05d35SDavide Italiano   if (IsValid())
70578f05d35SDavide Italiano     return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
70678f05d35SDavide Italiano   return false;
70778f05d35SDavide Italiano }
70878f05d35SDavide Italiano 
709a1e5dc86SGreg Clayton // Get the index of the child of "clang_type" whose name matches. This function
710a1e5dc86SGreg Clayton // doesn't descend into the children, but only looks one level deep and name
711a1e5dc86SGreg Clayton // matches can include base class names.
712a1e5dc86SGreg Clayton 
713a1e5dc86SGreg Clayton uint32_t
GetIndexOfChildWithName(const char * name,bool omit_empty_base_classes) const714b9c1b51eSKate Stone CompilerType::GetIndexOfChildWithName(const char *name,
715b9c1b51eSKate Stone                                       bool omit_empty_base_classes) const {
716b9c1b51eSKate Stone   if (IsValid() && name && name[0]) {
717b9c1b51eSKate Stone     return m_type_system->GetIndexOfChildWithName(m_type, name,
718b9c1b51eSKate Stone                                                   omit_empty_base_classes);
719a1e5dc86SGreg Clayton   }
720a1e5dc86SGreg Clayton   return UINT32_MAX;
721a1e5dc86SGreg Clayton }
722a1e5dc86SGreg Clayton 
723a1e5dc86SGreg Clayton // Dumping types
724a1e5dc86SGreg Clayton 
DumpValue(ExecutionContext * exe_ctx,Stream * s,lldb::Format format,const DataExtractor & data,lldb::offset_t data_byte_offset,size_t data_byte_size,uint32_t bitfield_bit_size,uint32_t bitfield_bit_offset,bool show_types,bool show_summary,bool verbose,uint32_t depth)725b9c1b51eSKate Stone void CompilerType::DumpValue(ExecutionContext *exe_ctx, Stream *s,
72629cb868aSZachary Turner                              lldb::Format format, const DataExtractor &data,
727a1e5dc86SGreg Clayton                              lldb::offset_t data_byte_offset,
728b9c1b51eSKate Stone                              size_t data_byte_size, uint32_t bitfield_bit_size,
729b9c1b51eSKate Stone                              uint32_t bitfield_bit_offset, bool show_types,
730b9c1b51eSKate Stone                              bool show_summary, bool verbose, uint32_t depth) {
731a1e5dc86SGreg Clayton   if (!IsValid())
732a1e5dc86SGreg Clayton     return;
733b9c1b51eSKate Stone   m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset,
734b9c1b51eSKate Stone                            data_byte_size, bitfield_bit_size,
735b9c1b51eSKate Stone                            bitfield_bit_offset, show_types, show_summary,
736b9c1b51eSKate Stone                            verbose, depth);
737a1e5dc86SGreg Clayton }
738a1e5dc86SGreg Clayton 
DumpTypeValue(Stream * s,lldb::Format format,const DataExtractor & data,lldb::offset_t byte_offset,size_t byte_size,uint32_t bitfield_bit_size,uint32_t bitfield_bit_offset,ExecutionContextScope * exe_scope)739b9c1b51eSKate Stone bool CompilerType::DumpTypeValue(Stream *s, lldb::Format format,
74029cb868aSZachary Turner                                  const DataExtractor &data,
741b9c1b51eSKate Stone                                  lldb::offset_t byte_offset, size_t byte_size,
742a1e5dc86SGreg Clayton                                  uint32_t bitfield_bit_size,
743a1e5dc86SGreg Clayton                                  uint32_t bitfield_bit_offset,
744b9c1b51eSKate Stone                                  ExecutionContextScope *exe_scope) {
745a1e5dc86SGreg Clayton   if (!IsValid())
746a1e5dc86SGreg Clayton     return false;
747b9c1b51eSKate Stone   return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset,
748b9c1b51eSKate Stone                                       byte_size, bitfield_bit_size,
749b9c1b51eSKate Stone                                       bitfield_bit_offset, exe_scope);
750a1e5dc86SGreg Clayton }
751a1e5dc86SGreg Clayton 
DumpSummary(ExecutionContext * exe_ctx,Stream * s,const DataExtractor & data,lldb::offset_t data_byte_offset,size_t data_byte_size)752b9c1b51eSKate Stone void CompilerType::DumpSummary(ExecutionContext *exe_ctx, Stream *s,
75329cb868aSZachary Turner                                const DataExtractor &data,
754a1e5dc86SGreg Clayton                                lldb::offset_t data_byte_offset,
755b9c1b51eSKate Stone                                size_t data_byte_size) {
756a1e5dc86SGreg Clayton   if (IsValid())
757b9c1b51eSKate Stone     m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset,
758b9c1b51eSKate Stone                                data_byte_size);
759a1e5dc86SGreg Clayton }
760a1e5dc86SGreg Clayton 
DumpTypeDescription(lldb::DescriptionLevel level) const761681466f5SAdrian Prantl void CompilerType::DumpTypeDescription(lldb::DescriptionLevel level) const {
762a1e5dc86SGreg Clayton   if (IsValid())
763681466f5SAdrian Prantl     m_type_system->DumpTypeDescription(m_type, level);
764a1e5dc86SGreg Clayton }
765a1e5dc86SGreg Clayton 
DumpTypeDescription(Stream * s,lldb::DescriptionLevel level) const766681466f5SAdrian Prantl void CompilerType::DumpTypeDescription(Stream *s,
767681466f5SAdrian Prantl                                        lldb::DescriptionLevel level) const {
768b9c1b51eSKate Stone   if (IsValid()) {
769681466f5SAdrian Prantl     m_type_system->DumpTypeDescription(m_type, s, level);
770a1e5dc86SGreg Clayton   }
771a1e5dc86SGreg Clayton }
772a1e5dc86SGreg Clayton 
7730c72a42aSAdrian Prantl #ifndef NDEBUG
dump() const7740c72a42aSAdrian Prantl LLVM_DUMP_METHOD void CompilerType::dump() const {
7750c72a42aSAdrian Prantl   if (IsValid())
7760c72a42aSAdrian Prantl     m_type_system->dump(m_type);
7770c72a42aSAdrian Prantl   else
7780c72a42aSAdrian Prantl     llvm::errs() << "<invalid>\n";
7790c72a42aSAdrian Prantl }
7800c72a42aSAdrian Prantl #endif
7810c72a42aSAdrian Prantl 
GetValueAsScalar(const lldb_private::DataExtractor & data,lldb::offset_t data_byte_offset,size_t data_byte_size,Scalar & value,ExecutionContextScope * exe_scope) const782b9c1b51eSKate Stone bool CompilerType::GetValueAsScalar(const lldb_private::DataExtractor &data,
783a1e5dc86SGreg Clayton                                     lldb::offset_t data_byte_offset,
78402f58373SAdrian Prantl                                     size_t data_byte_size, Scalar &value,
78502f58373SAdrian Prantl                                     ExecutionContextScope *exe_scope) const {
786a1e5dc86SGreg Clayton   if (!IsValid())
787a1e5dc86SGreg Clayton     return false;
788a1e5dc86SGreg Clayton 
789b9c1b51eSKate Stone   if (IsAggregateType()) {
790a1e5dc86SGreg Clayton     return false; // Aggregate types don't have scalar values
791b9c1b51eSKate Stone   } else {
792a1e5dc86SGreg Clayton     uint64_t count = 0;
793a1e5dc86SGreg Clayton     lldb::Encoding encoding = GetEncoding(count);
794a1e5dc86SGreg Clayton 
795a1e5dc86SGreg Clayton     if (encoding == lldb::eEncodingInvalid || count != 1)
796a1e5dc86SGreg Clayton       return false;
797a1e5dc86SGreg Clayton 
79802f58373SAdrian Prantl     llvm::Optional<uint64_t> byte_size = GetByteSize(exe_scope);
799d963a7c3SAdrian Prantl     if (!byte_size)
800d963a7c3SAdrian Prantl       return false;
801a1e5dc86SGreg Clayton     lldb::offset_t offset = data_byte_offset;
802b9c1b51eSKate Stone     switch (encoding) {
803a1e5dc86SGreg Clayton     case lldb::eEncodingInvalid:
804a1e5dc86SGreg Clayton       break;
805a1e5dc86SGreg Clayton     case lldb::eEncodingVector:
806a1e5dc86SGreg Clayton       break;
807a1e5dc86SGreg Clayton     case lldb::eEncodingUint:
808d963a7c3SAdrian Prantl       if (*byte_size <= sizeof(unsigned long long)) {
809d963a7c3SAdrian Prantl         uint64_t uval64 = data.GetMaxU64(&offset, *byte_size);
810d963a7c3SAdrian Prantl         if (*byte_size <= sizeof(unsigned int)) {
811a1e5dc86SGreg Clayton           value = (unsigned int)uval64;
812a1e5dc86SGreg Clayton           return true;
813d963a7c3SAdrian Prantl         } else if (*byte_size <= sizeof(unsigned long)) {
814a1e5dc86SGreg Clayton           value = (unsigned long)uval64;
815a1e5dc86SGreg Clayton           return true;
816d963a7c3SAdrian Prantl         } else if (*byte_size <= sizeof(unsigned long long)) {
817a1e5dc86SGreg Clayton           value = (unsigned long long)uval64;
818a1e5dc86SGreg Clayton           return true;
819b9c1b51eSKate Stone         } else
820a1e5dc86SGreg Clayton           value.Clear();
821a1e5dc86SGreg Clayton       }
822a1e5dc86SGreg Clayton       break;
823a1e5dc86SGreg Clayton 
824a1e5dc86SGreg Clayton     case lldb::eEncodingSint:
825d963a7c3SAdrian Prantl       if (*byte_size <= sizeof(long long)) {
826d963a7c3SAdrian Prantl         int64_t sval64 = data.GetMaxS64(&offset, *byte_size);
827d963a7c3SAdrian Prantl         if (*byte_size <= sizeof(int)) {
828a1e5dc86SGreg Clayton           value = (int)sval64;
829a1e5dc86SGreg Clayton           return true;
830d963a7c3SAdrian Prantl         } else if (*byte_size <= sizeof(long)) {
831a1e5dc86SGreg Clayton           value = (long)sval64;
832a1e5dc86SGreg Clayton           return true;
833d963a7c3SAdrian Prantl         } else if (*byte_size <= sizeof(long long)) {
834a1e5dc86SGreg Clayton           value = (long long)sval64;
835a1e5dc86SGreg Clayton           return true;
836b9c1b51eSKate Stone         } else
837a1e5dc86SGreg Clayton           value.Clear();
838a1e5dc86SGreg Clayton       }
839a1e5dc86SGreg Clayton       break;
840a1e5dc86SGreg Clayton 
841a1e5dc86SGreg Clayton     case lldb::eEncodingIEEE754:
842d963a7c3SAdrian Prantl       if (*byte_size <= sizeof(long double)) {
843a1e5dc86SGreg Clayton         uint32_t u32;
844a1e5dc86SGreg Clayton         uint64_t u64;
845d963a7c3SAdrian Prantl         if (*byte_size == sizeof(float)) {
846b9c1b51eSKate Stone           if (sizeof(float) == sizeof(uint32_t)) {
847a1e5dc86SGreg Clayton             u32 = data.GetU32(&offset);
848a1e5dc86SGreg Clayton             value = *((float *)&u32);
849a1e5dc86SGreg Clayton             return true;
850b9c1b51eSKate Stone           } else if (sizeof(float) == sizeof(uint64_t)) {
851a1e5dc86SGreg Clayton             u64 = data.GetU64(&offset);
852a1e5dc86SGreg Clayton             value = *((float *)&u64);
853a1e5dc86SGreg Clayton             return true;
854a1e5dc86SGreg Clayton           }
855d963a7c3SAdrian Prantl         } else if (*byte_size == sizeof(double)) {
856b9c1b51eSKate Stone           if (sizeof(double) == sizeof(uint32_t)) {
857a1e5dc86SGreg Clayton             u32 = data.GetU32(&offset);
858a1e5dc86SGreg Clayton             value = *((double *)&u32);
859a1e5dc86SGreg Clayton             return true;
860b9c1b51eSKate Stone           } else if (sizeof(double) == sizeof(uint64_t)) {
861a1e5dc86SGreg Clayton             u64 = data.GetU64(&offset);
862a1e5dc86SGreg Clayton             value = *((double *)&u64);
863a1e5dc86SGreg Clayton             return true;
864a1e5dc86SGreg Clayton           }
865d963a7c3SAdrian Prantl         } else if (*byte_size == sizeof(long double)) {
866b9c1b51eSKate Stone           if (sizeof(long double) == sizeof(uint32_t)) {
867a1e5dc86SGreg Clayton             u32 = data.GetU32(&offset);
868a1e5dc86SGreg Clayton             value = *((long double *)&u32);
869a1e5dc86SGreg Clayton             return true;
870b9c1b51eSKate Stone           } else if (sizeof(long double) == sizeof(uint64_t)) {
871a1e5dc86SGreg Clayton             u64 = data.GetU64(&offset);
872a1e5dc86SGreg Clayton             value = *((long double *)&u64);
873a1e5dc86SGreg Clayton             return true;
874a1e5dc86SGreg Clayton           }
875a1e5dc86SGreg Clayton         }
876a1e5dc86SGreg Clayton       }
877a1e5dc86SGreg Clayton       break;
878a1e5dc86SGreg Clayton     }
879a1e5dc86SGreg Clayton   }
880a1e5dc86SGreg Clayton   return false;
881a1e5dc86SGreg Clayton }
882a1e5dc86SGreg Clayton 
883ea960371SAdrian Prantl #ifndef NDEBUG
Verify() const884ea960371SAdrian Prantl bool CompilerType::Verify() const {
885ea960371SAdrian Prantl   return !IsValid() || m_type_system->Verify(m_type);
886ea960371SAdrian Prantl }
887ea960371SAdrian Prantl #endif
888ea960371SAdrian Prantl 
operator ==(const lldb_private::CompilerType & lhs,const lldb_private::CompilerType & rhs)889b9c1b51eSKate Stone bool lldb_private::operator==(const lldb_private::CompilerType &lhs,
890b9c1b51eSKate Stone                               const lldb_private::CompilerType &rhs) {
891b9c1b51eSKate Stone   return lhs.GetTypeSystem() == rhs.GetTypeSystem() &&
892b9c1b51eSKate Stone          lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
893a1e5dc86SGreg Clayton }
894a1e5dc86SGreg Clayton 
operator !=(const lldb_private::CompilerType & lhs,const lldb_private::CompilerType & rhs)895b9c1b51eSKate Stone bool lldb_private::operator!=(const lldb_private::CompilerType &lhs,
896b9c1b51eSKate Stone                               const lldb_private::CompilerType &rhs) {
897223032f7SDavide Italiano   return !(lhs == rhs);
898a1e5dc86SGreg Clayton }
899