feat(lex_parser, pprocessor): rename identifier header check and add macro system

- Rename `scc_lex_parse_is_identifier_header` to `scc_lex_parse_is_identifier_prefix` for clarity and add a TODO comment
- Update lexer to use the renamed function for consistency
- Fix package and dependency names in `cbuild.toml` (`smcc_pprocesser` → `scc_pprocesser`, `smcc_lex_parser` → `lex_parser`)
- Introduce new macro system with header file `pp_macro.h` defining macro types, structures, and management functions
- Refactor preprocessor initialization and cleanup in `pprocessor.c` to use new macro table and stream handling
- Replace legacy `hashmap` with `scc_pp_macro_table_t` for macro storage
- Improve error handling and resource management in preprocessor lifecycle
This commit is contained in:
zzy
2025-12-13 16:09:46 +08:00
parent 874a58281f
commit 07a76d82f4
16 changed files with 970 additions and 490 deletions

View File

@@ -4,7 +4,7 @@
#include <stdlib.h>
#include <utest/acutest.h>
static core_stream_t *from_file_stream(FILE *fp) {
static scc_probe_stream_t *from_file_stream(FILE *fp) {
if (fseek(fp, 0, SEEK_END) != 0) {
perror("fseek failed");
return NULL;
@@ -20,9 +20,9 @@ static core_stream_t *from_file_stream(FILE *fp) {
usize read_ret = fread(buffer, 1, fsize, fp);
fclose(fp);
core_mem_stream_t *mem_stream = malloc(sizeof(core_mem_stream_t));
core_stream_t *stream =
core_mem_stream_init(mem_stream, buffer, fsize, true);
scc_mem_probe_stream_t *mem_stream = malloc(sizeof(scc_mem_probe_stream_t));
scc_probe_stream_t *stream =
scc_mem_probe_stream_init(mem_stream, buffer, fsize, true);
return stream;
}
@@ -37,28 +37,34 @@ static void test_file(const char *name) {
FILE *fexpect = fopen(expected_fname, "r");
assert(fexpect != NULL);
smcc_pp_t pp;
core_mem_stream_t stream;
core_stream_t *output_stream = pp_init(&pp, from_file_stream(fsrc));
core_stream_t *expect_stream = from_file_stream(fexpect);
scc_pproc_t pp;
scc_mem_probe_stream_t stream;
scc_probe_stream_t *output_stream =
scc_pproc_init(&pp, from_file_stream(fsrc));
scc_probe_stream_t *expect_stream = from_file_stream(fexpect);
TEST_CASE(src_fname);
while (1) {
int output_ch = core_stream_next_char(output_stream);
int expect_ch = core_stream_next_char(expect_stream);
int output_ch = scc_probe_stream_consume(output_stream);
int expect_ch = scc_probe_stream_consume(expect_stream);
TEST_CHECK(output_ch == expect_ch);
TEST_MSG("output: %c, expect: %c", output_ch, expect_ch);
if (output_ch == core_stream_eof) {
TEST_MSG("output: %c %x, expect: %c %x", output_ch, output_ch,
expect_ch, expect_ch);
if (output_ch != expect_ch) {
break;
}
if (output_ch == scc_stream_eof) {
break;
}
}
pp_drop(&pp);
scc_pproc_drop(&pp);
}
static void test_basic(void) {
char name[32];
// for (int i = 1; i <= 22; ++i) {
// snprintf(name, sizeof(name), "%02d", i);
// test_file(name);
// }
for (int i = 1; i <= 22; ++i) {
// snprintf(name, sizeof(name), "%02d", i);
// test_file(name);
}
}
TEST_LIST = {