Now that we get types from modules, we occasionally

encounter clang::ExternalASTSources that are not instances
of ClangExternalASTSourceCommon.  We used to blithely
assume that all are, and so we could use static_cast<>.
That's no longer the case, so we have to have these AST
sources register themselves.

llvm-svn: 223560
This commit is contained in:
Sean Callanan 2014-12-06 01:03:30 +00:00
parent 67d7af9c34
commit ceeb74e606
3 changed files with 37 additions and 16 deletions

View File

@ -169,10 +169,13 @@ public:
ClangExternalASTSourceCommon();
~ClangExternalASTSourceCommon();
virtual ClangASTMetadata *GetMetadata(const void *object);
virtual void SetMetadata(const void *object, ClangASTMetadata &metadata);
virtual bool HasMetadata(const void *object);
private:
ClangASTMetadata *GetMetadata(const void *object);
void SetMetadata(const void *object, ClangASTMetadata &metadata);
bool HasMetadata(const void *object);
static ClangExternalASTSourceCommon *
Lookup(clang::ExternalASTSource *source);
private:
typedef llvm::DenseMap<const void *, ClangASTMetadata> MetadataMap;
MetadataMap m_metadata;

View File

@ -2106,7 +2106,7 @@ ClangASTContext::SetMetadata (clang::ASTContext *ast,
ClangASTMetadata &metadata)
{
ClangExternalASTSourceCommon *external_source =
static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource());
ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
if (external_source)
external_source->SetMetadata(object, metadata);
@ -2117,7 +2117,7 @@ ClangASTContext::GetMetadata (clang::ASTContext *ast,
const void *object)
{
ClangExternalASTSourceCommon *external_source =
static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource());
ClangExternalASTSourceCommon::Lookup(ast->getExternalSource());
if (external_source && external_source->HasMetadata(object))
return external_source->GetMetadata(object);

View File

@ -9,30 +9,52 @@
#include "lldb/Symbol/ClangExternalASTSourceCommon.h"
#include "lldb/Core/Stream.h"
#include "lldb/Host/Mutex.h"
using namespace lldb_private;
#define ClangExternalASTSourceCommon_MAGIC (0x00112233aabbccddull)
uint64_t g_TotalSizeOfMetadata = 0;
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)
{
ASTSourceMap &source_map = GetSourceMap();
ASTSourceMap::iterator iter = source_map.find(source);
if (iter == source_map.end())
{
return iter->second;
}
else
{
return nullptr;
}
}
ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
{
m_magic = ClangExternalASTSourceCommon_MAGIC;
g_TotalSizeOfMetadata += m_metadata.size();
GetSourceMap()[this] = this;
}
ClangExternalASTSourceCommon::~ClangExternalASTSourceCommon()
{
GetSourceMap().erase(this);
g_TotalSizeOfMetadata -= m_metadata.size();
}
ClangASTMetadata *
ClangExternalASTSourceCommon::GetMetadata (const void *object)
{
assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
if (HasMetadata (object))
return &m_metadata[object];
else
@ -42,8 +64,6 @@ ClangExternalASTSourceCommon::GetMetadata (const void *object)
void
ClangExternalASTSourceCommon::SetMetadata (const void *object, ClangASTMetadata &metadata)
{
assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
uint64_t orig_size = m_metadata.size();
m_metadata[object] = metadata;
uint64_t new_size = m_metadata.size();
@ -53,8 +73,6 @@ ClangExternalASTSourceCommon::SetMetadata (const void *object, ClangASTMetadata
bool
ClangExternalASTSourceCommon::HasMetadata (const void *object)
{
assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
return m_metadata.find(object) != m_metadata.end();
}