[Lldb-commits] [lldb] r142690 - in /lldb/trunk: include/lldb/Expression/ClangExpressionDeclMap.h include/lldb/Symbol/ClangASTImporter.h source/Expression/ClangExpressionDeclMap.cpp source/Symbol/ClangASTImporter.cpp

Sean Callanan scallanan at apple.com
Fri Oct 21 15:18:07 PDT 2011


Author: spyffe
Date: Fri Oct 21 17:18:07 2011
New Revision: 142690

URL: http://llvm.org/viewvc/llvm-project?rev=142690&view=rev
Log:
Implemented an extension to the namespace map that
permits a namespace map to be created and populated
when the namespace is imported, not just when it is
requested via FindExternalVisibleDecls().

Modified:
    lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
    lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Symbol/ClangASTImporter.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=142690&r1=142689&r2=142690&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Fri Oct 21 17:18:07 2011
@@ -56,7 +56,7 @@
 /// Fourth and finally, it "dematerializes" the struct after the JITted code has
 /// has executed, placing the new values back where it found the old ones.
 //----------------------------------------------------------------------
-class ClangExpressionDeclMap
+class ClangExpressionDeclMap : public ClangASTImporter::NamespaceMapCompleter
 {
 public:
     //------------------------------------------------------------------
@@ -695,6 +695,25 @@
         assert(m_parser_vars.get());
         m_parser_vars->m_enable_lookups = true;
     }
+    
+    //------------------------------------------------------------------
+    /// [Used by ClangASTImporter] Look up the modules containing a
+    /// given namespace and put the appropriate entries in the namespace
+    /// map.
+    ///
+    /// @param[in] namespace_map
+    ///     The map to be completed.
+    ///
+    /// @param[in] name
+    ///     The name of the namespace to be found.
+    ///
+    /// @param[in] parent_map
+    ///     The map for the namespace's parent namespace, if there is
+    ///     one.
+    //------------------------------------------------------------------
+    void CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
+                               const ConstString &name,
+                               ClangASTImporter::NamespaceMapSP &parent_map) const;
 
 private:
     ClangExpressionVariableList    m_found_entities;           ///< All entities that were looked up for the parser.
@@ -707,7 +726,8 @@
     class ParserVars 
     {
     public:
-        ParserVars() :
+        ParserVars(ClangExpressionDeclMap &decl_map) :
+            m_decl_map(decl_map),
             m_exe_ctx(NULL),
             m_sym_ctx(),
             m_persistent_vars(NULL),
@@ -734,6 +754,8 @@
             if (m_ast_importer->TargetASTContext() != ast_context)
                 return NULL;
             
+            m_ast_importer->InstallMapCompleter(m_decl_map);
+            
             return m_ast_importer.get();
         }
         
@@ -745,6 +767,7 @@
         std::auto_ptr<ClangASTImporter> m_ast_importer; ///< The importer used to import types on the parser's behalf.
         TargetInfo                  m_target_info;      ///< Basic information about the target.
     private:
+        ClangExpressionDeclMap     &m_decl_map;
         DISALLOW_COPY_AND_ASSIGN (ParserVars);
     };
     
@@ -757,7 +780,7 @@
     EnableParserVars()
     {
         if (!m_parser_vars.get())
-            m_parser_vars.reset(new ParserVars);
+            m_parser_vars.reset(new ParserVars(*this));
     }
     
     //----------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Symbol/ClangASTImporter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTImporter.h?rev=142690&r1=142689&r2=142690&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTImporter.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTImporter.h Fri Oct 21 17:18:07 2011
@@ -71,10 +71,27 @@
     typedef std::vector < std::pair<lldb::ModuleSP, ClangNamespaceDecl> > NamespaceMap;
     typedef lldb::SharedPtr<NamespaceMap>::Type NamespaceMapSP;
     
