@@ -29,89 +29,69 @@ using Args = std::vector<const char*>;
2929
3030void * createInterpreter (const Args& ExtraArgs = {})
3131{
32- Args ClangArgs = {/* "-xc++"*/ " -v" };
33- if (std::find_if (
34- ExtraArgs.begin (),
35- ExtraArgs.end (),
36- [](const std::string& s)
37- {
38- return s == " -resource-dir" ;
39- }
40- )
41- == ExtraArgs.end ())
42- {
32+ Args ClangArgs = {/* "-xc++"*/ " -v" };
33+ if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
34+ return s == " -resource-dir" ;}) == ExtraArgs.end ()) {
4335 std::string resource_dir = Cpp::DetectResourceDir ();
44- if (!resource_dir.empty ())
45- {
36+ if (!resource_dir.empty ()) {
4637 ClangArgs.push_back (" -resource-dir" );
4738 ClangArgs.push_back (resource_dir.c_str ());
48- }
49- else
50- {
39+ } else {
5140 std::cerr << " Failed to detect the resource-dir\n " ;
5241 }
5342 }
5443 std::vector<std::string> CxxSystemIncludes;
5544 Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
56- for (const std::string& CxxInclude : CxxSystemIncludes)
57- {
45+ for (const std::string& CxxInclude : CxxSystemIncludes) {
5846 ClangArgs.push_back (" -isystem" );
5947 ClangArgs.push_back (CxxInclude.c_str ());
6048 }
6149 ClangArgs.insert (ClangArgs.end (), ExtraArgs.begin (), ExtraArgs.end ());
6250
6351 // FIXME: We should process the kernel input options and conditionally pass
6452 // the gpu args here.
65- if (std::find_if (
66- ExtraArgs.begin (),
67- ExtraArgs.end (),
68- [](const std::string& s)
69- {
70- return s == " -gdwarf-4" ;
71- }
72- )
73- == ExtraArgs.end ())
74- {
53+ if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
54+ return s == " -gdwarf-4" ;}) == ExtraArgs.end ()) {
7555 // If no debugger option, then use the non-OOP JIT execution.
7656 return Cpp::CreateInterpreter (ClangArgs /* , {"-cuda"}*/ );
7757 }
7858
79- // If debugger option is set, then use the OOP JIT execution.
59+ #ifdef XEUS_CPP_USE_DEBUGGER
60+ // If debugger option is set, then use the OOP JIT execution.
8061 return Cpp::CreateInterpreter (ClangArgs, {}, true );
62+ #else
63+ return Cpp::CreateInterpreter (ClangArgs);
64+ #endif
8165}
8266
8367using namespace std ::placeholders;
8468
8569namespace xcpp
8670{
87- struct StreamRedirectRAII
88- {
89- std::string &out, &err;
90-
91- StreamRedirectRAII (std::string& o, std::string& e)
92- : out(o)
93- , err(e)
94- {
95- Cpp::BeginStdStreamCapture (Cpp::kStdErr );
96- Cpp::BeginStdStreamCapture (Cpp::kStdOut );
97- }
98-
99- ~StreamRedirectRAII ()
100- {
101- out = Cpp::EndStdStreamCapture ();
102- err = Cpp::EndStdStreamCapture ();
103- }
71+ struct StreamRedirectRAII {
72+ std::string &err;
73+ StreamRedirectRAII (std::string &e) : err(e) {
74+ Cpp::BeginStdStreamCapture (Cpp::kStdErr );
75+ Cpp::BeginStdStreamCapture (Cpp::kStdOut );
76+ }
77+ ~StreamRedirectRAII () {
78+ std::string out = Cpp::EndStdStreamCapture ();
79+ err = Cpp::EndStdStreamCapture ();
80+ std::cout << out;
81+ }
10482 };
10583
10684 void interpreter::configure_impl ()
10785 {
10886 xeus::register_interpreter (this );
10987 }
11088
89+ #ifdef XEUS_CPP_USE_DEBUGGER
11190 pid_t interpreter::get_current_pid ()
11291 {
11392 return Cpp::GetExecutorPID ();
11493 }
94+ #endif
11595
11696 static std::string get_stdopt ()
11797 {
@@ -140,8 +120,8 @@ __get_cxx_version ()
140120 return std::to_string (cxx_version);
141121 }
142122
143- interpreter::interpreter (int argc, const char * const * argv)
144- : xmagics()
123+ interpreter::interpreter (int argc, const char * const * argv):
124+ xmagics ()
145125 , p_cout_strbuf(nullptr )
146126 , p_cerr_strbuf(nullptr )
147127 , m_cout_buffer(std::bind(&interpreter::publish_stdout, this , _1))
@@ -202,12 +182,12 @@ __get_cxx_version ()
202182 std::cerr.rdbuf (&null);
203183 }
204184
205- std::string out, err;
185+ std::string err;
206186
207187 // Attempt normal evaluation
208188 try
209189 {
210- StreamRedirectRAII R (out, err);
190+ StreamRedirectRAII R (err);
211191 compilation_result = Cpp::Process (code.c_str ());
212192 }
213193 catch (std::exception& e)
@@ -229,10 +209,6 @@ __get_cxx_version ()
229209 evalue = " Compilation error! " + err;
230210 std::cerr << err;
231211 }
232- else
233- {
234- std::cout << out;
235- }
236212
237213 // Flush streams
238214 std::cout << std::flush;
@@ -254,8 +230,7 @@ __get_cxx_version ()
254230 //
255231 // JupyterLab displays the "{ename}: {evalue}" if the traceback is
256232 // empty.
257- if (evalue.size () < 4 )
258- {
233+ if (evalue.size () < 4 ) {
259234 ename = " " ;
260235 }
261236 std::vector<std::string> traceback ({ename + evalue});
@@ -301,8 +276,7 @@ __get_cxx_version ()
301276
302277 Cpp::CodeComplete (results, code.c_str (), 1 , _cursor_pos + 1 );
303278
304- return xeus::create_complete_reply (
305- results /* matches*/ ,
279+ return xeus::create_complete_reply (results /* matches*/ ,
306280 cursor_pos - to_complete.length () /* cursor_start*/ ,
307281 cursor_pos /* cursor_end*/
308282 );
@@ -514,11 +488,11 @@ __get_cxx_version ()
514488
515489 void interpreter::init_preamble ()
516490 {
517- // NOLINTBEGIN(cppcoreguidelines-owning-memory)
491+ // NOLINTBEGIN(cppcoreguidelines-owning-memory)
518492 preamble_manager.register_preamble (" introspection" , std::make_unique<xintrospection>());
519493 preamble_manager.register_preamble (" magics" , std::make_unique<xmagics_manager>());
520494 preamble_manager.register_preamble (" shell" , std::make_unique<xsystem>());
521- // NOLINTEND(cppcoreguidelines-owning-memory)
495+ // NOLINTEND(cppcoreguidelines-owning-memory)
522496 }
523497
524498 void interpreter::init_magic ()
0 commit comments