From fdda0a1797b8f39d752b64c4b6a7fa8fd2939e7a Mon Sep 17 00:00:00 2001 From: omdxp Date: Wed, 4 Sep 2024 12:41:45 +0100 Subject: [PATCH] impl undef --- preprocessor/preprocessor.c | 16 ++++++++++++++++ test.c | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/preprocessor/preprocessor.c b/preprocessor/preprocessor.c index 9a5e87f..c000478 100644 --- a/preprocessor/preprocessor.c +++ b/preprocessor/preprocessor.c @@ -471,6 +471,14 @@ bool preprocessor_token_is_define(struct token *token) { return S_EQ(token->sval, "define"); } +bool preprocessor_token_is_undef(struct token *token) { + if (!preprocessor_token_is_preprocessor_keyword(token)) { + return false; + } + + return S_EQ(token->sval, "undef"); +} + void preprocessor_multi_value_insert_to_vector(struct compile_process *compiler, struct vector *vec) { struct token *value_token = preprocessor_next_token(compiler); @@ -586,6 +594,11 @@ void preprocessor_handle_definition_token(struct compile_process *compiler) { preprocessor); } +void preprocessor_handle_undef_token(struct compile_process *compiler) { + struct token *name_token = preprocessor_next_token(compiler); + preprocessor_definition_remove(compiler->preprocessor, name_token->sval); +} + int preprocessor_handle_hashtag_token(struct compile_process *compiler, struct token *token) { bool is_preprocessed = false; @@ -593,6 +606,9 @@ int preprocessor_handle_hashtag_token(struct compile_process *compiler, if (preprocessor_token_is_define(next_token)) { preprocessor_handle_definition_token(compiler); is_preprocessed = true; + } else if (preprocessor_token_is_undef(next_token)) { + preprocessor_handle_undef_token(compiler); + is_preprocessed = true; } return is_preprocessed; diff --git a/test.c b/test.c index 52170da..83e700c 100644 --- a/test.c +++ b/test.c @@ -1 +1,2 @@ -#define ABC(x, y) +#define ABC 1 +#undef ABC