-    void RegisterNamespaceMap(const clang::NamespaceDecl *decl, 
-                              NamespaceMapSP &namespace_map);
+    void RegisterNamespaceMap (const clang::NamespaceDecl *decl, 
+                               NamespaceMapSP &namespace_map);
     
-    NamespaceMapSP GetNamespaceMap(const clang::NamespaceDecl *decl);
+    class NamespaceMapCompleter 
+    {
+    public:
+        virtual ~NamespaceMapCompleter ();
+        
+        virtual void CompleteNamespaceMap (NamespaceMapSP &namespace_map,
+                                           const ConstString &name,
+                                           NamespaceMapSP &parent_map) const = 0;
+    };
+    
+    void InstallMapCompleter (NamespaceMapCompleter &completer)
+    {
+        m_map_completer = &completer;
+    }
+                           
+    NamespaceMapSP GetNamespaceMap (const clang::NamespaceDecl *decl);
+    
+    void BuildNamespaceMap (const clang::NamespaceDecl *decl);
 private:
     
     struct DeclOrigin 
@@ -166,12 +183,13 @@
     
     typedef std::map <const clang::NamespaceDecl *, NamespaceMapSP> NamespaceMetaMap;
     
-    NamespaceMetaMap    m_namespace_maps;
-    clang::FileManager  m_file_manager;
-    clang::ASTContext  *m_target_ctx;
-    MinionMap           m_minions;
-    MinionMap           m_minimal_minions;
-    OriginMap           m_origins;
+    NamespaceMetaMap        m_namespace_maps;
+    NamespaceMapCompleter  *m_map_completer;
+    clang::FileManager      m_file_manager;
+    clang::ASTContext      *m_target_ctx;
+    MinionMap               m_minions;
+    MinionMap               m_minimal_minions;
+    OriginMap               m_origins;
 };
     
 }

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=142690&r1=142689&r2=142690&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Oct 21 17:18:07 2011
@@ -2036,6 +2036,103 @@
     return VariableSP();
 }
 
+// Interface for ClangASTImporter
+
+void 
+ClangExpressionDeclMap::CompleteNamespaceMap (ClangASTImporter::NamespaceMapSP &namespace_map,
+                                              const ConstString &name,
+                                              ClangASTImporter::NamespaceMapSP &parent_map) const
+{
+    static unsigned int invocation_id = 0;
+    unsigned int current_id = invocation_id++;
+    
+    lldb::LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
+    
+    if (log)
+    {
+        if (parent_map && parent_map->size())
+            log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s in namespace %s",
+                        current_id,
+                        name.GetCString(),
+                        parent_map->begin()->second.GetNamespaceDecl()->getDeclName().getAsString().c_str());
+        else
+            log->Printf("CompleteNamespaceMap[%u] Searching for namespace %s",
+                        current_id,
+                        name.GetCString());
+    }
+
+    
+    if (parent_map)
+    {
+        for (ClangASTImporter::NamespaceMap::iterator i = parent_map->begin(), e = parent_map->end();
+             i != e;
+             ++i)
+        {
+            ClangNamespaceDecl found_namespace_decl;
+            
+            ModuleSP module_sp = i->first;
+            ClangNamespaceDecl module_parent_namespace_decl = i->second;
+            
+            SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
+            
+            if (!symbol_vendor)
+                continue;
+            
+            SymbolContext null_sc;
+                
+            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &module_parent_namespace_decl);
+                
+            if (!found_namespace_decl)
+                continue;
+                
+            namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(module_sp, found_namespace_decl));
+                    
+            if (log)
+                log->Printf("  CMN[%u] Found namespace %s in module %s",
+                            current_id,
+                            name.GetCString(), 
+                            module_sp->GetFileSpec().GetFilename().GetCString());
+        }
+    }
+    else
+    {
+        ModuleList &images = m_parser_vars->m_sym_ctx.target_sp->GetImages();
+        ClangNamespaceDecl null_namespace_decl;
+        
+        for (uint32_t i = 0, e = images.GetSize();
+             i != e;
+             ++i)
+        {
+            ModuleSP image = images.GetModuleAtIndex(i);
+            
+            if (!image)
+                continue;
+            
+            ClangNamespaceDecl found_namespace_decl;
+            
+            SymbolVendor *symbol_vendor = image->GetSymbolVendor();
+            
+            if (!symbol_vendor)
+                continue;
+            
+            SymbolContext null_sc;
+            
+            found_namespace_decl = symbol_vendor->FindNamespace(null_sc, name, &null_namespace_decl);
+            
+            if (!found_namespace_decl)
+                continue;
+            
+            namespace_map->push_back(std::pair<ModuleSP, ClangNamespaceDecl>(image, found_namespace_decl));
+                
+            if (log)
+                log->Printf("  CMN[%u] Found namespace %s in module %s",
+                            current_id,
+                            name.GetCString(), 
+                            image->GetFileSpec().GetFilename().GetCString());
+        }
+    }
+}
+
 // Interface for ClangASTSource
 
 void
