fix(tpv): 裸名 typedef 强转改 resolve_typedef_or_map 统一口径(BYTEPTR 等)

- 阶段2 删除 map_t_type 的 stdint 别名后,BYTEPTR(x) 裸名 typedef 强转
  判定 map_t_type 返回 None → 误走外部函数路径 fail-fast
  (string.vp L104 TypeError 根因)
- 裸名 typedef call(BYTEPTR/HANDLE/size_t 等)改经 resolve_typedef_or_map:
  CTypedef 动态表优先 + t/c 核心 map_t_type 兜底,所有 CTypedef/t 库类型
  call 恢复强转语义
This commit is contained in:
TermiNexus committed 2026-08-29 06:22:30 +08:00
1 parent fa90586a83
commit 8a69719acf
1 file changed
+13 -4
+13 -4
View File
@@ -457,10 +457,11 @@ class CallGenDispatch(CallGenBase.CallGenBase):
# 裸名 typedef 调用: BYTEPTR(ptr1), HANDLE(val), CHARPTR(str) 等
# 用户通过 `from stdint import *` 导入 typedef 后,可直接用裸名做类型转换
# map_t_type 包含所有内置 typedef 名称(BYTEPTR/HANDLE/LPCSTR/size_t 等)
# 统一口径:所有 CTypedef 名与 t/c 库原始类型的 call 都具备强转功能
# (BYTEPTR/HANDLE/size_t 等库 typedef + CInt/CBool 等 t/c 核心原语)。
# 泛型类型参数转换: 泛型上下文(类特化/泛型函数)中 T(x) → 先解析 T 为具体
# 类型名(如 "int")再走 map_t_type(Box[int].__init__ 的 self.value = T(v)、
# combine[T1,T2] 的 T1(b) 依赖此路径)
# 类型名(如 "int")再走 resolve_typedef_or_map(Box[int].__init__ 的
# self.value = T(v)、combine[T1,T2] 的 T1(b) 依赖此路径)
if cl.func is not None and cl.func.kind() == ast.ASTKind.Name:
bare_fn_name: str = self.Gen.TypeGenBase.resolve_generic_type_name(func_name)
bare_ty: llvmlite.LLVMType | t.CPtr = None
@@ -471,7 +472,15 @@ class CallGenDispatch(CallGenBase.CallGenBase):
elif string.strcmp(bare_fn_name, "float") == 0:
bare_ty = llvmlite.Float(pool)
else:
bare_ty = self.Gen.TypeGenResolve.map_t_type(pool, bare_fn_name)
# 统一口径:CTypedef 动态表优先(BYTEPTR 等库 typedef 强转),
# miss 回退 map_t_type(t/c 核心原语强转,阶段2 收敛后 map_t_type
# 不再含 stdint 别名,故必须走动态表)。
bare_imp_c: str = None
bare_fi_c: str = None
if trans is not None:
bare_imp_c = trans._imported_modules
bare_fi_c = trans._from_imports
bare_ty = self.Gen.TypeGenResolve.resolve_typedef_or_map(pool, bare_fn_name, bare_imp_c, bare_fi_c)
# 泛型上下文替换出的类型名(如 T→"t.CInt")map_t_type 不识别(只认无前缀名),
# 回退用 resolve_annotation_type 解析(支持 t.CXxx / 结构体类名 / 别名等)。
# GenericTest4 Box[t.CInt].__init__ 的 self.value = T(v) 依赖此路径。