zturner created this revision.
zturner added a reviewer: clayborg.
zturner added a subscriber: lldb-commits.

This patch attempts to remove the coupling between `ClangASTContext` and DWARF 
debug information.  Previously, `TypeSystem` exposed a method called 
`GetDWARFParser`, which means that any TypeSystem had to have some concept of 
DWARF.  If we want to implement a PDB TypeSystem though, it doesn't make sense 
to support DWARF, and we don't want to go adding something like `GetPDBParser` 
to the generic `TypeSystem` either.  

This patch removes all of this code from `TypeSystem` and implements it 
specifically on `ClangASTContext`.  `SymbolFileDWARF` and related classes 
(which are all DWARF specific anyway) can now use llvm casting mechanics to 
check if the TypeSystem is a `ClangASTContext`, and if so it can use 
`GetDWARFParser`.  

In a followup patch, this will allow PDB and DWARF debug information to in 
theory live side by side for the same module.

This patch doesn't introduce a `PDBASTParser` yet, it just lays the framework 
to make this possible in a followup patch.

http://reviews.llvm.org/D18381

Files:
  include/lldb/Symbol/ClangASTContext.h
  include/lldb/Symbol/ClangTypeImportHelper.h
  include/lldb/Symbol/GoASTContext.h
  include/lldb/Symbol/JavaASTContext.h
  include/lldb/Symbol/SymbolFile.h
  include/lldb/Symbol/TypeSystem.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Symbol/CMakeLists.txt
  source/Symbol/ClangASTContext.cpp
  source/Symbol/ClangTypeImportHelper.cpp
  source/Symbol/GoASTContext.cpp
  source/Symbol/JavaASTContext.cpp

Index: source/Symbol/JavaASTContext.cpp
===================================================================
--- source/Symbol/JavaASTContext.cpp
+++ source/Symbol/JavaASTContext.cpp
@@ -496,14 +496,6 @@
     return m_pointer_byte_size;
 }
 
-DWARFASTParser *
-JavaASTContext::GetDWARFParser()
-{
-    if (!m_dwarf_ast_parser_ap)
-        m_dwarf_ast_parser_ap.reset(new DWARFASTParserJava(*this));
-    return m_dwarf_ast_parser_ap.get();
-}
-
 ConstString
 JavaASTContext::DeclGetName(void *opaque_decl)
 {
Index: source/Symbol/GoASTContext.cpp
===================================================================
--- source/Symbol/GoASTContext.cpp
+++ source/Symbol/GoASTContext.cpp
@@ -1639,14 +1639,6 @@
     return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE;
 }
 
-DWARFASTParser *
-GoASTContext::GetDWARFParser()
-{
-    if (!m_dwarf_ast_parser_ap)
-        m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this));
-    return m_dwarf_ast_parser_ap.get();
-}
-
 UserExpression *
 GoASTContextForExpr::GetUserExpression(const char *expr, const char *expr_prefix, lldb::LanguageType language,
                                        Expression::ResultType desired_type, const EvaluateExpressionOptions &options)
