mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-28 02:37:37 +00:00
[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.
This commit is contained in:
parent
4c257bb44e
commit
5a4d78064e
@ -185,6 +185,101 @@ bool ClangASTSource::FindExternalVisibleDeclsByName(
|
||||
return (name_decls.size() != 0);
|
||||
}
|
||||
|
||||
TagDecl *ClangASTSource::FindCompleteType(const TagDecl *decl) {
|
||||
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
|
||||
|
||||
if (const NamespaceDecl *namespace_context =
|
||||
dyn_cast<NamespaceDecl>(decl->getDeclContext())) {
|
||||
ClangASTImporter::NamespaceMapSP namespace_map =
|
||||
m_ast_importer_sp->GetNamespaceMap(namespace_context);
|
||||
|
||||
LLDB_LOGV(log, " CTD Inspecting namespace map{0} ({1} entries)",
|
||||
namespace_map.get(), namespace_map->size());
|
||||
|
||||
if (!namespace_map)
|
||||
return nullptr;
|
||||
|
||||
for (const ClangASTImporter::NamespaceMapItem &item : *namespace_map) {
|
||||
LLDB_LOG(log, " CTD Searching namespace {0} in module {1}",
|
||||
item.second.GetName(), item.first->GetFileSpec().GetFilename());
|
||||
|
||||
TypeList types;
|
||||
|
||||
ConstString name(decl->getName());
|
||||
|
||||
item.first->FindTypesInNamespace(name, item.second, UINT32_MAX, types);
|
||||
|
||||
for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) {
|
||||
lldb::TypeSP type = types.GetTypeAtIndex(ti);
|
||||
|
||||
if (!type)
|
||||
continue;
|
||||
|
||||
CompilerType clang_type(type->GetFullCompilerType());
|
||||
|
||||
if (!ClangUtil::IsClangType(clang_type))
|
||||
continue;
|
||||
|
||||
const TagType *tag_type =
|
||||
ClangUtil::GetQualType(clang_type)->getAs<TagType>();
|
||||
|
||||
if (!tag_type)
|
||||
continue;
|
||||
|
||||
TagDecl *candidate_tag_decl =
|
||||
const_cast<TagDecl *>(tag_type->getDecl());
|
||||
|
||||
if (TypeSystemClang::GetCompleteDecl(
|
||||
&candidate_tag_decl->getASTContext(), candidate_tag_decl))
|
||||
return candidate_tag_decl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TypeList types;
|
||||
|
||||
ConstString name(decl->getName());
|
||||
|
||||
const ModuleList &module_list = m_target->GetImages();
|
||||
|
||||
bool exact_match = false;
|
||||
llvm::DenseSet<SymbolFile *> searched_symbol_files;
|
||||
module_list.FindTypes(nullptr, name, exact_match, UINT32_MAX,
|
||||
searched_symbol_files, types);
|
||||
|
||||
for (uint32_t ti = 0, te = types.GetSize(); ti != te; ++ti) {
|
||||
lldb::TypeSP type = types.GetTypeAtIndex(ti);
|
||||
|
||||
if (!type)
|
||||
continue;
|
||||
|
||||
CompilerType clang_type(type->GetFullCompilerType());
|
||||
|
||||
if (!ClangUtil::IsClangType(clang_type))
|
||||
continue;
|
||||
|
||||
const TagType *tag_type =
|
||||
ClangUtil::GetQualType(clang_type)->getAs<TagType>();
|
||||
|
||||
if (!tag_type)
|
||||
continue;
|
||||
|
||||
TagDecl *candidate_tag_decl = const_cast<TagDecl *>(tag_type->getDecl());
|
||||
|
||||
// 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 (TypeSystemClang::GetCompleteDecl(&candidate_tag_decl->getASTContext(),
|
||||
candidate_tag_decl))
|
||||
return candidate_tag_decl;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ClangASTSource::CompleteType(TagDecl *tag_decl) {
|
||||
Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS));
|
||||
|
||||
@ -207,105 +302,8 @@ void ClangASTSource::CompleteType(TagDecl *tag_decl) {
|
||||
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_LOG(log, " CTD Type could not be completed in the module in "
|
||||
"which it was first found.");
|
||||
|
||||
bool found = false;
|
||||
|
||||
DeclContext *decl_ctx = tag_decl->getDeclContext();
|
||||
|
||||
if (const NamespaceDecl *namespace_context =
|
||||
dyn_cast<NamespaceDecl>(decl_ctx)) {
|
||||
ClangASTImporter::NamespaceMapSP namespace_map =
|
||||
m_ast_importer_sp->GetNamespaceMap(namespace_context);
|
||||
|
||||
LLDB_LOGV(log, " CTD Inspecting namespace map{0} ({1} entries)",
|
||||
namespace_map.get(), namespace_map->size());
|
||||
|
||||
if (!namespace_map)
|
||||
return;
|
||||
|
||||
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());
|
||||
|
||||
TypeList types;
|
||||
|
||||
ConstString name(tag_decl->getName().str().c_str());
|
||||
|
||||
i->first->FindTypesInNamespace(name, i->second, UINT32_MAX, types);
|
||||
|
||||
for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
|
||||
lldb::TypeSP type = types.GetTypeAtIndex(ti);
|
||||
|
||||
if (!type)
|
||||
continue;
|
||||
|
||||
CompilerType clang_type(type->GetFullCompilerType());
|
||||
|
||||
if (!ClangUtil::IsClangType(clang_type))
|
||||
continue;
|
||||
|
||||
const TagType *tag_type =
|
||||
ClangUtil::GetQualType(clang_type)->getAs<TagType>();
|
||||
|
||||
if (!tag_type)
|
||||
continue;
|
||||
|
||||
TagDecl *candidate_tag_decl =
|
||||
const_cast<TagDecl *>(tag_type->getDecl());
|
||||
|
||||
if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
|
||||
candidate_tag_decl))
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
TypeList types;
|
||||
|
||||
ConstString name(tag_decl->getName().str().c_str());
|
||||
|
||||
const ModuleList &module_list = m_target->GetImages();
|
||||
|
||||
bool exact_match = false;
|
||||
llvm::DenseSet<SymbolFile *> searched_symbol_files;
|
||||
module_list.FindTypes(nullptr, name, exact_match, UINT32_MAX,
|
||||
searched_symbol_files, types);
|
||||
|
||||
for (uint32_t ti = 0, te = types.GetSize(); ti != te && !found; ++ti) {
|
||||
lldb::TypeSP type = types.GetTypeAtIndex(ti);
|
||||
|
||||
if (!type)
|
||||
continue;
|
||||
|
||||
CompilerType clang_type(type->GetFullCompilerType());
|
||||
|
||||
if (!ClangUtil::IsClangType(clang_type))
|
||||
continue;
|
||||
|
||||
const TagType *tag_type =
|
||||
ClangUtil::GetQualType(clang_type)->getAs<TagType>();
|
||||
|
||||
if (!tag_type)
|
||||
continue;
|
||||
|
||||
TagDecl *candidate_tag_decl =
|
||||
const_cast<TagDecl *>(tag_type->getDecl());
|
||||
|
||||
// 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;
|
||||
|
||||
if (m_ast_importer_sp->CompleteTagDeclWithOrigin(tag_decl,
|
||||
candidate_tag_decl))
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
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));
|
||||
|
@ -372,6 +372,8 @@ protected:
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user