尝试进行 Qt 测试,增加了 AI 人机调试工具 _console,以及 TransPyV 进行修正

This commit is contained in:
2026-07-21 14:41:22 +08:00
parent a277ded8d4
commit 135aa05485
311 changed files with 7084 additions and 2131 deletions

View File

@@ -254,7 +254,7 @@ class DeclarationGenerator:
"""解析基类名称的类型种类(支持别名)
Returns:
'enum' | 'union' | 'renum' | 'struct' | None
'enum' | 'union' | 'renum' | 'struct' | 'ctype_marker' | None
"""
# 1) 查 t 别名映射from t import CEnum as en
if base_name in self._t_alias_map:
@@ -265,6 +265,10 @@ class DeclarationGenerator:
return 'union'
if issubclass(t_cls, t.CStruct):
return 'struct'
# CType 及其子类CChar/CInt/CVoid/CPtr 等)是"类型强转"标记,
# 不应被编译为真实结构体,也不应被生成 stub 声明。
if issubclass(t_cls, t.CType):
return 'ctype_marker'
# 2) 直接查 t 模块属性
t_cls: type | None = getattr(t, base_name, None)
@@ -275,6 +279,8 @@ class DeclarationGenerator:
return 'union'
if issubclass(t_cls, t.CStruct):
return 'struct'
# CType 及其子类是"类型强转"标记,不编译为结构体。
return 'ctype_marker'
return None
@@ -313,6 +319,10 @@ class DeclarationGenerator:
is_union = True
elif kind == 'renum':
is_renum = True
elif kind == 'ctype_marker':
# CType 及其子类CChar/CInt/CVoid/CPtr/CTypeDefault 等)是
# "类型强转"标记,不应被编译为真实结构体,也不生成 stub 声明。
return decls
if is_exception:
return decls
if is_enum:

View File

@@ -10,6 +10,7 @@ from lib.Projectrans.Utils import compute_sha1, get_file_dependencies, find_reac
from lib.Projectrans.DeclarationGenerator import DeclarationGenerator
from lib.core.VLogger import get_logger as _vlog
from lib.constants.config import mode as _ConfigMode
from lib.includes import t
from StubGen import PythonToStubConverter
# 全局缓存目录(不被 --clean 清除),用于缓存库文件的 .pyi / .stub.ll / .doc.json
@@ -509,6 +510,15 @@ class Phase1Generator:
exception_names: set[str] = set()
struct_sha1_map: dict[str, str] = {}
class_def_map: dict[str, ast.ClassDef] = {}
# 预先收集所有 CType 子类名称(来自 t 模块和别名映射),
# 用于在 struct 注册表中跳过"类型强转"标记类。
ctype_marker_names: set[str] = set()
for attr_name in dir(t):
t_cls: type | None = getattr(t, attr_name, None)
if isinstance(t_cls, type) and issubclass(t_cls, t.CType) and t_cls is not t.CType:
if not issubclass(t_cls, (t.CEnum, t.REnum, t.CUnion, t.CStruct)):
ctype_marker_names.add(t_cls.__name__)
ctype_marker_names.add(attr_name)
valid_sha1_keys: set[str] = set(self.sha1_map.keys())
for fname in os.listdir(self.temp_dir):
if not fname.endswith('.pyi'):
@@ -526,6 +536,7 @@ class Phase1Generator:
is_enum: bool = False
is_renum: bool = False
is_exception: bool = False
is_ctype_marker: bool = False
if node.bases:
for base in node.bases:
if isinstance(base, ast.Attribute) and hasattr(base, 'attr'):
@@ -538,6 +549,9 @@ class Phase1Generator:
elif base.attr == 'Exception' or base.attr in exception_names:
is_exception = True
break
elif base.attr in ctype_marker_names:
is_ctype_marker = True
break
elif isinstance(base, ast.Name) and hasattr(base, 'id'):
if base.id == 'REnum':
is_renum = True
@@ -548,8 +562,11 @@ class Phase1Generator:
elif base.id == 'Exception' or base.id in exception_names:
is_exception = True
break
elif base.id in ctype_marker_names:
is_ctype_marker = True
break
# 也检查装饰器形式 @t.CEnum / @t.REnum
if not is_enum and not is_renum and not is_exception and hasattr(node, 'decorator_list') and node.decorator_list:
if not is_enum and not is_renum and not is_exception and not is_ctype_marker and hasattr(node, 'decorator_list') and node.decorator_list:
for deco in node.decorator_list:
deco_attr: str | None = None
if isinstance(deco, ast.Attribute) and hasattr(deco, 'attr'):
@@ -562,6 +579,10 @@ class Phase1Generator:
elif deco_attr in ('CEnum', 'Enum'):
is_enum = True
break
# CType 及其子类是"类型强转"标记,不加入 struct_names / enum_names / exception_names
# 也不加入 class_def_map避免下游误将其作为结构体处理
if is_ctype_marker:
continue
# REnum 是结构体类型(带 __tag + payload需加入 struct_names 以便
# DeclarationGenerator._get_type_str 返回 %Name* 而非 i32
if is_renum: