-
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
Implement #elifdef and #elifndef #467
Conversation
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.
Looks good! And thanks for updating this for the latest master.
src/Preprocessor.zig
Outdated
} | ||
switch (if_kind.get(if_level)) { | ||
until_else => { | ||
const macro_name = (try pp.expectMacroName(&tokenizer)) orelse continue; |
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 think a missing macro name should be considered false
similarly to a missing expression with #if
.
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 have tested it with clang and you are right, i have also added a test for checking the missing macro name in the commit ef844b6
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.
Clang generate this output:
test/cases/#elifdefc2x_error.c:7:9: error: macro name missing
#elifdef
^
# 10 "test/cases/#elifdefc2x_error.c"
inttest/cases/#elifdefc2x_error.c:16:10: error: macro name missing
#elifndef
^
# 19 "test/cases/#elifdefc2x_error.c"
int
2 errors generated.
And Gcc genete this:
# 10 "test/cases/#elifdefc2x_error.c"
int
# 19 "test/cases/#elifdefc2x_error.c"
int
I think the behaviour of gcc looks more correct, i'm going to commit to the pull request to reflect this.
With the change now both #elifdef and #elifndef are considered false when the macro name is missing.
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.
If there are not more issues, I think that with commit e156730 it should be ready to merge.
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.
It looks like they have the same output with clang missing a newline after the int
.
Implement C23 feature #elifdef and #elifndef from #430.
For testing added two new Preproccesor tests #elifdef.c and #elifdefc2x.c to check it is proccessed correctly with the -std=c2x flag
Also changed build.zig to compile with current master branch of zig.