-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preprocessor whitespace fixes #599
Conversation
src/aro/Preprocessor.zig
Outdated
@@ -1462,6 +1466,15 @@ fn handleBuiltinMacro(pp: *Preprocessor, builtin: RawToken.Id, param_toks: []con | |||
} | |||
} | |||
|
|||
fn getPasteArgs(args: []const []const Token, end: u32) []const Token { | |||
const placemarker = &[1]Token{tokFromRaw(.{ .id = .placemarker, .source = .generated })}; | |||
if (args[end].len == 0) return placemarker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this actually work? It looks like it's returning an address of a stack variable - is it because it's a comptime-known constant and it's getting hoisted up to some static-lifetime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tokFromRaw
is being called at runtime so it is indeed returning an address of a stack variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised it's not crashing then, lol. In any of the modes I tried, at least. I rewrote it so getPasteArgs
returns an optional instead.
If a paste arg is entirely whitespace tokens, treat it as empty
263184f
to
7c83431
Compare
for (args) |tok| { | ||
if (tok.id != .macro_ws) return args; | ||
} | ||
return &[1]Token{.{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this safe to do if there aren't any runtime dependencies (like the old tokFromRaw
call)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's doing pretty much the same as string literals.
Replacing empty object macros with placemarkers broke the fix in e7437dc so this re implements it.
Treats whitespace-only paste arguments as placemarkers
Replace empty macros with placemarkers (this has the effect of blocking function-like macro expansion in some case, see
empty macro block expansion.c
Closes #597