From a8718aa75104fae57119ae4ef3356b6cfd7ca710 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Sun, 18 Oct 2026 14:00:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(type):=20t/c=20=E6=A8=A1=E5=9D=97=E5=89=8D?= =?UTF-8?q?=E7=BC=80=E6=8A=A5=E9=94=99=E8=A1=A5=E5=85=A8=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E3=80=81=E8=A1=8C=E5=88=97=E4=B8=8E=E6=9B=BF=E4=BB=A3=E5=86=99?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SymbolExtractor 在提取符号前记录 CurrentFile;类型注解拒绝 t./c. 时输出 文件:行:列、完整写法与改写建议。 --- lib/core/SymbolExtractor.py | 1 + lib/core/TypeAnnotationResolver.py | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/core/SymbolExtractor.py b/lib/core/SymbolExtractor.py index c61a146..bfd7a8d 100644 --- a/lib/core/SymbolExtractor.py +++ b/lib/core/SymbolExtractor.py @@ -23,6 +23,7 @@ class ASTSymbolExtractor: def extract(self, file_path: str) -> ModuleSymbols: """提取文件中的所有符号信息""" + setattr(self._symtab, 'CurrentFile', file_path) with open(file_path, 'r', encoding='utf-8') as f: code: str = f.read() tree: ast.Module = ast.parse(code, file_path) diff --git a/lib/core/TypeAnnotationResolver.py b/lib/core/TypeAnnotationResolver.py index 959d46d..c0abfe0 100644 --- a/lib/core/TypeAnnotationResolver.py +++ b/lib/core/TypeAnnotationResolver.py @@ -963,9 +963,14 @@ class TypeAnnotationResolver: return CTypeInfo() if isinstance(Current, ast.Name) and Current.id in ("t", "c"): + FullName: str = f'{Current.id}.{TypeName}' + Line: int = getattr(Node, 'lineno', 0) or 0 + Col: int = (getattr(Node, 'col_offset', 0) or 0) + 1 + File: str = getattr(SymbolTable, 'CurrentFile', '') or '' + Where: str = f'{File}:{Line}:{Col}' if File else f'第 {Line} 行第 {Col} 列' raise TypeError( - f"[TPC] 类型注解不再接受 \"{Current.id}.\" 模块前缀;" - f"请直接写内建类型名(如 CPtr、CInt、CArray)。") + f"[TPC] 类型注解不支持模块前缀 \"{FullName}\"({Where})。" + f"请改写为 \"{TypeName}\";指针写 CPtr[T] / rawptr[T]。") # 解析 import 别名: 如 import vpsdk.window as window -> window -> vpsdk.window if ModulePath: resolved: bool = False