1717
1818#include " xinput.hpp"
1919#include " xinspect.hpp"
20- #include " xmagics/os.hpp"
2120#include " xmagics/execution.hpp"
21+ #include " xmagics/os.hpp"
2222#ifndef EMSCRIPTEN
2323#include " xmagics/xassist.hpp"
2424#endif
2727
2828using Args = std::vector<const char *>;
2929
30- void * createInterpreter (const Args &ExtraArgs = {}) {
31- Args ClangArgs = {/* "-xc++"*/ " -v" }; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
30+ void * createInterpreter (const Args& ExtraArgs = {})
31+ {
32+ Args ClangArgs = {/* "-xc++"*/ " -v" }; // ? {"-Xclang", "-emit-llvm-only", "-Xclang",
33+ // "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
3234#ifdef EMSCRIPTEN
33- ClangArgs.push_back (" -std=c++20" );
35+ ClangArgs.push_back (" -std=c++20" );
3436#else
35- if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
36- return s == " -resource-dir" ;}) == ExtraArgs.end ()) {
37- std::string resource_dir = Cpp::DetectResourceDir ();
38- if (resource_dir.empty ())
39- std::cerr << " Failed to detect the resource-dir\n " ;
40- ClangArgs.push_back (" -resource-dir" );
41- ClangArgs.push_back (resource_dir.c_str ());
42- }
43- std::vector<std::string> CxxSystemIncludes;
44- Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
45- for (const std::string& CxxInclude : CxxSystemIncludes) {
46- ClangArgs.push_back (" -isystem" );
47- ClangArgs.push_back (CxxInclude.c_str ());
48- }
37+ if (std::find_if (
38+ ExtraArgs.begin (),
39+ ExtraArgs.end (),
40+ [](const std::string& s)
41+ {
42+ return s == " -resource-dir" ;
43+ }
44+ )
45+ == ExtraArgs.end ())
46+ {
47+ std::string resource_dir = Cpp::DetectResourceDir ();
48+ if (resource_dir.empty ())
49+ {
50+ std::cerr << " Failed to detect the resource-dir\n " ;
51+ }
52+ ClangArgs.push_back (" -resource-dir" );
53+ ClangArgs.push_back (resource_dir.c_str ());
54+ }
55+ std::vector<std::string> CxxSystemIncludes;
56+ Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
57+ for (const std::string& CxxInclude : CxxSystemIncludes)
58+ {
59+ ClangArgs.push_back (" -isystem" );
60+ ClangArgs.push_back (CxxInclude.c_str ());
61+ }
4962#endif
50- ClangArgs.insert (ClangArgs.end (), ExtraArgs.begin (), ExtraArgs.end ());
51- // FIXME: We should process the kernel input options and conditionally pass
52- // the gpu args here.
53- return Cpp::CreateInterpreter (ClangArgs/* , {"-cuda"}*/ );
63+ ClangArgs.insert (ClangArgs.end (), ExtraArgs.begin (), ExtraArgs.end ());
64+ // FIXME: We should process the kernel input options and conditionally pass
65+ // the gpu args here.
66+ return Cpp::CreateInterpreter (ClangArgs /* , {"-cuda"}*/ );
5467}
5568
5669using namespace std ::placeholders;
5770
5871namespace xcpp
5972{
60- struct StreamRedirectRAII {
61- std::string &err;
62- StreamRedirectRAII (std::string &e) : err(e) {
63- Cpp::BeginStdStreamCapture (Cpp::kStdErr );
64- Cpp::BeginStdStreamCapture (Cpp::kStdOut );
65- }
66- ~StreamRedirectRAII () {
67- std::string out = Cpp::EndStdStreamCapture ();
68- err = Cpp::EndStdStreamCapture ();
69- std::cout << out;
70- }
73+ struct StreamRedirectRAII
74+ {
75+ std::string& err;
76+
77+ StreamRedirectRAII (std::string& e)
78+ : err(e)
79+ {
80+ Cpp::BeginStdStreamCapture (Cpp::kStdErr );
81+ Cpp::BeginStdStreamCapture (Cpp::kStdOut );
82+ }
83+
84+ ~StreamRedirectRAII ()
85+ {
86+ std::string out = Cpp::EndStdStreamCapture ();
87+ err = Cpp::EndStdStreamCapture ();
88+ std::cout << out;
89+ }
7190 };
7291
7392 void interpreter::configure_impl ()
@@ -102,14 +121,14 @@ __get_cxx_version ()
102121 return std::to_string (cxx_version);
103122 }
104123
105- interpreter::interpreter (int argc, const char * const * argv) :
106- xmagics ()
124+ interpreter::interpreter (int argc, const char * const * argv)
125+ : xmagics()
107126 , p_cout_strbuf(nullptr )
108127 , p_cerr_strbuf(nullptr )
109128 , m_cout_buffer(std::bind(&interpreter::publish_stdout, this , _1))
110129 , m_cerr_buffer(std::bind(&interpreter::publish_stderr, this , _1))
111130 {
112- // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
131+ // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
113132 createInterpreter (Args (argv ? argv + 1 : argv, argv + argc));
114133 m_version = get_stdopt ();
115134 redirect_output ();
@@ -212,10 +231,11 @@ __get_cxx_version ()
212231 //
213232 // JupyterLab displays the "{ename}: {evalue}" if the traceback is
214233 // empty.
215- if (evalue.size () < 4 ) {
234+ if (evalue.size () < 4 )
235+ {
216236 ename = " " ;
217237 }
218- std::vector<std::string> traceback ({ename + evalue});
238+ std::vector<std::string> traceback ({ename + evalue});
219239 if (!config.silent )
220240 {
221241 publish_execution_error (ename, evalue, traceback);
@@ -258,7 +278,8 @@ __get_cxx_version ()
258278
259279 Cpp::CodeComplete (results, code.c_str (), 1 , _cursor_pos + 1 );
260280
261- return xeus::create_complete_reply (results /* matches*/ ,
281+ return xeus::create_complete_reply (
282+ results /* matches*/ ,
262283 cursor_pos - to_complete.length () /* cursor_start*/ ,
263284 cursor_pos /* cursor_end*/
264285 );
@@ -279,13 +300,17 @@ __get_cxx_version ()
279300
280301 nl::json interpreter::is_complete_request_impl (const std::string& code)
281302 {
282- if (!code.empty () && code[code.size () - 1 ] == ' \\ ' ) {
303+ if (!code.empty () && code[code.size () - 1 ] == ' \\ ' )
304+ {
283305 auto found = code.rfind (' \n ' );
284306 if (found == std::string::npos)
307+ {
285308 found = -1 ;
309+ }
286310 auto found1 = found++;
287- while (isspace (code[++found1])) ;
288- return xeus::create_is_complete_reply (" incomplete" , code.substr (found, found1-found));
311+ while (isspace (code[++found1]))
312+ ;
313+ return xeus::create_is_complete_reply (" incomplete" , code.substr (found, found1 - found));
289314 }
290315
291316 return xeus::create_is_complete_reply (" complete" );
@@ -359,11 +384,11 @@ __get_cxx_version ()
359384
360385 void interpreter::init_preamble ()
361386 {
362- // NOLINTBEGIN(cppcoreguidelines-owning-memory)
387+ // NOLINTBEGIN(cppcoreguidelines-owning-memory)
363388 preamble_manager.register_preamble (" introspection" , std::make_unique<xintrospection>());
364389 preamble_manager.register_preamble (" magics" , std::make_unique<xmagics_manager>());
365390 preamble_manager.register_preamble (" shell" , std::make_unique<xsystem>());
366- // NOLINTEND(cppcoreguidelines-owning-memory)
391+ // NOLINTEND(cppcoreguidelines-owning-memory)
367392 }
368393
369394 void interpreter::init_magic ()
@@ -374,7 +399,10 @@ __get_cxx_version ()
374399 // timeit(&m_interpreter));
375400 // preamble_manager["magics"].get_cast<xmagics_manager>().register_magic("python", pythonexec());
376401 preamble_manager[" magics" ].get_cast <xmagics_manager>().register_magic (" file" , writefile ());
377- preamble_manager[" magics" ].get_cast <xmagics_manager>().register_magic (" timeit" , timeit (Cpp::GetInterpreter ()));
402+ preamble_manager[" magics" ].get_cast <xmagics_manager>().register_magic (
403+ " timeit" ,
404+ timeit (Cpp::GetInterpreter ())
405+ );
378406#ifndef EMSCRIPTEN
379407 preamble_manager[" magics" ].get_cast <xmagics_manager>().register_magic (" xassist" , xassist ());
380408#endif
0 commit comments