fix(cdef): 跨模块 CDefine 匹配放宽到 t.C 类型注解

原行匹配只认 "t.CDefine"(9 字符精确),漏掉 t.CSizeT/t.CInt 等注解的
模块级常量全局(如 Phase1.PYI_BUF_SIZE: t.CSizeT = 262144,是 i64 全局
常量而非 CDefine)→ "跨模块 CDefine 未找到" 误报。本函数仅被 ALL_CAPS
名触发,放宽为 t.C<大写> 类型 + 字面量初值即视为编译期常量;模块限定
(Phase1.PYI_BUF_SIZE)与 from-import 裸名(from Phase1 import PYI_BUF_SIZE)
两条路径均经本函数,一并覆盖。
This commit is contained in:
TermiNexus committed 2026-08-19 05:35:02 +08:00
1 parent cf9207f171
commit 677373c629
1 file changed
+8 -7
+8 -7
View File
@@ -441,16 +441,17 @@ class ExprGenCdef(ExprGenBase.ExprGenBase):
if pyi_buf[line_start + name_len] != ':':
continue
# 检查行是否包含 "t.CDefine"
# 在行中查找 "t.CDefine"
# 检查行是否包含 t.C 类型注解(CDefine 或 t.CSizeT/t.CInt 等常量类型)
# 原实现只认 "t.CDefine"(9 字符精确匹配),漏掉 t.CSizeT 等注解的
# 模块级常量全局(如 Phase1.PYI_BUF_SIZE: t.CSizeT = 262144,是 i64
# 全局常量而非 CDefine)→ "跨模块 CDefine 未找到" 误报。本函数仅被
# ALL_CAPS 名触发,t.C<大写> 类型 + 字面量初值即视为编译期常量。
has_cdefine: int = 0
ci: t.CSizeT = line_start + name_len + 1
while ci + 8 <= line_start + line_len:
while ci + 2 <= line_start + line_len:
if (pyi_buf[ci] == 't' and pyi_buf[ci + 1] == '.' and
pyi_buf[ci + 2] == 'C' and pyi_buf[ci + 3] == 'D' and
pyi_buf[ci + 4] == 'e' and pyi_buf[ci + 5] == 'f' and
pyi_buf[ci + 6] == 'i' and pyi_buf[ci + 7] == 'n' and
pyi_buf[ci + 8] == 'e'):
pyi_buf[ci + 2] == 'C' and ci + 3 < line_start + line_len
and pyi_buf[ci + 3] >= 'A' and pyi_buf[ci + 3] <= 'Z'):
has_cdefine = 1
break
ci += 1