Type.h revision bdcb6abaa287df2c5f312c51d993c1d0b0cb120c
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 EncodingDataTypeTag 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 typedef enum ResolveStateTag 39 { 40 eResolveStateUnresolved = 0, 41 eResolveStateForward = 1, 42 eResolveStateLayout = 2, 43 eResolveStateFull = 3 44 } ResolveState; 45 46 Type (lldb::user_id_t uid, 47 SymbolFile* symbol_file, 48 const ConstString &name, 49 uint32_t byte_size, 50 SymbolContextScope *context, 51 lldb::user_id_t encoding_uid, 52 EncodingDataType encoding_uid_type, 53 const Declaration& decl, 54 lldb::clang_type_t clang_qual_type, 55 ResolveState clang_type_resolve_state); 56 57 // This makes an invalid type. Used for functions that return a Type when they 58 // get an error. 59 Type(); 60 61 Type (const Type &rhs); 62 63 const Type& 64 operator= (const Type& rhs); 65 66 void 67 Dump(Stream *s, bool show_context); 68 69 void 70 DumpTypeName(Stream *s); 71 72 73 void 74 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); 75 76 SymbolFile * 77 GetSymbolFile() 78 { 79 return m_symbol_file; 80 } 81 const SymbolFile * 82 GetSymbolFile() const 83 { 84 return m_symbol_file; 85 } 86 87 TypeList* 88 GetTypeList(); 89 90 const ConstString& 91 GetName(); 92 93 uint32_t 94 GetByteSize(); 95 96 uint32_t 97 GetNumChildren (bool omit_empty_base_classes); 98 99 bool 100 IsAggregateType (); 101 102 bool 103 IsValidType () 104 { 105 return m_encoding_uid_type != eEncodingInvalid; 106 } 107 108 void 109 SetByteSize(uint32_t byte_size); 110 111 const ConstString & 112 GetName () const 113 { 114 return m_name; 115 } 116 117 void 118 DumpValue(ExecutionContext *exe_ctx, 119 Stream *s, 120 const DataExtractor &data, 121 uint32_t data_offset, 122 bool show_type, 123 bool show_summary, 124 bool verbose, 125 lldb::Format format = lldb::eFormatDefault); 126 127 bool 128 DumpValueInMemory(ExecutionContext *exe_ctx, 129 Stream *s, 130 lldb::addr_t address, 131 lldb::AddressType address_type, 132 bool show_types, 133 bool show_summary, 134 bool verbose); 135 136 bool 137 ReadFromMemory (ExecutionContext *exe_ctx, 138 lldb::addr_t address, 139 lldb::AddressType address_type, 140 DataExtractor &data); 141 142 bool 143 WriteToMemory (ExecutionContext *exe_ctx, 144 lldb::addr_t address, 145 lldb::AddressType address_type, 146 DataExtractor &data); 147 148 bool 149 GetIsDeclaration() const; 150 151 void 152 SetIsDeclaration(bool b); 153 154 bool 155 GetIsExternal() const; 156 157 void 158 SetIsExternal(bool b); 159 160 lldb::Format 161 GetFormat (); 162 163 lldb::Encoding 164 GetEncoding (uint32_t &count); 165 166 SymbolContextScope * 167 GetSymbolContextScope() 168 { 169 return m_context; 170 } 171 const SymbolContextScope * 172 GetSymbolContextScope() const 173 { 174 return m_context; 175 } 176 void 177 SetSymbolContextScope(SymbolContextScope *context) 178 { 179 m_context = context; 180 } 181 182 const lldb_private::Declaration & 183 GetDeclaration () const; 184 185 // Get the clang type, and resolve definitions for any 186 // class/struct/union/enum types completely. 187 lldb::clang_type_t 188 GetClangType (); 189 190 // Get the clang type, and resolve definitions enough so that the type could 191 // have layout performed. This allows ptrs and refs to class/struct/union/enum 192 // types remain forward declarations. 193 lldb::clang_type_t 194 GetClangLayoutType (); 195 196 // Get the clang type and leave class/struct/union/enum types as forward 197 // declarations if they haven't already been fully defined. 198 lldb::clang_type_t 199 GetClangForwardType (); 200 201 clang::ASTContext * 202 GetClangAST (); 203 204 ClangASTContext & 205 GetClangASTContext (); 206 207 static int 208 Compare(const Type &a, const Type &b); 209 210 void 211 SetEncodingType (Type *encoding_type) 212 { 213 m_encoding_type = encoding_type; 214 } 215 216 uint32_t 217 GetEncodingMask (); 218 219 void * 220 CreateClangPointerType (Type *type); 221 222 void * 223 CreateClangTypedefType (Type *typedef_type, Type *base_type); 224 225 // For C++98 references (&) 226 void * 227 CreateClangLValueReferenceType (Type *type); 228 229 // For C++0x references (&&) 230 void * 231 CreateClangRValueReferenceType (Type *type); 232 233 234protected: 235 ConstString m_name; 236 SymbolFile *m_symbol_file; 237 SymbolContextScope *m_context; // The symbol context in which this type is defined 238 Type *m_encoding_type; 239 uint32_t m_encoding_uid; 240 EncodingDataType m_encoding_uid_type; 241 uint32_t m_byte_size; 242 Declaration m_decl; 243 lldb::clang_type_t m_clang_type; 244 ResolveState m_clang_type_resolve_state; 245 246 Type * 247 GetEncodingType (); 248 249 bool 250 ResolveClangType (ResolveState clang_type_resolve_state); 251}; 252 253} // namespace lldb_private 254 255#endif // liblldb_Type_h_ 256 257