|  | 
| 1 | 1 | #include "Utils.h" | 
| 2 | 2 | 
 | 
| 3 | 3 | #include "clang/Interpreter/CppInterOp.h" | 
|  | 4 | + | 
|  | 5 | +#ifdef USE_CLING | 
|  | 6 | +#include "cling/Interpreter/Interpreter.h" | 
|  | 7 | +#endif // USE_CLING | 
|  | 8 | + | 
|  | 9 | +#ifdef USE_REPL | 
|  | 10 | +#include "clang/Interpreter/Interpreter.h" | 
|  | 11 | +#endif // USE_REPL | 
|  | 12 | + | 
| 4 | 13 | #include "clang/Basic/Version.h" | 
| 5 | 14 | 
 | 
| 6 | 15 | #include "llvm/ADT/SmallString.h" | 
| @@ -162,3 +171,33 @@ TEST(InterpreterTest, CodeCompletion) { | 
| 162 | 171 |   GTEST_SKIP(); | 
| 163 | 172 | #endif | 
| 164 | 173 | } | 
|  | 174 | + | 
|  | 175 | +TEST(InterpreterTest, ExternalInterpreterTest) { | 
|  | 176 | + | 
|  | 177 | +#ifdef USE_REPL | 
|  | 178 | +  llvm::ExitOnError ExitOnErr; | 
|  | 179 | +  clang::IncrementalCompilerBuilder CB; | 
|  | 180 | +  CB.SetCompilerArgs({"-std=c++20"}); // pass `-xc` for a C REPL. | 
|  | 181 | + | 
|  | 182 | +  // Create the incremental compiler instance. | 
|  | 183 | +  std::unique_ptr<clang::CompilerInstance> CI; | 
|  | 184 | +  CI = ExitOnErr(CB.CreateCpp()); | 
|  | 185 | + | 
|  | 186 | +  // Create the interpreter instance. | 
|  | 187 | +  std::unique_ptr<Interpreter> I = | 
|  | 188 | +      ExitOnErr(Interpreter::create(std::move(CI))); | 
|  | 189 | + | 
|  | 190 | +  auto ExtInterp = I.get(); | 
|  | 191 | +#endif | 
|  | 192 | + | 
|  | 193 | +#ifdef USE_CLING | 
|  | 194 | +  const char* LLVMRESDIR = "/usr/local/"; // path to llvm resource directory | 
|  | 195 | +  cling::Interpreter interp(argc, argv, LLVMRESDIR); | 
|  | 196 | +  compat::Interpreter ExtInterp = &interp; | 
|  | 197 | +#endif | 
|  | 198 | + | 
|  | 199 | +  std::cout << "External Interpreter:" << ExtInterp; | 
|  | 200 | +  EXPECT_NE(ExtInterp, nullptr); | 
|  | 201 | +  Cpp::UseExternalInterpreter(ExtInterp); | 
|  | 202 | +  EXPECT_FALSE(Cpp::OwnsInterpreter()); | 
|  | 203 | +} | 
0 commit comments