Index: source/Symbol/ClangTypeImportHelper.cpp
===================================================================
--- /dev/null
+++ source/Symbol/ClangTypeImportHelper.cpp
@@ -0,0 +1,71 @@
+//===-- ClangTypeImportHelper.cpp -------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Symbol/ClangTypeImportHelper.h"
+#include "lldb/Symbol/ClangASTContext.h"
+#include "lldb/Symbol/ClangASTImporter.h"
+
+using namespace lldb_private;
+
+bool
+ClangTypeImportHelper::CanCompleteType(const CompilerType &compiler_type, ClangASTImporter &importer)
+{
+    return ClangASTContext::CanImport(compiler_type, importer);
+}
+
+bool
+ClangTypeImportHelper::CompleteType(const CompilerType &compiler_type, ClangASTImporter &importer)
+{
+    if (!CanCompleteType(compiler_type, importer))
+        return false;
+
+    if (ClangASTContext::Import(compiler_type, importer))
+    {
+        ClangASTContext::CompleteTagDeclarationDefinition(compiler_type);
+        return true;
+    }
+
+    ClangASTContext::SetHasExternalStorage(compiler_type.GetOpaqueQualType(), false);
+    return false;
+}
+
+bool
+ClangTypeImportHelper::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
+                                        llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
+                                        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
+                                        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
+{
+    RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find(record_decl);
+    bool success = false;
+    base_offsets.clear();
+    vbase_offsets.clear();
+    if (pos != m_record_decl_to_layout_map.end())
+    {
+        bit_size = pos->second.bit_size;
+        alignment = pos->second.alignment;
+        field_offsets.swap(pos->second.field_offsets);
+        base_offsets.swap(pos->second.base_offsets);
+        vbase_offsets.swap(pos->second.vbase_offsets);
+        m_record_decl_to_layout_map.erase(pos);
+        success = true;
+    }
+    else
+    {
+        bit_size = 0;
+        alignment = 0;
+        field_offsets.clear();
+    }
+    return success;
+}
+
+void
+ClangTypeImportHelper::InsertRecordDecl(clang::RecordDecl *decl, const LayoutInfo &layout)
+{
+    m_record_decl_to_layout_map.insert(std::make_pair(decl, layout));
+}
\ No newline at end of file
Index: source/Symbol/ClangASTContext.cpp
===================================================================
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -687,7 +687,7 @@
     }
 
     void
-    HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const clang::Diagnostic &info)
+    HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &info)
     {
         if (m_log)
         {
@@ -9668,9 +9668,8 @@
     }
 }
 
-
-DWARFASTParser *
-ClangASTContext::GetDWARFParser ()
+DWARFASTParserClang *
+ClangASTContext::GetDWARFParser()
 {
     if (!m_dwarf_ast_parser_ap)
         m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this));
Index: source/Symbol/CMakeLists.txt
===================================================================
--- source/Symbol/CMakeLists.txt
+++ source/Symbol/CMakeLists.txt
@@ -5,6 +5,7 @@
   ClangASTImporter.cpp
   ClangExternalASTSourceCallbacks.cpp
   ClangExternalASTSourceCommon.cpp
+  ClangTypeImportHelper.cpp
   CompilerDecl.cpp
   CompilerDeclContext.cpp
   CompilerType.cpp
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -243,7 +243,6 @@
                    const lldb_private::ConstString &name,
                    const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
 
-
     //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -54,20 +54,21 @@
 #include "lldb/Utility/TaskPool.h"
 
 #include "DWARFASTParser.h"
+#include "DWARFASTParserClang.h"
 #include "DWARFCompileUnit.h"
+#include "DWARFDIECollection.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
 #include "DWARFDebugLine.h"
 #include "DWARFDebugMacro.h"
 #include "DWARFDebugPubnames.h"
 #include "DWARFDebugRanges.h"
 #include "DWARFDeclContext.h"
-#include "DWARFDIECollection.h"
 #include "DWARFFormValue.h"
 #include "LogChannelDWARF.h"
-#include "SymbolFileDWARFDwo.h"
 #include "SymbolFileDWARFDebugMap.h"
+#include "SymbolFileDWARFDwo.h"
 
 #include <map>
 
@@ -993,10 +994,10 @@
     if (die.IsValid())
     {
         TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
-
-        if (type_system)
+        ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system);
+        if (clang_type_system)
         {
-            DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+            DWARFASTParser *dwarf_ast = clang_type_system->GetDWARFParser();
             if (dwarf_ast)
                 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
         }
