[Lldb-commits] [lldb] r143275 - in /lldb/trunk: include/lldb/Expression/ClangASTSource.h include/lldb/Expression/ClangExpressionDeclMap.h source/Expression/ClangASTSource.cpp source/Expression/ClangExpressionDeclMap.cpp source/Expression/ClangUserExpression.cpp source/Expression/ClangUtilityFunction.cpp

Sean Callanan scallanan at apple.com
Fri Oct 28 18:58:46 PDT 2011


Author: spyffe
Date: Fri Oct 28 20:58:46 2011
New Revision: 143275

URL: http://llvm.org/viewvc/llvm-project?rev=143275&view=rev
Log:
I moved the responsibility for interacting with the
AST importer on completing namespace mappings from
ClangExpressionDeclMap to ClangASTSource.

ClangASTSource now contains a TargetSP which it
uses to lookup namespaces in all of a target's
modules.  I will use the TargetSP in the future to
look up globals.

Modified:
    lldb/trunk/include/lldb/Expression/ClangASTSource.h
    lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
    lldb/trunk/source/Expression/ClangASTSource.cpp
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/ClangUserExpression.cpp
    lldb/trunk/source/Expression/ClangUtilityFunction.cpp

Modified: lldb/trunk/include/lldb/Expression/ClangASTSource.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangASTSource.h?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangASTSource.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangASTSource.h Fri Oct 28 20:58:46 2011
@@ -15,11 +15,10 @@
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "lldb/Symbol/ClangASTImporter.h"
+#include "lldb/Target/Target.h"
 
 namespace lldb_private {
     
-class ClangExpressionDeclMap;
-
 //----------------------------------------------------------------------
 /// @class ClangASTSource ClangASTSource.h "lldb/Expression/ClangASTSource.h"
 /// @brief Provider for named objects defined in the debug info for Clang
@@ -31,7 +30,9 @@
 /// to Clang for these names, consulting the ClangExpressionDeclMap to do
 /// the actual lookups.
 //----------------------------------------------------------------------
-class ClangASTSource : public clang::ExternalASTSource 
+class ClangASTSource : 
+    public clang::ExternalASTSource,
+    public ClangASTImporter::NamespaceMapCompleter
 {
 public:
     //------------------------------------------------------------------
@@ -42,11 +43,12 @@
     /// @param[in] declMap
     ///     A reference to the LLDB object that handles entity lookup.
     //------------------------------------------------------------------
-	ClangASTSource () :
+	ClangASTSource (const lldb::TargetSP &target) :
         m_ast_context (NULL),
         m_active_lookups (),
         m_import_in_progress (false),
-        m_lookups_enabled (false)
+        m_lookups_enabled (false),
+        m_target (target)
     {
     }
     
@@ -69,6 +71,13 @@
 	
     void InstallASTContext (clang::ASTContext *ast_context)
     {
+        if (!m_ast_importer.get() ||
+            m_ast_importer->TargetASTContext() != ast_context)
+        {
+            m_ast_importer.reset(new ClangASTImporter(ast_context));
+            m_ast_importer->InstallMapCompleter(*this);
+        }
+        
         m_ast_context = ast_context;
     }
     
@@ -145,6 +154,29 @@
     void StartTranslationUnit (clang::ASTConsumer *Consumer);
     
     //
+    // APIs for NamespaceMapCompleter
+    //
+    
+    
+    //------------------------------------------------------------------
+    /// 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;
+    
+    //
     // Helper APIs
     //
     
@@ -223,8 +255,10 @@
     bool                    m_import_in_progress;
     bool                    m_lookups_enabled;
 
-	clang::ASTContext      *m_ast_context;     ///< The parser's AST context, for copying types into
-    std::set<const char *>  m_active_lookups;
+    const lldb::TargetSP                m_target;           ///< The target to use in finding variables and types.
+	clang::ASTContext                  *m_ast_context;      ///< The parser's AST context, for copying types into
+    std::auto_ptr<ClangASTImporter>     m_ast_importer;
+    std::set<const char *>              m_active_lookups;
 };
 
 //----------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h (original)
+++ lldb/trunk/include/lldb/Expression/ClangExpressionDeclMap.h Fri Oct 28 20:58:46 2011
@@ -58,8 +58,7 @@
 /// has executed, placing the new values back where it found the old ones.
 //----------------------------------------------------------------------
 class ClangExpressionDeclMap : 
-    public ClangASTSource,
-    public ClangASTImporter::NamespaceMapCompleter
+    public ClangASTSource
 {
 public:
     //------------------------------------------------------------------
@@ -72,7 +71,8 @@
     ///     the result persistent variable, and instead marks the variable
     ///     as persisting.
     //------------------------------------------------------------------
-    ClangExpressionDeclMap (bool keep_result_in_memory);
+    ClangExpressionDeclMap (bool keep_result_in_memory,
+                            ExecutionContext &exe_ctx);
     
     //------------------------------------------------------------------
     /// Destructor
@@ -663,25 +663,6 @@
     //------------------------------------------------------------------
     void
     CompleteType (clang::ObjCInterfaceDecl *interface_decl);
-    
-    //------------------------------------------------------------------
-    /// [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.
@@ -714,19 +695,6 @@
             return NULL;
         }
         
-        ClangASTImporter *GetASTImporter (clang::ASTContext *ast_context)
-        {            
-            if (!m_ast_importer.get())
-                m_ast_importer.reset(new ClangASTImporter(ast_context));
-            
-            if (m_ast_importer->TargetASTContext() != ast_context)
-                return NULL;
-            
-            m_ast_importer->InstallMapCompleter(m_decl_map);
-            
-            return m_ast_importer.get();
-        }
-        
         ExecutionContext           *m_exe_ctx;          ///< The execution context to use when parsing.
         SymbolContext               m_sym_ctx;          ///< The symbol context to use in finding variables and types.
         ClangPersistentVariables   *m_persistent_vars;  ///< The persistent variables for the process.

Modified: lldb/trunk/source/Expression/ClangASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangASTSource.cpp?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangASTSource.cpp (original)
+++ lldb/trunk/source/Expression/ClangASTSource.cpp Fri Oct 28 20:58:46 2011
@@ -11,9 +11,13 @@
 #include "clang/AST/ASTContext.h"
 #include "lldb/Core/Log.h"
 #include "lldb/Core/Module.h"
+#include "lldb/Core/ModuleList.h"
 #include "lldb/Expression/ClangASTSource.h"
 #include "lldb/Expression/ClangExpression.h"
 #include "lldb/Expression/ClangExpressionDeclMap.h"
+#include "lldb/Symbol/ClangNamespaceDecl.h"
+#include "lldb/Symbol/SymbolVendor.h"
+#include "lldb/Target/Target.h"
 
 using namespace clang;
 using namespace lldb_private;
@@ -143,6 +147,101 @@
     return ELR_Success;
 }
 
