You can see that macro stringification depends on the whitespace between the tokens. But clang does not give this information easily. When I tried to implement this in my crate I had to ask for extent for each token and then compare source location for the current token's Start with the previous token's End. If they are equal it means the tokens are next to each other with no space in between. If locations are not equal than we just assume there is at least one space between them. It doesn't matter how many spaces are there, they should all be replaced with only one in the end.
Given this C code (godbolt link) it should produce correct strings for this macros
You can see that macro stringification depends on the whitespace between the tokens. But clang does not give this information easily. When I tried to implement this in my crate I had to ask for
extent
for each token and then compare source location for the current token'sStart
with the previous token'sEnd
. If they are equal it means the tokens are next to each other with no space in between. If locations are not equal than we just assume there is at least one space between them. It doesn't matter how many spaces are there, they should all be replaced with only one in the end.