refactor(type): 全面清理旧联合与 t/c 标记判断
审计并修复 23 个文件:类型注解中的 T1 | T2 一律 fail-fast;typedef/define/export/extern/static/const/volatile/attribute 优先读取 Markers/Attributes/ByteOrder/BitWidth;指针统一 CPtr/rawptr/CRef/CTempRef/CArrayPtr/CAutoPtr Subscript;stub 输出统一新语法。
This commit is contained in:
1 parent
a410de2cf7
commit
0bded58999
23 files changed
+887
-694
No files matched your search
@@ -693,7 +693,7 @@ class BaseGenMixin:
|
||||
if packed and isinstance(existing, ir.IdentifiedStructType) and not existing.packed:
|
||||
existing.packed = True
|
||||
return existing
|
||||
if clean_name in {'typedef', 'CType', 'CVolatile', 'CEnum', 'CUnion', 'CStruct', 'enum', 'REnum', 'renum', 'Void', 'void'}:
|
||||
if clean_name in {'typedef', 'CType', 'CTypedef', 'CEnum', 'CUnion', 'CStruct', 'enum', 'REnum', 'renum', 'Void', 'void'}:
|
||||
return ir.IntType(8)
|
||||
# typing.Any 是"任意类型"标记,应解析为 i8*(通用指针),
|
||||
# 而非创建为 opaque 结构体(否则包含 Any 字段的结构体会变成 unsized)。
|
||||
@@ -865,7 +865,7 @@ class BaseGenMixin:
|
||||
# 解决时序问题:_parse_llvm_declare 从 stub.ll 解析时 dict 可能尚未注册到 Gen.structs,
|
||||
# 但 SymbolTable 在 .pyi 解析阶段已就绪,可通过 is_struct 检查区分 class 和 typedef。
|
||||
_SPECIAL_TYPEDEFS: set[str] = {
|
||||
'typedef', 'CType', 'CVolatile', 'CEnum', 'CUnion',
|
||||
'typedef', 'CType', 'CTypedef', 'CEnum', 'CUnion',
|
||||
'CStruct', 'enum', 'REnum', 'renum',
|
||||
'list', 'dict', 'tuple', 'set', 'str', 'bytes', 'array', 'type', 'CArray',
|
||||
}
|
||||
@@ -1431,26 +1431,43 @@ class BaseGenMixin:
|
||||
|
||||
@staticmethod
|
||||
def _AnnotationHasQualifier(Annotation: Any, AttrName: str) -> bool:
|
||||
"""注解子树里是否出现 `t.<AttrName>`(与 ViperC TypeGenErr.has_decorator_marker 同口径)。"""
|
||||
"""注解子树里是否带指定限定符(读取 AST 的 Markers 字段)。
|
||||
|
||||
AttrName 兼容旧书写名(CConst/CVolatile)与关键字名(const/volatile);
|
||||
修饰信息一律来自 `Markers`,不再匹配裸名/Attribute 文本。
|
||||
"""
|
||||
if Annotation is None:
|
||||
return False
|
||||
from lib.core.SymbolUtils import RejectTypeUnionAnnotation
|
||||
RejectTypeUnionAnnotation(Annotation)
|
||||
MarkerName: str = {
|
||||
'CConst': 'const', 'CVolatile': 'volatile',
|
||||
'const': 'const', 'volatile': 'volatile',
|
||||
}.get(AttrName, AttrName)
|
||||
for n in ast.walk(Annotation):
|
||||
if isinstance(n, ast.Attribute) and n.attr == AttrName:
|
||||
if MarkerName in (getattr(n, 'Markers', None) or ()):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _AnnotationHasPointeeVolatile(Annotation: Any) -> bool:
|
||||
"""注解是否为 `rawptr[CVolatile | T]`(volatile 指针指向物,等价 C 的 volatile T*)。
|
||||
"""注解是否为「指向物 volatile」(`volatile T*` / `volatile rawptr[T]`)。
|
||||
|
||||
与 ViperC TypeGenErr.has_pointee_volatile_marker 同口径:只看 `rawptr[...]`
|
||||
的下标实参子树里有没有 CVolatile;多级指针(slice 仍是 Subscript)明确不支持。
|
||||
读取 AST 字段:`rawptr[...]` / `CPtr[...]` 节点自身的 Markers 含
|
||||
'volatile',或其下标子树的 Markers 含 'volatile'(多级指针不另行展开)。
|
||||
"""
|
||||
if not isinstance(Annotation, ast.Subscript):
|
||||
return False
|
||||
base: Any = Annotation.value
|
||||
if not isinstance(base, ast.Name) or base.id != 'rawptr':
|
||||
BaseName: str = ''
|
||||
if isinstance(base, ast.Name):
|
||||
BaseName = base.id
|
||||
elif isinstance(base, ast.Attribute):
|
||||
BaseName = base.attr
|
||||
if BaseName not in ('rawptr', 'CPtr'):
|
||||
return False
|
||||
if 'volatile' in (getattr(Annotation, 'Markers', None) or ()):
|
||||
return True
|
||||
return BaseGenMixin._AnnotationHasQualifier(Annotation.slice, 'CVolatile')
|
||||
|
||||
def RegisterVarQualifiers(self, Name: str, Info: Any, Annotation: Any,
|
||||
|
||||
Reference in new issue
Block a user