feat(argparse): 添加列表类型参数支持

新增 scc_argparse_list_t 类型用于处理多个字符串值的参数,
并添加相应的配置函数 scc_argparse_spec_setup_list。

fix(lexer): 调整关键字标记处理逻辑

将关键字子类型从 SCC_TOK_SUBTYPE_KEYWORD 改为
SCC_TOK_SUBTYPE_IDENTIFIER,并移除相关的枚举定义。

refactor(lexer): 优化跳过换行功能实现

修改 scc_lexer_skip_until_newline 函数实现,改进循环逻辑和错误处理。

feat(pproc): 完善预处理器条件编译支持

重构条件编译状态管理,添加对 #ifdef、#ifndef、#elifdef、
#else、#endif 等指令的支持,并实现嵌套条件处理。

refactor(pproc): 优化文件包含路径处理

添加最大包含深度限制,改进包含路径添加功能,
修复文件状态结构命名。

docs(log): 更新日志模块标准库依赖

调整 stdarg.h 包含逻辑,更新编译器内置宏定义名称。

feat(core): 扩展核心类型定义

添加基础数据类型别名定义,完善类型系统支持。

feat(main): 实现命令行包含路径参数

添加 -I/--include 参数支持,允许用户指定额外的头文件搜索路径。
This commit is contained in:
zzy
2026-02-21 10:46:49 +08:00
parent 9c2b4db22a
commit b705e5d0ad
12 changed files with 452 additions and 78 deletions

View File

@@ -11,6 +11,7 @@ typedef struct {
const char *input_file;
const char *output_file;
int verbose;
scc_argparse_list_t include_paths;
cbool emit_lex;
cbool emit_pp;
cbool emit_ast;
@@ -89,9 +90,12 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
scc_argparse_spec_set_required(&arg_input.spec, true);
scc_argparse_cmd_add_arg(root, &arg_input);
// -I, --include (添加额外的系统头文件搜索路径)
scc_argparse_opt_t opt_include;
scc_argparse_opt_init(&opt_include, 0, "include",
scc_argparse_opt_init(&opt_include, 'I', "include",
scc_hints[SCC_HINT_INCLUDE_PATH]);
scc_argparse_spec_setup_list(&opt_include.spec, &(config->include_paths));
scc_argparse_cmd_add_opt(root, &opt_include);
// -v, --verbose (计数)
scc_argparse_opt_t opt_verbose;
@@ -194,6 +198,8 @@ int main(int argc, const char **argv, const char **envp) {
.emit_ast = false,
.emit_ir = false,
};
scc_vec_init(config.include_paths);
scc_argparse_t argparse;
setup_argparse(&argparse, &config, SCC_ARGPARSE_LANG_ZH);
int ret = scc_argparse_parse(&argparse, argc, argv);
@@ -223,6 +229,15 @@ int main(int argc, const char **argv, const char **envp) {
scc_pproc_t pproc;
scc_pproc_init(&pproc, scc_lexer_to_ring(&lexer, 8, true));
scc_vec_foreach(config.include_paths, i) {
scc_pproc_add_include_path_cstr(&pproc,
scc_vec_at(config.include_paths, i));
}
scc_lexer_tok_vec_t pproc_tok_vec;
scc_vec_init(pproc_tok_vec);
scc_cstring_t pproc_macro_name = scc_cstring_from_cstr("__SCC__");
scc_pproc_add_object_macro(&(pproc.macro_table), &pproc_macro_name,
&pproc_tok_vec);
if (config.emit_pp) {
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pproc, 8);
if (config.output_file == null) {