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);
309 /// Sometimes you can find the name of the type corresponding to an object, but we don't have debug
310 /// information for it. If that is the case, you can return one of these objects, and then if it
311 /// has a full type, you can use that, but if not at least you can print the name for informational
319 TypeAndOrName (lldb::TypeSP &type_sp);
320 TypeAndOrName (const char *type_str);
321 TypeAndOrName (const TypeAndOrName &rhs);
322 TypeAndOrName (ConstString &type_const_string);
325 operator= (const TypeAndOrName &rhs);
328 operator==(const TypeAndOrName &other) const;
331 operator!=(const TypeAndOrName &other) const;
333 ConstString GetName () const;
342 SetName (const ConstString &type_name);
345 SetName (const char *type_name_cstr);
348 SetTypeSP (lldb::TypeSP type_sp);
369 lldb::TypeSP m_type_sp;
370 ConstString m_type_name;
373 // the two classes here are used by the public API as a backend to
374 // the SBType and SBTypeList classes
386 TypeImpl(const TypeImpl& rhs) :
387 m_clang_ast_type(rhs.m_clang_ast_type),
388 m_type_sp(rhs.m_type_sp)
392 TypeImpl(const lldb_private::ClangASTType& type);
394 TypeImpl(const lldb::TypeSP& type);
397 operator = (const TypeImpl& rhs);
400 operator == (const TypeImpl& rhs)
402 return m_clang_ast_type == rhs.m_clang_ast_type && m_type_sp.get() == rhs.m_type_sp.get();
406 operator != (const TypeImpl& rhs)
408 return m_clang_ast_type != rhs.m_clang_ast_type || m_type_sp.get() != rhs.m_type_sp.get();
414 return m_type_sp.get() != NULL || m_clang_ast_type.IsValid();
417 const lldb_private::ClangASTType &
418 GetClangASTType() const
420 return m_clang_ast_type;
439 GetDescription (lldb_private::Stream &strm,
440 lldb::DescriptionLevel description_level);
443 SetType (const lldb::TypeSP &type_sp);
446 ClangASTType m_clang_ast_type;
447 lldb::TypeSP m_type_sp;
459 Append (const lldb::TypeImplSP& type)
461 m_content.push_back(type);
467 AppendVisitor(TypeListImpl &type_list) :
468 m_type_list(type_list)
473 operator() (const lldb::TypeImplSP& type)
475 m_type_list.Append(type);
479 TypeListImpl &m_type_list;
483 Append (const lldb_private::TypeList &type_list);
486 GetTypeAtIndex(size_t idx)
488 lldb::TypeImplSP type_sp;
490 type_sp = m_content[idx];
497 return m_content.size();
501 std::vector<lldb::TypeImplSP> m_content;
511 m_bitfield_bit_size (0),
512 m_is_bitfield (false)
517 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp,
519 const ConstString &name,
520 uint32_t bitfield_bit_size = 0,
521 bool is_bitfield = false) :
522 m_type_impl_sp (type_impl_sp),
523 m_bit_offset (bit_offset),
525 m_bitfield_bit_size (bitfield_bit_size),
526 m_is_bitfield (is_bitfield)
530 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp,
531 uint64_t bit_offset):
532 m_type_impl_sp (type_impl_sp),
533 m_bit_offset (bit_offset),
535 m_bitfield_bit_size (0),
536 m_is_bitfield (false)
539 m_name = m_type_impl_sp->GetName();
542 const lldb::TypeImplSP &
545 return m_type_impl_sp;
555 GetBitOffset () const
561 GetBitfieldBitSize () const
563 return m_bitfield_bit_size;
567 SetBitfieldBitSize (uint32_t bitfield_bit_size)
569 m_bitfield_bit_size = bitfield_bit_size;
573 GetIsBitfield () const
575 return m_is_bitfield;
579 SetIsBitfield (bool is_bitfield)
581 m_is_bitfield = is_bitfield;
585 lldb::TypeImplSP m_type_impl_sp;
586 uint64_t m_bit_offset;
588 uint32_t m_bitfield_bit_size; // Bit size for bitfield members only
593 } // namespace lldb_private
595 #endif // liblldb_Type_h_