1 //===-- ClangExternalASTSourceCommon.cpp ------------------------*- 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 #include "lldb/Symbol/ClangExternalASTSourceCommon.h" 11 #include "lldb/Core/Stream.h" 12 13 using namespace lldb_private; 14 15 #define ClangExternalASTSourceCommon_MAGIC (0x00112233aabbccddull) 16 17 uint64_t g_TotalSizeOfMetadata = 0; 18 ClangExternalASTSourceCommon()19ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource() 20 { 21 m_magic = ClangExternalASTSourceCommon_MAGIC; 22 23 g_TotalSizeOfMetadata += m_metadata.size(); 24 } 25 ~ClangExternalASTSourceCommon()26ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() 27 { 28 g_TotalSizeOfMetadata -= m_metadata.size(); 29 } 30 31 ClangASTMetadata * GetMetadata(const void * object)32ClangExternalASTSourceCommon::GetMetadata (const void *object) 33 { 34 assert (m_magic == ClangExternalASTSourceCommon_MAGIC); 35 36 if (HasMetadata (object)) 37 return &m_metadata[object]; 38 else 39 return NULL; 40 } 41 42 void SetMetadata(const void * object,ClangASTMetadata & metadata)43ClangExternalASTSourceCommon::SetMetadata (const void *object, ClangASTMetadata &metadata) 44 { 45 assert (m_magic == ClangExternalASTSourceCommon_MAGIC); 46 47 uint64_t orig_size = m_metadata.size(); 48 m_metadata[object] = metadata; 49 uint64_t new_size = m_metadata.size(); 50 g_TotalSizeOfMetadata += (new_size - orig_size); 51 } 52 53 bool HasMetadata(const void * object)54ClangExternalASTSourceCommon::HasMetadata (const void *object) 55 { 56 assert (m_magic == ClangExternalASTSourceCommon_MAGIC); 57 58 return m_metadata.find(object) != m_metadata.end(); 59 } 60 61 void Dump(Stream * s)62ClangASTMetadata::Dump (Stream *s) 63 { 64 lldb::user_id_t uid = GetUserID (); 65 66 if (uid != LLDB_INVALID_UID) 67 { 68 s->Printf ("uid=0x%" PRIx64, uid); 69 } 70 71 uint64_t isa_ptr = GetISAPtr (); 72 if (isa_ptr != 0) 73 { 74 s->Printf ("isa_ptr=0x%" PRIx64, isa_ptr); 75 } 76 77 const char *obj_ptr_name = GetObjectPtrName(); 78 if (obj_ptr_name) 79 { 80 s->Printf ("obj_ptr_name=\"%s\" ", obj_ptr_name); 81 } 82 83 if (m_is_dynamic_cxx) 84 { 85 s->Printf ("is_dynamic_cxx=%i ", m_is_dynamic_cxx); 86 } 87 s->EOL(); 88 } 89 90