@@ -1461,7 +1462,11 @@
 SymbolFileDWARF::ParseDeclsForContext (CompilerDeclContext decl_ctx)
 {
     TypeSystem *type_system = decl_ctx.GetTypeSystem();
-    DWARFASTParser *ast_parser = type_system->GetDWARFParser();
+    ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system);
+    if (!clang_type_system)
+        return;
+
+    DWARFASTParser *ast_parser = clang_type_system->GetDWARFParser();
     std::vector<DWARFDIE> decl_ctx_die_list = ast_parser->GetDIEForDeclContext(decl_ctx);
 
     for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
@@ -1609,13 +1614,15 @@
         return true;
     }
     TypeSystem *type_system = compiler_type.GetTypeSystem();
-    if (type_system)
-    {
-        DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-        if (dwarf_ast)
-            return dwarf_ast->CanCompleteType(compiler_type);
-    }
-    return false;
+    ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system);
+    if (!clang_type_system)
+        return false;
+
+    DWARFASTParserClang *ast_parser = clang_type_system->GetDWARFParser();
+    if (!ast_parser)
+        return false;
+
+    return ast_parser->CanCompleteType(compiler_type);
 }
 
 
@@ -1625,9 +1632,10 @@
     lldb_private::Mutex::Locker locker(GetObjectFile()->GetModule()->GetMutex());
 
     TypeSystem *type_system = compiler_type.GetTypeSystem();
-    if (type_system)
+    ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system);
+    if (clang_type_system)
     {
-        DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+        DWARFASTParserClang *dwarf_ast = clang_type_system->GetDWARFParser();
         if (dwarf_ast && dwarf_ast->CanCompleteType(compiler_type))
             return dwarf_ast->CompleteType(compiler_type);
     }
