feat(pproc): 添加预处理器包含路径支持和改进头文件查找逻辑

添加了新的类型定义 scc_pproc_cstr_vec_t 用于存储包含路径,
并在 scc_pproc 结构中添加 include_paths 字段。实现改进的
switch_file_stack 函数,支持从当前目录、父目录和系统包含路径
中查找头文件,提供更完整的 #include 指令处理能力。

fix(core): 重命名环形缓冲区内联宏避免命名冲突

将 scc_ring_phys 宏重命名为 _scc_ring_phys,并添加其他相关
内部宏如 _scc_ring_cap、_scc_ring_head 等,以避免与外部接口
的命名冲突并提高代码清晰度。

refactor(main): 添加命令行包含路径选项并清理标准库引用

在命令行参数解析中添加 -I/--include 选项支持,允许用户指定
额外的头文件搜索路径。同时移除不必要的 stdio.h 引用并清理
一些调试相关的缓冲区设置。
This commit is contained in:
zzy
2026-02-19 19:30:00 +08:00
parent a52ff33e30
commit bc0b1d23e3
5 changed files with 62 additions and 14 deletions

View File

@@ -7,8 +7,6 @@
// #include <ir_dump.h>
// #include <scc_ast2ir.h>
#include <stdio.h>
typedef struct {
const char *input_file;
const char *output_file;
@@ -26,6 +24,7 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
SCC_HINT_DESCRIPTION,
SCC_HINT_OUTPUT_FILE,
SCC_HINT_INPUT_FILE,
SCC_HINT_INCLUDE_PATH,
SCC_HINT_VERBOSE,
SCC_HINT_EMIT_LEX,
@@ -38,6 +37,7 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
[SCC_HINT_DESCRIPTION] = "A simple C compiler",
[SCC_HINT_OUTPUT_FILE] = "Output file",
[SCC_HINT_INPUT_FILE] = "Input source file",
[SCC_HINT_INCLUDE_PATH] = "SCC_HINT_INCLUDE_PATH",
[SCC_HINT_VERBOSE] = "Increase verbosity (can be used multiple times)",
[SCC_HINT_EMIT_LEX] = "Generate lexer sources tokens and exit",
[SCC_HINT_EMIT_PP] = "Generate preprocessed tokens and exit",
@@ -49,6 +49,7 @@ static void setup_argparse(scc_argparse_t *argparse, scc_config_t *config,
[SCC_HINT_DESCRIPTION] = "一个简单的C编译器",
[SCC_HINT_OUTPUT_FILE] = "输出文件",
[SCC_HINT_INPUT_FILE] = "输入源文件",
[SCC_HINT_INCLUDE_PATH] = "SCC_HINT_INCLUDE_PATH",
[SCC_HINT_VERBOSE] = "增加详细输出(可多次使用)",
[SCC_HINT_EMIT_LEX] = "生成`源代码的词法单元`并退出",
[SCC_HINT_EMIT_PP] = "生成`预处理后的词法单元`并退出",
@@ -88,6 +89,10 @@ 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);
scc_argparse_opt_t opt_include;
scc_argparse_opt_init(&opt_include, 0, "include",
scc_hints[SCC_HINT_INCLUDE_PATH]);
// -v, --verbose (计数)
scc_argparse_opt_t opt_verbose;
scc_argparse_opt_init(&opt_verbose, 'V', "verbose",
@@ -175,7 +180,6 @@ int main(int argc, const char **argv, const char **envp) {
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
#endif
setbuf(stdout, NULL);
#ifdef _WIN32
#define OUTPUT_DEFAULT_FILE "a.exe"