Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/xinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ using namespace std::placeholders;
namespace xcpp
{
struct StreamRedirectRAII {
std::string &out;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'out' of type 'std::string &' (aka 'basic_string &') is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

      std::string &out;
                   ^

std::string &err;
StreamRedirectRAII(std::string &e) : err(e) {
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
StreamRedirectRAII(std::string &o, std::string &e)
: out(o), err(e)
{
Cpp::BeginStdStreamCapture(Cpp::kStdOut);
Cpp::BeginStdStreamCapture(Cpp::kStdErr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Cpp::kStdErr" is directly included [misc-include-cleaner]

        Cpp::BeginStdStreamCapture(Cpp::kStdErr);
                                        ^

}
~StreamRedirectRAII() {
std::string out = Cpp::EndStdStreamCapture();
err = Cpp::EndStdStreamCapture();
std::cout << out;
out = Cpp::EndStdStreamCapture();
}
};

Expand Down Expand Up @@ -163,11 +165,12 @@ __get_cxx_version ()
}

std::string err;
std::string out;

// Attempt normal evaluation
try
{
StreamRedirectRAII R(err);
StreamRedirectRAII R(out, err);
compilation_result = Cpp::Process(code.c_str());
}
catch (std::exception& e)
Expand All @@ -182,13 +185,8 @@ __get_cxx_version ()
ename = "Error: ";
}

if (compilation_result)
{
errorlevel = 1;
ename = "Error: ";
evalue = "Compilation error! " + err;
std::cerr << err;
}
if (!out.empty()) std::cout << out;
if (!err.empty()) std::cerr << err;

// Flush streams
std::cout << std::flush;
Expand All @@ -201,6 +199,13 @@ __get_cxx_version ()
std::cerr.rdbuf(cerr_strbuf);
}

if (compilation_result)
{
errorlevel = 1;
ename = "Error: ";
evalue = "Compilation error! " + err;
}

// Depending of error level, publish execution result or execution
// error, and compose execute_reply message.
if (errorlevel)
Expand Down
Loading