ned14 / pcpp

A C99 preprocessor written in pure Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing new line after passing through includes

trelau opened this issue · comments

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 #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 :

pcpp/pcpp/preprocessor.py

Lines 897 to 898 in 113605e

for tok in self.include(args):
pass

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.

commented

Good

Can confirm the bug and the fix, PR at #58

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

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.