feat(ast): 更新AST字面量表示方式

更新AST定义以使用词素字符串代替常量值,
并修改AST转储功能以正确显示字面量内容。

BREAKING CHANGE: AST表达式结构体中literal成员从value改为lexme字段。

refactor(pproc): 重构宏展开和文件包含逻辑

将宏展开函数重构为独立接口,实现文件包含处理逻辑,
改进预处理器的状态管理机制。

fix(sstream): 修复文件流初始化错误码返回

修正文件打开失败时的错误码返回值,确保调用方能正确处理异常情况。
This commit is contained in:
zzy
2026-02-19 15:56:05 +08:00
parent 27a87d17ab
commit a52ff33e30
9 changed files with 156 additions and 27 deletions

View File

@@ -81,26 +81,35 @@ static inline void scc_copy_expand(scc_pproc_expand_t *expand_ctx,
scc_vec_init(copyed_ctx->output);
}
void scc_pproc_expand_by_src(scc_pproc_t *pp, const scc_pproc_macro_t *macro) {
scc_pproc_expand_t ctx;
void scc_pproc_expand_by_src(scc_pproc_macro_table_t *macro_table,
scc_lexer_tok_ring_t *input,
scc_lexer_tok_ring_t *output,
const scc_pproc_macro_t *macro) {
scc_lexer_tok_vec_t expaned_buffer;
scc_vec_init(expaned_buffer);
int ok;
scc_lexer_tok_t tok;
scc_ring_next_consume(*pp->cur_ring, tok, ok);
scc_ring_next_consume(*input, tok, ok);
if (macro->type == SCC_PP_MACRO_NONE || ok == false) {
UNREACHABLE();
} else if (macro->type == SCC_PP_MACRO_OBJECT) {
scc_vec_push(expaned_buffer, tok);
} else if (macro->type == SCC_PP_MACRO_FUNCTION) {
scc_vec_push(expaned_buffer, tok);
scc_pproc_parse_macro_arguments(pp->cur_ring, &expaned_buffer, true);
scc_pproc_parse_macro_arguments(input, &expaned_buffer, true);
}
scc_lexer_tok_ring_t ring = scc_lexer_array_to_ring(&expaned_buffer);
scc_pproc_expand_by_vec(macro_table, &expaned_buffer, output);
}
void scc_pproc_expand_by_vec(scc_pproc_macro_table_t *macro_table,
scc_lexer_tok_vec_t *input,
scc_lexer_tok_ring_t *output) {
scc_pproc_expand_t ctx;
scc_lexer_tok_ring_t ring = scc_lexer_array_to_ring(input);
ctx.input = ˚
ctx.macro_table = &pp->macro_table;
ctx.macro_table = macro_table;
ctx.need_rescan = false;
scc_vec_init(ctx.output);
scc_pproc_macro_table_t expanded_set;
@@ -108,7 +117,7 @@ void scc_pproc_expand_by_src(scc_pproc_t *pp, const scc_pproc_macro_t *macro) {
scc_pproc_marco_table_init(ctx.expanded_set);
scc_pproc_expand_macro(&ctx);
pp->expanded_ring = scc_lexer_array_to_ring(&ctx.output);
*output = scc_lexer_array_to_ring(&ctx.output);
scc_pproc_macro_table_drop(ctx.expanded_set);
}