Skip to content

Commit a4ef5ab

Browse files
committed
Move print_colon_errors behind a cmdline flag.
1 parent ff482b8 commit a4ef5ab

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

source/common.h

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ struct comment
104104
//
105105
struct error
106106
{
107-
// Controls whether we print `FILE:line:col: error:` or `FILE(line,col):
108-
// error:`. Need to integrate with editors that jump to errors, etc.
109-
// TODO: This should become a compiler flag.
110-
#ifdef _MSC_VER
111-
static constexpr bool print_colon_errors = false;
112-
#else
113-
static constexpr bool print_colon_errors = true;
114-
#endif
115-
116107
source_position where;
117108
std::string msg;
118109
bool internal = false;
@@ -121,30 +112,7 @@ struct error
121112
: where{w}, msg{m}, internal{i}
122113
{ }
123114

124-
auto print(auto& o, std::string const& file) const -> void
125-
{
126-
o << file ;
127-
if (where.lineno > 0) {
128-
if (print_colon_errors) {
129-
o << ":"<< (where.lineno);
130-
if (where.colno >= 0) {
131-
o << ":" << where.colno;
132-
}
133-
}
134-
else {
135-
o << "("<< (where.lineno);
136-
if (where.colno >= 0) {
137-
o << "," << where.colno;
138-
}
139-
o << ")";
140-
}
141-
}
142-
o << ":";
143-
if (internal) {
144-
o << " internal compiler";
145-
}
146-
o << " error: " << msg << "\n";
147-
}
115+
auto print(auto& o, std::string const& file) const -> void;
148116
};
149117

150118

source/cppfront.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,44 @@ static cmdline_processor::register_flag cmd_cpp1_filename(
115115
[](std::string const& name) { flag_cpp1_filename = name; }
116116
);
117117

118+
static auto flag_print_colon_errors = false;
119+
static cmdline_processor::register_flag cmd_print_colon_errors(
120+
2,
121+
"format-colon-errors",
122+
"Emit ':line:col:' format for error messages",
123+
[]{ flag_print_colon_errors = true; }
124+
);
118125

119126
struct text_with_pos{
120127
std::string text;
121128
source_position pos;
122129
text_with_pos(std::string const& t, source_position p) : text{t}, pos{p} { }
123130
};
124131

132+
// Defined out of line so we can use flag_print_colon_errors.
133+
auto error::print(auto& o, std::string const& file) const -> void {
134+
o << file ;
135+
if (where.lineno > 0) {
136+
if (flag_print_colon_errors) {
137+
o << ":"<< (where.lineno);
138+
if (where.colno >= 0) {
139+
o << ":" << where.colno;
140+
}
141+
}
142+
else {
143+
o << "("<< (where.lineno);
144+
if (where.colno >= 0) {
145+
o << "," << where.colno;
146+
}
147+
o << ")";
148+
}
149+
}
150+
o << ":";
151+
if (internal) {
152+
o << " internal compiler";
153+
}
154+
o << " error: " << msg << "\n";
155+
}
125156

126157
class positional_printer
127158
{
@@ -1838,7 +1869,7 @@ class cppfront
18381869
assert (i->expr_list);
18391870
if (!i->expr_list->expressions.empty()) {
18401871
local_args.text_chunks = print_to_text_chunks(*i->expr_list);
1841-
}
1872+
}
18421873

18431874
flush_args();
18441875
args.emplace(std::move(local_args));
@@ -1940,7 +1971,7 @@ class cppfront
19401971

19411972
if (i->expr_list) {
19421973
auto text = print_to_text_chunks(*i->expr_list);
1943-
for (auto&& e: text) {
1974+
for (auto&& e: text) {
19441975
suffix.push_back(e);
19451976
}
19461977
}

0 commit comments

Comments
 (0)