Type.h revision bf8e42b9da0e1c6349a727d644ad37610b00d556
1//===-- Type.h --------------------------------------------------*- 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#ifndef liblldb_Type_h_ 11#define liblldb_Type_h_ 12 13#include "lldb/lldb-private.h" 14#include "lldb/Core/ClangForward.h" 15#include "lldb/Core/UserID.h" 16#include "lldb/Symbol/Declaration.h" 17#include <set> 18 19namespace lldb_private { 20 21class Type : public UserID 22{ 23public: 24 typedef enum 25 { 26 eEncodingInvalid, 27 eEncodingIsUID, ///< This type is the type whose UID is m_encoding_uid 28 eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added 29 eEncodingIsRestrictUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added 30 eEncodingIsVolatileUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added 31 eEncodingIsTypedefUID, ///< This type is pointer to a type whose UID is m_encoding_uid 32 eEncodingIsPointerUID, ///< This type is pointer to a type whose UID is m_encoding_uid 33 eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type whose UID is m_encoding_uid 34 eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type whose UID is m_encoding_uid 35 eEncodingIsSyntheticUID 36 } EncodingDataType; 37 38 Type (lldb::user_id_t uid, 39 SymbolFile* symbol_file, 40 const ConstString &name, 41 uint32_t byte_size, 42 SymbolContextScope *context, 43 uintptr_t encoding_uid, 44 EncodingDataType encoding_type, 45 const Declaration& decl, 46 lldb::clang_type_t clang_qual_type, 47 bool is_forward_decl); 48 49 // This makes an invalid type. Used for functions that return a Type when they 50 // get an error. 51 Type(); 52 53 const Type& 54 operator= (const Type& rhs); 55 56 void 57 Dump(Stream *s, bool show_context); 58 59 void 60 DumpTypeName(Stream *s); 61 62 63 void 64 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); 65 66 SymbolFile * 67 GetSymbolFile() 68 { 69 return m_symbol_file; 70 } 71 const SymbolFile * 72 GetSymbolFile() const 73 { 74 return m_symbol_file; 75 } 76 77 TypeList* 78 GetTypeList(); 79 80 const ConstString& 81 GetName(); 82 83 uint64_t 84 GetByteSize(); 85 86 uint32_t 87 GetNumChildren (bool omit_empty_base_classes); 88 89 bool 90 IsAggregateType (); 91 92 bool 93 IsValidType () 94 { 95 return m_encoding_uid_type != eEncodingInvalid; 96 } 97 98 void 99 SetByteSize(uint32_t byte_size); 100 101 const ConstString & 102 GetName () const 103 { 104 return m_name; 105 } 106 107 void 108 DumpValue(ExecutionContext *exe_ctx, 109 Stream *s, 110 const DataExtractor &data, 111 uint32_t data_offset, 112 bool show_type, 113 bool show_summary, 114 bool verbose, 115 lldb::Format format = lldb::eFormatDefault); 116 117 bool 118 DumpValueInMemory(ExecutionContext *exe_ctx, 119 Stream *s, 120 lldb::addr_t address, 121 lldb::AddressType address_type, 122 bool show_types, 123 bool show_summary, 124 bool verbose); 125 126 bool 127 ReadFromMemory (ExecutionContext *exe_ctx, 128 lldb::addr_t address, 129 lldb::AddressType address_type, 130 DataExtractor &data); 131 132 bool 133 WriteToMemory (ExecutionContext *exe_ctx, 134 lldb::addr_t address, 135 lldb::AddressType address_type, 136 DataExtractor &data); 137 138 bool 139 GetIsDeclaration() const; 140 141 void 142 SetIsDeclaration(bool b); 143 144 bool 145 GetIsExternal() const; 146 147 void 148 SetIsExternal(bool b); 149 150 lldb::Format 151 GetFormat (); 152 153 lldb::Encoding 154 GetEncoding (uint32_t &count); 155 156 SymbolContextScope * 157 GetSymbolContextScope() 158 { 159 return m_context; 160 } 161 const SymbolContextScope * 162 GetSymbolContextScope() const 163 { 164 return m_context; 165 } 166 void 167 SetSymbolContextScope(SymbolContextScope *context) 168 { 169 m_context = context; 170 } 171 172 const lldb_private::Declaration & 173 GetDeclaration () const; 174 175 // Get the clang type, and resolve definitions for any 176 // class/struct/union/enum types completely. 177 lldb::clang_type_t 178 GetClangType (); 179 180 // Get the clang type and leave class/struct/union/enum types as forward 181 // declarations if they haven't already been fully defined. 182 lldb::clang_type_t 183 GetClangForwardType (); 184 185 clang::ASTContext * 186 GetClangAST (); 187 188 ClangASTContext & 189 GetClangASTContext (); 190 191 lldb::clang_type_t 192 GetChildClangTypeAtIndex (const char *parent_name, 193 uint32_t idx, 194 bool transparent_pointers, 195 bool omit_empty_base_classes, 196 ConstString& name, 197 uint32_t &child_byte_size, 198 int32_t &child_byte_offset, 199 uint32_t &child_bitfield_bit_size, 200 uint32_t &child_bitfield_bit_offset, 201 bool &child_is_base_class); 202 203 static int 204 Compare(const Type &a, const Type &b); 205 206protected: 207 ConstString m_name; 208 SymbolFile *m_symbol_file; 209 SymbolContextScope *m_context; // The symbol context in which this type is defined 210 Type *m_encoding_type; 211 EncodingDataType m_encoding_uid_type; 212 uint32_t m_encoding_uid; 213 uint32_t m_byte_size; 214 Declaration m_decl; 215 lldb::clang_type_t m_clang_type; 216 bool m_is_forward_decl:1, 217 m_encoding_type_forward_decl_resolved:1, 218 m_encoding_type_decl_resolved:1; 219 220 Type * 221 GetEncodingType (); 222 223 bool ResolveClangType(bool forward_decl_is_ok = false); 224}; 225 226} // namespace lldb_private 227 228#endif // liblldb_Type_h_ 229 230