ned14 / pcpp

A C99 preprocessor written in pure Python
Other
220 stars 41 forks source link

Fixed some issues with multiline comments in pass-thru mode #14

Closed p2k closed 6 years ago

p2k commented 6 years ago

(Getting to the point straight away:)

Sample input 1:


/*
multiline
comment
*/

void shouldBeOnLineSeven();

Output of $ pcpp --passthru-comments test1.h before patch:


/*
multiline
comment
*/

void shouldBeOnLineSeven();

Sample input 2:


/*
a
comment
that
spans
eight
lines
*/

void shouldBeOnLineEleven();

Output of $ pcpp --passthru-comments test2.h before patch:


/*
a
comment
that
spans
eight
lines
*/
#line 11 "test2.h"
void shouldBeOnLineEleven();

After patching, it correctly outputs the same output as the respective input. While the result of the second example is non-fatal, the first example shifts the line numbers illegally.

The fix addresses the problem with a rather simple trick of adjusting the last line number while iterating over the final token list. I also took the liberty of removing the blankacc list that wasn't used.

ned14 commented 6 years ago

Many thanks for the bug report. I've got the unit tests correctly failing with your sample inputs. I'll look into the bug fix tomorrow night.

ned14 commented 6 years ago

I rewrote it and did a bit more refactoring. Thanks for the bug report and fix!