重置上传,新增了多个标准库,开始 TransPyV 自举实验
This commit is contained in:
@@ -537,12 +537,32 @@ class ClassHandle(BaseHandle):
|
||||
Gen.class_members[ClassName] = inherited + Gen.class_members[ClassName]
|
||||
if ParentClass in Gen.class_methods:
|
||||
parent_methods: list = list(Gen.class_methods[ParentClass])
|
||||
# 构建子类已有方法映射(方法短名 -> 方法全名)
|
||||
child_method_map: dict[str, str] = {}
|
||||
for m in Gen.class_methods[ClassName]:
|
||||
method_name: str = m.split('.')[-1] if '.' in m else m
|
||||
child_method_map[method_name] = m
|
||||
# 父类方法在前(保证 vtable 布局一致性,子类多态分派索引正确),
|
||||
# 子类新增方法在后。子类覆盖的方法放在父类方法的位置(用子类实现)。
|
||||
new_methods: list = []
|
||||
covered_names: set[str] = set()
|
||||
for pm in parent_methods:
|
||||
method_name: str = pm.split('.')[-1] if '.' in pm else pm
|
||||
child_method: str = f"{ClassName}.{method_name}"
|
||||
if child_method not in Gen.class_methods[ClassName]:
|
||||
Gen.class_methods[ClassName].append(child_method)
|
||||
if method_name in child_method_map:
|
||||
# 子类覆盖了父类方法 — 用子类的实现,放在父类的位置
|
||||
new_methods.append(child_method_map[method_name])
|
||||
covered_names.add(method_name)
|
||||
else:
|
||||
# 父类独有方法 — 子类未覆盖,注册子类包装器
|
||||
child_method: str = f"{ClassName}.{method_name}"
|
||||
new_methods.append(child_method)
|
||||
Gen.register_method(ClassName, child_method)
|
||||
# 添加子类新增方法(不在父类中的)
|
||||
for m in Gen.class_methods[ClassName]:
|
||||
method_name: str = m.split('.')[-1] if '.' in m else m
|
||||
if method_name not in covered_names:
|
||||
new_methods.append(m)
|
||||
Gen.class_methods[ClassName] = new_methods
|
||||
# 提取首个裸字符串字面量作为结构体 __doc__ docstring
|
||||
if (Node.body and isinstance(Node.body[0], ast.Expr)
|
||||
and isinstance(Node.body[0].value, ast.Constant)
|
||||
@@ -666,7 +686,19 @@ class ClassHandle(BaseHandle):
|
||||
例如 Label 继承 Widget.place,生成 Label.place 函数,
|
||||
内部将 self 从 Label* bitcast 为 Widget*,然后调用 Widget.place。
|
||||
"""
|
||||
methods: list = Gen.class_methods.get(ClassName, [])
|
||||
# 收集本类方法 + 沿继承链收集父类方法名
|
||||
# 原代码只遍历 class_methods[ClassName],遗漏父类独有方法(如 __enter__),
|
||||
# 导致子类调用继承的方法时链接失败(undefined reference)
|
||||
methods: list = list(Gen.class_methods.get(ClassName, []))
|
||||
p: str | None = Gen.class_parent.get(ClassName) if hasattr(Gen, 'class_parent') else None
|
||||
while p:
|
||||
parent_methods: list = Gen.class_methods.get(p, [])
|
||||
for pm in parent_methods:
|
||||
pm_short: str = pm.split('.')[-1] if '.' in pm else pm
|
||||
# 避免重复:如果子类已覆写同名方法,不添加
|
||||
if not any(m.split('.')[-1] == pm_short for m in methods):
|
||||
methods.append(pm)
|
||||
p = Gen.class_parent.get(p)
|
||||
if not methods:
|
||||
return
|
||||
if ClassName not in Gen.structs:
|
||||
|
||||
Reference in New Issue
Block a user