@@ -3817,41 +3825,41 @@
 {
     TypeSP type_sp;
 
-    if (die)
-    {
-        TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
+    if (!die)
+        return TypeSP();
 
-        if (type_system)
+    TypeSystem *type_system = GetTypeSystemForLanguage(die.GetCU()->GetLanguageType());
+    ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(type_system);
+    if (!clang_type_system)
+        return TypeSP();
+
+    DWARFASTParser *dwarf_ast = clang_type_system->GetDWARFParser();
+    if (!dwarf_ast)
+        return TypeSP();
+
+    Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
+    type_sp = dwarf_ast->ParseTypeFromDWARF(sc, die, log, type_is_new_ptr);
+    if (!type_sp)
+        return TypeSP();
+
+    TypeList *type_list = GetTypeList();
+    if (type_list)
+        type_list->Insert(type_sp);
+
+    if (die.Tag() == DW_TAG_subprogram)
+    {
+        DIERef die_ref = die.GetDIERef();
+        std::string scope_qualified_name(GetDeclContextForUID(die.GetID()).GetScopeQualifiedName().AsCString(""));
+        if (scope_qualified_name.size())
         {
-            DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-            if (dwarf_ast)
+            NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
+            if (iter != m_function_scope_qualified_name_map.end())
+                (*iter).second->insert(die_ref);
+            else
             {
-                Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
-                type_sp = dwarf_ast->ParseTypeFromDWARF (sc, die, log, type_is_new_ptr);
-                if (type_sp)
-                {
-                    TypeList* type_list = GetTypeList();
-                    if (type_list)
-                        type_list->Insert(type_sp);
-
-                    if (die.Tag() == DW_TAG_subprogram)
-                    {
-                        DIERef die_ref = die.GetDIERef();
-                        std::string scope_qualified_name(GetDeclContextForUID(die.GetID()).GetScopeQualifiedName().AsCString(""));
-                        if (scope_qualified_name.size())
-                        {
-                            NameToOffsetMap::iterator iter = m_function_scope_qualified_name_map.find(scope_qualified_name);
-                            if (iter != m_function_scope_qualified_name_map.end())
-                                (*iter).second->insert(die_ref);
-                            else
-                            {
-                                DIERefSetSP new_set(new std::set<DIERef>);
-                                new_set->insert(die_ref);
-                                m_function_scope_qualified_name_map.emplace(std::make_pair(scope_qualified_name, new_set));
-                            }
-                        }
-                    }
-                }
+                DIERefSetSP new_set(new std::set<DIERef>);
+                new_set->insert(die_ref);
+                m_function_scope_qualified_name_map.emplace(std::make_pair(scope_qualified_name, new_set));
             }
         }
     }
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -9,22 +9,26 @@
 
 #include "DWARFDIE.h"
 
+#include "DWARFASTParser.h"
 #include "DWARFCompileUnit.h"
+#include "DWARFDIECollection.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
 #include "DWARFDebugInfoEntry.h"
 #include "DWARFDebugRanges.h"
 #include "DWARFDeclContext.h"
-#include "DWARFDIECollection.h"
 #include "DWARFFormValue.h"
 #include "SymbolFileDWARF.h"
 
 #include "lldb/Core/Module.h"
+#include "lldb/Symbol/ClangASTContext.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/TypeSystem.h"
 
+#include "Plugins\SymbolFile\DWARF\DWARFASTParserClang.h"
+
 using namespace lldb_private;
 
 DIERef
@@ -404,11 +408,10 @@
 DWARFASTParser *
 DWARFDIE::GetDWARFParser () const
 {
-    lldb_private::TypeSystem *type_system = GetTypeSystem ();
-    if (type_system)
-        return type_system->GetDWARFParser();
-    else
+    ClangASTContext *clang_type_system = llvm::dyn_cast_or_null<ClangASTContext>(GetTypeSystem());
+    if (!clang_type_system)
         return nullptr;
+    return clang_type_system->GetDWARFParser();
 }
 
 bool
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -19,11 +19,12 @@
 #include "clang/AST/CharUnits.h"
 
 // Project includes
+#include "DWARFASTParser.h"
+#include "DWARFDefines.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Symbol/ClangASTContext.h"
-#include "DWARFDefines.h"
-#include "DWARFASTParser.h"
+#include "lldb/Symbol/ClangTypeImportHelper.h"
 
 class DWARFDebugInfoEntry;
 class DWARFDIECollection;
@@ -35,27 +36,17 @@
 
     ~DWARFASTParserClang() override;
 
+    // DWARFASTParser interface.
     lldb::TypeSP
-    ParseTypeFromDWARF (const lldb_private::SymbolContext& sc,
-                        const DWARFDIE &die,
-                        lldb_private::Log *log,
-                        bool *type_is_new_ptr) override;
-
+    ParseTypeFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die, lldb_private::Log *log,
+                       bool *type_is_new_ptr) override;
 
     lldb_private::Function *
-    ParseFunctionFromDWARF (const lldb_private::SymbolContext& sc,
-                            const DWARFDIE &die) override;
-
-    bool
-    CanCompleteType (const lldb_private::CompilerType &compiler_type) override;
+    ParseFunctionFromDWARF(const lldb_private::SymbolContext &sc, const DWARFDIE &die) override;
 
     bool
-    CompleteType (const lldb_private::CompilerType &compiler_type) override;
-
-    bool
-    CompleteTypeFromDWARF (const DWARFDIE &die,
-                           lldb_private::Type *type,
-                           lldb_private::CompilerType &compiler_type) override;
+    CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
+                          lldb_private::CompilerType &compiler_type) override;
 
     lldb_private::CompilerDecl
     GetDeclForUIDFromDWARF (const DWARFDIE &die) override;
@@ -70,61 +61,41 @@
     GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) override;
 
     bool
