[Lldb-commits] [lldb] 5a4d780 - [lldb] Split ClangASTSource::CompleteType
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 23 02:48:00 PDT 2020
Author: Pavel Labath
Date: 2020-06-23T11:47:52+02:00
New Revision: 5a4d78064e2cf7ea6b4e59c2b33e936588ae38a5
URL: https://github.com/llvm/llvm-project/commit/5a4d78064e2cf7ea6b4e59c2b33e936588ae38a5
DIFF: https://github.com/llvm/llvm-project/commit/5a4d78064e2cf7ea6b4e59c2b33e936588ae38a5.diff
LOG: [lldb] Split ClangASTSource::CompleteType
Move the part of the code which is responsible for finding a complete
definition of the type into a separate function (FindCompleteType). This
is split off from D81561, as it's a generally useful cleanup.
No functional change.
Added:
Modified:
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
Removed:
################################################################################
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
index da25fa3ebcb5..4a81b1ae6a3b 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.cpp
@@ -185,127 +185,125 @@ bool ClangASTSource::FindExternalVisibleDeclsByName(
return (name_decls.size() != 0);
}
-void ClangASTSource::CompleteType(TagDecl *tag_decl) {
+TagDecl *ClangASTSource::FindCompleteType(const TagDecl *decl) {
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
- if (log) {
- LLDB_LOG(log,
- " CompleteTagDecl on (ASTContext*){0} Completing "
- "(TagDecl*){1} named {2}",
- m_clang_ast_context->getDisplayName(), tag_decl,
- tag_decl->getName());
-
- LLDB_LOG(log, " CTD Before:\n{0}", ClangUtil::DumpDecl(tag_decl));
- }
-
- auto iter = m_active_lexical_decls.find(tag_decl);
- if (iter != m_active_lexical_decls.end())
- return;
- m_active_lexical_decls.insert(tag_decl);
- ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
+ if (const NamespaceDecl *namespace_context =
+ dyn_cast<NamespaceDecl>(decl->getDeclContext())) {
+ ClangASTImporter::NamespaceMapSP namespace_map =
+ m_ast_importer_sp->GetNamespaceMap(namespace_context);
- if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) {
- // We couldn't complete the type. Maybe there's a definition somewhere
- // else that can be completed.
+ LLDB_LOGV(log, " CTD Inspecting namespace map{0} ({1} entries)",
+ namespace_map.get(), namespace_map->size());
- LLDB_LOG(log, " CTD Type could not be completed in the module in "
- "which it was first found.");
+ if (!namespace_map)
+ return nullptr;
- bool found = false;
+ for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
+ LLDB_LOG(log, " CTD Searching namespace {0} in module {1}",
+ item.second.GetName(), item.first->GetFileSpec().GetFilename());
- DeclContext *decl_ctx = tag_decl->getDeclContext();
+ TypeList types;
- if (const NamespaceDecl *namespace_context =
- dyn_cast<NamespaceDecl>(decl_ctx)) {
- ClangASTImporter::NamespaceMapSP namespace_map =
- m_ast_importer_sp->GetNamespaceMap(namespace_context);
+ ConstString name(decl->getName());
- LLDB_LOGV(log, " CTD Inspecting namespace map{0} ({1} entries)",
- namespace_map.get(), namespace_map->size());
+ item.first->FindTypesInNamespace(name, item.second, UINT32_MAX, types);
- if (!namespace_map)
- return;
+ for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) {
+ lldb::TypeSP type = types.GetTypeAtIndex(ti);
- for (ClangASTImporter::NamespaceMap::iterator i = namespace_map->begin(),
- e = namespace_map->end();
- i != e && !found; ++i) {
- LLDB_LOG(log, " CTD Searching namespace {0} in module {1}",
- i->second.GetName(), i->first->GetFileSpec().GetFilename());
+ if (!type)
+ continue;
- TypeList types;
+ CompilerType clang_type(type->GetFullCompilerType());
- ConstString name(tag_decl->getName().str().c_str());
+ if (!ClangUtil::IsClangType(clang_type))
+ continue;
- i->first->FindTypesInNamespace(name, i->second, UINT32_MAX, types);
+ const TagType *tag_type =
+ ClangUtil::GetQualType(clang_type)->getAs<TagType>();
- for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
- lldb::TypeSP type = types.GetTypeAtIndex(ti);
+ if (!tag_type)
+ continue;
- if (!type)
- continue;
+ TagDecl *candidate_tag_decl =
+ const_cast<TagDecl *>(tag_type->getDecl());
- CompilerType clang_type(type->GetFullCompilerType());
+ if (TypeSystemClang::GetCompleteDecl(
+ &candidate_tag_decl->getASTContext(), candidate_tag_decl))
+ return candidate_tag_decl;
+ }
+ }
+ } else {
+ TypeList types;
- if (!ClangUtil::IsClangType(clang_type))
- continue;
+ ConstString name(decl->getName());
- const TagType *tag_type =
- ClangUtil::GetQualType(clang_type)->getAs<TagType>();
+ const ModuleList &module_list = m_target->GetImages();
- if (!tag_type)
- continue;
+ bool exact_match = false;
+ llvm::DenseSet<SymbolFile *> searched_symbol_files;
+ module_list.FindTypes(nullptr, name, exact_match, UINT32_MAX,
+ searched_symbol_files, types);
- TagDecl *candidate_tag_decl =
- const_cast<TagDecl *>(tag_type->getDecl());
+ for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) {
+ lldb::TypeSP type = types.GetTypeAtIndex(ti);
- if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
- candidate_tag_decl))
- found = true;
- }
- }
- } else {
- TypeList types;
+ if (!type)
+ continue;
- ConstString name(tag_decl->getName().str().c_str());
+ CompilerType clang_type(type->GetFullCompilerType());
- const ModuleList &module_list = m_target->GetImages();
+ if (!ClangUtil::IsClangType(clang_type))
+ continue;
- bool exact_match = false;
- llvm::DenseSet<SymbolFile *> searched_symbol_files;
- module_list.FindTypes(nullptr, name, exact_match, UINT32_MAX,
- searched_symbol_files, types);
+ const TagType *tag_type =
+ ClangUtil::GetQualType(clang_type)->getAs<TagType>();
- for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
- lldb::TypeSP type = types.GetTypeAtIndex(ti);
+ if (!tag_type)
+ continue;
- if (!type)
- continue;
+ TagDecl *candidate_tag_decl = const_cast<TagDecl *>(tag_type->getDecl());
- CompilerType clang_type(type->GetFullCompilerType());
+ // We have found a type by basename and we need to make sure the decl
+ // contexts are the same before we can try to complete this type with
+ // another
+ if (!TypeSystemClang::DeclsAreEquivalent(const_cast<TagDecl *>(decl),
+ candidate_tag_decl))
+ continue;
- if (!ClangUtil::IsClangType(clang_type))
- continue;
+ if (TypeSystemClang::GetCompleteDecl(&candidate_tag_decl->getASTContext(),
+ candidate_tag_decl))
+ return candidate_tag_decl;
+ }
+ }
+ return nullptr;
+}
- const TagType *tag_type =
- ClangUtil::GetQualType(clang_type)->getAs<TagType>();
+void ClangASTSource::CompleteType(TagDecl *tag_decl) {
+ Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
- if (!tag_type)
- continue;
+ if (log) {
+ LLDB_LOG(log,
+ " CompleteTagDecl on (ASTContext*){0} Completing "
+ "(TagDecl*){1} named {2}",
+ m_clang_ast_context->getDisplayName(), tag_decl,
+ tag_decl->getName());
- TagDecl *candidate_tag_decl =
- const_cast<TagDecl *>(tag_type->getDecl());
+ LLDB_LOG(log, " CTD Before:\n{0}", ClangUtil::DumpDecl(tag_decl));
+ }
- // We have found a type by basename and we need to make sure the decl
- // contexts are the same before we can try to complete this type with
- // another
- if (!TypeSystemClang::DeclsAreEquivalent(tag_decl, candidate_tag_decl))
- continue;
+ auto iter = m_active_lexical_decls.find(tag_decl);
+ if (iter != m_active_lexical_decls.end())
+ return;
+ m_active_lexical_decls.insert(tag_decl);
+ ScopedLexicalDeclEraser eraser(m_active_lexical_decls, tag_decl);
- if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
- candidate_tag_decl))
- found = true;
- }
- }
+ if (!m_ast_importer_sp->CompleteTagDecl(tag_decl)) {
+ // We couldn't complete the type. Maybe there's a definition somewhere
+ // else that can be completed.
+ if (TagDecl *alternate = FindCompleteType(tag_decl))
+ m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl, alternate);
}
LLDB_LOG(log, " [CTD] After:\n{0}", ClangUtil::DumpDecl(tag_decl));
diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
index 2563c6499de3..847a99abfff0 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangASTSource.h
@@ -372,6 +372,8 @@ class ClangASTSource : public clang::ExternalASTSource,
void FillNamespaceMap(NameSearchContext &context, lldb::ModuleSP module_sp,
const CompilerDeclContext &namespace_decl);
+ clang::TagDecl *FindCompleteType(const clang::TagDecl *decl);
+
friend struct NameSearchContext;
bool m_import_in_progress;
More information about the lldb-commits
mailing list