Skip to content

Commit 18303da

Browse files
committed
[lldb][ClangASTImporter] Report progress when importing decls
1 parent abd3149 commit 18303da

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "lldb/Core/Module.h"
10+
#include "lldb/Core/Progress.h"
1011
#include "lldb/Utility/LLDBAssert.h"
1112
#include "lldb/Utility/LLDBLog.h"
1213
#include "lldb/Utility/Log.h"
@@ -17,6 +18,7 @@
1718
#include "clang/AST/RecordLayout.h"
1819
#include "clang/Sema/Lookup.h"
1920
#include "clang/Sema/Sema.h"
21+
#include "llvm/ADT/ScopeExit.h"
2022
#include "llvm/Support/raw_ostream.h"
2123

2224
#include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
@@ -1131,6 +1133,7 @@ ClangASTImporter::ASTImporterDelegate::ImportImpl(Decl *From) {
11311133
LLDB_LOG(log, "[ClangASTImporter] Complete definition not found");
11321134
}
11331135

1136+
UpdateImportProgress(From);
11341137
return ASTImporter::ImportImpl(From);
11351138
}
11361139

@@ -1411,3 +1414,35 @@ clang::Decl *
14111414
ClangASTImporter::ASTImporterDelegate::GetOriginalDecl(clang::Decl *To) {
14121415
return m_main.GetDeclOrigin(To).decl;
14131416
}
1417+
1418+
void ClangASTImporter::ASTImporterDelegate::UpdateImportProgress(
1419+
clang::Decl const *From) {
1420+
assert(From &&
1421+
"Trying to report import progress using an invalid clang::Decl.");
1422+
1423+
// If we can't determine the decl's name, we don't know what to
1424+
// update the progress bar with. So bail out.
1425+
auto const *ND = dyn_cast<NamedDecl>(From);
1426+
if (!ND)
1427+
return;
1428+
1429+
if (!m_import_progress_up) {
1430+
auto const *from_ast =
1431+
TypeSystemClang::GetASTContext(&From->getASTContext());
1432+
auto const *to_ast = TypeSystemClang::GetASTContext(&getToContext());
1433+
1434+
assert(from_ast && to_ast);
1435+
1436+
llvm::SmallVector<llvm::StringRef> from_name_parts;
1437+
llvm::SplitString(from_ast->getDisplayName(), from_name_parts, "/");
1438+
auto from_name = from_name_parts.back();
1439+
1440+
llvm::SmallVector<llvm::StringRef> to_name_parts;
1441+
llvm::SplitString(to_ast->getDisplayName(), to_name_parts, "/");
1442+
auto to_name = to_name_parts.back();
1443+
m_import_progress_up = std::make_unique<Progress>(
1444+
llvm::formatv("Importing '{0}' to '{1}'", from_name, to_name));
1445+
}
1446+
1447+
m_import_progress_up->Increment(1, ND->getNameAsString());
1448+
}

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/Basic/FileManager.h"
2323
#include "clang/Basic/FileSystemOptions.h"
2424

25+
#include "lldb/Core/Progress.h"
2526
#include "lldb/Host/FileSystem.h"
2627
#include "lldb/Symbol/CompilerDeclContext.h"
2728
#include "lldb/Utility/LLDBAssert.h"
@@ -346,6 +347,8 @@ class ClangASTImporter {
346347
llvm::Expected<clang::Decl *> ImportImpl(clang::Decl *From) override;
347348

348349
private:
350+
void UpdateImportProgress(clang::Decl const *From);
351+
349352
/// Decls we should ignore when mapping decls back to their original
350353
/// ASTContext. Used by the CxxModuleHandler to mark declarations that
351354
/// were created from the 'std' C++ module to prevent that the Importer
@@ -356,6 +359,7 @@ class ClangASTImporter {
356359
CxxModuleHandler *m_std_handler = nullptr;
357360
/// The currently attached listener.
358361
NewDeclListener *m_new_decl_listener = nullptr;
362+
std::unique_ptr<lldb_private::Progress> m_import_progress_up = nullptr;
359363
};
360364

361365
typedef std::shared_ptr<ASTImporterDelegate> ImporterDelegateSP;

0 commit comments

Comments
 (0)