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