3131
3232using Args = std::vector<const char *>;
3333
34- void * createInterpreter (const Args &ExtraArgs = {}) {
35- Args ClangArgs = {/* "-xc++"*/ " -v" }; // ? {"-Xclang", "-emit-llvm-only", "-Xclang", "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
36- if (std::find_if (ExtraArgs.begin (), ExtraArgs.end (), [](const std::string& s) {
37- return s == " -resource-dir" ;}) == ExtraArgs.end ()) {
38- std::string resource_dir = Cpp::DetectResourceDir ();
39- if (resource_dir.empty ())
40- std::cerr << " Failed to detect the resource-dir\n " ;
41- ClangArgs.push_back (" -resource-dir" );
42- ClangArgs.push_back (resource_dir.c_str ());
43- }
44- std::vector<std::string> CxxSystemIncludes;
45- Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
46- for (const std::string& CxxInclude : CxxSystemIncludes) {
47- ClangArgs.push_back (" -isystem" );
48- ClangArgs.push_back (CxxInclude.c_str ());
49- }
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"}*/ );
34+ void * createInterpreter (const Args& ExtraArgs = {})
35+ {
36+ Args ClangArgs = {/* "-xc++"*/ " -v" }; // ? {"-Xclang", "-emit-llvm-only", "-Xclang",
37+ // "-diagnostic-log-file", "-Xclang", "-", "-xc++"};
38+ if (std::find_if (
39+ ExtraArgs.begin (),
40+ ExtraArgs.end (),
41+ [](const std::string& s)
42+ {
43+ return s == " -resource-dir" ;
44+ }
45+ )
46+ == ExtraArgs.end ())
47+ {
48+ std::string resource_dir = Cpp::DetectResourceDir ();
49+ if (resource_dir.empty ())
50+ {
51+ std::cerr << " Failed to detect the resource-dir\n " ;
52+ }
53+ ClangArgs.push_back (" -resource-dir" );
54+ ClangArgs.push_back (resource_dir.c_str ());
55+ }
56+ std::vector<std::string> CxxSystemIncludes;
57+ Cpp::DetectSystemCompilerIncludePaths (CxxSystemIncludes);
58+ for (const std::string& CxxInclude : CxxSystemIncludes)
59+ {
60+ ClangArgs.push_back (" -isystem" );
61+ ClangArgs.push_back (CxxInclude.c_str ());
62+ }
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 ()
@@ -103,15 +122,14 @@ __get_cxx_version ()
103122 return std::to_string (cxx_version);
104123 }
105124
106-
107- interpreter::interpreter (int argc, const char * const * argv) :
108- xmagics ()
125+ interpreter::interpreter (int argc, const char * const * argv)
126+ : xmagics()
109127 , p_cout_strbuf(nullptr )
110128 , p_cerr_strbuf(nullptr )
111129 , m_cout_buffer(std::bind(&interpreter::publish_stdout, this , _1))
112130 , m_cerr_buffer(std::bind(&interpreter::publish_stderr, this , _1))
113131 {
114- // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
132+ // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
115133 createInterpreter (Args (argv ? argv + 1 : argv, argv + argc));
116134 m_version = get_stdopt ();
117135 redirect_output ();
@@ -215,10 +233,11 @@ __get_cxx_version ()
215233 //
216234 // JupyterLab displays the "{ename}: {evalue}" if the traceback is
217235 // empty.
218- if (evalue.size () < 4 ) {
236+ if (evalue.size () < 4 )
237+ {
219238 ename = " " ;
220239 }
221- std::vector<std::string> traceback ({ename + evalue});
240+ std::vector<std::string> traceback ({ename + evalue});
222241 if (!config.silent )
223242 {
224243 publish_execution_error (ename, evalue, traceback);
@@ -261,7 +280,8 @@ __get_cxx_version ()
261280
262281 Cpp::CodeComplete (results, code.c_str (), 1 , _cursor_pos + 1 );
263282
264- return xeus::create_complete_reply (results /* matches*/ ,
283+ return xeus::create_complete_reply (
284+ results /* matches*/ ,
265285 cursor_pos - to_complete.length () /* cursor_start*/ ,
266286 cursor_pos /* cursor_end*/
267287 );
@@ -282,13 +302,17 @@ __get_cxx_version ()
282302
283303 nl::json interpreter::is_complete_request_impl (const std::string& code)
284304 {
285- if (!code.empty () && code[code.size () - 1 ] == ' \\ ' ) {
305+ if (!code.empty () && code[code.size () - 1 ] == ' \\ ' )
306+ {
286307 auto found = code.rfind (' \n ' );
287308 if (found == std::string::npos)
309+ {
288310 found = -1 ;
311+ }
289312 auto found1 = found++;
290- while (isspace (code[++found1])) ;
291- return xeus::create_is_complete_reply (" incomplete" , code.substr (found, found1-found));
313+ while (isspace (code[++found1]))
314+ ;
315+ return xeus::create_is_complete_reply (" incomplete" , code.substr (found, found1 - found));
292316 }
293317
294318 return xeus::create_is_complete_reply (" complete" );
@@ -382,21 +406,30 @@ __get_cxx_version ()
382406 std::istringstream stream (non_standard_paths);
383407 std::string path;
384408 while (std::getline (stream, path, path_separator))
409+ <<<<<<< HEAD
385410+ {
386411 if (!path.empty ())
387412+ {
388413 Cpp::AddIncludePath (path.c_str ());
389414+ }
390415+ }
416+ =======
417+ {
418+ if (!path.empty ())
419+ {
420+ Cpp::AddIncludePath (path.c_str ());
421+ }
422+ }
423+ >>>>>>> 489e506 (Format xinterpreter.cpp with clang-format)
391424 }
392425
393426 void interpreter::init_preamble ()
394427 {
395- // NOLINTBEGIN(cppcoreguidelines-owning-memory)
428+ // NOLINTBEGIN(cppcoreguidelines-owning-memory)
396429 preamble_manager.register_preamble (" introspection" , std::make_unique<xintrospection>());
397430 preamble_manager.register_preamble (" magics" , std::make_unique<xmagics_manager>());
398431 preamble_manager.register_preamble (" shell" , std::make_unique<xsystem>());
399- // NOLINTEND(cppcoreguidelines-owning-memory)
432+ // NOLINTEND(cppcoreguidelines-owning-memory)
400433 }
401434
402435 void interpreter::init_magic ()
0 commit comments