mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-27 16:46:08 +00:00
[clang-repl] Enable basic multiline support.
This patch allows the users to use backslash to tell clang-repl that more input is coming. This would help support OpenMP directives which generally require to be in separate lines.
This commit is contained in:
parent
b7fb2a3fec
commit
c96c5edb58
24
clang/test/Interpreter/multiline.cpp
Normal file
24
clang/test/Interpreter/multiline.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
// REQUIRES: host-supports-jit
|
||||
// UNSUPPORTED: system-aix
|
||||
// RUN: cat %s | clang-repl | FileCheck %s
|
||||
|
||||
extern "C" int printf(const char*,...);
|
||||
int i = \
|
||||
12;
|
||||
|
||||
printf("i=%d\n", i);
|
||||
// CHECK: i=12
|
||||
|
||||
void f(int x) \
|
||||
{ \
|
||||
printf("x=\
|
||||
%d", x); \
|
||||
}
|
||||
f(i);
|
||||
// CHECK: x=12
|
||||
|
||||
// FIXME: Support preprocessor directives.
|
||||
// #if 0 \
|
||||
// #error "Can't be!" \
|
||||
// #endif
|
||||
|
@ -113,28 +113,38 @@ int main(int argc, const char **argv) {
|
||||
if (OptInputs.empty()) {
|
||||
llvm::LineEditor LE("clang-repl");
|
||||
// FIXME: Add LE.setListCompleter
|
||||
std::string Input;
|
||||
while (std::optional<std::string> Line = LE.readLine()) {
|
||||
if (*Line == R"(%quit)")
|
||||
llvm::StringRef L = *Line;
|
||||
L = L.trim();
|
||||
if (L.endswith("\\")) {
|
||||
// FIXME: Support #ifdef X \ ...
|
||||
Input += L.drop_back(1);
|
||||
LE.setPrompt("clang-repl... ");
|
||||
continue;
|
||||
}
|
||||
|
||||
Input += L;
|
||||
|
||||
if (Input == R"(%quit)") {
|
||||
break;
|
||||
if (*Line == R"(%undo)") {
|
||||
} else if (Input == R"(%undo)") {
|
||||
if (auto Err = Interp->Undo()) {
|
||||
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
|
||||
HasError = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (Line->rfind("%lib ", 0) == 0) {
|
||||
if (auto Err = Interp->LoadDynamicLibrary(Line->data() + 5)) {
|
||||
} else if (Input.rfind("%lib ", 0) == 0) {
|
||||
if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5)) {
|
||||
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
|
||||
HasError = true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto Err = Interp->ParseAndExecute(*Line)) {
|
||||
} else if (auto Err = Interp->ParseAndExecute(Input)) {
|
||||
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
Input = "";
|
||||
LE.setPrompt("clang-repl> ");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user