danmar / simplecpp

C++ preprocessor
BSD Zero Clause License
206 stars 82 forks source link

Prevent change of spacing #135

Open agners opened 6 years ago

agners commented 6 years ago

When trying to reuse the simplecpp for device tree it turns out that simplecpp changes spacing such that the output can't be read by the device tree compiler. simplepcc inserts a space between the ampersand and the label, such that they can not be read by dtc, e.g. & gpio).

It would be nice to have an option which preserves spaces as much as possible.

danmar commented 6 years ago

how do you use simplecpp? on the command line like this:

simplecpp 1.c

?

I would personally prefer that you use the token list output instead but that might be more complex for you. you then have to write a c++ program (you can just tweak simplecpp/main.cpp) that uses simplecpp.

danmar commented 6 years ago

I think that we want to have 2 different behaviors. For debugging I want to see what tokens are created so I want to have the extra space. Users do not want to have extra spaces. So I need to add some debug flag that I can use.

If you want to try to fix this the feel free to look at it. I believe that you can just tweak simplecpp::TokenList::stringify in simplecpp.cpp.

agners commented 6 years ago

I try to use it as drop in replacement for GCC's preprocessor to preprocess Linux kernel device trees. The GCC command looks like this:

cpp -nostdinc -x assembler-with-cpp -I../linux/include/ -o output.dts.tmp input.dts

The simplecpp command looks like this:

simplecpp -D__DTS__ -I../linux/include/ input.dts > output.dts.tmp
danmar commented 5 years ago

Why not use gcc? The text output is for debugging purposes. It is tricky to get the spacing exactly as gcc and I rather not worry about if the debug output is exactly like gcc or not.

danmar commented 5 years ago

To me this is currently a low prio issue.