Implement #undef.

This commit is contained in:
Andrius Štikonas 2021-11-02 21:51:38 +00:00
parent e3651879a5
commit 2da7b3f9a0
3 changed files with 47 additions and 7 deletions

View File

@ -142,6 +142,36 @@ struct macro_list* lookup_macro(struct token_list* token)
return NULL;
}
void remove_macro(struct token_list* token)
{
struct macro_list* hold = macro_env;
struct macro_list* temp;
/* Deal with the first element */
if (match(token->s, hold->symbol)) {
macro_env = hold->next;
free(hold);
return;
}
/* Remove element form the middle of linked list */
while (NULL != hold->next)
{
if (match(token->s, hold->next->symbol))
{
temp = hold->next;
hold->next = hold->next->next;
free(temp);
return;
}
hold = hold->next;
}
/* nothing to undefine */
return;
}
int macro_expression();
int macro_variable()
{
@ -423,7 +453,13 @@ void handle_define()
eat_current_token();
}
}
void handle_undef()
{
eat_current_token();
remove_macro(macro_token);
eat_current_token();
}
void handle_error()
@ -576,6 +612,10 @@ void macro_directive()
{
handle_define();
}
else if(match("#undef", macro_token->s))
{
handle_undef();
}
else if(match("#error", macro_token->s))
{
handle_error();

View File

@ -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
bf1d23078b04a88ad8eeb615a3208f76cf1c2bd4c7070452f887c569ad94b684 test/results/test1000-aarch64-binary
aeb6d1cbb3616b8e6fc20b195dcc164cc77c835810c1a3c90504c3749f662385 test/results/test1000-amd64-binary
bb88a105f120d8dc1d34de87114b371363801fbcf4341e510bcb5bcc08e76037 test/results/test1000-armv7l-binary
85318559fd43f582cefbaf60e4300a59e9589745782b4a9083601152d231fcb6 test/results/test1000-knight-posix-binary
de7107777e9008b8467c52c5fab7ca91580b4216cf0f6c6737ee538cfb0f2ab3 test/results/test1000-riscv64-binary
bd66e02f6bfa34187d36116c147f32977c4e3bc34f46df66da4fe828984727e8 test/results/test1000-x86-binary
163b9e09a19f8cd592af1ad1ff289c985e769df17eb67eea33bf7f9fff140654 test/results/test1000-aarch64-binary
c8c56324ce5e53e0ce75a0c84db88c39397f79f761b3e2fbec5714b9f058b37c test/results/test1000-amd64-binary
19e79a0a80d43e22f1cbd1636985b362273fb2c8bafe27eede2f79aea16b07e5 test/results/test1000-armv7l-binary
b0c4cb6ba049f97704df3e3694b47364c1302b28e88d87065b27887642ebda76 test/results/test1000-knight-posix-binary
efe53ac2f7bd3bce3823160232da05af3b8e21e576a38f694272b9dc577a2baa test/results/test1000-riscv64-binary
430978cbac169ce8447eb485632698e5b35abcbb49d4d5156a6b66a607117b32 test/results/test1000-x86-binary

View File

@ -1 +1 @@
e018a50ea8e2547020473cfdc60066a41cd3793b9d7c164bba5ce7e80a06dd8b test/test1000/proof
d9883c3c138fcf943bab6320855cbb30dfa8a7384c6431d4174cb4c137ed644f test/test1000/proof