-    LayoutRecordType(const clang::RecordDecl *record_decl,
-                     uint64_t &bit_size,
-                     uint64_t &alignment,
+    CanCompleteType(const lldb_private::CompilerType &compiler_type);
+
+    bool
+    CompleteType(const lldb_private::CompilerType &compiler_type);
+
+    bool
+    LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
                      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
 
 protected:
     class DelayedAddObjCClassProperty;
     typedef std::vector <DelayedAddObjCClassProperty> DelayedPropertyList;
 
-    struct LayoutInfo
-    {
-        LayoutInfo () :
-        bit_size(0),
-        alignment(0),
-        field_offsets(),
-        base_offsets(),
-        vbase_offsets()
-        {
-        }
-        uint64_t bit_size;
-        uint64_t alignment;
-        llvm::DenseMap<const clang::FieldDecl *, uint64_t> field_offsets;
-        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> base_offsets;
-        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> vbase_offsets;
-    };
-
     clang::BlockDecl *
     ResolveBlockDIE (const DWARFDIE &die);
 
     clang::NamespaceDecl *
     ResolveNamespaceDIE (const DWARFDIE &die);
 
-    typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo> RecordDeclToLayoutMap;
-
     bool
     ParseTemplateDIE (const DWARFDIE &die,
                       lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos);
     bool
     ParseTemplateParameterInfos (const DWARFDIE &parent_die,
                                  lldb_private::ClangASTContext::TemplateParameterInfos &template_param_infos);
 
     bool
-    ParseChildMembers (const lldb_private::SymbolContext& sc,
-                       const DWARFDIE &die,
-                       lldb_private::CompilerType &class_compiler_type,
-                       const lldb::LanguageType class_language,
-                       std::vector<clang::CXXBaseSpecifier *>& base_classes,
-                       std::vector<int>& member_accessibilities,
-                       DWARFDIECollection& member_function_dies,
-                       DelayedPropertyList& delayed_properties,
-                       lldb::AccessType &default_accessibility,
-                       bool &is_a_class,
-                       LayoutInfo &layout_info);
+    ParseChildMembers(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
+                      lldb_private::CompilerType &class_compiler_type, const lldb::LanguageType class_language,
+                      std::vector<clang::CXXBaseSpecifier *> &base_classes, std::vector<int> &member_accessibilities,
+                      DWARFDIECollection &member_function_dies, DelayedPropertyList &delayed_properties,
+                      lldb::AccessType &default_accessibility, bool &is_a_class,
+                      lldb_private::ClangTypeImportHelper::LayoutInfo &layout_info);
 
     size_t
     ParseChildParameters (const lldb_private::SymbolContext& sc,
@@ -207,7 +178,7 @@
     DeclToDIEMap m_decl_to_die;
     DIEToDeclContextMap m_die_to_decl_ctx;
     DeclContextToDIEMap m_decl_ctx_to_die;
-    RecordDeclToLayoutMap m_record_decl_to_layout_map;
+    lldb_private::ClangTypeImportHelper m_type_import_helper;
     std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_ap;
 };
 
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -123,13 +123,10 @@
 DWARFASTParserClang::GetClangASTImporter()
 {
     if (!m_clang_ast_importer_ap)
-    {
         m_clang_ast_importer_ap.reset (new ClangASTImporter);
-    }
     return *m_clang_ast_importer_ap;
 }
 
-
 TypeSP
 DWARFASTParserClang::ParseTypeFromDWO (const DWARFDIE &die, Log *log)
 {
@@ -865,7 +862,8 @@
                                 clang::RecordDecl *record_decl = ClangASTContext::GetAsRecordDecl(clang_type);
 
                                 if (record_decl)
-                                    m_record_decl_to_layout_map.insert(std::make_pair(record_decl, LayoutInfo()));
+                                    m_type_import_helper.InsertRecordDecl(record_decl,
+                                                                          ClangTypeImportHelper::LayoutInfo());
                             }
                         }
                         else if (clang_type_was_created)
