1 //===-- Type.h --------------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_Type_h_
11 #define liblldb_Type_h_
13 #include "lldb/lldb-private.h"
14 #include "lldb/Core/ClangForward.h"
15 #include "lldb/Core/ConstString.h"
16 #include "lldb/Core/UserID.h"
17 #include "lldb/Symbol/ClangASTType.h"
18 #include "lldb/Symbol/Declaration.h"
22 namespace lldb_private {
24 class SymbolFileType :
25 public std::enable_shared_from_this<SymbolFileType>,
29 SymbolFileType (SymbolFile &symbol_file, lldb::user_id_t uid) :
31 m_symbol_file (symbol_file)
49 SymbolFile &m_symbol_file;
50 lldb::TypeSP m_type_sp;
54 public std::enable_shared_from_this<Type>,
58 typedef enum EncodingDataTypeTag
61 eEncodingIsUID, ///< This type is the type whose UID is m_encoding_uid
62 eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added
63 eEncodingIsRestrictUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added
64 eEncodingIsVolatileUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added
65 eEncodingIsTypedefUID, ///< This type is pointer to a type whose UID is m_encoding_uid
66 eEncodingIsPointerUID, ///< This type is pointer to a type whose UID is m_encoding_uid
67 eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type whose UID is m_encoding_uid
68 eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type whose UID is m_encoding_uid
69 eEncodingIsSyntheticUID
72 typedef enum ResolveStateTag
74 eResolveStateUnresolved = 0,
75 eResolveStateForward = 1,
76 eResolveStateLayout = 2,
80 Type (lldb::user_id_t uid,
81 SymbolFile* symbol_file,
82 const ConstString &name,
84 SymbolContextScope *context,
85 lldb::user_id_t encoding_uid,
86 EncodingDataType encoding_uid_type,
87 const Declaration& decl,
88 const ClangASTType &clang_qual_type,
89 ResolveState clang_type_resolve_state);
91 // This makes an invalid type. Used for functions that return a Type when they
95 Type (const Type &rhs);
98 operator= (const Type& rhs);
101 Dump(Stream *s, bool show_context);
104 DumpTypeName(Stream *s);
108 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name);
113 return m_symbol_file;
116 GetSymbolFile() const
118 return m_symbol_file;
131 GetNumChildren (bool omit_empty_base_classes);
139 return m_encoding_uid_type != eEncodingInvalid;
145 return m_encoding_uid_type == eEncodingIsTypedefUID;
161 DumpValue(ExecutionContext *exe_ctx,
163 const DataExtractor &data,
164 uint32_t data_offset,
168 lldb::Format format = lldb::eFormatDefault);
171 DumpValueInMemory(ExecutionContext *exe_ctx,
173 lldb::addr_t address,
174 AddressType address_type,
180 ReadFromMemory (ExecutionContext *exe_ctx,
181 lldb::addr_t address,
182 AddressType address_type,
183 DataExtractor &data);
186 WriteToMemory (ExecutionContext *exe_ctx,
187 lldb::addr_t address,
188 AddressType address_type,
189 DataExtractor &data);
192 GetIsDeclaration() const;
195 SetIsDeclaration(bool b);
198 GetIsExternal() const;
201 SetIsExternal(bool b);
207 GetEncoding (uint64_t &count);
210 GetSymbolContextScope()
214 const SymbolContextScope *
215 GetSymbolContextScope() const
220 SetSymbolContextScope(SymbolContextScope *context)
225 const lldb_private::Declaration &
226 GetDeclaration () const;
228 // Get the clang type, and resolve definitions for any
229 // class/struct/union/enum types completely.
233 // Get the clang type, and resolve definitions enough so that the type could
234 // have layout performed. This allows ptrs and refs to class/struct/union/enum
235 // types remain forward declarations.
237 GetClangLayoutType ();
239 // Get the clang type and leave class/struct/union/enum types as forward
240 // declarations if they haven't already been fully defined.
242 GetClangForwardType ();
245 GetClangASTContext ();
248 Compare(const Type &a, const Type &b);
250 // From a fully qualified typename, split the type into the type basename
251 // and the remaining type scope (namespaces/classes).
253 GetTypeScopeAndBasename (const char* &name_cstr,
255 std::string &basename,
256 lldb::TypeClass &type_class);
258 SetEncodingType (Type *encoding_type)
260 m_encoding_type = encoding_type;
267 CreateClangTypedefType (Type *typedef_type, Type *base_type);
273 IsCompleteObjCClass()
275 return m_flags.is_complete_objc_class;
279 SetIsCompleteObjCClass(bool is_complete_objc_class)
281 m_flags.is_complete_objc_class = is_complete_objc_class;
286 SymbolFile *m_symbol_file;
287 SymbolContextScope *m_context; // The symbol context in which this type is defined
288 Type *m_encoding_type;
289 lldb::user_id_t m_encoding_uid;
290 EncodingDataType m_encoding_uid_type;
291 uint64_t m_byte_size;
293 ClangASTType m_clang_type;
296 ResolveState clang_type_resolve_state : 2;
297 bool is_complete_objc_class : 1;
304 ResolveClangType (ResolveState clang_type_resolve_state);
307 // these classes are used to back the SBType* objects
311 ClangASTType clang_type;
312 lldb::TypeSP type_sp;
315 TypePair () : clang_type(), type_sp() {}
316 TypePair (ClangASTType type) :
322 TypePair (lldb::TypeSP type) :
326 clang_type = type_sp->GetClangForwardType();
332 return clang_type.IsValid() || (type_sp.get() != nullptr);
335 explicit operator bool () const
341 operator == (const TypePair& rhs) const
343 return clang_type == rhs.clang_type &&
344 type_sp.get() == rhs.type_sp.get();
348 operator != (const TypePair& rhs) const
350 return clang_type != rhs.clang_type ||
351 type_sp.get() != rhs.type_sp.get();
365 return type_sp->GetName();
367 return clang_type.GetTypeName();
368 return ConstString ();
372 SetType (ClangASTType type)
379 SetType (lldb::TypeSP type)
382 clang_type = type_sp->GetClangForwardType();
392 GetClangASTType () const
398 GetPointerType () const
401 return type_sp->GetClangLayoutType().GetPointerType();
402 return clang_type.GetPointerType();
406 GetPointeeType () const
409 return type_sp->GetClangFullType().GetPointeeType();
410 return clang_type.GetPointeeType();
414 GetReferenceType () const
417 return type_sp->GetClangLayoutType().GetLValueReferenceType();
418 return clang_type.GetLValueReferenceType();
422 GetTypedefedType () const
425 return type_sp->GetClangFullType().GetTypedefedType();
426 return clang_type.GetTypedefedType();
430 GetDereferencedType () const
433 return type_sp->GetClangFullType().GetNonReferenceType();
434 return clang_type.GetNonReferenceType();
438 GetUnqualifiedType () const
441 return type_sp->GetClangLayoutType().GetFullyUnqualifiedType();
442 return clang_type.GetFullyUnqualifiedType();
446 GetCanonicalType () const
449 return type_sp->GetClangFullType().GetCanonicalType();
450 return clang_type.GetCanonicalType();
454 GetClangASTContext () const
456 return clang_type.GetASTContext();
468 TypeImpl(const TypeImpl& rhs);
470 TypeImpl (lldb::TypeSP type_sp);
472 TypeImpl (ClangASTType clang_type);
474 TypeImpl (lldb::TypeSP type_sp, ClangASTType dynamic);
476 TypeImpl (ClangASTType clang_type, ClangASTType dynamic);
478 TypeImpl (TypePair pair, ClangASTType dynamic);
481 SetType (lldb::TypeSP type_sp);
484 SetType (ClangASTType clang_type);
487 SetType (lldb::TypeSP type_sp, ClangASTType dynamic);
490 SetType (ClangASTType clang_type, ClangASTType dynamic);
493 SetType (TypePair pair, ClangASTType dynamic);
496 operator = (const TypeImpl& rhs);
499 operator == (const TypeImpl& rhs) const;
502 operator != (const TypeImpl& rhs) const;
507 explicit operator bool () const;
515 GetPointerType () const;
518 GetPointeeType () const;
521 GetReferenceType () const;
524 GetTypedefedType () const;
527 GetDereferencedType () const;
530 GetUnqualifiedType() const;
533 GetCanonicalType() const;
536 GetClangASTType (bool prefer_dynamic);
539 GetClangASTContext (bool prefer_dynamic);
542 GetDescription (lldb_private::Stream &strm,
543 lldb::DescriptionLevel description_level);
546 TypePair m_static_type;
547 ClangASTType m_dynamic_type;
559 Append (const lldb::TypeImplSP& type)
561 m_content.push_back(type);
567 AppendVisitor(TypeListImpl &type_list) :
568 m_type_list(type_list)
573 operator() (const lldb::TypeImplSP& type)
575 m_type_list.Append(type);
579 TypeListImpl &m_type_list;
583 Append (const lldb_private::TypeList &type_list);
586 GetTypeAtIndex(size_t idx)
588 lldb::TypeImplSP type_sp;
590 type_sp = m_content[idx];
597 return m_content.size();
601 std::vector<lldb::TypeImplSP> m_content;
611 m_bitfield_bit_size (0),
612 m_is_bitfield (false)
617 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp,
619 const ConstString &name,
620 uint32_t bitfield_bit_size = 0,
621 bool is_bitfield = false) :
622 m_type_impl_sp (type_impl_sp),
623 m_bit_offset (bit_offset),
625 m_bitfield_bit_size (bitfield_bit_size),
626 m_is_bitfield (is_bitfield)
630 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp,
631 uint64_t bit_offset):
632 m_type_impl_sp (type_impl_sp),
633 m_bit_offset (bit_offset),
635 m_bitfield_bit_size (0),
636 m_is_bitfield (false)
639 m_name = m_type_impl_sp->GetName();
642 const lldb::TypeImplSP &
645 return m_type_impl_sp;
655 GetBitOffset () const
661 GetBitfieldBitSize () const
663 return m_bitfield_bit_size;
667 SetBitfieldBitSize (uint32_t bitfield_bit_size)
669 m_bitfield_bit_size = bitfield_bit_size;
673 GetIsBitfield () const
675 return m_is_bitfield;
679 SetIsBitfield (bool is_bitfield)
681 m_is_bitfield = is_bitfield;
685 lldb::TypeImplSP m_type_impl_sp;
686 uint64_t m_bit_offset;
688 uint32_t m_bitfield_bit_size; // Bit size for bitfield members only
694 /// Sometimes you can find the name of the type corresponding to an object, but we don't have debug
695 /// information for it. If that is the case, you can return one of these objects, and then if it
696 /// has a full type, you can use that, but if not at least you can print the name for informational
704 TypeAndOrName (lldb::TypeSP &type_sp);
705 TypeAndOrName (const ClangASTType &clang_type);
706 TypeAndOrName (const char *type_str);
707 TypeAndOrName (const TypeAndOrName &rhs);
708 TypeAndOrName (ConstString &type_const_string);
711 operator= (const TypeAndOrName &rhs);
714 operator==(const TypeAndOrName &other) const;
717 operator!=(const TypeAndOrName &other) const;
719 ConstString GetName () const;
724 return m_type_pair.GetTypeSP();
728 GetClangASTType () const
730 return m_type_pair.GetClangASTType();
734 SetName (const ConstString &type_name);
737 SetName (const char *type_name_cstr);
740 SetTypeSP (lldb::TypeSP type_sp);
743 SetClangASTType (ClangASTType clang_type);
755 HasClangASTType () const;
760 return HasTypeSP() || HasClangASTType();
766 explicit operator bool ()
772 TypePair m_type_pair;
773 ConstString m_type_name;
776 } // namespace lldb_private
778 #endif // liblldb_Type_h_