Skip to content

[Suggestion] Add a compile time flag to control the line error output format. #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 1 addition & 16 deletions source/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,7 @@ struct error
: where{w}, msg{m}, internal{i}
{ }

auto print(auto& o, std::string const& file) const -> void
{
o << file ;
if (where.lineno > 0) {
o << "("<< (where.lineno);
if (where.colno >= 0) {
o << "," << where.colno;
}
o << ")";
}
o << ":";
if (internal) {
o << " internal compiler";
}
o << " error: " << msg << "\n";
}
auto print(auto& o, std::string const& file) const -> void;
};


Expand Down
35 changes: 33 additions & 2 deletions source/cppfront.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,44 @@ static cmdline_processor::register_flag cmd_cpp1_filename(
[](std::string const& name) { flag_cpp1_filename = name; }
);

static auto flag_print_colon_errors = false;
static cmdline_processor::register_flag cmd_print_colon_errors(
2,
"format-colon-errors",
"Emit ':line:col:' format for error messages",
[]{ flag_print_colon_errors = true; }
);

struct text_with_pos{
std::string text;
source_position pos;
text_with_pos(std::string const& t, source_position p) : text{t}, pos{p} { }
};

// Defined out of line so we can use flag_print_colon_errors.
auto error::print(auto& o, std::string const& file) const -> void {
o << file ;
if (where.lineno > 0) {
if (flag_print_colon_errors) {
o << ":"<< (where.lineno);
if (where.colno >= 0) {
o << ":" << where.colno;
}
}
else {
o << "("<< (where.lineno);
if (where.colno >= 0) {
o << "," << where.colno;
}
o << ")";
}
}
o << ":";
if (internal) {
o << " internal compiler";
}
o << " error: " << msg << "\n";
}

class positional_printer
{
Expand Down Expand Up @@ -1838,7 +1869,7 @@ class cppfront
assert (i->expr_list);
if (!i->expr_list->expressions.empty()) {
local_args.text_chunks = print_to_text_chunks(*i->expr_list);
}
}

flush_args();
args.emplace(std::move(local_args));
Expand Down Expand Up @@ -1940,7 +1971,7 @@ class cppfront

if (i->expr_list) {
auto text = print_to_text_chunks(*i->expr_list);
for (auto&& e: text) {
for (auto&& e: text) {
suffix.push_back(e);
}
}
Expand Down