ned14 / pcpp

A C99 preprocessor written in pure Python
Other
215 stars 39 forks source link

Missing new line after passing through includes #57

Closed trelau closed 3 years ago

trelau commented 3 years ago

Great tool. I'm preprocessing some header files to expand macros, but I don't care to pull the included content into the file. This is more or less the effect I am trying to achieve https://github.com/ned14/pcpp/pull/51.

When I use the passthru_includes option it doesn't seem to add a new line after the include file and it makes my downstream parsing break. Attached are a few sample files to demonstrate the issue. If you process foo.hxx, I'd expect to get:

#include <bar.hxx>
class A;

class B
{

};

but instead I get (notice class A is not on the new line):

#include <bar.hxx>class A;

class B
{

};

Contents of foo.hxx:

#include <bar.hxx>
class A;

class B
{

};

and contents of bar.hxx:

class C;

At this location of the source :

https://github.com/ned14/pcpp/blob/113605e5827295eafce675c99df89c45b6c4b475/pcpp/preprocessor.py#L897-L898

if I simply return a new line token after the precedingtoks and dirtokens loops then things come out fine. I tried to override on_directive_handle to handle it there, but couldn't quite get it right.

kguuh commented 3 years ago

Good

virtuald commented 3 years ago

Can confirm the bug and the fix, PR at https://github.com/ned14/pcpp/pull/58

ned14 commented 3 years ago

Thanks for the BR. Will try to process later this week.

ned14 commented 3 years ago

Fixing this was much harder than expected. Thanks @virtuald for the PR, however it broke other stuff. It turned out the original implementation was simply incorrect, and hopefully now it works as it is supposed to.