修正了一些错误

This commit is contained in:
2026-07-26 20:32:26 +08:00
parent ca7c2120b8
commit 1837339f69
203 changed files with 374300 additions and 2638 deletions

View File

@@ -218,18 +218,18 @@ class Phase2Translator:
if sha1 not in self.stub_files:
self.stub_files[sha1] = os.path.join(_GLOBAL_CACHE_DIR, fname)
sha1_file_path = os.path.join(self.temp_dir, '_sha1_map.txt')
if os.path.exists(sha1_file_path):
with open(sha1_file_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if ':' in line:
sha1, rel = line.split(':', 1)
self.sha1_map[sha1] = rel
if rel.startswith('includes/'):
module_name = os.path.splitext(os.path.basename(rel))[0]
self.include_py_map[module_name] = sha1
# 从内存存储器读取 SHA1 映射_sha1_map.txt 仅人类可读,不再作为机器数据源)
# 延迟导入避免循环依赖Config 导入 Phase2Translator
from lib.Projectrans.Config import get_sha1_map_store
mem_store: dict[str, str] = get_sha1_map_store()
if mem_store:
for sha1, rel in mem_store.items():
self.sha1_map[sha1] = rel
if rel.startswith('includes/'):
module_name = os.path.splitext(os.path.basename(rel))[0]
self.include_py_map[module_name] = sha1
else:
# 内存存储器为空(独立运行 Phase2 的回退):从 stub 文件名推断
for sha1, stub_path in self.stub_files.items():
self.sha1_map[sha1] = sha1
@@ -2534,7 +2534,7 @@ class Phase2Translator:
# 注册到 sig_files 和 _source_module_sig_files
if os.path.isfile(sig_path):
self.sig_files[sha1] = sig_path
self.sha1_map[sha1] = f"includes/{mod_full.replace('.', os.sep)}.py"
self.sha1_map[sha1] = f"includes/{mod_full.replace('.', '/')}.py"
if self._shared_source_module_sig_files is not None:
self._shared_source_module_sig_files[mod_full] = sig_path
self._shared_source_module_sig_files[module_name] = sig_path
@@ -2759,15 +2759,18 @@ class Phase2Translator:
py_path = os.path.join(abs_includes, py_file)
try:
# 复用 parse_python_file 的 AST 缓存
_, py_tree = parse_python_file(py_path)
py_content, py_tree = parse_python_file(py_path)
if py_tree is None:
continue
# 计算 include 文件的 SHA1供特化时统一命名空间
py_sha1: str = compute_sha1(py_content)
for node in py_tree.body:
if isinstance(node, ast.ClassDef) and hasattr(node, 'type_params') and node.type_params:
type_params = [tp.name for tp in node.type_params]
generic_class_templates[node.name] = {
'node': node,
'type_params': type_params,
'sha1': py_sha1,
}
except Exception as _e:
if _config_mode == "strict":
@@ -2817,9 +2820,9 @@ class Phase2Translator:
scan_dirs = []
if self.src_root and os.path.isdir(self.src_root):
scan_dirs.append(self.src_root)
project_dir = os.path.dirname(self.output_dir)
if project_dir and os.path.isdir(project_dir) and project_dir not in scan_dirs:
scan_dirs.append(project_dir)
# 不再扫描 output_dir 的父目录:当 output_dir 位于顶层时,
# 父目录是整个仓库根,会误扫到 ViperOS/includes/vqt6 等无关 C/C++ 源文件。
# 项目特定的 C/汇编文件应放在 src_root 下,或通过 extra_compile_files 指定。
for scan_dir in scan_dirs:
for root, dirs, files in os.walk(scan_dir):
dirs[:] = [d for d in dirs if not d.startswith('.') and d != '__pycache__']