feat(pproc): 添加宏定义禁用机制和defined操作符解析功能

添加SCC_TOK_DISABLED标记类型用于表示被禁用的token
实现disable/enable/need_skip函数来管理宏展开过程中的递归控制
重构defined操作符解析逻辑到独立的parse_defined函数中
移除原有的need_rescan标志和相关重扫描逻辑

fix(sstream): 修复位置日志中行列号格式化问题

将snprintf格式字符串中的%u替换为%llu以支持更大的行列数值

test(pproc): 补充宏定义相关的单元测试用例

添加嵌套宏、自引用宏和无参数宏的测试用例
This commit is contained in:
zzy
2026-03-01 12:16:23 +08:00
parent 0fede5f46e
commit 8cbb9e6987
4 changed files with 100 additions and 70 deletions

View File

@@ -151,8 +151,12 @@ static void test_define_nested_macros(void) {
// CHECK_PP_OUTPUT_EXACT("#define str(x) # x\n"
// "str()\n",
// "\"\"\n");
CHECK_PP_OUTPUT_EXACT("#define w 0,1\n"
"#define m(a) a(w)\n"
"m(f)\n",
"f(0,1)\n");
TEST_CASE("TODO");
TEST_CASE("self-reference");
CHECK_PP_OUTPUT_EXACT("#define x 1\n"
"#define f(a) f(x * (a))\n"
"f(0)\n"
@@ -167,6 +171,11 @@ static void test_define_nested_macros(void) {
"f(x(0) * (f(x(0) * (0))))\n"
"f(x(0) * (f(x(0) * (x(0)))))\n"
"f(x(0) * (f(x(0) * (a))))\n");
TEST_CASE("NO NAME");
CHECK_PP_OUTPUT_EXACT("#define f() int\n"
"f()\n",
"int\n");
}
static void test_undef_macros(void) {
@@ -538,9 +547,10 @@ static void test_c99_docs(void) {
"#define str(x) # x\n"
"f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);\n"
"g(x+(3,4)-w) | h 5) & m\n"
" (f)^m(m);\n"
" (f)^m(m);\n"
"p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };\n"
"char c[2][6] = { str(hello), str() };\n",
"f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);\n"
"f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);\n"
"int i[] = { 1, 23, 4, 5, };\n"