Type.h revision f03d97e519811a029578cc120a7a2725cdf2aad1
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/ConstString.h" 16#include "lldb/Core/UserID.h" 17#include "lldb/Symbol/ClangASTType.h" 18#include "lldb/Symbol/Declaration.h" 19#include <set> 20 21namespace lldb_private { 22 23class SymbolFileType : 24 public ReferenceCountedBaseVirtual<SymbolFileType>, 25 public UserID 26 { 27 public: 28 SymbolFileType (SymbolFile &symbol_file, lldb::user_id_t uid) : 29 UserID (uid), 30 m_symbol_file (symbol_file) 31 { 32 } 33 34 ~SymbolFileType () 35 { 36 } 37 38 Type * 39 operator->() 40 { 41 return GetType (); 42 } 43 44 Type * 45 GetType (); 46 47 protected: 48 SymbolFile &m_symbol_file; 49 lldb::TypeSP m_type_sp; 50 }; 51 52class Type : 53 public ReferenceCountedBaseVirtual<Type>, 54 public UserID 55{ 56public: 57 typedef enum EncodingDataTypeTag 58 { 59 eEncodingInvalid, 60 eEncodingIsUID, ///< This type is the type whose UID is m_encoding_uid 61 eEncodingIsConstUID, ///< This type is the type whose UID is m_encoding_uid with the const qualifier added 62 eEncodingIsRestrictUID, ///< This type is the type whose UID is m_encoding_uid with the restrict qualifier added 63 eEncodingIsVolatileUID, ///< This type is the type whose UID is m_encoding_uid with the volatile qualifier added 64 eEncodingIsTypedefUID, ///< This type is pointer to a type whose UID is m_encoding_uid 65 eEncodingIsPointerUID, ///< This type is pointer to a type whose UID is m_encoding_uid 66 eEncodingIsLValueReferenceUID, ///< This type is L value reference to a type whose UID is m_encoding_uid 67 eEncodingIsRValueReferenceUID, ///< This type is R value reference to a type whose UID is m_encoding_uid 68 eEncodingIsSyntheticUID 69 } EncodingDataType; 70 71 typedef enum ResolveStateTag 72 { 73 eResolveStateUnresolved = 0, 74 eResolveStateForward = 1, 75 eResolveStateLayout = 2, 76 eResolveStateFull = 3 77 } ResolveState; 78 79 Type (lldb::user_id_t uid, 80 SymbolFile* symbol_file, 81 const ConstString &name, 82 uint32_t byte_size, 83 SymbolContextScope *context, 84 lldb::user_id_t encoding_uid, 85 EncodingDataType encoding_uid_type, 86 const Declaration& decl, 87 lldb::clang_type_t clang_qual_type, 88 ResolveState clang_type_resolve_state); 89 90 // This makes an invalid type. Used for functions that return a Type when they 91 // get an error. 92 Type(); 93 94 Type (const Type &rhs); 95 96 const Type& 97 operator= (const Type& rhs); 98 99 void 100 Dump(Stream *s, bool show_context); 101 102 void 103 DumpTypeName(Stream *s); 104 105 106 void 107 GetDescription (Stream *s, lldb::DescriptionLevel level, bool show_name); 108 109 SymbolFile * 110 GetSymbolFile() 111 { 112 return m_symbol_file; 113 } 114 const SymbolFile * 115 GetSymbolFile() const 116 { 117 return m_symbol_file; 118 } 119 120 TypeList* 121 GetTypeList(); 122 123 const ConstString& 124 GetName(); 125 126 uint32_t 127 GetByteSize(); 128 129 uint32_t 130 GetNumChildren (bool omit_empty_base_classes); 131 132 bool 133 IsAggregateType (); 134 135 bool 136 IsValidType () 137 { 138 return m_encoding_uid_type != eEncodingInvalid; 139 } 140 141 void 142 SetByteSize(uint32_t byte_size); 143 144 const ConstString & 145 GetName () const 146 { 147 return m_name; 148 } 149 150 void 151 DumpValue(ExecutionContext *exe_ctx, 152 Stream *s, 153 const DataExtractor &data, 154 uint32_t data_offset, 155 bool show_type, 156 bool show_summary, 157 bool verbose, 158 lldb::Format format = lldb::eFormatDefault); 159 160 bool 161 DumpValueInMemory(ExecutionContext *exe_ctx, 162 Stream *s, 163 lldb::addr_t address, 164 AddressType address_type, 165 bool show_types, 166 bool show_summary, 167 bool verbose); 168 169 bool 170 ReadFromMemory (ExecutionContext *exe_ctx, 171 lldb::addr_t address, 172 AddressType address_type, 173 DataExtractor &data); 174 175 bool 176 WriteToMemory (ExecutionContext *exe_ctx, 177 lldb::addr_t address, 178 AddressType address_type, 179 DataExtractor &data); 180 181 bool 182 GetIsDeclaration() const; 183 184 void 185 SetIsDeclaration(bool b); 186 187 bool 188 GetIsExternal() const; 189 190 void 191 SetIsExternal(bool b); 192 193 lldb::Format 194 GetFormat (); 195 196 lldb::Encoding 197 GetEncoding (uint32_t &count); 198 199 SymbolContextScope * 200 GetSymbolContextScope() 201 { 202 return m_context; 203 } 204 const SymbolContextScope * 205 GetSymbolContextScope() const 206 { 207 return m_context; 208 } 209 void 210 SetSymbolContextScope(SymbolContextScope *context) 211 { 212 m_context = context; 213 } 214 215 const lldb_private::Declaration & 216 GetDeclaration () const; 217 218 // Get the clang type, and resolve definitions for any 219 // class/struct/union/enum types completely. 220 lldb::clang_type_t 221 GetClangFullType (); 222 223 // Get the clang type, and resolve definitions enough so that the type could 224 // have layout performed. This allows ptrs and refs to class/struct/union/enum 225 // types remain forward declarations. 226 lldb::clang_type_t 227 GetClangLayoutType (); 228 229 // Get the clang type and leave class/struct/union/enum types as forward 230 // declarations if they haven't already been fully defined. 231 lldb::clang_type_t 232 GetClangForwardType (); 233 234 clang::ASTContext * 235 GetClangAST (); 236 237 ClangASTContext & 238 GetClangASTContext (); 239 240 static int 241 Compare(const Type &a, const Type &b); 242 243 void 244 SetEncodingType (Type *encoding_type) 245 { 246 m_encoding_type = encoding_type; 247 } 248 249 uint32_t 250 GetEncodingMask (); 251 252 void * 253 CreateClangPointerType (Type *type); 254 255 void * 256 CreateClangTypedefType (Type *typedef_type, Type *base_type); 257 258 // For C++98 references (&) 259 void * 260 CreateClangLValueReferenceType (Type *type); 261 262 // For C++0x references (&&) 263 void * 264 CreateClangRValueReferenceType (Type *type); 265 266 bool 267 IsRealObjCClass(); 268 269protected: 270 ConstString m_name; 271 SymbolFile *m_symbol_file; 272 SymbolContextScope *m_context; // The symbol context in which this type is defined 273 Type *m_encoding_type; 274 uint32_t m_encoding_uid; 275 EncodingDataType m_encoding_uid_type; 276 uint32_t m_byte_size; 277 Declaration m_decl; 278 lldb::clang_type_t m_clang_type; 279 ResolveState m_clang_type_resolve_state; 280 281 Type * 282 GetEncodingType (); 283 284 bool 285 ResolveClangType (ResolveState clang_type_resolve_state); 286}; 287 288 289/// 290/// Sometimes you can find the name of the type corresponding to an object, but we don't have debug 291/// information for it. If that is the case, you can return one of these objects, and then if it 292/// has a full type, you can use that, but if not at least you can print the name for informational 293/// purposes. 294/// 295 296class TypeAndOrName 297{ 298public: 299 TypeAndOrName (); 300 TypeAndOrName (lldb::TypeSP &type_sp); 301 TypeAndOrName (const char *type_str); 302 TypeAndOrName (const TypeAndOrName &rhs); 303 TypeAndOrName (ConstString &type_const_string); 304 305 TypeAndOrName & 306 operator= (const TypeAndOrName &rhs); 307 308 ConstString GetName () const; 309 310 lldb::TypeSP 311 GetTypeSP () const 312 { 313 return m_type_sp; 314 } 315 316 void 317 SetName (ConstString &type_name_const_str); 318 319 void 320 SetName (const char *type_name_str); 321 322 void 323 SetTypeSP (lldb::TypeSP type_sp); 324 325 bool 326 IsEmpty (); 327 328private: 329 lldb::TypeSP m_type_sp; 330 ConstString m_type_name; 331}; 332 333// the two classes here are used by the public API as a backend to 334// the SBType and SBTypeList classes 335 336class TypeImpl 337{ 338public: 339 340 TypeImpl() : 341 m_clang_ast_type(), 342 m_type_sp() 343 { 344 } 345 346 TypeImpl(const TypeImpl& rhs) : 347 m_clang_ast_type(rhs.m_clang_ast_type), 348 m_type_sp(rhs.m_type_sp) 349 { 350 } 351 352 TypeImpl(const lldb_private::ClangASTType& type); 353 354 TypeImpl(const lldb::TypeSP& type); 355 356 TypeImpl& 357 operator = (const TypeImpl& rhs); 358 359 bool 360 operator == (const TypeImpl& rhs) 361 { 362 return m_clang_ast_type == rhs.m_clang_ast_type && m_type_sp.get() == rhs.m_type_sp.get(); 363 } 364 365 bool 366 operator != (const TypeImpl& rhs) 367 { 368 return m_clang_ast_type != rhs.m_clang_ast_type || m_type_sp.get() != rhs.m_type_sp.get(); 369 } 370 371 bool 372 IsValid() 373 { 374 return m_type_sp.get() != NULL || m_clang_ast_type.IsValid(); 375 } 376 377 const lldb_private::ClangASTType & 378 GetClangASTType() const 379 { 380 return m_clang_ast_type; 381 } 382 383 clang::ASTContext* 384 GetASTContext(); 385 386 lldb::clang_type_t 387 GetOpaqueQualType(); 388 389 bool 390 GetDescription (lldb_private::Stream &strm, 391 lldb::DescriptionLevel description_level); 392 393 394private: 395 ClangASTType m_clang_ast_type; 396 lldb::TypeSP m_type_sp; 397}; 398 399class TypeListImpl 400{ 401public: 402 TypeListImpl() : 403 m_content() 404 { 405 } 406 407 void 408 Append (const lldb::TypeImplSP& type) 409 { 410 m_content.push_back(type); 411 } 412 413 lldb::TypeImplSP 414 GetTypeAtIndex(size_t idx) 415 { 416 lldb::TypeImplSP type_sp; 417 if (idx < GetSize()) 418 type_sp = m_content[idx]; 419 return type_sp; 420 } 421 422 size_t 423 GetSize() 424 { 425 return m_content.size(); 426 } 427 428private: 429 std::vector<lldb::TypeImplSP> m_content; 430}; 431 432class TypeMemberImpl 433{ 434public: 435 TypeMemberImpl () : 436 m_type_impl_sp (), 437 m_bit_offset (0), 438 m_name () 439 { 440 } 441 442 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 443 uint64_t bit_offset, 444 const ConstString &name) : 445 m_type_impl_sp (type_impl_sp), 446 m_bit_offset (bit_offset), 447 m_name (name) 448 { 449 } 450 451 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 452 uint64_t bit_offset): 453 m_type_impl_sp (type_impl_sp), 454 m_bit_offset (bit_offset), 455 m_name () 456 { 457 } 458 459 const lldb::TypeImplSP & 460 GetTypeImpl () 461 { 462 return m_type_impl_sp; 463 } 464 465 const ConstString & 466 GetName () const 467 { 468 return m_name; 469 } 470 471 uint64_t 472 GetBitOffset () const 473 { 474 return m_bit_offset; 475 } 476 477protected: 478 lldb::TypeImplSP m_type_impl_sp; 479 uint64_t m_bit_offset; 480 ConstString m_name; 481}; 482 483 484} // namespace lldb_private 485 486#endif // liblldb_Type_h_ 487 488