[Lldb-commits] [lldb] r144835 - in /lldb/trunk: include/lldb/Symbol/ClangASTImporter.h source/Symbol/ClangASTImporter.cpp
Sean Callanan
scallanan at apple.com
Wed Nov 16 13:40:57 PST 2011
Author: spyffe
Date: Wed Nov 16 15:40:57 2011
New Revision: 144835
URL: http://llvm.org/viewvc/llvm-project?rev=144835&view=rev
Log:
Changed the ClangASTImporter to store metadata
for each AST context it knows about in a single
object. This makes it faster to look up the
appropriate ASTImpoter for a given ASTContext
pair and also makes it much easier to delete all
metadata for a given AST context.
In the future, this fix will allow the
ClangASTImporter to propagate completion
information between the metadata for different
AST contexts as its minions move AST objects
around.
Modified:
lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
lldb/trunk/source/Symbol/ClangASTImporter.cpp
Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=144835&r1=144834&r2=144835&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Wed Nov 16 15:40:57 2011
@@ -84,9 +84,22 @@
NamespaceMapSP &parent_map) const = 0;
};
- void InstallMapCompleter (NamespaceMapCompleter &completer)
+ void InstallMapCompleter (clang::ASTContext *dst_ctx, NamespaceMapCompleter &completer)
{
- m_map_completer = &completer;
+ ASTContextMetadataSP context_md;
+ ContextMetadataMap::iterator context_md_iter = m_metadata_map.find(dst_ctx);
+
+ if (context_md_iter == m_metadata_map.end())
+ {
+ context_md = ASTContextMetadataSP(new ASTContextMetadata(dst_ctx));
+ m_metadata_map[dst_ctx] = context_md;
+ }
+ else
+ {
+ context_md = context_md_iter->second;
+ }
+
+ context_md->m_map_completer = &completer;
}
NamespaceMapSP GetNamespaceMap (const clang::NamespaceDecl *decl);
@@ -150,61 +163,78 @@
clang::ASTContext *m_source_ctx;
};
- typedef lldb::SharedPtr<Minion>::Type MinionSP;
+ typedef lldb::SharedPtr<Minion>::Type MinionSP;
+
+ typedef std::map<clang::ASTContext *, MinionSP> MinionMap;
- struct MinionSpec
+ typedef std::map<const clang::NamespaceDecl *, NamespaceMapSP> NamespaceMetaMap;
+
+ struct ASTContextMetadata
{
- clang::ASTContext *dst;
- clang::ASTContext *src;
-
- MinionSpec (clang::ASTContext *_dst,
- clang::ASTContext *_src) :
- dst(_dst),
- src(_src)
+ ASTContextMetadata(clang::ASTContext *dst_ctx) :
+ m_dst_ctx (dst_ctx),
+ m_minions (),
+ m_origins (),
+ m_namespace_maps (),
+ m_map_completer (NULL)
{
}
- bool operator<(const MinionSpec &rhs) const
- {
- if (dst < rhs.dst)
- return true;
- if (dst == rhs.dst && src < rhs.src)
- return true;
- return false;
- }
+ clang::ASTContext *m_dst_ctx;
+ MinionMap m_minions;
+ OriginMap m_origins;
+
+ NamespaceMetaMap m_namespace_maps;
+ NamespaceMapCompleter *m_map_completer;
};
- typedef std::map<MinionSpec, MinionSP> MinionMap;
+ typedef lldb::SharedPtr<ASTContextMetadata>::Type ASTContextMetadataSP;
- MinionSP
- GetMinion (clang::ASTContext *target_ctx, clang::ASTContext *source_ctx)
+ typedef std::map<const clang::ASTContext *, ASTContextMetadataSP> ContextMetadataMap;
+
+ ContextMetadataMap m_metadata_map;
+
+ ASTContextMetadataSP
+ GetContextMetadata (clang::ASTContext *dst_ctx)
{
- MinionSpec spec(target_ctx, source_ctx);
+ ContextMetadataMap::iterator context_md_iter = m_metadata_map.find(dst_ctx);
- if (m_minions.find(spec) == m_minions.end())
- m_minions[spec] = MinionSP(new Minion(*this, target_ctx, source_ctx));
-
- return m_minions[spec];
+ if (context_md_iter == m_metadata_map.end())
+ {
+ ASTContextMetadataSP context_md = ASTContextMetadataSP(new ASTContextMetadata(dst_ctx));
+ m_metadata_map[dst_ctx] = context_md;
+ return context_md;
+ }
+ else
+ {
+ return context_md_iter->second;
+ }
}
- DeclOrigin
- GetDeclOrigin (const clang::Decl *decl)
+ MinionSP
+ GetMinion (clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx)
{
- OriginMap::iterator iter = m_origins.find(decl);
+ ASTContextMetadataSP context_md = GetContextMetadata(dst_ctx);
- if (iter != m_origins.end())
- return iter->second;
+ MinionMap &minions = context_md->m_minions;
+ MinionMap::iterator minion_iter = minions.find(src_ctx);
+
+ if (minion_iter == minions.end())
+ {
+ MinionSP minion = MinionSP(new Minion(*this, dst_ctx, src_ctx));
+ minions[src_ctx] = minion;
+ return minion;
+ }
else
- return DeclOrigin();
+ {
+ return minion_iter->second;
+ }
}
- typedef std::map <const clang::NamespaceDecl *, NamespaceMapSP> NamespaceMetaMap;
-
- NamespaceMetaMap m_namespace_maps;
- NamespaceMapCompleter *m_map_completer;
+ DeclOrigin
+ GetDeclOrigin (const clang::Decl *decl);
+
clang::FileManager m_file_manager;
- MinionMap m_minions;
- OriginMap m_origins;
};
}
Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=144835&r1=144834&r2=144835&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Wed Nov 16 15:40:57 2011
@@ -113,19 +113,40 @@
return;
}
+ClangASTImporter::DeclOrigin
+ClangASTImporter::GetDeclOrigin(const clang::Decl *decl)
+{
+ ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
+
+ OriginMap &origins = context_md->m_origins;
+
+ OriginMap::iterator iter = origins.find(decl);
+
+ if (iter != origins.end())
+ return iter->second;
+ else
+ return DeclOrigin();
+}
+
void
ClangASTImporter::RegisterNamespaceMap(const clang::NamespaceDecl *decl,
NamespaceMapSP &namespace_map)
{
- m_namespace_maps[decl] = namespace_map;
+ ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
+
+ context_md->m_namespace_maps[decl] = namespace_map;
}
ClangASTImporter::NamespaceMapSP
ClangASTImporter::GetNamespaceMap(const clang::NamespaceDecl *decl)
{
- NamespaceMetaMap::iterator iter = m_namespace_maps.find(decl);
+ ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
+
+ NamespaceMetaMap &namespace_maps = context_md->m_namespace_maps;
- if (iter != m_namespace_maps.end())
+ NamespaceMetaMap::iterator iter = namespace_maps.find(decl);
+
+ if (iter != namespace_maps.end())
return iter->second;
else
return NamespaceMapSP();
@@ -134,6 +155,8 @@
void
ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
{
+ ASTContextMetadataSP context_md = GetContextMetadata(&decl->getASTContext());
+
const DeclContext *parent_context = decl->getDeclContext();
const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
NamespaceMapSP parent_map;
@@ -145,11 +168,11 @@
new_map.reset(new NamespaceMap);
- if (m_map_completer)
+ if (context_md->m_map_completer)
{
std::string namespace_string = decl->getDeclName().getAsString();
- m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
+ context_md->m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
}
RegisterNamespaceMap (decl, new_map);
@@ -158,13 +181,7 @@
void
ClangASTImporter::PurgeMaps (clang::ASTContext *dst_ast)
{
- for (MinionMap::iterator i = m_minions.begin(); i != m_minions.end(); )
- {
- if ((*i).first.dst == dst_ast)
- m_minions.erase(i++);
- else
- ++i;
- }
+ m_metadata_map.erase(dst_ast);
}
ClangASTImporter::NamespaceMapCompleter::~NamespaceMapCompleter ()
@@ -177,7 +194,9 @@
{
lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
- m_master.m_origins[to] = DeclOrigin (m_source_ctx, from);
+ ASTContextMetadataSP context_md = m_master.GetContextMetadata(&to->getASTContext());
+
+ context_md->m_origins[to] = DeclOrigin (m_source_ctx, from);
if (TagDecl *from_tag_decl = dyn_cast<TagDecl>(from))
{
More information about the lldb-commits
mailing list