refactor(tpc): 退役 t/c 模块并将定宽类型升级为内建
删除 lib/includes/t.py、c.py,类型模型迁入 lib/core/TypeSystem.py;移除 IsTModule/_T_MODULE_NAMES 等名称判据,语法糖与内部标记统一为裸名;builtins 的 sizet/intN/uintN/fast/least/uchar/short/long 等改为编译器内建短名。
This commit is contained in:
1 parent
8d27747c7c
commit
f19d25782f
66 files changed
+2445
-3638
No files matched your search
@@ -6,12 +6,12 @@ import importlib
|
||||
import types
|
||||
from typing import Any
|
||||
|
||||
import lib._bootstrap # noqa: F401 设置 sys.path(项目根 + lib/includes)
|
||||
import lib._bootstrap # noqa: F401 设置 sys.path(项目根 + lib)
|
||||
|
||||
from lib.core.Handles.HandlesBase import CTypeInfo
|
||||
from lib.core.SymbolUtils import IsTModule, AnnotationContainsName, ExpandSoftKeywords
|
||||
from lib.includes import t
|
||||
from lib.includes.t import CType, CEnum
|
||||
from lib.core.SymbolUtils import AnnotationContainsName, ExpandSoftKeywords
|
||||
from lib.core import TypeSystem
|
||||
from lib.core.TypeSystem import CType, CEnum
|
||||
from lib.constants.config import mode as _config_mode
|
||||
from lib.core.VLogger import get_logger as _vlog
|
||||
|
||||
@@ -47,7 +47,7 @@ class AnnotationLoaderMixin:
|
||||
# 注册枚举类型
|
||||
EnumNode: CTypeInfo = CTypeInfo()
|
||||
EnumNode.Name = AttrName
|
||||
EnumNode.BaseType = t.CEnum()
|
||||
EnumNode.BaseType = TypeSystem.CEnum()
|
||||
EnumNode.IsEnum = True
|
||||
EnumNode.set('enum_class', attr)
|
||||
EnumNode.set('source', 'annotation_module')
|
||||
@@ -71,7 +71,7 @@ class AnnotationLoaderMixin:
|
||||
if isinstance(member, int):
|
||||
MemberNode: CTypeInfo = CTypeInfo()
|
||||
MemberNode.Name = MemberName
|
||||
MemberNode.BaseType = t.CEnum(AttrName)
|
||||
MemberNode.BaseType = TypeSystem.CEnum(AttrName)
|
||||
MemberNode.value = member
|
||||
MemberNode.EnumName = AttrName
|
||||
MemberNode.library_name = lib_name
|
||||
@@ -230,10 +230,10 @@ class AnnotationLoaderMixin:
|
||||
self.SymbolTable.insert(FullName, TypeInfo)
|
||||
count += 1
|
||||
|
||||
# 再次遍历 AST,查找注解文件中的 typedef 语句(AnnAssign with t.CTypedef)
|
||||
# 再次遍历 AST,查找注解文件中的 typedef 语句(AnnAssign with CTypedef)
|
||||
# 注意:必须在类定义处理完之后再处理 typedef
|
||||
typedef_annots: list[tuple[str, str]] = []
|
||||
# 查找 CEnum 成员变量(AnnAssign with t.CEnum | t.State 或 t.CEnum)
|
||||
# 查找 CEnum 成员变量(AnnAssign with CEnum | State 或 CEnum)
|
||||
cEnumMembers: list[tuple[str, int | None]] = []
|
||||
try:
|
||||
with open(ModuleName, 'r', encoding='utf-8') as f:
|
||||
@@ -241,7 +241,7 @@ class AnnotationLoaderMixin:
|
||||
ann_content = ExpandSoftKeywords(ann_content)
|
||||
ann_tree: ast.Module = ast.parse(ann_content, ModuleName)
|
||||
for node in ann_tree.body:
|
||||
# 检测 xxx: t.CEnum 形式的枚举成员变量
|
||||
# 检测 xxx: CEnum 形式的枚举成员变量
|
||||
if isinstance(node, ast.AnnAssign):
|
||||
if isinstance(node.target, ast.Name) and node.annotation:
|
||||
TargetName: str = node.target.id
|
||||
@@ -252,8 +252,8 @@ class AnnotationLoaderMixin:
|
||||
if AnnotationContainsName(node.annotation, 'CEnum'):
|
||||
IsCenum = True
|
||||
elif isinstance(node.annotation, ast.Attribute):
|
||||
# 直接是 t.CEnum
|
||||
if node.annotation.attr == t.CEnum.__name__:
|
||||
# 直接是 CEnum
|
||||
if node.annotation.attr == TypeSystem.CEnum.__name__:
|
||||
IsCenum = True
|
||||
|
||||
if IsCenum:
|
||||
@@ -273,7 +273,7 @@ class AnnotationLoaderMixin:
|
||||
# 注册枚举成员
|
||||
MemberNode: CTypeInfo = CTypeInfo()
|
||||
MemberNode.Name = TargetName
|
||||
MemberNode.BaseType = t.CEnum(TypePrefix)
|
||||
MemberNode.BaseType = TypeSystem.CEnum(TypePrefix)
|
||||
MemberNode.value = value
|
||||
MemberNode.EnumName = TypePrefix
|
||||
MemberNode.library_name = TypePrefix
|
||||
@@ -288,14 +288,14 @@ class AnnotationLoaderMixin:
|
||||
ann_content = ExpandSoftKeywords(ann_content)
|
||||
ann_tree: ast.Module = ast.parse(ann_content, ModuleName)
|
||||
for node in ann_tree.body:
|
||||
# 检测 xxx: t.CTypedef = xxx 形式的 typedef 语句
|
||||
# 检测 xxx: CTypedef = xxx 形式的 typedef 语句
|
||||
if isinstance(node, ast.AnnAssign):
|
||||
if isinstance(node.target, ast.Name) and node.annotation and node.value:
|
||||
TargetName: str = node.target.id
|
||||
# 检查注解是否是 t.CTypedef
|
||||
# 检查注解是否是 CTypedef
|
||||
if isinstance(node.annotation, ast.Attribute):
|
||||
if isinstance(node.annotation.value, ast.Name):
|
||||
if IsTModule(node.annotation.value.id) and node.annotation.attr == 'CTypedef':
|
||||
if node.annotation.attr == 'CTypedef':
|
||||
# 检查值是否是 Name
|
||||
if isinstance(node.value, ast.Name):
|
||||
original_name: str = node.value.id
|
||||
|
||||
Reference in new issue
Block a user