Skip to content
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

Add support for empty defines. #26

Merged
merged 2 commits into from Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 61 additions & 3 deletions cc_macro.c
Expand Up @@ -395,9 +395,9 @@ void handle_define()
{
if(NULL == expansion_end)
{
line_error_token(line_start);
fputs("#define missing actual definition\n", stderr);
exit(EXIT_FAILURE);
hold->expansion = NULL;
expansion_end = macro_token;
return;
}
expansion_end->next = NULL;
return;
Expand Down Expand Up @@ -444,6 +444,60 @@ void macro_directive()

t->previous_condition_matched = t->include;
}
else if(match("#ifdef", macro_token->s))
{
eat_current_token();
require(NULL != macro_token, "got an EOF terminated macro defined expression\n");
if (NULL != lookup_macro(macro_token))
{
result = TRUE;
}
else
{
result = FALSE;
}
eat_current_token();

/* push conditional inclusion */
t = calloc(1, sizeof(struct conditional_inclusion));
t->prev = conditional_inclusion_top;
conditional_inclusion_top = t;
t->include = TRUE;

if(FALSE == result)
{
t->include = FALSE;
}

t->previous_condition_matched = t->include;
}
else if(match("#ifndef", macro_token->s))
{
eat_current_token();
require(NULL != macro_token, "got an EOF terminated macro defined expression\n");
if (NULL != lookup_macro(macro_token))
{
result = FALSE;
}
else
{
result = TRUE;
}
eat_current_token();

/* push conditional inclusion */
t = calloc(1, sizeof(struct conditional_inclusion));
t->prev = conditional_inclusion_top;
conditional_inclusion_top = t;
t->include = TRUE;

if(FALSE == result)
{
t->include = FALSE;
}

t->previous_condition_matched = t->include;
}
else if(match("#elif", macro_token->s))
{
eat_current_token();
Expand Down Expand Up @@ -518,6 +572,10 @@ struct token_list* maybe_expand(struct token_list* token)
}

token = eat_token(token);
if (NULL == hold->expansion)
{
return token->next;
}
hold2 = insert_tokens(token, hold->expansion);

return hold2->next;
Expand Down
12 changes: 6 additions & 6 deletions test/test.answers
Expand Up @@ -212,9 +212,9 @@ eb1f6aab09a1a4966f9f49a518d8aa03ca97aa7c46e443871d758a306671a85e test/results/t
a2cbfd5f76d3be8049c6737e3fa02f191caf29b6885db006fa23f86e6eacc186 test/results/test0106-knight-posix-binary
d75e450e2fcdf19df63f9d6a3fe5e032933e57b33f6f06b39a8ed2f3dc759f17 test/results/test0106-riscv64-binary
473cc504d6cba9eaf648abcf15c83a317ff3f4a7f08f5e8936e3b35b2cc4fbc6 test/results/test0106-x86-binary
57fea76f6b769284fc64f4b80ab6b1859d56a9810c563c5e2f18cbea1eee2cd0 test/results/test1000-aarch64-binary
02ec3f7cf3359e6d6b7abce74cb59aa75df73c7275c9e3d16a42daa6f0eb81e8 test/results/test1000-amd64-binary
9b6e60a3e874b3d53ea616b857e360a7b2ad12297c020ccba6c834a965e224aa test/results/test1000-armv7l-binary
51596bd8a6afea9c888fb5e14b6a965557d04df291f0bd818477229df5ab5ee7 test/results/test1000-knight-posix-binary
41b3cbd0e742f98c49e220edb52e0cdcca92a170bdcfdd9d5dafb4106ee97aba test/results/test1000-riscv64-binary
13a684245ab8b33ee52d6d9d97ee169e8dab5915b139dfcc1cae5e40bc699847 test/results/test1000-x86-binary
4788501ea76eb118df6f7283b10c17208eb1dccfe815c9cdd7fd507401d68890 test/results/test1000-aarch64-binary
9a5d03495ea6280a3a062bce4d67401d2cbece26027c6b5de5cf44e1423d6774 test/results/test1000-amd64-binary
e44aea1acca281ae79bad7e53220af38c34b0f3773a4aaa3a63fcd7532d76b20 test/results/test1000-armv7l-binary
9e00a11729f5e300f75d89c8a05b04f1ce69269a8ca9990aa505a18b59751314 test/results/test1000-knight-posix-binary
e4239c5b8b712522004f2f85f9c84d300cbd8752a24a03a521c8b55a6f2bfd0b test/results/test1000-riscv64-binary
44e7fe235a083c26c3a51b8e98c95fb6feacb64e3d23a6b213a1320013f998df test/results/test1000-x86-binary
2 changes: 1 addition & 1 deletion test/test1000/proof.answer
@@ -1 +1 @@
7d3a7dcb758d348a1822c8e1313ca8180676a7eba2846eec2accb13a1f8602e0 test/test1000/proof
6f9f414baebe52c30f700a50876d04aeeabccaa17f6d1f95799501dc58017938 test/test1000/proof