From 8a69719acf7a6405caf2bdab4d93d4c2b374be55 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sat, 29 Aug 2026 06:22:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(tpv):=20=E8=A3=B8=E5=90=8D=20typedef=20?= =?UTF-8?q?=E5=BC=BA=E8=BD=AC=E6=94=B9=20resolve=5Ftypedef=5For=5Fmap=20?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=8F=A3=E5=BE=84=EF=BC=88BYTEPTR=20?= =?UTF-8?q?=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 阶段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 恢复强转语义 --- App/lib/core/Gen/Call/CallGenDispatch.vp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/App/lib/core/Gen/Call/CallGenDispatch.vp b/App/lib/core/Gen/Call/CallGenDispatch.vp index dbb171e..d9ec939 100644 --- a/App/lib/core/Gen/Call/CallGenDispatch.vp +++ b/App/lib/core/Gen/Call/CallGenDispatch.vp @@ -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) 依赖此路径。