31
31
32
32
using Args = std::vector<const char *>;
33
33
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"}*/ );
54
67
}
55
68
56
69
using namespace std ::placeholders;
57
70
58
71
namespace xcpp
59
72
{
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
+ }
71
90
};
72
91
73
92
void interpreter::configure_impl ()
@@ -103,15 +122,14 @@ __get_cxx_version ()
103
122
return std::to_string (cxx_version);
104
123
}
105
124
106
-
107
- interpreter::interpreter (int argc, const char * const * argv) :
108
- xmagics ()
125
+ interpreter::interpreter (int argc, const char * const * argv)
126
+ : xmagics()
109
127
, p_cout_strbuf(nullptr )
110
128
, p_cerr_strbuf(nullptr )
111
129
, m_cout_buffer(std::bind(&interpreter::publish_stdout, this , _1))
112
130
, m_cerr_buffer(std::bind(&interpreter::publish_stderr, this , _1))
113
131
{
114
- // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
132
+ // NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
115
133
createInterpreter (Args (argv ? argv + 1 : argv, argv + argc));
116
134
m_version = get_stdopt ();
117
135
redirect_output ();
@@ -215,10 +233,11 @@ __get_cxx_version ()
215
233
//
216
234
// JupyterLab displays the "{ename}: {evalue}" if the traceback is
217
235
// empty.
218
- if (evalue.size () < 4 ) {
236
+ if (evalue.size () < 4 )
237
+ {
219
238
ename = " " ;
220
239
}
221
- std::vector<std::string> traceback ({ename + evalue});
240
+ std::vector<std::string> traceback ({ename + evalue});
222
241
if (!config.silent )
223
242
{
224
243
publish_execution_error (ename, evalue, traceback);
@@ -261,7 +280,8 @@ __get_cxx_version ()
261
280
262
281
Cpp::CodeComplete (results, code.c_str (), 1 , _cursor_pos + 1 );
263
282
264
- return xeus::create_complete_reply (results /* matches*/ ,
283
+ return xeus::create_complete_reply (
284
+ results /* matches*/ ,
265
285
cursor_pos - to_complete.length () /* cursor_start*/ ,
266
286
cursor_pos /* cursor_end*/
267
287
);
@@ -282,13 +302,17 @@ __get_cxx_version ()
282
302
283
303
nl::json interpreter::is_complete_request_impl (const std::string& code)
284
304
{
285
- if (!code.empty () && code[code.size () - 1 ] == ' \\ ' ) {
305
+ if (!code.empty () && code[code.size () - 1 ] == ' \\ ' )
306
+ {
286
307
auto found = code.rfind (' \n ' );
287
308
if (found == std::string::npos)
309
+ {
288
310
found = -1 ;
311
+ }
289
312
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));
292
316
}
293
317
294
318
return xeus::create_is_complete_reply (" complete" );
@@ -382,21 +406,30 @@ __get_cxx_version ()
382
406
std::istringstream stream (non_standard_paths);
383
407
std::string path;
384
408
while (std::getline (stream, path, path_separator))
409
+ <<<<<<< HEAD
385
410
+ {
386
411
if (!path.empty ())
387
412
+ {
388
413
Cpp::AddIncludePath (path.c_str ());
389
414
+ }
390
415
+ }
416
+ =======
417
+ {
418
+ if (!path.empty ())
419
+ {
420
+ Cpp::AddIncludePath (path.c_str ());
421
+ }
422
+ }
423
+ >>>>>>> 489e506 (Format xinterpreter.cpp with clang-format)
391
424
}
392
425
393
426
void interpreter::init_preamble ()
394
427
{
395
- // NOLINTBEGIN(cppcoreguidelines-owning-memory)
428
+ // NOLINTBEGIN(cppcoreguidelines-owning-memory)
396
429
preamble_manager.register_preamble (" introspection" , std::make_unique<xintrospection>());
397
430
preamble_manager.register_preamble (" magics" , std::make_unique<xmagics_manager>());
398
431
preamble_manager.register_preamble (" shell" , std::make_unique<xsystem>());
399
- // NOLINTEND(cppcoreguidelines-owning-memory)
432
+ // NOLINTEND(cppcoreguidelines-owning-memory)
400
433
}
401
434
402
435
void interpreter::init_magic ()
0 commit comments