feat(lexer, preprocessor): replace cstring conversion with copy and refactor macro expansion

- Replace `scc_cstring_from_cstr(scc_cstring_as_cstr(...))` with `scc_cstring_copy()` in lexer to fix memory leaks
- Extract macro expansion logic into separate `expand_macro.c` file
- Remove `expand_stack` parameter from `scc_pp_expand_macro()` function
- Add new parsing functions for macro replacement lists and arguments
- Add string utility functions for whitespace trimming and string joining
- Update memory stream documentation for clarity
This commit is contained in:
zzy
2025-12-15 20:24:39 +08:00
parent 73d74f5e13
commit 07f5d9331b
15 changed files with 574 additions and 346 deletions

View File

@@ -79,7 +79,7 @@ void scc_lexer_init(scc_lexer_t *lexer, scc_probe_stream_t *stream) {
lexer->stream = stream;
lexer->pos = scc_pos_init();
// FIXME
lexer->pos.name = scc_cstring_from_cstr(scc_cstring_as_cstr(&stream->name));
lexer->pos.name = scc_cstring_copy(&stream->name);
}
#define set_err_token(token) ((token)->type = SCC_TOK_UNKNOWN)
@@ -135,7 +135,7 @@ static void parse_line(scc_lexer_t *lexer, scc_lexer_tok_t *token) {
scc_lex_parse_skip_line(lexer->stream, &lexer->pos);
token->loc.line = n;
// FIXME memory leak
token->loc.name = scc_cstring_from_cstr(scc_cstring_as_cstr(&str));
token->loc.name = scc_cstring_copy(&str);
scc_cstring_free(&str);
return;
SKIP_LINE: