Skip to content

Commit

Permalink
Implementing the error macro
Browse files Browse the repository at this point in the history
  • Loading branch information
fedi-nabli committed Mar 28, 2024
1 parent ed6397f commit 88f9628
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions preprocessor/preprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,16 @@ bool preprocessor_token_is_warning(struct token* token)
return (S_EQ(token->sval, "warning"));
}

bool preprocessor_token_is_error(struct token* token)
{
if (!preprocessor_token_is_preprocessor_keyword(token))
{
return false;
}

return (S_EQ(token->sval, "error"));
}

void preprocessor_multi_value_insert_to_vector(struct compile_process* compiler, struct vector* value_token_vec)
{
struct token* value_token = preprocessor_next_token(compiler);
Expand Down Expand Up @@ -665,6 +675,12 @@ void preprocessor_handle_warning_token(struct compile_process* compiler)
preprocessor_execute_warning(compiler, buffer_ptr(str_buf));
}

void preprocessor_handle_error_token(struct compile_process* compiler)
{
struct buffer* str_buf = preprocessor_multi_value_string(compiler);
preprocessor_execute_error(compiler, buffer_ptr(str_buf));
}

int preprocessor_handle_hashtag_token(struct compile_process* compiler, struct token* token)
{
bool is_preprocessed = false;
Expand All @@ -686,6 +702,11 @@ int preprocessor_handle_hashtag_token(struct compile_process* compiler, struct t
preprocessor_handle_warning_token(compiler);
is_preprocessed = true;
}
else if (preprocessor_token_is_error(next_token))
{
preprocessor_handle_error_token(compiler);
is_preprocessed = false;
}

return is_preprocessed;
}
Expand Down
3 changes: 2 additions & 1 deletion test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define ABC(x, y)
#undef ABC
#warning "Hello world"
#warning "Hello world"
#error "hello world"

0 comments on commit 88f9628

Please sign in to comment.