aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Interpreter/Interpreter.cpp
diff options
context:
space:
mode:
authorFred Fu <moonsolo@gmail.com>2023-08-28 20:05:35 +0000
committerVassil Vassilev <v.g.vassilev@gmail.com>2023-08-28 20:09:03 +0000
commit79af92bb99dd86cc36d6a81066063fb9cd77c78a (patch)
tree955f40c7b7b932ff5e2b1277ef8e2ea0ad8ced1d /clang/lib/Interpreter/Interpreter.cpp
parent752f87cd6a1a354790f4728848827077467ac15d (diff)
downloadllvm-79af92bb99dd86cc36d6a81066063fb9cd77c78a.zip
llvm-79af92bb99dd86cc36d6a81066063fb9cd77c78a.tar.gz
llvm-79af92bb99dd86cc36d6a81066063fb9cd77c78a.tar.bz2
Reland "[clang-repl] support code completion at a REPL."
Original commit message: " This patch enabled code completion for ClangREPL. The feature was built upon three existing Clang components: a list completer for LineEditor, a CompletionConsumer from SemaCodeCompletion, and the ASTUnit::codeComplete method. The first component serves as the main entry point of handling interactive inputs. Because a completion point for a compiler instance has to be unchanged once it is set, an incremental compiler instance is created for each code completion. Such a compiler instance carries over AST context source from the main interpreter compiler in order to obtain declarations or bindings from previous input in the same REPL session. The most important API codeComplete in Interpreter/CodeCompletion is a thin wrapper that calls with ASTUnit::codeComplete with necessary arguments, such as a code completion point and a ReplCompletionConsumer, which communicates completion results from SemaCodeCompletion back to the list completer for the REPL. In addition, PCC_TopLevelOrExpression and CCC_TopLevelOrExpression` top levels were added so that SemaCodeCompletion can treat top level statements like expression statements at the REPL. For example, clang-repl> int foo = 42; clang-repl> f<tab> From a parser's persective, the cursor is at a top level. If we used code completion without any changes, PCC_Namespace would be supplied to Sema::CodeCompleteOrdinaryName, and thus the completion results would not include foo. Currently, the way we use PCC_TopLevelOrExpression and CCC_TopLevelOrExpression is no different from the way we use PCC_Statement and CCC_Statement respectively. Differential revision: https://reviews.llvm.org/D154382 " The new patch also fixes clangd and several memory issues that the bots reported and upload the missing files.
Diffstat (limited to 'clang/lib/Interpreter/Interpreter.cpp')
-rw-r--r--clang/lib/Interpreter/Interpreter.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 4e10452..7968c62 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -11,13 +11,11 @@
//
//===----------------------------------------------------------------------===//
-#include "clang/Interpreter/Interpreter.h"
-
#include "DeviceOffload.h"
#include "IncrementalExecutor.h"
#include "IncrementalParser.h"
-
#include "InterpreterUtils.h"
+
#include "clang/AST/ASTContext.h"
#include "clang/AST/Mangle.h"
#include "clang/AST/TypeVisitor.h"
@@ -33,6 +31,7 @@
#include "clang/Driver/Tool.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Interpreter/Interpreter.h"
#include "clang/Interpreter/Value.h"
#include "clang/Lex/PreprocessorOptions.h"
#include "clang/Sema/Lookup.h"
@@ -127,7 +126,6 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
Clang->getFrontendOpts().DisableFree = false;
Clang->getCodeGenOpts().DisableFree = false;
-
return std::move(Clang);
}
@@ -276,6 +274,7 @@ Interpreter::create(std::unique_ptr<CompilerInstance> CI) {
std::unique_ptr<Interpreter>(new Interpreter(std::move(CI), Err));
if (Err)
return std::move(Err);
+
auto PTU = Interp->Parse(Runtimes);
if (!PTU)
return PTU.takeError();