windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
337 stars 36 forks source link

ppci-cc: cpp stringify operator # expansions too simplistic #56

Closed tstreiff closed 4 years ago

tstreiff commented 4 years ago

The preprocessor stringify operator # is supported but the resulting expansions are not always correct. (behaviour for 0.5.7)

define S(a) #a

S(word) => "word" // correct S("string") => ""string"" // instead of "\"string\"" (double quotes should be escaped) S('a') => "'a'" // correct S("aa\tbb") => ""aa\tbb" // instead of "\"aa\tbb\"" (backslashes should be escaped) S( 1) =>> " 1" au lieu de "1" // leading and trailing blanks should be ignored S( 1 2 3 ) => " 1 2 3" au lieu de "1 2 3" // only one separator is kept between tokens

windelbouwman commented 4 years ago

Wow, nice catch. The preprocessor never ceases to amaze me :).

Implemented a fix in 26239aad6fec269b2aa34724dece80351da63761

tstreiff commented 4 years ago

The fix looks good. "#" is tricky but "##" is even worse!

windelbouwman commented 4 years ago

Closing this issue, since it seems to operate properly.