refactor(format): 移除SCF格式相关文件

移除了libs/format目录下的所有文件,包括:
- cbuild.toml构建配置文件
- include/scf.h头文件
- include/scf_impl.h实现头文件
- src/scf.c源文件
- tests/test_scf.c测试文件
- tests/test_scf_x64.c x64架构测试文件

这些文件包含了SCF(scc format)格式的完整实现,但现在不再需要。

feat(lexer): 添加布尔字面量数字生成函数

在lexer工具头文件中添加了两个内联函数用于生成布尔值的数字字面量:
- scc_lexer_gen_number_true: 将token类型设为整数字面量,值为"1"
- scc_lexer_gen_number_false: 将token类型设为整数字面量,值为"0"

refactor(lexer): 改进词法分析器错误处理

- 移除了多余的头文件包含
- 更新错误报告方式,使用SCC_ERROR宏替代LEX_ERROR,提供更准确的错误位置信息

refactor(pproc): 更新预处理器扩展器数据结构

- 将need_rescan字段类型从int改为cbool
- 添加need_parse_defined字段用于控制defined操作符解析
- 更新函数签名以支持defined操作符解析参数
This commit is contained in:
zzy
2026-02-26 10:25:45 +08:00
parent d2eaf2247f
commit f56b13da2c
19 changed files with 215 additions and 1023 deletions

View File

@@ -1,4 +1,5 @@
#include <pproc_expand.h>
#include <scc_lexer_utils.h>
#include <scc_pproc.h>
static scc_lexer_tok_t stringify_argument(scc_lexer_tok_vec_t *arg_tokens) {
@@ -78,6 +79,7 @@ static inline void scc_copy_expand(scc_pproc_expand_t *expand_ctx,
copyed_ctx->expanded_set = expand_ctx->expanded_set;
copyed_ctx->macro_table = expand_ctx->macro_table;
copyed_ctx->need_rescan = false;
copyed_ctx->need_parse_defined = expand_ctx->need_parse_defined;
scc_vec_init(copyed_ctx->output);
}
@@ -100,17 +102,19 @@ void scc_pproc_expand_by_src(scc_pproc_macro_table_t *macro_table,
scc_pproc_parse_macro_arguments(input, &expaned_buffer, true);
}
scc_pproc_expand_by_vec(macro_table, &expaned_buffer, output);
scc_pproc_expand_by_vec(macro_table, &expaned_buffer, output, false);
}
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_lexer_tok_ring_t *output,
cbool need_parse_defined) {
scc_pproc_expand_t ctx;
scc_lexer_tok_ring_t ring = scc_lexer_array_to_ring(input);
ctx.input = &ring;
ctx.macro_table = macro_table;
ctx.need_rescan = false;
ctx.need_parse_defined = need_parse_defined;
scc_vec_init(ctx.output);
scc_pproc_macro_table_t expanded_set;
ctx.expanded_set = &expanded_set;
@@ -272,10 +276,12 @@ static inline void expand_function_macro(scc_pproc_expand_t *expand_ctx,
scc_pproc_macro_extened_params_t splited_params;
scc_vec_init(splited_params);
split_arguments(&splited_params, &raw_args, macro);
Assert(scc_vec_size(splited_params) >= scc_vec_size(macro->params));
scc_pproc_macro_extened_params_t expanded_params;
scc_vec_init(expanded_params);
expand_arguments(&expanded_params, &splited_params, expand_ctx);
Assert(scc_vec_size(expanded_params) >= scc_vec_size(macro->params));
// replace
scc_vec_foreach(macro->replaces, i) {
@@ -470,6 +476,57 @@ void scc_pproc_expand_macro(scc_pproc_expand_t *expand_ctx) {
scc_vec_push(expand_ctx->output, tok);
continue;
}
if (expand_ctx->need_parse_defined &&
scc_strcmp(scc_cstring_as_cstr(&tok.lexeme), "defined") == 0) {
scc_lexer_tok_t next_tok = {0};
if (scc_lexer_next_non_blank(expand_ctx->input, &next_tok) ==
false) {
SCC_ERROR(tok.loc, "Unexpected before defined EOF");
scc_lexer_tok_drop(&tok);
}
scc_lexer_tok_drop(&tok);
if (next_tok.type == SCC_TOK_L_PAREN) {
scc_lexer_tok_drop(&next_tok);
scc_lexer_next_non_blank(expand_ctx->input, &next_tok);
if (scc_get_tok_subtype(next_tok.type) !=
SCC_TOK_SUBTYPE_IDENTIFIER) {
SCC_ERROR(next_tok.loc,
"Expected identifier before defined");
scc_lexer_tok_drop(&next_tok);
}
if (scc_pproc_macro_table_get(expand_ctx->macro_table,
&next_tok.lexeme) == null) {
scc_lexer_gen_number_false(&tok);
} else {
scc_lexer_gen_number_true(&tok);
}
scc_lexer_tok_drop(&next_tok);
scc_vec_push(expand_ctx->output, tok);
if (scc_lexer_next_non_blank(expand_ctx->input, &next_tok)) {
if (next_tok.type == SCC_TOK_R_PAREN) {
scc_lexer_tok_drop(&next_tok);
break;
} else {
SCC_ERROR(next_tok.loc, "Expected ')'");
scc_lexer_tok_drop(&next_tok);
}
}
} else if (scc_get_tok_subtype(next_tok.type) ==
SCC_TOK_SUBTYPE_IDENTIFIER) {
if (scc_pproc_macro_table_get(expand_ctx->macro_table,
&next_tok.lexeme) == null) {
scc_lexer_gen_number_false(&tok);
} else {
scc_lexer_gen_number_true(&tok);
}
scc_lexer_tok_drop(&next_tok);
scc_vec_push(expand_ctx->output, tok);
}
continue;
}
// maybe expanded
scc_pproc_macro_t *macro =
scc_pproc_macro_table_get(expand_ctx->macro_table, &tok.lexeme);