+void 
+ClangASTSource::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;
+            
+            lldb::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<lldb::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_target->GetImages();
+        ClangNamespaceDecl null_namespace_decl;
+        
+        for (uint32_t i = 0, e = images.GetSize();
+             i != e;
+             ++i)
+        {
+            lldb::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<lldb::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());
+        }
+    }
+}
+
 clang::NamedDecl *
 NameSearchContext::AddVarDecl(void *type) 
 {

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Fri Oct 28 20:58:46 2011
@@ -48,7 +48,8 @@
 using namespace lldb_private;
 using namespace clang;
 
-ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory) :
+ClangExpressionDeclMap::ClangExpressionDeclMap (bool keep_result_in_memory, ExecutionContext &exe_ctx) :
+    ClangASTSource (exe_ctx.GetTargetSP()),
     m_found_entities (),
     m_struct_members (),
     m_keep_result_in_memory (keep_result_in_memory),
@@ -2128,103 +2129,6 @@
     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
@@ -2260,7 +2164,7 @@
         
     if (const NamespaceDecl *namespace_context = dyn_cast<NamespaceDecl>(context.m_decl_context))
     {
-        ClangASTImporter::NamespaceMapSP namespace_map = m_parser_vars->GetASTImporter(m_ast_context)->GetNamespaceMap(namespace_context);
+        ClangASTImporter::NamespaceMapSP namespace_map = m_ast_importer->GetNamespaceMap(namespace_context);
         
         if (log && log->GetVerbose())
             log->Printf("  FEVD[%u] Inspecting namespace map %p (%d entries)", 
@@ -2757,9 +2661,7 @@
     
     if (!context_decl)
         return ELR_Failure;
-    
-    ASTContext *ast_context = &context_decl->getASTContext();
-    
+        
     static unsigned int invocation_id = 0;
     unsigned int current_id = invocation_id++;
     
@@ -2785,12 +2687,7 @@
     Decl *original_decl = NULL;
     ASTContext *original_ctx = NULL;
     
-    ClangASTImporter *ast_importer = m_parser_vars->GetASTImporter(ast_context);
-    
-    if (!ast_importer)
-        return ELR_Failure;
-    
-    if (!ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
+    if (!m_ast_importer->ResolveDeclOrigin(context_decl, &original_decl, &original_ctx))
         return ELR_Failure;
     
     if (log)
@@ -2829,7 +2726,7 @@
                     log->Printf("  FELD[%d] Adding lexical decl %s", current_id, ast_dumper.GetCString());
             }
                         
-            Decl *copied_decl = ast_importer->CopyDecl(original_ctx, decl);
+            Decl *copied_decl = m_ast_importer->CopyDecl(original_ctx, decl);
             
             decls.push_back(copied_decl);
         }
@@ -2853,7 +2750,7 @@
         dumper.ToLog(log, "      [CTD] ");
     }
         
