jyn514 / saltwater

A C compiler written in Rust, with a focus on good error messages.
BSD 3-Clause "New" or "Revised" License
294 stars 27 forks source link

The order of preprocessor stringifying is wrong. #513

Open hdamron17 opened 4 years ago

hdamron17 commented 4 years ago

Stringify should be applied before doing replacement on the function parameters, but that replacement should occur before passing them to deeper functions (I think). I expect this has been broken since #456 but I will dig deeper.

Sample Code

#define str(a) # a
#define xstr(a) str(a)
#define f(x) [x]

str(f(5))
xstr(f(5))

Expected Behavior

"f(5)"
"[5]"

Actual Behavior

"f(5)"
"f(5)"
hdamron17 commented 4 years ago

Confirmed: this originated in #456 (specifically commit 3d2d038 but it didn't compile from 34e5ad2..8ef29cf and stringify was not implemented in ..0ef39e4).