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:
@@ -17,7 +17,7 @@ static cbool process_input(const char *input, scc_cstring_t *output) {
|
||||
scc_pproc_init(&pp, scc_lexer_to_ring(&lexer, 8, true));
|
||||
|
||||
scc_lexer_tok_ring_t *tok_ring = scc_pproc_to_ring(&pp, 8);
|
||||
*output = scc_cstring_create();
|
||||
*output = scc_cstring_from_cstr("");
|
||||
scc_lexer_tok_t tok;
|
||||
while (1) {
|
||||
scc_ring_next_consume(*tok_ring, tok, ret);
|
||||
@@ -31,7 +31,6 @@ static cbool process_input(const char *input, scc_cstring_t *output) {
|
||||
scc_pproc_drop(&pp);
|
||||
scc_lexer_drop(&lexer);
|
||||
scc_sstream_drop(&mem_stream);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -127,6 +126,12 @@ static void test_define_nested_macros(void) {
|
||||
CHECK_PP_OUTPUT_EXACT(
|
||||
"#define A 1\n#define B (A + 1)\n#define C (B + 1)\nC\n",
|
||||
"((1 + 1) + 1)\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#define A\n", "");
|
||||
CHECK_PP_OUTPUT_EXACT("#undef A\n", "");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT(" # define A 1\nA", "1");
|
||||
// CHECK_PP_OUTPUT_EXACT(" # define A 1 \nA", "1"); // TODO
|
||||
}
|
||||
|
||||
static void test_undef_macros(void) {
|
||||
@@ -225,6 +230,126 @@ static void test_edge_cases(void) {
|
||||
CHECK_PP_OUTPUT_EXACT("#define A B\n#define B C\n#define C 1\nA\n", "1\n");
|
||||
}
|
||||
|
||||
static void test_conditional_ifdef(void) {
|
||||
TEST_CASE("ifdef and ifndef");
|
||||
|
||||
// 基本 ifdef / ifndef
|
||||
CHECK_PP_OUTPUT_EXACT("#define FOO\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#endif\n",
|
||||
"foo\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#define FOO\n"
|
||||
"#ifndef FOO\n"
|
||||
"foo\n"
|
||||
"#endif\n",
|
||||
"");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#undef FOO\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#endif\n",
|
||||
"");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#undef FOO\n"
|
||||
"#ifndef FOO\n"
|
||||
"foo\n"
|
||||
"#endif\n",
|
||||
"foo\n");
|
||||
|
||||
// ifdef + else
|
||||
CHECK_PP_OUTPUT_EXACT("#define FOO\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#else\n"
|
||||
"bar\n"
|
||||
"#endif\n",
|
||||
"foo\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#undef FOO\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#else\n"
|
||||
"bar\n"
|
||||
"#endif\n",
|
||||
"bar\n");
|
||||
|
||||
// ifdef + elifdef (C23)
|
||||
CHECK_PP_OUTPUT_EXACT("#define FOO\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#elifdef FOO\n"
|
||||
"foo2\n"
|
||||
"#endif\n",
|
||||
"foo\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#undef FOO\n"
|
||||
"#define BAR\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#elifdef BAR\n"
|
||||
"bar\n"
|
||||
"#else\n"
|
||||
"none\n"
|
||||
"#endif\n",
|
||||
"bar\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#undef FOO\n"
|
||||
"#undef BAR\n"
|
||||
"#ifdef FOO\n"
|
||||
"foo\n"
|
||||
"#elifdef BAR\n"
|
||||
"bar\n"
|
||||
"#else\n"
|
||||
"none\n"
|
||||
"#endif\n",
|
||||
"none\n");
|
||||
|
||||
// 嵌套
|
||||
CHECK_PP_OUTPUT_EXACT("#define A\n"
|
||||
"#ifdef A\n"
|
||||
" #ifdef B\n"
|
||||
" inner\n"
|
||||
" #endif\n"
|
||||
" outer\n"
|
||||
"#endif\n",
|
||||
" outer\n");
|
||||
|
||||
CHECK_PP_OUTPUT_EXACT("#define B\n"
|
||||
"#ifndef A\n"
|
||||
" #ifdef B\n"
|
||||
" inner\n"
|
||||
" #endif\n"
|
||||
" outer\n"
|
||||
"#endif\n",
|
||||
" inner\n outer\n");
|
||||
|
||||
// 外层假,内层真
|
||||
CHECK_PP_OUTPUT_EXACT("#ifdef __NONE\n"
|
||||
"#define OUTER\n"
|
||||
"#endif\n"
|
||||
"#ifdef OUTER\n"
|
||||
"should not appear\n"
|
||||
"#endif\n",
|
||||
""); // 期望为空
|
||||
|
||||
// 更复杂的嵌套条件
|
||||
CHECK_PP_OUTPUT_EXACT("#define X\n"
|
||||
"#ifdef X\n"
|
||||
"x defined\n"
|
||||
"#ifdef Y\n"
|
||||
"Y defined\n"
|
||||
"#else\n"
|
||||
"Y not defined\n"
|
||||
"#endif\n"
|
||||
"after inner\n"
|
||||
"#else\n"
|
||||
"X not defined\n"
|
||||
"#endif\n",
|
||||
"x defined\nY not defined\nafter inner\n");
|
||||
}
|
||||
|
||||
#define TEST_LIST_CASE(func_name) {#func_name, func_name}
|
||||
TEST_LIST = {
|
||||
TEST_LIST_CASE(test_define_simple_no_macro),
|
||||
@@ -237,5 +362,6 @@ TEST_LIST = {
|
||||
TEST_LIST_CASE(test_define_nested_macros),
|
||||
TEST_LIST_CASE(test_undef_macros),
|
||||
TEST_LIST_CASE(hard_test_define_func_macros),
|
||||
TEST_LIST_CASE(test_conditional_ifdef),
|
||||
{NULL, NULL},
|
||||
};
|
||||
Reference in New Issue
Block a user