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 uint64_t g_TotalSizeOfMetadata = 0; 16 17 typedef llvm::DenseMap<clang::ExternalASTSource *, 18 ClangExternalASTSourceCommon *> 19 ASTSourceMap; 20 21 static ASTSourceMap &GetSourceMap() { 22 // Intentionally leaked to avoid problems with global destructors. 23 static ASTSourceMap *s_source_map = new ASTSourceMap; 24 return *s_source_map; 25 } 26 27 ClangExternalASTSourceCommon * 28 ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source) { 29 ASTSourceMap &source_map = GetSourceMap(); 30 31 ASTSourceMap::iterator iter = source_map.find(source); 32 33 if (iter != source_map.end()) { 34 return iter->second; 35 } else { 36 return nullptr; 37 } 38 } 39 40 ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() 41 : clang::ExternalASTSource() { 42 g_TotalSizeOfMetadata += m_metadata.size(); 43 GetSourceMap()[this] = this; 44 } 45 46 ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon() { 47 GetSourceMap().erase(this); 48 g_TotalSizeOfMetadata -= m_metadata.size(); 49 } 50 51 ClangASTMetadata * 52 ClangExternalASTSourceCommon::GetMetadata(const void *object) { 53 if (HasMetadata(object)) 54 return &m_metadata[object]; 55 else 56 return nullptr; 57 } 58 59 void ClangExternalASTSourceCommon::SetMetadata(const void *object, 60 ClangASTMetadata &metadata) { 61 uint64_t orig_size = m_metadata.size(); 62 m_metadata[object] = metadata; 63 uint64_t new_size = m_metadata.size(); 64 g_TotalSizeOfMetadata += (new_size - orig_size); 65 } 66 67 bool ClangExternalASTSourceCommon::HasMetadata(const void *object) { 68 return m_metadata.find(object) != m_metadata.end(); 69 } 70 71 void ClangASTMetadata::Dump(Stream *s) { 72 lldb::user_id_t uid = GetUserID(); 73 74 if (uid != LLDB_INVALID_UID) { 75 s->Printf("uid=0x%" PRIx64, uid); 76 } 77 78 uint64_t isa_ptr = GetISAPtr(); 79 if (isa_ptr != 0) { 80 s->Printf("isa_ptr=0x%" PRIx64, isa_ptr); 81 } 82 83 const char *obj_ptr_name = GetObjectPtrName(); 84 if (obj_ptr_name) { 85 s->Printf("obj_ptr_name=\"%s\" ", obj_ptr_name); 86 } 87 88 if (m_is_dynamic_cxx) { 89 s->Printf("is_dynamic_cxx=%i ", m_is_dynamic_cxx); 90 } 91 s->EOL(); 92 } 93