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