diff options
Diffstat (limited to 'contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp | 130 |
1 files changed, 115 insertions, 15 deletions
diff --git a/contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp b/contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp index dd73b35d86a9..141937072c73 100644 --- a/contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp +++ b/contrib/llvm/tools/lldb/source/Symbol/ClangASTImporter.cpp @@ -16,7 +16,6 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/ClangASTImporter.h" #include "lldb/Symbol/ClangExternalASTSourceCommon.h" -#include "lldb/Symbol/ClangNamespaceDecl.h" #include "lldb/Utility/LLDBAssert.h" using namespace lldb_private; @@ -60,14 +59,39 @@ ClangASTImporter::CopyType (clang::ASTContext *dst_ast, return QualType(); } -lldb::clang_type_t +lldb::opaque_compiler_type_t ClangASTImporter::CopyType (clang::ASTContext *dst_ast, clang::ASTContext *src_ast, - lldb::clang_type_t type) + lldb::opaque_compiler_type_t type) { return CopyType (dst_ast, src_ast, QualType::getFromOpaquePtr(type)).getAsOpaquePtr(); } +CompilerType +ClangASTImporter::CopyType (ClangASTContext &dst_ast, + const CompilerType &src_type) +{ + clang::ASTContext *dst_clang_ast = dst_ast.getASTContext(); + if (dst_clang_ast) + { + ClangASTContext *src_ast = llvm::dyn_cast_or_null<ClangASTContext>(src_type.GetTypeSystem()); + if (src_ast) + { + clang::ASTContext *src_clang_ast = src_ast->getASTContext(); + if (src_clang_ast) + { + lldb::opaque_compiler_type_t dst_clang_type = CopyType(dst_clang_ast, + src_clang_ast, + src_type.GetOpaqueQualType()); + + if (dst_clang_type) + return CompilerType(&dst_ast, dst_clang_type); + } + } + } + return CompilerType(); +} + clang::Decl * ClangASTImporter::CopyDecl (clang::ASTContext *dst_ast, clang::ASTContext *src_ast, @@ -238,11 +262,19 @@ public: } }; -lldb::clang_type_t +lldb::opaque_compiler_type_t ClangASTImporter::DeportType (clang::ASTContext *dst_ctx, clang::ASTContext *src_ctx, - lldb::clang_type_t type) -{ + lldb::opaque_compiler_type_t type) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); + + if (log) + log->Printf(" [ClangASTImporter] DeportType called on (%sType*)0x%llx from (ASTContext*)%p to (ASTContext*)%p", + QualType::getFromOpaquePtr(type)->getTypeClassName(), (unsigned long long)type, + static_cast<void*>(src_ctx), + static_cast<void*>(dst_ctx)); + MinionSP minion_sp (GetMinion (dst_ctx, src_ctx)); if (!minion_sp) @@ -261,7 +293,7 @@ ClangASTImporter::DeportType (clang::ASTContext *dst_ctx, minion_sp->InitDeportWorkQueues(&decls_to_deport, &decls_already_deported); - lldb::clang_type_t result = CopyType(dst_ctx, src_ctx, type); + lldb::opaque_compiler_type_t result = CopyType(dst_ctx, src_ctx, type); minion_sp->ExecuteDeportWorkQueues(); @@ -280,7 +312,7 @@ ClangASTImporter::DeportDecl (clang::ASTContext *dst_ctx, Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); if (log) - log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContex*)%p", + log->Printf(" [ClangASTImporter] DeportDecl called on (%sDecl*)%p from (ASTContext*)%p to (ASTContext*)%p", decl->getDeclKindName(), static_cast<void*>(decl), static_cast<void*>(src_ctx), static_cast<void*>(dst_ctx)); @@ -422,6 +454,68 @@ ClangASTImporter::CompleteObjCInterfaceDecl (clang::ObjCInterfaceDecl *interface } bool +ClangASTImporter::CompleteAndFetchChildren (clang::QualType type) +{ + if (!RequireCompleteType(type)) + return false; + + if (const TagType *tag_type = type->getAs<TagType>()) + { + TagDecl *tag_decl = tag_type->getDecl(); + + DeclOrigin decl_origin = GetDeclOrigin(tag_decl); + + if (!decl_origin.Valid()) + return false; + + MinionSP minion_sp (GetMinion(&tag_decl->getASTContext(), decl_origin.ctx)); + + TagDecl *origin_tag_decl = llvm::dyn_cast<TagDecl>(decl_origin.decl); + + for (Decl *origin_child_decl : origin_tag_decl->decls()) + { + minion_sp->Import(origin_child_decl); + } + + if (RecordDecl *record_decl = dyn_cast<RecordDecl>(origin_tag_decl)) + { + record_decl->setHasLoadedFieldsFromExternalStorage(true); + } + + return true; + } + + if (const ObjCObjectType *objc_object_type = type->getAs<ObjCObjectType>()) + { + if (ObjCInterfaceDecl *objc_interface_decl = objc_object_type->getInterface()) + { + DeclOrigin decl_origin = GetDeclOrigin(objc_interface_decl); + + if (!decl_origin.Valid()) + return false; + + MinionSP minion_sp (GetMinion(&objc_interface_decl->getASTContext(), decl_origin.ctx)); + + ObjCInterfaceDecl *origin_interface_decl = llvm::dyn_cast<ObjCInterfaceDecl>(decl_origin.decl); + + for (Decl *origin_child_decl : origin_interface_decl->decls()) + { + minion_sp->Import(origin_child_decl); + } + + return true; + } + else + { + return false; + } + } + + return true; +} + + +bool ClangASTImporter::RequireCompleteType (clang::QualType type) { if (type.isNull()) @@ -600,7 +694,7 @@ void ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *decls_to_deport, std::set<clang::NamedDecl *> *decls_already_deported) { - assert(!m_decls_to_deport); // TODO make debug only + assert(!m_decls_to_deport); assert(!m_decls_already_deported); m_decls_to_deport = decls_to_deport; @@ -610,7 +704,7 @@ ClangASTImporter::Minion::InitDeportWorkQueues (std::set<clang::NamedDecl *> *de void ClangASTImporter::Minion::ExecuteDeportWorkQueues () { - assert(m_decls_to_deport); // TODO make debug only + assert(m_decls_to_deport); assert(m_decls_already_deported); ASTContextMetadataSP to_context_md = m_master.GetContextMetadata(&getToContext()); @@ -623,6 +717,7 @@ ClangASTImporter::Minion::ExecuteDeportWorkQueues () m_decls_to_deport->erase(decl); DeclOrigin &origin = to_context_md->m_origins[decl]; + UNUSED_IF_ASSERT_DISABLED(origin); assert (origin.ctx == m_source_ctx); // otherwise we should never have added this // because it doesn't need to be deported @@ -763,7 +858,8 @@ ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to) if (to_context_md->m_origins.find(to) == to_context_md->m_origins.end() || user_id != LLDB_INVALID_UID) { - to_context_md->m_origins[to] = origin_iter->second; + if (origin_iter->second.ctx != &to->getASTContext()) + to_context_md->m_origins[to] = origin_iter->second; } MinionSP direct_completer = m_master.GetMinion(&to->getASTContext(), origin_iter->second.ctx); @@ -784,10 +880,14 @@ ClangASTImporter::Minion::Imported (clang::Decl *from, clang::Decl *to) { if (isa<TagDecl>(to) || isa<ObjCInterfaceDecl>(to)) { - NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to); - - if (!m_decls_already_deported->count(to_named_decl)) - m_decls_to_deport->insert(to_named_decl); + RecordDecl *from_record_decl = dyn_cast<RecordDecl>(from); + if (from_record_decl == nullptr || from_record_decl->isInjectedClassName() == false) + { + NamedDecl *to_named_decl = dyn_cast<NamedDecl>(to); + + if (!m_decls_already_deported->count(to_named_decl)) + m_decls_to_deport->insert(to_named_decl); + } } } |