Skip to content

Commit 05299c5

Browse files
committed
[NFC][CIFactory] Make ASTConsumer optional for autocomplete paths
1 parent b5102f7 commit 05299c5

5 files changed

Lines changed: 28 additions & 24 deletions

File tree

core/dictgen/src/LinkdefReader.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,9 +1058,9 @@ bool LinkdefReader::Parse(SelectionRules &sr, llvm::StringRef code, const std::v
10581058

10591059
// Extract all #pragmas
10601060
std::unique_ptr<llvm::MemoryBuffer> memBuf = llvm::MemoryBuffer::getMemBuffer(code, "CLING #pragma extraction");
1061-
clang::CompilerInstance *pragmaCI = cling::CIFactory::createCI(std::move(memBuf), parserArgsC.size(),
1062-
&parserArgsC[0], llvmdir, nullptr /*Consumer*/,
1063-
{} /*ModuleFileExtension*/, true /*OnlyLex*/);
1061+
clang::CompilerInstance *pragmaCI =
1062+
cling::CIFactory::createCI(std::move(memBuf), parserArgsC.size(), &parserArgsC[0], llvmdir,
1063+
std::nullopt /*Consumer*/, {} /*ModuleFileExtension*/, true /*OnlyLex*/);
10641064

10651065
clang::Preprocessor &PP = pragmaCI->getPreprocessor();
10661066
clang::DiagnosticConsumer &DClient = pragmaCI->getDiagnosticClient();

interpreter/cling/include/cling/Interpreter/CIFactory.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ namespace cling {
3737

3838
clang::CompilerInstance*
3939
createCI(llvm::StringRef Code, const InvocationOptions& Opts,
40-
const char* LLVMDir, std::unique_ptr<clang::ASTConsumer> consumer,
40+
const char* LLVMDir,
41+
std::optional<std::unique_ptr<clang::ASTConsumer>> consumerOpt,
4142
const ModuleFileExtensions& moduleExtensions,
4243
bool AutoComplete = false);
4344

4445
clang::CompilerInstance*
4546
createCI(MemBufPtr_t Buffer, int Argc, const char* const* Argv,
46-
const char* LLVMDir, std::unique_ptr<clang::ASTConsumer> consumer,
47+
const char* LLVMDir,
48+
std::optional<std::unique_ptr<clang::ASTConsumer>> consumerOpt,
4749
const ModuleFileExtensions& moduleExtensions,
4850
bool OnlyLex = false);
4951
} // namespace CIFactory

interpreter/cling/lib/Interpreter/CIFactory.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,7 +1700,7 @@ namespace {
17001700

17011701
std::vector<std::unique_ptr<ASTConsumer>> Consumers;
17021702

1703-
if (!OnlyLex) {
1703+
if (!OnlyLex && !AutoComplete) {
17041704
assert(customConsumer && "Need to specify a custom consumer"
17051705
" when not in OnlyLex mode");
17061706
Consumers.push_back(std::move(customConsumer));
@@ -1834,25 +1834,27 @@ namespace {
18341834

18351835
namespace cling {
18361836

1837-
CompilerInstance*
1838-
CIFactory::createCI(llvm::StringRef Code, const InvocationOptions& Opts,
1839-
const char* LLVMDir,
1840-
std::unique_ptr<clang::ASTConsumer> consumer,
1841-
const ModuleFileExtensions& moduleExtensions,
1842-
bool AutoComplete /*false*/) {
1837+
CompilerInstance* CIFactory::createCI(
1838+
llvm::StringRef Code, const InvocationOptions& Opts, const char* LLVMDir,
1839+
std::optional<std::unique_ptr<clang::ASTConsumer>> consumerOpt,
1840+
const ModuleFileExtensions& moduleExtensions,
1841+
bool AutoComplete /*false*/) {
18431842
return createCIImpl(llvm::MemoryBuffer::getMemBuffer(Code),
1844-
Opts.CompilerOpts, LLVMDir, std::move(consumer),
1843+
Opts.CompilerOpts, LLVMDir,
1844+
consumerOpt ? std::move(*consumerOpt) : nullptr,
18451845
moduleExtensions, false /*OnlyLex*/,
18461846
!Opts.IsInteractive(), AutoComplete);
18471847
}
18481848

1849-
CompilerInstance* CIFactory::createCI(
1850-
MemBufPtr_t Buffer, int argc, const char* const* argv, const char* LLVMDir,
1851-
std::unique_ptr<clang::ASTConsumer> consumer,
1852-
const ModuleFileExtensions& moduleExtensions, bool OnlyLex /*false*/) {
1853-
return createCIImpl(std::move(Buffer), CompilerOptions(argc, argv), LLVMDir,
1854-
std::move(consumer), moduleExtensions, OnlyLex);
1855-
}
1849+
CompilerInstance* CIFactory::createCI(
1850+
MemBufPtr_t Buffer, int argc, const char* const* argv,
1851+
const char* LLVMDir,
1852+
std::optional<std::unique_ptr<clang::ASTConsumer>> consumerOpt,
1853+
const ModuleFileExtensions& moduleExtensions, bool OnlyLex /*false*/) {
1854+
return createCIImpl(std::move(Buffer), CompilerOptions(argc, argv), LLVMDir,
1855+
consumerOpt ? std::move(*consumerOpt) : nullptr,
1856+
moduleExtensions, OnlyLex);
1857+
}
18561858

18571859
} // namespace cling
18581860

interpreter/cling/lib/Interpreter/IncrementalParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ namespace cling {
293293
std::unique_ptr<cling::DeclCollector> consumer;
294294
consumer.reset(m_Consumer = new cling::DeclCollector());
295295
m_CI.reset(CIFactory::createCI("\n", interp->getOptions(), llvmdir,
296-
std::move(consumer), moduleExtensions));
296+
std::make_optional(std::move(consumer)),
297+
moduleExtensions));
297298

298299
if (!m_CI) {
299300
cling::errs() << "Compiler instance could not be created.\n";

interpreter/cling/lib/Interpreter/Interpreter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,12 +1036,11 @@ namespace cling {
10361036
std::string llvmDir = parentResourceDir.str();
10371037

10381038
// arguments for constructing CI
1039-
auto declCollector = std::make_unique<cling::DeclCollector>();
10401039
const ModuleFileExtensions& moduleExtensions = {};
10411040

10421041
auto InterpCI = std::unique_ptr<clang::CompilerInstance>(
1043-
CIFactory::createCI("\n", getOptions(), llvmDir.c_str(),
1044-
std::move(declCollector), moduleExtensions,
1042+
CIFactory::createCI("\n", getOptions(), llvmDir.c_str(), std::nullopt,
1043+
moduleExtensions,
10451044
/*AutoComplete=*/true));
10461045

10471046
auto CC = ClingCodeCompleter();

0 commit comments

Comments
 (0)