-    m_parser_vars->GetASTImporter(&tag_decl->getASTContext())->CompleteTagDecl (tag_decl);
+    m_ast_importer->CompleteTagDecl (tag_decl);
 
     if (log)
     {
@@ -2878,7 +2775,7 @@
         dumper.ToLog(log, "      [COID] ");    
     }
     
-    m_parser_vars->GetASTImporter(&interface_decl->getASTContext())->CompleteObjCInterfaceDecl (interface_decl);
+    m_ast_importer->CompleteObjCInterfaceDecl (interface_decl);
 
     if (log)
     {
@@ -3251,12 +3148,11 @@
     
     const ClangNamespaceDecl &namespace_decl = namespace_decls->begin()->second;
     
-    Decl *copied_decl = m_parser_vars->GetASTImporter(m_ast_context)->CopyDecl(namespace_decl.GetASTContext(), 
-                                                                               namespace_decl.GetNamespaceDecl());
+    Decl *copied_decl = m_ast_importer->CopyDecl(namespace_decl.GetASTContext(), namespace_decl.GetNamespaceDecl());
     
     NamespaceDecl *copied_namespace_decl = dyn_cast<NamespaceDecl>(copied_decl);
     
-    m_parser_vars->GetASTImporter(m_ast_context)->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
+    m_ast_importer->RegisterNamespaceMap(copied_namespace_decl, namespace_decls);
     
     return dyn_cast<NamespaceDecl>(copied_decl);
 }
@@ -3416,11 +3312,8 @@
     assert (m_parser_vars.get());
     
     m_parser_vars->m_ignore_lookups = true;
-    
-    lldb_private::ClangASTImporter *importer = m_parser_vars->GetASTImporter(dest_context);
-    
-    QualType ret_qual_type = importer->CopyType (source_context,
-                                                 QualType::getFromOpaquePtr(clang_type));
+        
+    QualType ret_qual_type = m_ast_importer->CopyType (source_context, QualType::getFromOpaquePtr(clang_type));
     
     void *ret = ret_qual_type.getAsOpaquePtr();
     

Modified: lldb/trunk/source/Expression/ClangUserExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUserExpression.cpp?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUserExpression.cpp (original)
+++ lldb/trunk/source/Expression/ClangUserExpression.cpp Fri Oct 28 20:58:46 2011
@@ -231,7 +231,7 @@
     
     m_desired_type = desired_type;
     
-    m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory));
+    m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx));
     
     if (!m_expr_decl_map->WillParse(exe_ctx))
     {

Modified: lldb/trunk/source/Expression/ClangUtilityFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangUtilityFunction.cpp?rev=143275&r1=143274&r2=143275&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangUtilityFunction.cpp (original)
+++ lldb/trunk/source/Expression/ClangUtilityFunction.cpp Fri Oct 28 20:58:46 2011
@@ -99,7 +99,7 @@
     
     bool keep_result_in_memory = false;
     
-    m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory));
+    m_expr_decl_map.reset(new ClangExpressionDeclMap(keep_result_in_memory, exe_ctx));
     
     m_data_allocator.reset(new ProcessDataAllocator(*process));
     





More information about the lldb-commits mailing list