@@ -1990,34 +1988,27 @@
 bool
 DWARFASTParserClang::CanCompleteType (const lldb_private::CompilerType &compiler_type)
 {
-    if (m_clang_ast_importer_ap)
-        return ClangASTContext::CanImport(compiler_type, GetClangASTImporter());
-    else
-        return false;
+    return m_type_import_helper.CanCompleteType(compiler_type, GetClangASTImporter());
 }
 
 bool
 DWARFASTParserClang::CompleteType (const lldb_private::CompilerType &compiler_type)
 {
-    if (CanCompleteType(compiler_type))
-    {
-        if (ClangASTContext::Import(compiler_type, GetClangASTImporter()))
-        {
-            ClangASTContext::CompleteTagDeclarationDefinition(compiler_type);
-            return true;
-        }
-        else
-        {
-            ClangASTContext::SetHasExternalStorage (compiler_type.GetOpaqueQualType(), false);
-        }
-    }
-    return false;
+    return m_type_import_helper.CompleteType(compiler_type, GetClangASTImporter());
+}
+
+bool
+DWARFASTParserClang::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
+                                      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
+                                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
+                                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
+{
+    return m_type_import_helper.LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets,
+                                                 vbase_offsets);
 }
 
 bool
-DWARFASTParserClang::CompleteTypeFromDWARF (const DWARFDIE &die,
-                                            lldb_private::Type *type,
-                                            CompilerType &clang_type)
+DWARFASTParserClang::CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type, CompilerType &clang_type)
 {
     SymbolFileDWARF *dwarf = die.GetDWARF();
 
@@ -2047,7 +2038,7 @@
         case DW_TAG_union_type:
         case DW_TAG_class_type:
         {
-            LayoutInfo layout_info;
+            ClangTypeImportHelper::LayoutInfo layout_info;
 
             {
                 if (die.HasChildren())
@@ -2283,7 +2274,7 @@
 
                         }
                     }
-                    m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info));
+                    m_type_import_helper.InsertRecordDecl(record_decl, layout_info);
                 }
             }
         }
@@ -2623,19 +2614,14 @@
     return NULL;
 }
 
-
 bool
-DWARFASTParserClang::ParseChildMembers (const SymbolContext& sc,
-                                        const DWARFDIE &parent_die,
-                                        CompilerType &class_clang_type,
-                                        const LanguageType class_language,
-                                        std::vector<clang::CXXBaseSpecifier *>& base_classes,
-                                        std::vector<int>& member_accessibilities,
-                                        DWARFDIECollection& member_function_dies,
-                                        DelayedPropertyList& delayed_properties,
-                                        AccessType& default_accessibility,
-                                        bool &is_a_class,
-                                        LayoutInfo &layout_info)
+DWARFASTParserClang::ParseChildMembers(const SymbolContext &sc, const DWARFDIE &parent_die,
+                                       CompilerType &class_clang_type, const LanguageType class_language,
+                                       std::vector<clang::CXXBaseSpecifier *> &base_classes,
+                                       std::vector<int> &member_accessibilities,
+                                       DWARFDIECollection &member_function_dies,
+                                       DelayedPropertyList &delayed_properties, AccessType &default_accessibility,
+                                       bool &is_a_class, ClangTypeImportHelper::LayoutInfo &layout_info)
 {
     if (!parent_die)
         return 0;
@@ -4071,34 +4057,3 @@
     return (failures.Size() != 0);
 }
 
-
-bool
-DWARFASTParserClang::LayoutRecordType(const clang::RecordDecl *record_decl,
-                                      uint64_t &bit_size,
-                                      uint64_t &alignment,
-                                      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
-                                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
-                                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
-{
-    RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl);
-    bool success = false;
-    base_offsets.clear();
-    vbase_offsets.clear();
-    if (pos != m_record_decl_to_layout_map.end())
-    {
-        bit_size = pos->second.bit_size;
-        alignment = pos->second.alignment;
-        field_offsets.swap(pos->second.field_offsets);
-        base_offsets.swap (pos->second.base_offsets);
-        vbase_offsets.swap (pos->second.vbase_offsets);
-        m_record_decl_to_layout_map.erase(pos);
-        success = true;
-    }
-    else
-    {
-        bit_size = 0;
-        alignment = 0;
-        field_offsets.clear();
-    }
-    return success;
-}
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -33,18 +33,6 @@
                             const DWARFDIE &die) = 0;
 
     virtual bool
