2011-12-03 11:15:28 +08:00
|
|
|
//===-- ClangExternalASTSourceCommon.cpp ------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
|
2013-03-27 09:48:02 +08:00
|
|
|
#include "lldb/Core/Stream.h"
|
2014-12-06 09:03:30 +08:00
|
|
|
#include "lldb/Host/Mutex.h"
|
2011-12-03 11:15:28 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2012-04-13 08:10:03 +08:00
|
|
|
uint64_t g_TotalSizeOfMetadata = 0;
|
|
|
|
|
2014-12-06 09:03:30 +08:00
|
|
|
typedef llvm::DenseMap<clang::ExternalASTSource *, ClangExternalASTSourceCommon *> ASTSourceMap;
|
|
|
|
|
|
|
|
static ASTSourceMap &GetSourceMap()
|
|
|
|
{
|
|
|
|
static ASTSourceMap s_source_map;
|
|
|
|
return s_source_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangExternalASTSourceCommon *
|
|
|
|
ClangExternalASTSourceCommon::Lookup(clang::ExternalASTSource *source)
|
2011-12-03 11:15:28 +08:00
|
|
|
{
|
2014-12-06 09:03:30 +08:00
|
|
|
ASTSourceMap &source_map = GetSourceMap();
|
|
|
|
|
|
|
|
ASTSourceMap::iterator iter = source_map.find(source);
|
2012-04-13 08:10:03 +08:00
|
|
|
|
2014-12-06 10:31:49 +08:00
|
|
|
if (iter != source_map.end())
|
2014-12-06 09:03:30 +08:00
|
|
|
{
|
|
|
|
return iter->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
|
|
|
|
{
|
2012-04-13 08:10:03 +08:00
|
|
|
g_TotalSizeOfMetadata += m_metadata.size();
|
2014-12-06 09:03:30 +08:00
|
|
|
GetSourceMap()[this] = this;
|
2012-04-13 08:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon()
|
|
|
|
{
|
2014-12-06 09:03:30 +08:00
|
|
|
GetSourceMap().erase(this);
|
2012-04-13 08:10:03 +08:00
|
|
|
g_TotalSizeOfMetadata -= m_metadata.size();
|
2011-12-03 11:15:28 +08:00
|
|
|
}
|
|
|
|
|
2012-10-27 10:54:13 +08:00
|
|
|
ClangASTMetadata *
|
2013-03-27 09:48:02 +08:00
|
|
|
ClangExternalASTSourceCommon::GetMetadata (const void *object)
|
2011-12-03 11:15:28 +08:00
|
|
|
{
|
2012-10-27 10:54:13 +08:00
|
|
|
if (HasMetadata (object))
|
|
|
|
return &m_metadata[object];
|
|
|
|
else
|
2014-04-20 21:17:36 +08:00
|
|
|
return nullptr;
|
2011-12-03 11:15:28 +08:00
|
|
|
}
|
|
|
|
|
2012-10-27 10:54:13 +08:00
|
|
|
void
|
2013-03-27 09:48:02 +08:00
|
|
|
ClangExternalASTSourceCommon::SetMetadata (const void *object, ClangASTMetadata &metadata)
|
2011-12-03 11:15:28 +08:00
|
|
|
{
|
2012-04-13 08:10:03 +08:00
|
|
|
uint64_t orig_size = m_metadata.size();
|
2011-12-03 11:15:28 +08:00
|
|
|
m_metadata[object] = metadata;
|
2012-04-13 08:10:03 +08:00
|
|
|
uint64_t new_size = m_metadata.size();
|
|
|
|
g_TotalSizeOfMetadata += (new_size - orig_size);
|
2011-12-03 11:15:28 +08:00
|
|
|
}
|
|
|
|
|
2012-10-27 10:54:13 +08:00
|
|
|
bool
|
2013-03-27 09:48:02 +08:00
|
|
|
ClangExternalASTSourceCommon::HasMetadata (const void *object)
|
2011-12-03 11:15:28 +08:00
|
|
|
{
|
|
|
|
return m_metadata.find(object) != m_metadata.end();
|
2011-12-04 04:02:42 +08:00
|
|
|
}
|
2013-03-27 09:48:02 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
ClangASTMetadata::Dump (Stream *s)
|
|
|
|
{
|
|
|
|
lldb::user_id_t uid = GetUserID ();
|
|
|
|
|
|
|
|
if (uid != LLDB_INVALID_UID)
|
|
|
|
{
|
|
|
|
s->Printf ("uid=0x%" PRIx64, uid);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t isa_ptr = GetISAPtr ();
|
|
|
|
if (isa_ptr != 0)
|
|
|
|
{
|
|
|
|
s->Printf ("isa_ptr=0x%" PRIx64, isa_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *obj_ptr_name = GetObjectPtrName();
|
|
|
|
if (obj_ptr_name)
|
|
|
|
{
|
|
|
|
s->Printf ("obj_ptr_name=\"%s\" ", obj_ptr_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_is_dynamic_cxx)
|
|
|
|
{
|
|
|
|
s->Printf ("is_dynamic_cxx=%i ", m_is_dynamic_cxx);
|
|
|
|
}
|
|
|
|
s->EOL();
|
|
|
|
}
|
|
|
|
|