]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - source/Symbol/CompilerType.cpp
Vendor import of lldb release_39 branch r276489:
[FreeBSD/FreeBSD.git] / source / Symbol / CompilerType.cpp
1 //===-- CompilerType.cpp ----------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Symbol/CompilerType.h"
11
12 #include "lldb/Core/ConstString.h"
13 #include "lldb/Core/DataBufferHeap.h"
14 #include "lldb/Core/DataExtractor.h"
15 #include "lldb/Core/Debugger.h"
16 #include "lldb/Core/Scalar.h"
17 #include "lldb/Core/Stream.h"
18 #include "lldb/Core/StreamFile.h"
19 #include "lldb/Core/StreamString.h"
20 #include "lldb/Symbol/ClangASTContext.h"
21 #include "lldb/Symbol/ClangExternalASTSourceCommon.h"
22 #include "lldb/Symbol/Type.h"
23 #include "lldb/Target/ExecutionContext.h"
24 #include "lldb/Target/Process.h"
25
26 #include <iterator>
27 #include <mutex>
28
29 using namespace lldb;
30 using namespace lldb_private;
31
32 CompilerType::CompilerType (TypeSystem *type_system,
33                             lldb::opaque_compiler_type_t type) :
34     m_type (type),
35     m_type_system (type_system)
36 {
37 }
38
39 CompilerType::CompilerType (clang::ASTContext *ast,
40                             clang::QualType qual_type) :
41     m_type (qual_type.getAsOpaquePtr()),
42     m_type_system (ClangASTContext::GetASTContext(ast))
43 {
44 #ifdef LLDB_CONFIGURATION_DEBUG
45     if (m_type)
46         assert(m_type_system != nullptr);
47 #endif
48 }
49
50 CompilerType::~CompilerType()
51 {
52 }
53
54 //----------------------------------------------------------------------
55 // Tests
56 //----------------------------------------------------------------------
57
58 bool
59 CompilerType::IsAggregateType () const
60 {
61     if (IsValid())
62         return m_type_system->IsAggregateType(m_type);
63     return false;
64 }
65
66 bool
67 CompilerType::IsAnonymousType () const
68 {
69     if (IsValid())
70         return m_type_system->IsAnonymousType(m_type);
71     return false;
72 }
73
74 bool
75 CompilerType::IsArrayType (CompilerType *element_type_ptr,
76                            uint64_t *size,
77                            bool *is_incomplete) const
78 {
79     if (IsValid())
80         return m_type_system->IsArrayType(m_type, element_type_ptr, size, is_incomplete);
81
82     if (element_type_ptr)
83         element_type_ptr->Clear();
84     if (size)
85         *size = 0;
86     if (is_incomplete)
87         *is_incomplete = false;
88     return false;
89 }
90
91 bool
92 CompilerType::IsVectorType (CompilerType *element_type,
93                             uint64_t *size) const
94 {
95     if (IsValid())
96         return m_type_system->IsVectorType(m_type, element_type, size);
97     return false;
98 }
99
100 bool
101 CompilerType::IsRuntimeGeneratedType () const
102 {
103     if (IsValid())
104         return m_type_system->IsRuntimeGeneratedType(m_type);
105     return false;
106 }
107
108 bool
109 CompilerType::IsCharType () const
110 {
111     if (IsValid())
112         return m_type_system->IsCharType(m_type);
113     return false;
114 }
115
116
117 bool
118 CompilerType::IsCompleteType () const
119 {
120     if (IsValid())
121         return m_type_system->IsCompleteType(m_type);
122     return false;
123 }
124
125 bool
126 CompilerType::IsConst() const
127 {
128     if (IsValid())
129         return m_type_system->IsConst(m_type);
130     return false;
131 }
132
133 bool
134 CompilerType::IsCStringType (uint32_t &length) const
135 {
136     if (IsValid())
137         return m_type_system->IsCStringType(m_type, length);
138     return false;
139 }
140
141 bool
142 CompilerType::IsFunctionType (bool *is_variadic_ptr) const
143 {
144     if (IsValid())
145         return m_type_system->IsFunctionType(m_type, is_variadic_ptr);
146     return false;
147 }
148
149 // Used to detect "Homogeneous Floating-point Aggregates"
150 uint32_t
151 CompilerType::IsHomogeneousAggregate (CompilerType* base_type_ptr) const
152 {
153     if (IsValid())
154         return m_type_system->IsHomogeneousAggregate(m_type, base_type_ptr);
155     return 0;
156 }
157
158 size_t
159 CompilerType::GetNumberOfFunctionArguments () const
160 {
161     if (IsValid())
162         return m_type_system->GetNumberOfFunctionArguments(m_type);
163     return 0;
164 }
165
166 CompilerType
167 CompilerType::GetFunctionArgumentAtIndex (const size_t index) const
168 {
169     if (IsValid())
170         return m_type_system->GetFunctionArgumentAtIndex(m_type, index);
171     return CompilerType();
172 }
173
174 bool
175 CompilerType::IsFunctionPointerType () const
176 {
177     if (IsValid())
178         return m_type_system->IsFunctionPointerType(m_type);
179     return false;
180 }
181
182 bool
183 CompilerType::IsBlockPointerType (CompilerType *function_pointer_type_ptr) const
184 {
185     if (IsValid())
186         return m_type_system->IsBlockPointerType(m_type, function_pointer_type_ptr);
187     return 0;
188 }
189
190 bool
191 CompilerType::IsIntegerType (bool &is_signed) const
192 {
193     if (IsValid())
194         return m_type_system->IsIntegerType(m_type, is_signed);
195     return false;
196 }
197
198 bool
199 CompilerType::IsEnumerationType (bool &is_signed) const
200 {
201     if (IsValid())
202         return m_type_system->IsEnumerationType(m_type, is_signed);
203     return false;
204 }
205
206 bool
207 CompilerType::IsIntegerOrEnumerationType (bool &is_signed) const
208 {
209     return IsIntegerType(is_signed) || IsEnumerationType(is_signed);
210 }
211
212 bool
213 CompilerType::IsPointerType (CompilerType *pointee_type) const
214 {
215     if (IsValid())
216     {
217         return m_type_system->IsPointerType(m_type, pointee_type);
218     }
219     if (pointee_type)
220         pointee_type->Clear();
221     return false;
222 }
223
224
225 bool
226 CompilerType::IsPointerOrReferenceType (CompilerType *pointee_type) const
227 {
228     if (IsValid())
229     {
230         return m_type_system->IsPointerOrReferenceType(m_type, pointee_type);
231     }
232     if (pointee_type)
233         pointee_type->Clear();
234     return false;
235 }
236
237
238 bool
239 CompilerType::IsReferenceType (CompilerType *pointee_type, bool* is_rvalue) const
240 {
241     if (IsValid())
242     {
243         return m_type_system->IsReferenceType(m_type, pointee_type, is_rvalue);
244     }
245     if (pointee_type)
246         pointee_type->Clear();
247     return false;
248 }
249
250 bool
251 CompilerType::ShouldTreatScalarValueAsAddress () const
252 {
253     if (IsValid())
254         return m_type_system->ShouldTreatScalarValueAsAddress(m_type);
255     return false;
256 }
257
258 bool
259 CompilerType::IsFloatingPointType (uint32_t &count, bool &is_complex) const
260 {
261     if (IsValid())
262     {
263         return m_type_system->IsFloatingPointType(m_type, count, is_complex);
264     }
265     count = 0;
266     is_complex = false;
267     return false;
268 }
269
270
271 bool
272 CompilerType::IsDefined() const
273 {
274     if (IsValid())
275         return m_type_system->IsDefined(m_type);
276     return true;
277 }
278
279 bool
280 CompilerType::IsPolymorphicClass () const
281 {
282     if (IsValid())
283     {
284         return m_type_system->IsPolymorphicClass(m_type);
285     }
286     return false;
287 }
288
289 bool
290 CompilerType::IsPossibleDynamicType (CompilerType *dynamic_pointee_type,
291                                      bool check_cplusplus,
292                                      bool check_objc) const
293 {
294     if (IsValid())
295         return m_type_system->IsPossibleDynamicType(m_type, dynamic_pointee_type, check_cplusplus, check_objc);
296     return false;
297 }
298
299
300 bool
301 CompilerType::IsScalarType () const
302 {
303     if (!IsValid())
304         return false;
305
306     return m_type_system->IsScalarType(m_type);
307 }
308
309 bool
310 CompilerType::IsTypedefType () const
311 {
312     if (!IsValid())
313         return false;
314     return m_type_system->IsTypedefType(m_type);
315 }
316
317 bool
318 CompilerType::IsVoidType () const
319 {
320     if (!IsValid())
321         return false;
322     return m_type_system->IsVoidType(m_type);
323 }
324
325 bool
326 CompilerType::IsPointerToScalarType () const
327 {
328     if (!IsValid())
329         return false;
330     
331     return IsPointerType() && GetPointeeType().IsScalarType();
332 }
333
334 bool
335 CompilerType::IsArrayOfScalarType () const
336 {
337     CompilerType element_type;
338     if (IsArrayType(&element_type, nullptr, nullptr))
339         return element_type.IsScalarType();
340     return false;
341 }
342
343 bool
344 CompilerType::IsBeingDefined () const
345 {
346     if (!IsValid())
347         return false;
348     return m_type_system->IsBeingDefined(m_type);
349 }
350
351 //----------------------------------------------------------------------
352 // Type Completion
353 //----------------------------------------------------------------------
354
355 bool
356 CompilerType::GetCompleteType () const
357 {
358     if (!IsValid())
359         return false;
360     return m_type_system->GetCompleteType(m_type);
361 }
362
363 //----------------------------------------------------------------------
364 // AST related queries
365 //----------------------------------------------------------------------
366 size_t
367 CompilerType::GetPointerByteSize () const
368 {
369     if (m_type_system)
370         return m_type_system->GetPointerByteSize();
371     return 0;
372 }
373
374 ConstString
375 CompilerType::GetConstQualifiedTypeName () const
376 {
377     return GetConstTypeName ();
378 }
379
380 ConstString
381 CompilerType::GetConstTypeName () const
382 {
383     if (IsValid())
384     {
385         ConstString type_name (GetTypeName());
386         if (type_name)
387             return type_name;
388     }
389     return ConstString("<invalid>");
390 }
391
392 ConstString
393 CompilerType::GetTypeName () const
394 {
395     if (IsValid())
396     {
397         return m_type_system->GetTypeName(m_type);
398     }
399     return ConstString("<invalid>");
400 }
401
402 ConstString
403 CompilerType::GetDisplayTypeName () const
404 {
405     return GetTypeName();
406 }
407
408 uint32_t
409 CompilerType::GetTypeInfo (CompilerType *pointee_or_element_compiler_type) const
410 {
411     if (!IsValid())
412         return 0;
413     
414     return m_type_system->GetTypeInfo(m_type, pointee_or_element_compiler_type);
415 }
416
417
418
419 lldb::LanguageType
420 CompilerType::GetMinimumLanguage ()
421 {
422     if (!IsValid())
423         return lldb::eLanguageTypeC;
424     
425     return m_type_system->GetMinimumLanguage(m_type);
426 }
427
428 lldb::TypeClass
429 CompilerType::GetTypeClass () const
430 {
431     if (!IsValid())
432         return lldb::eTypeClassInvalid;
433     
434     return m_type_system->GetTypeClass(m_type);
435     
436 }
437
438 void
439 CompilerType::SetCompilerType (TypeSystem* type_system, lldb::opaque_compiler_type_t type)
440 {
441     m_type_system = type_system;
442     m_type = type;
443 }
444
445 void
446 CompilerType::SetCompilerType (clang::ASTContext *ast, clang::QualType qual_type)
447 {
448     m_type_system = ClangASTContext::GetASTContext(ast);
449     m_type = qual_type.getAsOpaquePtr();
450 }
451
452 unsigned
453 CompilerType::GetTypeQualifiers() const
454 {
455     if (IsValid())
456         return m_type_system->GetTypeQualifiers(m_type);
457     return 0;
458 }
459
460 //----------------------------------------------------------------------
461 // Creating related types
462 //----------------------------------------------------------------------
463
464 CompilerType
465 CompilerType::GetArrayElementType (uint64_t *stride) const
466 {
467     if (IsValid())
468     {
469         return m_type_system->GetArrayElementType(m_type, stride);
470         
471     }
472     return CompilerType();
473 }
474
475 CompilerType
476 CompilerType::GetCanonicalType () const
477 {
478     if (IsValid())
479         return m_type_system->GetCanonicalType(m_type);
480     return CompilerType();
481 }
482
483 CompilerType
484 CompilerType::GetFullyUnqualifiedType () const
485 {
486     if (IsValid())
487         return m_type_system->GetFullyUnqualifiedType(m_type);
488     return CompilerType();
489 }
490
491
492 int
493 CompilerType::GetFunctionArgumentCount () const
494 {
495     if (IsValid())
496     {
497         return m_type_system->GetFunctionArgumentCount(m_type);
498     }
499     return -1;
500 }
501
502 CompilerType
503 CompilerType::GetFunctionArgumentTypeAtIndex (size_t idx) const
504 {
505     if (IsValid())
506     {
507         return m_type_system->GetFunctionArgumentTypeAtIndex(m_type, idx);
508     }
509     return CompilerType();
510 }
511
512 CompilerType
513 CompilerType::GetFunctionReturnType () const
514 {
515     if (IsValid())
516     {
517         return m_type_system->GetFunctionReturnType(m_type);
518     }
519     return CompilerType();
520 }
521
522 size_t
523 CompilerType::GetNumMemberFunctions () const
524 {
525     if (IsValid())
526     {
527         return m_type_system->GetNumMemberFunctions(m_type);
528     }
529     return 0;
530 }
531
532 TypeMemberFunctionImpl
533 CompilerType::GetMemberFunctionAtIndex (size_t idx)
534 {
535     if (IsValid())
536     {
537         return m_type_system->GetMemberFunctionAtIndex(m_type, idx);
538     }
539     return TypeMemberFunctionImpl();
540 }
541
542 CompilerType
543 CompilerType::GetNonReferenceType () const
544 {
545     if (IsValid())
546         return m_type_system->GetNonReferenceType(m_type);
547     return CompilerType();
548 }
549
550 CompilerType
551 CompilerType::GetPointeeType () const
552 {
553     if (IsValid())
554     {
555         return m_type_system->GetPointeeType(m_type);
556     }
557     return CompilerType();
558 }
559
560 CompilerType
561 CompilerType::GetPointerType () const
562 {
563     if (IsValid())
564     {
565         return m_type_system->GetPointerType(m_type);
566     }
567     return CompilerType();
568 }
569
570 CompilerType
571 CompilerType::GetLValueReferenceType () const
572 {
573     if (IsValid())
574         return m_type_system->GetLValueReferenceType(m_type);
575     else
576         return CompilerType();
577 }
578
579 CompilerType
580 CompilerType::GetRValueReferenceType () const
581 {
582     if (IsValid())
583         return m_type_system->GetRValueReferenceType(m_type);
584     else
585         return CompilerType();
586 }
587
588 CompilerType
589 CompilerType::AddConstModifier () const
590 {
591     if (IsValid())
592         return m_type_system->AddConstModifier(m_type);
593     else
594         return CompilerType();
595 }
596
597 CompilerType
598 CompilerType::AddVolatileModifier () const
599 {
600     if (IsValid())
601         return m_type_system->AddVolatileModifier(m_type);
602     else
603         return CompilerType();
604 }
605
606 CompilerType
607 CompilerType::AddRestrictModifier () const
608 {
609     if (IsValid())
610         return m_type_system->AddRestrictModifier(m_type);
611     else
612         return CompilerType();
613 }
614
615 CompilerType
616 CompilerType::CreateTypedef (const char *name, const CompilerDeclContext &decl_ctx) const
617 {
618     if (IsValid())
619         return m_type_system->CreateTypedef(m_type, name, decl_ctx);
620     else
621         return CompilerType();
622 }
623
624 CompilerType
625 CompilerType::GetTypedefedType () const
626 {
627     if (IsValid())
628         return m_type_system->GetTypedefedType(m_type);
629     else
630         return CompilerType();
631 }
632
633 //----------------------------------------------------------------------
634 // Create related types using the current type's AST
635 //----------------------------------------------------------------------
636
637 CompilerType
638 CompilerType::GetBasicTypeFromAST (lldb::BasicType basic_type) const
639 {
640     if (IsValid())
641         return m_type_system->GetBasicTypeFromAST(basic_type);
642     return CompilerType();
643 }
644 //----------------------------------------------------------------------
645 // Exploring the type
646 //----------------------------------------------------------------------
647
648 uint64_t
649 CompilerType::GetBitSize (ExecutionContextScope *exe_scope) const
650 {
651     if (IsValid())
652     {
653         return m_type_system->GetBitSize(m_type, exe_scope);
654     }
655     return 0;
656 }
657
658 uint64_t
659 CompilerType::GetByteSize (ExecutionContextScope *exe_scope) const
660 {
661     return (GetBitSize (exe_scope) + 7) / 8;
662 }
663
664
665 size_t
666 CompilerType::GetTypeBitAlign () const
667 {
668     if (IsValid())
669         return m_type_system->GetTypeBitAlign(m_type);
670     return 0;
671 }
672
673
674 lldb::Encoding
675 CompilerType::GetEncoding (uint64_t &count) const
676 {
677     if (!IsValid())
678         return lldb::eEncodingInvalid;
679     
680     return m_type_system->GetEncoding(m_type, count);
681 }
682
683 lldb::Format
684 CompilerType::GetFormat () const
685 {
686     if (!IsValid())
687         return lldb::eFormatDefault;
688     
689     return m_type_system->GetFormat(m_type);
690 }
691
692 uint32_t
693 CompilerType::GetNumChildren (bool omit_empty_base_classes) const
694 {
695     if (!IsValid())
696         return 0;
697     return m_type_system->GetNumChildren(m_type, omit_empty_base_classes);
698 }
699
700 lldb::BasicType
701 CompilerType::GetBasicTypeEnumeration () const
702 {
703     if (IsValid())
704         return m_type_system->GetBasicTypeEnumeration(m_type);
705     return eBasicTypeInvalid;
706 }
707
708 void
709 CompilerType::ForEachEnumerator (std::function <bool (const CompilerType &integer_type, const ConstString &name, const llvm::APSInt &value)> const &callback) const
710 {
711     if (IsValid())
712         return m_type_system->ForEachEnumerator (m_type, callback);
713 }
714
715
716 uint32_t
717 CompilerType::GetNumFields () const
718 {
719     if (!IsValid())
720         return 0;
721     return m_type_system->GetNumFields(m_type);
722 }
723
724 CompilerType
725 CompilerType::GetFieldAtIndex (size_t idx,
726                                std::string& name,
727                                uint64_t *bit_offset_ptr,
728                                uint32_t *bitfield_bit_size_ptr,
729                                bool *is_bitfield_ptr) const
730 {
731     if (!IsValid())
732         return CompilerType();
733     return m_type_system->GetFieldAtIndex(m_type, idx, name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr);
734 }
735
736 uint32_t
737 CompilerType::GetNumDirectBaseClasses () const
738 {
739     if (IsValid())
740         return m_type_system->GetNumDirectBaseClasses (m_type);
741     return 0;
742 }
743
744 uint32_t
745 CompilerType::GetNumVirtualBaseClasses () const
746 {
747     if (IsValid())
748         return m_type_system->GetNumVirtualBaseClasses (m_type);
749     return 0;
750 }
751
752 CompilerType
753 CompilerType::GetDirectBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
754 {
755     if (IsValid())
756         return m_type_system->GetDirectBaseClassAtIndex (m_type, idx, bit_offset_ptr);
757     return CompilerType();
758 }
759
760 CompilerType
761 CompilerType::GetVirtualBaseClassAtIndex (size_t idx, uint32_t *bit_offset_ptr) const
762 {
763     if (IsValid())
764         return m_type_system->GetVirtualBaseClassAtIndex (m_type, idx, bit_offset_ptr);
765     return CompilerType();
766 }
767
768 uint32_t
769 CompilerType::GetIndexOfFieldWithName (const char* name,
770                                        CompilerType* field_compiler_type_ptr,
771                                        uint64_t *bit_offset_ptr,
772                                        uint32_t *bitfield_bit_size_ptr,
773                                        bool *is_bitfield_ptr) const
774 {
775     unsigned count = GetNumFields();
776     std::string field_name;
777     for (unsigned index = 0; index < count; index++)
778     {
779         CompilerType field_compiler_type (GetFieldAtIndex(index, field_name, bit_offset_ptr, bitfield_bit_size_ptr, is_bitfield_ptr));
780         if (strcmp(field_name.c_str(), name) == 0)
781         {
782             if (field_compiler_type_ptr)
783                 *field_compiler_type_ptr = field_compiler_type;
784             return index;
785         }
786     }
787     return UINT32_MAX;
788 }
789
790
791 CompilerType
792 CompilerType::GetChildCompilerTypeAtIndex (ExecutionContext *exe_ctx,
793                                            size_t idx,
794                                            bool transparent_pointers,
795                                            bool omit_empty_base_classes,
796                                            bool ignore_array_bounds,
797                                            std::string& child_name,
798                                            uint32_t &child_byte_size,
799                                            int32_t &child_byte_offset,
800                                            uint32_t &child_bitfield_bit_size,
801                                            uint32_t &child_bitfield_bit_offset,
802                                            bool &child_is_base_class,
803                                            bool &child_is_deref_of_parent,
804                                            ValueObject *valobj,
805                                            uint64_t &language_flags) const
806 {
807     if (!IsValid())
808         return CompilerType();
809     return m_type_system->GetChildCompilerTypeAtIndex(m_type,
810                                                       exe_ctx,
811                                                       idx,
812                                                       transparent_pointers,
813                                                       omit_empty_base_classes,
814                                                       ignore_array_bounds,
815                                                       child_name,
816                                                       child_byte_size,
817                                                       child_byte_offset,
818                                                       child_bitfield_bit_size,
819                                                       child_bitfield_bit_offset,
820                                                       child_is_base_class,
821                                                       child_is_deref_of_parent,
822                                                       valobj,
823                                                       language_flags);
824 }
825
826 // Look for a child member (doesn't include base classes, but it does include
827 // their members) in the type hierarchy. Returns an index path into "clang_type"
828 // on how to reach the appropriate member.
829 //
830 //    class A
831 //    {
832 //    public:
833 //        int m_a;
834 //        int m_b;
835 //    };
836 //
837 //    class B
838 //    {
839 //    };
840 //
841 //    class C :
842 //        public B,
843 //        public A
844 //    {
845 //    };
846 //
847 // If we have a clang type that describes "class C", and we wanted to looked
848 // "m_b" in it:
849 //
850 // With omit_empty_base_classes == false we would get an integer array back with:
851 // { 1,  1 }
852 // The first index 1 is the child index for "class A" within class C
853 // The second index 1 is the child index for "m_b" within class A
854 //
855 // With omit_empty_base_classes == true we would get an integer array back with:
856 // { 0,  1 }
857 // The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count)
858 // The second index 1 is the child index for "m_b" within class A
859
860 size_t
861 CompilerType::GetIndexOfChildMemberWithName (const char *name,
862                                              bool omit_empty_base_classes,
863                                              std::vector<uint32_t>& child_indexes) const
864 {
865     if (IsValid() && name && name[0])
866     {
867         return m_type_system->GetIndexOfChildMemberWithName(m_type, name, omit_empty_base_classes, child_indexes);
868     }
869     return 0;
870 }
871
872 size_t
873 CompilerType::GetNumTemplateArguments () const
874 {
875     if (IsValid())
876     {
877         return m_type_system->GetNumTemplateArguments(m_type);
878     }
879     return 0;
880 }
881
882 CompilerType
883 CompilerType::GetTemplateArgument (size_t idx,
884                                    lldb::TemplateArgumentKind &kind) const
885 {
886     if (IsValid())
887     {
888         return m_type_system->GetTemplateArgument(m_type, idx, kind);
889     }
890     return CompilerType();
891 }
892
893 CompilerType
894 CompilerType::GetTypeForFormatters () const
895 {
896     if (IsValid())
897         return m_type_system->GetTypeForFormatters(m_type);
898     return CompilerType();
899 }
900
901 LazyBool
902 CompilerType::ShouldPrintAsOneLiner (ValueObject* valobj) const
903 {
904     if (IsValid())
905         return m_type_system->ShouldPrintAsOneLiner(m_type, valobj);
906     return eLazyBoolCalculate;
907 }
908
909 bool
910 CompilerType::IsMeaninglessWithoutDynamicResolution () const
911 {
912     if (IsValid())
913         return m_type_system->IsMeaninglessWithoutDynamicResolution(m_type);
914     return false;
915 }
916
917 // Get the index of the child of "clang_type" whose name matches. This function
918 // doesn't descend into the children, but only looks one level deep and name
919 // matches can include base class names.
920
921 uint32_t
922 CompilerType::GetIndexOfChildWithName (const char *name, bool omit_empty_base_classes) const
923 {
924     if (IsValid() && name && name[0])
925     {
926         return m_type_system->GetIndexOfChildWithName(m_type, name, omit_empty_base_classes);
927     }
928     return UINT32_MAX;
929 }
930
931 size_t
932 CompilerType::ConvertStringToFloatValue (const char *s, uint8_t *dst, size_t dst_size) const
933 {
934     if (IsValid())
935         return m_type_system->ConvertStringToFloatValue(m_type, s, dst, dst_size);
936     return 0;
937 }
938
939
940
941 //----------------------------------------------------------------------
942 // Dumping types
943 //----------------------------------------------------------------------
944 #define DEPTH_INCREMENT 2
945
946 void
947 CompilerType::DumpValue (ExecutionContext *exe_ctx,
948                          Stream *s,
949                          lldb::Format format,
950                          const lldb_private::DataExtractor &data,
951                          lldb::offset_t data_byte_offset,
952                          size_t data_byte_size,
953                          uint32_t bitfield_bit_size,
954                          uint32_t bitfield_bit_offset,
955                          bool show_types,
956                          bool show_summary,
957                          bool verbose,
958                          uint32_t depth)
959 {
960     if (!IsValid())
961         return;
962     m_type_system->DumpValue(m_type, exe_ctx, s, format, data, data_byte_offset, data_byte_size, bitfield_bit_size, bitfield_bit_offset, show_types, show_summary, verbose, depth);
963 }
964
965
966
967
968 bool
969 CompilerType::DumpTypeValue (Stream *s,
970                              lldb::Format format,
971                              const lldb_private::DataExtractor &data,
972                              lldb::offset_t byte_offset,
973                              size_t byte_size,
974                              uint32_t bitfield_bit_size,
975                              uint32_t bitfield_bit_offset,
976                              ExecutionContextScope *exe_scope)
977 {
978     if (!IsValid())
979         return false;
980     return m_type_system->DumpTypeValue(m_type, s, format, data, byte_offset, byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope);
981 }
982
983
984
985 void
986 CompilerType::DumpSummary (ExecutionContext *exe_ctx,
987                            Stream *s,
988                            const lldb_private::DataExtractor &data,
989                            lldb::offset_t data_byte_offset,
990                            size_t data_byte_size)
991 {
992     if (IsValid())
993         m_type_system->DumpSummary(m_type, exe_ctx, s, data, data_byte_offset, data_byte_size);
994 }
995
996 void
997 CompilerType::DumpTypeDescription () const
998 {
999     if (IsValid())
1000         m_type_system->DumpTypeDescription(m_type);
1001 }
1002
1003 void
1004 CompilerType::DumpTypeDescription (Stream *s) const
1005 {
1006     if (IsValid())
1007     {
1008         m_type_system->DumpTypeDescription(m_type, s);
1009     }
1010 }
1011
1012 bool
1013 CompilerType::GetValueAsScalar (const lldb_private::DataExtractor &data,
1014                                 lldb::offset_t data_byte_offset,
1015                                 size_t data_byte_size,
1016                                 Scalar &value) const
1017 {
1018     if (!IsValid())
1019         return false;
1020     
1021     if (IsAggregateType ())
1022     {
1023         return false;   // Aggregate types don't have scalar values
1024     }
1025     else
1026     {
1027         uint64_t count = 0;
1028         lldb::Encoding encoding = GetEncoding (count);
1029         
1030         if (encoding == lldb::eEncodingInvalid || count != 1)
1031             return false;
1032         
1033         const uint64_t byte_size = GetByteSize(nullptr);
1034         lldb::offset_t offset = data_byte_offset;
1035         switch (encoding)
1036         {
1037             case lldb::eEncodingInvalid:
1038                 break;
1039             case lldb::eEncodingVector:
1040                 break;
1041             case lldb::eEncodingUint:
1042                 if (byte_size <= sizeof(unsigned long long))
1043                 {
1044                     uint64_t uval64 = data.GetMaxU64 (&offset, byte_size);
1045                     if (byte_size <= sizeof(unsigned int))
1046                     {
1047                         value = (unsigned int)uval64;
1048                         return true;
1049                     }
1050                     else if (byte_size <= sizeof(unsigned long))
1051                     {
1052                         value = (unsigned long)uval64;
1053                         return true;
1054                     }
1055                     else if (byte_size <= sizeof(unsigned long long))
1056                     {
1057                         value = (unsigned long long )uval64;
1058                         return true;
1059                     }
1060                     else
1061                         value.Clear();
1062                 }
1063                 break;
1064                 
1065             case lldb::eEncodingSint:
1066                 if (byte_size <= sizeof(long long))
1067                 {
1068                     int64_t sval64 = data.GetMaxS64 (&offset, byte_size);
1069                     if (byte_size <= sizeof(int))
1070                     {
1071                         value = (int)sval64;
1072                         return true;
1073                     }
1074                     else if (byte_size <= sizeof(long))
1075                     {
1076                         value = (long)sval64;
1077                         return true;
1078                     }
1079                     else if (byte_size <= sizeof(long long))
1080                     {
1081                         value = (long long )sval64;
1082                         return true;
1083                     }
1084                     else
1085                         value.Clear();
1086                 }
1087                 break;
1088                 
1089             case lldb::eEncodingIEEE754:
1090                 if (byte_size <= sizeof(long double))
1091                 {
1092                     uint32_t u32;
1093                     uint64_t u64;
1094                     if (byte_size == sizeof(float))
1095                     {
1096                         if (sizeof(float) == sizeof(uint32_t))
1097                         {
1098                             u32 = data.GetU32(&offset);
1099                             value = *((float *)&u32);
1100                             return true;
1101                         }
1102                         else if (sizeof(float) == sizeof(uint64_t))
1103                         {
1104                             u64 = data.GetU64(&offset);
1105                             value = *((float *)&u64);
1106                             return true;
1107                         }
1108                     }
1109                     else
1110                         if (byte_size == sizeof(double))
1111                         {
1112                             if (sizeof(double) == sizeof(uint32_t))
1113                             {
1114                                 u32 = data.GetU32(&offset);
1115                                 value = *((double *)&u32);
1116                                 return true;
1117                             }
1118                             else if (sizeof(double) == sizeof(uint64_t))
1119                             {
1120                                 u64 = data.GetU64(&offset);
1121                                 value = *((double *)&u64);
1122                                 return true;
1123                             }
1124                         }
1125                         else
1126                             if (byte_size == sizeof(long double))
1127                             {
1128                                 if (sizeof(long double) == sizeof(uint32_t))
1129                                 {
1130                                     u32 = data.GetU32(&offset);
1131                                     value = *((long double *)&u32);
1132                                     return true;
1133                                 }
1134                                 else if (sizeof(long double) == sizeof(uint64_t))
1135                                 {
1136                                     u64 = data.GetU64(&offset);
1137                                     value = *((long double *)&u64);
1138                                     return true;
1139                                 }
1140                             }
1141                 }
1142                 break;
1143         }
1144     }
1145     return false;
1146 }
1147
1148 bool
1149 CompilerType::SetValueFromScalar (const Scalar &value, Stream &strm)
1150 {
1151     if (!IsValid())
1152         return false;
1153
1154     // Aggregate types don't have scalar values
1155     if (!IsAggregateType ())
1156     {
1157         strm.GetFlags().Set(Stream::eBinary);
1158         uint64_t count = 0;
1159         lldb::Encoding encoding = GetEncoding (count);
1160         
1161         if (encoding == lldb::eEncodingInvalid || count != 1)
1162             return false;
1163         
1164         const uint64_t bit_width = GetBitSize(nullptr);
1165         // This function doesn't currently handle non-byte aligned assignments
1166         if ((bit_width % 8) != 0)
1167             return false;
1168         
1169         const uint64_t byte_size = (bit_width + 7 ) / 8;
1170         switch (encoding)
1171         {
1172             case lldb::eEncodingInvalid:
1173                 break;
1174             case lldb::eEncodingVector:
1175                 break;
1176             case lldb::eEncodingUint:
1177                 switch (byte_size)
1178             {
1179                 case 1: strm.PutHex8(value.UInt()); return true;
1180                 case 2: strm.PutHex16(value.UInt()); return true;
1181                 case 4: strm.PutHex32(value.UInt()); return true;
1182                 case 8: strm.PutHex64(value.ULongLong()); return true;
1183                 default:
1184                     break;
1185             }
1186                 break;
1187                 
1188             case lldb::eEncodingSint:
1189                 switch (byte_size)
1190             {
1191                 case 1: strm.PutHex8(value.SInt()); return true;
1192                 case 2: strm.PutHex16(value.SInt()); return true;
1193                 case 4: strm.PutHex32(value.SInt()); return true;
1194                 case 8: strm.PutHex64(value.SLongLong()); return true;
1195                 default:
1196                     break;
1197             }
1198                 break;
1199                 
1200             case lldb::eEncodingIEEE754:
1201                 if (byte_size <= sizeof(long double))
1202                 {
1203                     if (byte_size == sizeof(float))
1204                     {
1205                         strm.PutFloat(value.Float());
1206                         return true;
1207                     }
1208                     else
1209                         if (byte_size == sizeof(double))
1210                         {
1211                             strm.PutDouble(value.Double());
1212                             return true;
1213                         }
1214                         else
1215                             if (byte_size == sizeof(long double))
1216                             {
1217                                 strm.PutDouble(value.LongDouble());
1218                                 return true;
1219                             }
1220                 }
1221                 break;
1222         }
1223     }
1224     return false;
1225 }
1226
1227 bool
1228 CompilerType::ReadFromMemory (lldb_private::ExecutionContext *exe_ctx,
1229                               lldb::addr_t addr,
1230                               AddressType address_type,
1231                               lldb_private::DataExtractor &data)
1232 {
1233     if (!IsValid())
1234         return false;
1235     
1236     // Can't convert a file address to anything valid without more
1237     // context (which Module it came from)
1238     if (address_type == eAddressTypeFile)
1239         return false;
1240     
1241     if (!GetCompleteType())
1242         return false;
1243     
1244     const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
1245     if (data.GetByteSize() < byte_size)
1246     {
1247         lldb::DataBufferSP data_sp(new DataBufferHeap (byte_size, '\0'));
1248         data.SetData(data_sp);
1249     }
1250     
1251     uint8_t* dst = const_cast<uint8_t*>(data.PeekData(0, byte_size));
1252     if (dst != nullptr)
1253     {
1254         if (address_type == eAddressTypeHost)
1255         {
1256             if (addr == 0)
1257                 return false;
1258             // The address is an address in this process, so just copy it
1259             memcpy (dst, (uint8_t*)nullptr + addr, byte_size);
1260             return true;
1261         }
1262         else
1263         {
1264             Process *process = nullptr;
1265             if (exe_ctx)
1266                 process = exe_ctx->GetProcessPtr();
1267             if (process)
1268             {
1269                 Error error;
1270                 return process->ReadMemory(addr, dst, byte_size, error) == byte_size;
1271             }
1272         }
1273     }
1274     return false;
1275 }
1276
1277 bool
1278 CompilerType::WriteToMemory (lldb_private::ExecutionContext *exe_ctx,
1279                              lldb::addr_t addr,
1280                              AddressType address_type,
1281                              StreamString &new_value)
1282 {
1283     if (!IsValid())
1284         return false;
1285     
1286     // Can't convert a file address to anything valid without more
1287     // context (which Module it came from)
1288     if (address_type == eAddressTypeFile)
1289         return false;
1290     
1291     if (!GetCompleteType())
1292         return false;
1293     
1294     const uint64_t byte_size = GetByteSize(exe_ctx ? exe_ctx->GetBestExecutionContextScope() : NULL);
1295     
1296     if (byte_size > 0)
1297     {
1298         if (address_type == eAddressTypeHost)
1299         {
1300             // The address is an address in this process, so just copy it
1301             memcpy ((void *)addr, new_value.GetData(), byte_size);
1302             return true;
1303         }
1304         else
1305         {
1306             Process *process = nullptr;
1307             if (exe_ctx)
1308                 process = exe_ctx->GetProcessPtr();
1309             if (process)
1310             {
1311                 Error error;
1312                 return process->WriteMemory(addr, new_value.GetData(), byte_size, error) == byte_size;
1313             }
1314         }
1315     }
1316     return false;
1317 }
1318
1319 //clang::CXXRecordDecl *
1320 //CompilerType::GetAsCXXRecordDecl (lldb::opaque_compiler_type_t opaque_compiler_qual_type)
1321 //{
1322 //    if (opaque_compiler_qual_type)
1323 //        return clang::QualType::getFromOpaquePtr(opaque_compiler_qual_type)->getAsCXXRecordDecl();
1324 //    return NULL;
1325 //}
1326
1327 bool
1328 lldb_private::operator == (const lldb_private::CompilerType &lhs, const lldb_private::CompilerType &rhs)
1329 {
1330     return lhs.GetTypeSystem() == rhs.GetTypeSystem() && lhs.GetOpaqueQualType() == rhs.GetOpaqueQualType();
1331 }
1332
1333
1334 bool
1335 lldb_private::operator != (const lldb_private::CompilerType &lhs, const lldb_private::CompilerType &rhs)
1336 {
1337     return lhs.GetTypeSystem() != rhs.GetTypeSystem() || lhs.GetOpaqueQualType() != rhs.GetOpaqueQualType();
1338 }
1339
1340
1341