-    CanCompleteType (const lldb_private::CompilerType &compiler_type)
-    {
-        return false;
-    }
-
-    virtual bool
-    CompleteType (const lldb_private::CompilerType &compiler_type)
-    {
-        return false;
-    }
-
-    virtual bool
     CompleteTypeFromDWARF (const DWARFDIE &die,
                            lldb_private::Type *type,
                            lldb_private::CompilerType &compiler_type) = 0;
Index: include/lldb/Symbol/TypeSystem.h
===================================================================
--- include/lldb/Symbol/TypeSystem.h
+++ include/lldb/Symbol/TypeSystem.h
@@ -28,9 +28,6 @@
 #include "lldb/Symbol/CompilerDecl.h"
 #include "lldb/Symbol/CompilerDeclContext.h"
 
-class DWARFDIE;
-class DWARFASTParser;
-
 namespace lldb_private {
     
 //----------------------------------------------------------------------
@@ -99,12 +96,6 @@
     virtual void
     Finalize() {}
 
-    virtual DWARFASTParser *
-    GetDWARFParser ()
-    {
-        return nullptr;
-    }
-
     virtual SymbolFile *
     GetSymbolFile () const
     {
Index: include/lldb/Symbol/SymbolFile.h
===================================================================
--- include/lldb/Symbol/SymbolFile.h
+++ include/lldb/Symbol/SymbolFile.h
@@ -154,12 +154,10 @@
                                       lldb_private::TypeList &type_list) = 0;
 
     virtual lldb_private::TypeSystem *
-                            GetTypeSystemForLanguage (lldb::LanguageType language);
+    GetTypeSystemForLanguage(lldb::LanguageType language);
 
     virtual CompilerDeclContext
-                            FindNamespace (const SymbolContext& sc, 
-                                           const ConstString &name,
-                                           const CompilerDeclContext *parent_decl_ctx)
+    FindNamespace(const SymbolContext &sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx)
     {
         return CompilerDeclContext();
     }
Index: include/lldb/Symbol/JavaASTContext.h
===================================================================
--- include/lldb/Symbol/JavaASTContext.h
+++ include/lldb/Symbol/JavaASTContext.h
@@ -58,9 +58,6 @@
     static void
     Terminate();
 
-    DWARFASTParser *
-    GetDWARFParser() override;
-
     uint32_t
     GetPointerByteSize() override;
 
@@ -368,7 +365,6 @@
 
 private:
     uint32_t m_pointer_byte_size;
-    std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;
     JavaTypeMap m_array_type_map;
     JavaTypeMap m_base_type_map;
     JavaTypeMap m_reference_type_map;
Index: include/lldb/Symbol/GoASTContext.h
===================================================================
--- include/lldb/Symbol/GoASTContext.h
+++ include/lldb/Symbol/GoASTContext.h
@@ -59,8 +59,6 @@
 
     static void
     Terminate ();
-    
-    DWARFASTParser *GetDWARFParser() override;
 
     void
     SetAddressByteSize(int byte_size)
@@ -387,7 +385,6 @@
     int m_pointer_byte_size;
     int m_int_byte_size;
     std::unique_ptr<TypeMap> m_types;
-    std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;
 
     GoASTContext(const GoASTContext &) = delete;
     const GoASTContext &operator=(const GoASTContext &) = delete;
Index: include/lldb/Symbol/ClangTypeImportHelper.h
===================================================================
--- /dev/null
+++ include/lldb/Symbol/ClangTypeImportHelper.h
@@ -0,0 +1,61 @@
+//===-- ClangTypeImportHelper.h ---------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SYMBOL_CLANG_TYPE_IMPORT_HELPER_H
+#define LLDB_SYMBOL_CLANG_TYPE_IMPORT_HELPER_H
+
+#include "clang/AST/CharUnits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+
+#include "lldb/Symbol/ClangASTImporter.h"
+
+#include "llvm/ADT/DenseMap.h"
+
+namespace lldb_private
+{
+
+class ClangASTImporter;
+
+class ClangTypeImportHelper
+{
+public:
+    struct LayoutInfo
+    {
+        LayoutInfo() : bit_size(0), alignment(0), field_offsets(), base_offsets(), vbase_offsets() {}
+        uint64_t bit_size;
+        uint64_t alignment;
+        llvm::DenseMap<const clang::FieldDecl *, uint64_t> field_offsets;
+        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> base_offsets;
+        llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> vbase_offsets;
+    };
+
+    bool
+    CanCompleteType(const lldb_private::CompilerType &compiler_type, ClangASTImporter &importer);
+
+    bool
+    CompleteType(const lldb_private::CompilerType &compiler_type, ClangASTImporter &importer);
+
+    void
+    InsertRecordDecl(clang::RecordDecl *decl, const LayoutInfo &layout);
+
+    bool
+    LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
+                     llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
+                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
+                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
+
+private:
+    typedef llvm::DenseMap<const clang::RecordDecl *, LayoutInfo> RecordDeclToLayoutMap;
+
+    RecordDeclToLayoutMap m_record_decl_to_layout_map;
+};
+}
+
+#endif
Index: include/lldb/Symbol/ClangASTContext.h
===================================================================
--- include/lldb/Symbol/ClangASTContext.h
+++ include/lldb/Symbol/ClangASTContext.h
@@ -30,11 +30,13 @@
 
 // Project includes
 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
-#include "lldb/lldb-enumerations.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Core/ConstString.h"
 #include "lldb/Symbol/CompilerType.h"
 #include "lldb/Symbol/TypeSystem.h"
+#include "lldb/lldb-enumerations.h"
+
+class DWARFASTParserClang;
 
 namespace lldb_private {
 
@@ -64,6 +66,9 @@
     void
     Finalize() override;
 
+    DWARFASTParserClang *
+    GetDWARFParser();
+
     //------------------------------------------------------------------
     // PluginInterface functions
     //------------------------------------------------------------------
@@ -518,12 +523,6 @@
                              size_t bit_size);
 
     //------------------------------------------------------------------
-    // TypeSystem methods
-    //------------------------------------------------------------------
-    DWARFASTParser *
-    GetDWARFParser () override;
-
-    //------------------------------------------------------------------
     // ClangASTContext callbacks for external source lookups.
     //------------------------------------------------------------------
     static void
@@ -1212,6 +1211,7 @@
     //------------------------------------------------------------------
     // Classes that inherit from ClangASTContext can see and modify these
     //------------------------------------------------------------------
+    // clang-format off
     std::string                                     m_target_triple;
     std::unique_ptr<clang::ASTContext>              m_ast_ap;
     std::unique_ptr<clang::LangOptions>             m_language_options_ap;
@@ -1225,7 +1225,7 @@
     std::unique_ptr<clang::IdentifierTable>         m_identifier_table_ap;
     std::unique_ptr<clang::SelectorTable>           m_selector_table_ap;
     std::unique_ptr<clang::Builtin::Context>        m_builtins_ap;
-    std::unique_ptr<DWARFASTParser>                 m_dwarf_ast_parser_ap;
+    std::unique_ptr<DWARFASTParserClang>            m_dwarf_ast_parser_ap;
     std::unique_ptr<ClangASTSource>                 m_scratch_ast_source_ap;
     std::unique_ptr<clang::MangleContext>           m_mangle_ctx_ap;
     CompleteTagDeclCallback                         m_callback_tag_decl;
@@ -1235,7 +1235,7 @@
     bool                                            m_ast_owned;
     bool                                            m_can_evaluate_expressions;
     std::map<void *, std::shared_ptr<void>>         m_decl_objects;
-
+    // clang-format on
 private:
     //------------------------------------------------------------------
     // For ClangASTContext only
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to