diff --git a/clang/test/Interpreter/multiline.cpp b/clang/test/Interpreter/multiline.cpp new file mode 100644 index 0000000000000..054e61a7e3d62 --- /dev/null +++ b/clang/test/Interpreter/multiline.cpp @@ -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 + diff --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp index 33faf3fab58f0..5ac071fdbce3f 100644 --- a/clang/tools/clang-repl/ClangRepl.cpp +++ b/clang/tools/clang-repl/ClangRepl.cpp @@ -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 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> "); } }