[Lldb-commits] [lldb] r223560 - Now that we get types from modules, we occasionally
Sean Callanan
scallanan at apple.com
Fri Dec 5 17:03:31 PST 2014
Author: spyffe
Date: Fri Dec 5 19:03:30 2014
New Revision: 223560
URL: http://llvm.org/viewvc/llvm-project?rev=223560&view=rev
Log:
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.
Modified:
lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h
lldb/trunk/source/Symbol/ClangASTContext.cpp
lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp
Modified: lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h?rev=223560&r1=223559&r2=223560&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangExternalASTSourceCommon.h Fri Dec 5 19:03:30 2014
@@ -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;
Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=223560&r1=223559&r2=223560&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Fri Dec 5 19:03:30 2014
@@ -2106,7 +2106,7 @@ ClangASTContext::SetMetadata (clang::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::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);
Modified: lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp?rev=223560&r1=223559&r2=223560&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp (original)
+++ lldb/trunk/source/Symbol/ClangExternalASTSourceCommon.cpp Fri Dec 5 19:03:30 2014
@@ -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;
-ClangExternalASTSourceCommon::ClangExternalASTSourceCommon() : clang::ExternalASTSource()
+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)
{
- m_magic = ClangExternalASTSourceCommon_MAGIC;
+ 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()
+{
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::GetMetadat
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::SetMetadat
bool
ClangExternalASTSourceCommon::HasMetadata (const void *object)
{
- assert (m_magic == ClangExternalASTSourceCommon_MAGIC);
-
return m_metadata.find(object) != m_metadata.end();
}
More information about the lldb-commits
mailing list