@@ -2067,7 +2164,7 @@
         
     if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
     {
-        ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->m_ast_importer->GetNamespaceMap(namespace_context);
+        ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->GetASTImporter(context.GetASTContext())->GetNamespaceMap(namespace_context);
         
         if (log && log->GetVerbose())
             log->Printf("  FEVD[%u] Inspecting namespace map %p (%d entries)", 
@@ -2075,6 +2172,9 @@
                         namespace_map.get(), 
                         (int)namespace_map->size());
         
+        if (!namespace_map)
+            return;
+        
         for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(), e = namespace_map->end();
              i != e;
              ++i)

Modified: lldb/trunk/source/Symbol/ClangASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTImporter.cpp?rev=142690&r1=142689&r2=142690&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTImporter.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTImporter.cpp Fri Oct 21 17:18:07 2011
@@ -10,8 +10,10 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "lldb/Core/Log.h"
+#include "lldb/Core/Module.h
 #include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/ClangASTImporter.h"
+#include "lldb/Symbol/ClangNamespaceDecl.h"
 
 using namespace lldb_private;
 using namespace clang;
@@ -111,6 +113,35 @@
         return NamespaceMapSP();
 }
 
+void 
+ClangASTImporter::BuildNamespaceMap(const clang::NamespaceDecl *decl)
+{
+    const DeclContext *parent_context = decl->getDeclContext();
+    const NamespaceDecl *parent_namespace = dyn_cast<NamespaceDecl>(parent_context);
+    NamespaceMapSP parent_map;
+    
+    if (parent_namespace)
+        parent_map = GetNamespaceMap(parent_namespace);
+    
+    NamespaceMapSP new_map;
+    
+    new_map.reset(new NamespaceMap);
+ 
+    if (m_map_completer)
+    {
+        std::string namespace_string = decl->getDeclName().getAsString();
+    
+        m_map_completer->CompleteNamespaceMap (new_map, ConstString(namespace_string.c_str()), parent_map);
+    }
+    
+    RegisterNamespaceMap (decl, new_map);
+}
+
+ClangASTImporter::NamespaceMapCompleter::~NamespaceMapCompleter ()
+{
+    return;
+}
+
 clang::Decl 
 *ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to)
 {
@@ -131,6 +162,15 @@
                         (to_tag_decl->hasExternalVisibleStorage() ? " Visible" : ""));
     }
     
+    if (isa<NamespaceDecl>(from))
+    {
+        NamespaceDecl *to_namespace_decl = dyn_cast<NamespaceDecl>(to);
+        
+        m_master.BuildNamespaceMap(to_namespace_decl);
+        
+        to_namespace_decl->setHasExternalVisibleStorage();
+    }
+    
     if (isa<ObjCInterfaceDecl>(from))
     {
         ObjCInterfaceDecl *to_interface_decl = dyn_cast<ObjCInterfaceDecl>(to);





More information about the lldb-commits mailing list