Type.h revision 598df88bd6fc33c6fb330bc859bdc277795501f3
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 STD_ENABLE_SHARED_FROM_THIS(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 STD_ENABLE_SHARED_FROM_THIS(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 269 bool 270 IsCompleteObjCClass() 271 { 272 return m_flags.is_complete_objc_class; 273 } 274 275 void 276 SetIsCompleteObjCClass(bool is_complete_objc_class) 277 { 278 m_flags.is_complete_objc_class = is_complete_objc_class; 279 } 280 281protected: 282 ConstString m_name; 283 SymbolFile *m_symbol_file; 284 SymbolContextScope *m_context; // The symbol context in which this type is defined 285 Type *m_encoding_type; 286 uint32_t m_encoding_uid; 287 EncodingDataType m_encoding_uid_type; 288 uint32_t m_byte_size; 289 Declaration m_decl; 290 lldb::clang_type_t m_clang_type; 291 292 struct Flags { 293 ResolveState clang_type_resolve_state : 2; 294 bool is_complete_objc_class : 1; 295 } m_flags; 296 297 Type * 298 GetEncodingType (); 299 300 bool 301 ResolveClangType (ResolveState clang_type_resolve_state); 302}; 303 304 305/// 306/// Sometimes you can find the name of the type corresponding to an object, but we don't have debug 307/// information for it. If that is the case, you can return one of these objects, and then if it 308/// has a full type, you can use that, but if not at least you can print the name for informational 309/// purposes. 310/// 311 312class TypeAndOrName 313{ 314public: 315 TypeAndOrName (); 316 TypeAndOrName (lldb::TypeSP &type_sp); 317 TypeAndOrName (const char *type_str); 318 TypeAndOrName (const TypeAndOrName &rhs); 319 TypeAndOrName (ConstString &type_const_string); 320 321 TypeAndOrName & 322 operator= (const TypeAndOrName &rhs); 323 324 ConstString GetName () const; 325 326 lldb::TypeSP 327 GetTypeSP () const 328 { 329 return m_type_sp; 330 } 331 332 void 333 SetName (ConstString &type_name_const_str); 334 335 void 336 SetName (const char *type_name_str); 337 338 void 339 SetTypeSP (lldb::TypeSP type_sp); 340 341 bool 342 IsEmpty (); 343 344private: 345 lldb::TypeSP m_type_sp; 346 ConstString m_type_name; 347}; 348 349// the two classes here are used by the public API as a backend to 350// the SBType and SBTypeList classes 351 352class TypeImpl 353{ 354public: 355 356 TypeImpl() : 357 m_clang_ast_type(), 358 m_type_sp() 359 { 360 } 361 362 TypeImpl(const TypeImpl& rhs) : 363 m_clang_ast_type(rhs.m_clang_ast_type), 364 m_type_sp(rhs.m_type_sp) 365 { 366 } 367 368 TypeImpl(const lldb_private::ClangASTType& type); 369 370 TypeImpl(const lldb::TypeSP& type); 371 372 TypeImpl& 373 operator = (const TypeImpl& rhs); 374 375 bool 376 operator == (const TypeImpl& rhs) 377 { 378 return m_clang_ast_type == rhs.m_clang_ast_type && m_type_sp.get() == rhs.m_type_sp.get(); 379 } 380 381 bool 382 operator != (const TypeImpl& rhs) 383 { 384 return m_clang_ast_type != rhs.m_clang_ast_type || m_type_sp.get() != rhs.m_type_sp.get(); 385 } 386 387 bool 388 IsValid() 389 { 390 return m_type_sp.get() != NULL || m_clang_ast_type.IsValid(); 391 } 392 393 const lldb_private::ClangASTType & 394 GetClangASTType() const 395 { 396 return m_clang_ast_type; 397 } 398 399 clang::ASTContext* 400 GetASTContext(); 401 402 lldb::clang_type_t 403 GetOpaqueQualType(); 404 405 lldb::TypeSP 406 GetTypeSP () 407 { 408 return m_type_sp; 409 } 410 411 bool 412 GetDescription (lldb_private::Stream &strm, 413 lldb::DescriptionLevel description_level); 414 415 void 416 SetType (const lldb::TypeSP &type_sp); 417 418private: 419 ClangASTType m_clang_ast_type; 420 lldb::TypeSP m_type_sp; 421}; 422 423class TypeListImpl 424{ 425public: 426 TypeListImpl() : 427 m_content() 428 { 429 } 430 431 void 432 Append (const lldb::TypeImplSP& type) 433 { 434 m_content.push_back(type); 435 } 436 437 lldb::TypeImplSP 438 GetTypeAtIndex(size_t idx) 439 { 440 lldb::TypeImplSP type_sp; 441 if (idx < GetSize()) 442 type_sp = m_content[idx]; 443 return type_sp; 444 } 445 446 size_t 447 GetSize() 448 { 449 return m_content.size(); 450 } 451 452private: 453 std::vector<lldb::TypeImplSP> m_content; 454}; 455 456class TypeMemberImpl 457{ 458public: 459 TypeMemberImpl () : 460 m_type_impl_sp (), 461 m_bit_offset (0), 462 m_name () 463 { 464 } 465 466 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 467 uint64_t bit_offset, 468 const ConstString &name) : 469 m_type_impl_sp (type_impl_sp), 470 m_bit_offset (bit_offset), 471 m_name (name) 472 { 473 } 474 475 TypeMemberImpl (const lldb::TypeImplSP &type_impl_sp, 476 uint64_t bit_offset): 477 m_type_impl_sp (type_impl_sp), 478 m_bit_offset (bit_offset), 479 m_name () 480 { 481 } 482 483 const lldb::TypeImplSP & 484 GetTypeImpl () 485 { 486 return m_type_impl_sp; 487 } 488 489 const ConstString & 490 GetName () const 491 { 492 return m_name; 493 } 494 495 uint64_t 496 GetBitOffset () const 497 { 498 return m_bit_offset; 499 } 500 501protected: 502 lldb::TypeImplSP m_type_impl_sp; 503 uint64_t m_bit_offset; 504 ConstString m_name; 505}; 506 507 508} // namespace lldb_private 509 510#endif // liblldb_Type_h_ 511 512