From 13de9d713b721ea44c4f06edcab67f1272331f26 Mon Sep 17 00:00:00 2001 From: zzy <2450266535@qq.com> Date: Thu, 26 Feb 2026 10:52:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(pproc):=20=E4=BF=AE=E5=A4=8D=E9=A2=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=99=A8=E5=AF=B9=E7=A9=BA=E8=A1=8C=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了错误的ENDLINE类型提前返回逻辑 - 将ENDLINE类型的处理移到正确的位置 - 添加了针对条件编译中空行的测试用例 fix(cli): 更新include路径参数的帮助文本 - 修正英文帮助文本为"Add directory to the include search paths" - 修正中文帮助文本为"添加系统头文件到搜索路径" --- libs/pproc/src/scc_pproc.c | 11 +++++------ libs/pproc/tests/test_unit.c | 18 ++++++++++++++++++ src/main.c | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/libs/pproc/src/scc_pproc.c b/libs/pproc/src/scc_pproc.c index ac2a06c..70968f1 100644 --- a/libs/pproc/src/scc_pproc.c +++ b/libs/pproc/src/scc_pproc.c @@ -20,11 +20,6 @@ CONTINUE: if (ok == false) { return false; } - if (tok.type == SCC_TOK_ENDLINE) { - scc_ring_next_consume(*stream, *out, ok); - pp->at_line_start = true; - return true; - } if (pp->at_line_start) { if (tok.type == SCC_TOK_SHARP) { @@ -51,7 +46,11 @@ CONTINUE: goto CONTINUE; } - if (tok.type == SCC_TOK_IDENT) { + if (tok.type == SCC_TOK_ENDLINE) { + scc_ring_next_consume(*stream, *out, ok); + pp->at_line_start = true; + return true; + } else if (tok.type == SCC_TOK_IDENT) { // maybe expanded scc_pproc_macro_t *macro = scc_pproc_macro_table_get(&pp->macro_table, &tok.lexeme); diff --git a/libs/pproc/tests/test_unit.c b/libs/pproc/tests/test_unit.c index f38e978..9b65430 100644 --- a/libs/pproc/tests/test_unit.c +++ b/libs/pproc/tests/test_unit.c @@ -273,6 +273,24 @@ static void test_conditional_ifdef(void) { "#endif\n", "foo\n"); + CHECK_PP_OUTPUT_EXACT("#ifdef FOO\n" + "\n" + "#endif\n", + ""); + + CHECK_PP_OUTPUT_EXACT("#ifdef FOO\n" + "#endif\n", + ""); + + CHECK_PP_OUTPUT_EXACT("#ifndef FOO\n" + "\n" + "#endif\n", + "\n"); + + CHECK_PP_OUTPUT_EXACT("#ifndef FOO\n" + "#endif\n", + ""); + // ifdef + else CHECK_PP_OUTPUT_EXACT("#define FOO\n" "#ifdef FOO\n" diff --git a/src/main.c b/src/main.c index 1193a73..6994624 100644 --- a/src/main.c +++ b/src/main.c @@ -38,7 +38,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_INCLUDE_PATH] = "Add directory to the include search paths", [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", @@ -50,7 +50,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_INCLUDE_PATH] = "添加系统头文件到搜索路径", [SCC_HINT_VERBOSE] = "增加详细输出(可多次使用)", [SCC_HINT_EMIT_LEX] = "生成`源代码的词法单元`并退出", [SCC_HINT_EMIT_PP] = "生成`预处理后的词法单元`并退出",