Skip to content

Commit e0df1ee

Browse files
committed
Corrected #line output when using -output, closes #57
1 parent fe990ca commit e0df1ee

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

source/cppfront.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,14 @@ struct text_with_pos{
120120
class positional_printer
121121
{
122122
// Core information
123-
std::ofstream out = {}; // Cpp1 syntax output file
124-
std::string filename = {};
125-
std::vector<comment> const* pcomments = {}; // Cpp2 comments data
123+
std::ofstream out = {}; // Cpp1 syntax output file
124+
std::string cpp2_filename = {};
125+
std::string cpp1_filename = {};
126+
std::vector<comment> const* pcomments = {}; // Cpp2 comments data
126127

127-
source_position curr_pos = {}; // current (line,col) in output
128-
int next_comment = 0; // index of the next comment not yet printed
129-
bool last_was_cpp2 = false;
128+
source_position curr_pos = {}; // current (line,col) in output
129+
int next_comment = 0; // index of the next comment not yet printed
130+
bool last_was_cpp2 = false;
130131

131132
struct req_act_info {
132133
colno_t requested;
@@ -235,7 +236,7 @@ class positional_printer
235236

236237
// Not using print() here because this is transparent to the curr_pos
237238
if (!flag_clean_cpp1) {
238-
out << "#line " << line << " " << std::quoted(filename + "2") << "\n";
239+
out << "#line " << line << " " << std::quoted(cpp2_filename) << "\n";
239240
}
240241
}
241242

@@ -324,14 +325,16 @@ class positional_printer
324325
// Open
325326
//
326327
auto open(
327-
std::string cpp1_filename,
328+
std::string cpp2_filename_,
329+
std::string cpp1_filename_,
328330
std::vector<comment> const& comments
329331
)
330332
-> void
331333
{
334+
cpp2_filename = cpp2_filename_;
332335
assert (!out.is_open() && !pcomments && "ICE: tried to call .open twice");
333-
filename = cpp1_filename;
334-
out.open(filename);
336+
cpp1_filename = cpp1_filename_;
337+
out.open(cpp1_filename);
335338
pcomments = &comments;
336339
}
337340

@@ -352,7 +355,7 @@ class positional_printer
352355
return;
353356
}
354357
out.close();
355-
std::remove(filename.c_str());
358+
std::remove(cpp1_filename.c_str());
356359
}
357360

358361

@@ -730,6 +733,7 @@ class cppfront
730733
cpp1_filename = flag_cpp1_filename; // use override if present
731734
}
732735
printer.open(
736+
sourcefile,
733737
cpp1_filename,
734738
tokens.get_comments()
735739
);

0 commit comments

Comments
 (0)