refactor(tpv): 删除 AnnotClassName 字段,注解类名统一承载于 Spec.SourceName
- GenTypes 删 VarEntry.AnnotClassName / FieldEntry.AnnotClassName - set_var_annot_class_name / add_field 改为写入 Spec(Spec 为 None 时建 TS_UNKNOWN 承载, 不表态具体类型,等价原 Spec 缺失);删 1b 的 AnnotClassName 专属深拷贝 - var_annot_class_name / get_field_annot_class_name 去旧字段回退分支 - 剩余 7 处直读(StmtGenCifMixin list/dict 5 处、CallGenMixin CPtr 2 处)改走封装
This commit is contained in:
1 parent
95133d8483
commit
9e461d21cb
5 files changed
+75
-66
No files matched your search
@@ -115,49 +115,58 @@ class VarGenMixin:
|
||||
# ============================================================
|
||||
# set_var_annot_class_name — 设置变量的原始类型注解类名
|
||||
#
|
||||
# 在函数参数定义后调用,存储原始类型注解的类名。
|
||||
# 在函数参数定义后调用,存储原始类型注解的类名(Spec.SourceName)。
|
||||
# 方法调用检测时,当 alloca 类型是 Ptr(i8)(联合类型简化),
|
||||
# 通过 AnnotClassName 查找实际结构体类型。
|
||||
# 通过 Spec.SourceName 查找实际结构体类型。
|
||||
# ============================================================
|
||||
def set_var_annot_class_name(self, symtab: GenTypes.SymbolTable | t.CPtr,
|
||||
name: str,
|
||||
class_name: str) -> int:
|
||||
"""设置变量的原始类型注解类名,返回 0=成功 / 1=失败"""
|
||||
"""设置变量的原始类型注解类名(写入 Spec.SourceName),返回 0=成功 / 1=失败
|
||||
|
||||
[S4] 原 VarEntry.AnnotClassName 字段已删除,注解名统一承载在 Spec.SourceName:
|
||||
- 整数符号性:SpecFromLLVMType 反推恒 TS_INT(LLVM iN 不分符号),
|
||||
注解名携带真实无符号性(uint32/CUInt32T 等)→ 切 TS_INT→TS_UINT;
|
||||
- 来源名:`X | t.CPtr` 简化为 Ptr(i8) 后 Spec 里没有类名,附上供
|
||||
属性访问/方法分派恢复(消费点经 var_annot_class_name 读取)。
|
||||
类型信息缺失(SpecFromLLVMType 不适用致 Spec 为 None)时建 TS_UNKNOWN
|
||||
承载注解名 —— TS_UNKNOWN 不表态任何具体类型,等价于原来的"Spec 缺失"。
|
||||
"""
|
||||
if symtab is None or name is None:
|
||||
return 1
|
||||
entry: GenTypes.VarEntry | t.CPtr = self.lookup_var_entry(symtab, name)
|
||||
if entry is None:
|
||||
return 1
|
||||
entry.AnnotClassName = class_name
|
||||
# [S4 注解侧填 Spec] 把注解来源名附到 Spec(SourceName)供消费点逐步切读:
|
||||
# - 整数符号性:SpecFromLLVMType 反推恒 TS_INT(LLVM iN 不分符号),
|
||||
# 注解名携带真实无符号性(uint32/CUInt32T 等)→ 切 TS_INT→TS_UINT;
|
||||
# - 来源名:`X | t.CPtr` 简化为 Ptr(i8) 后 Spec 里没有类名,附上供
|
||||
# 属性访问/方法分派恢复。
|
||||
if entry.Spec is not None and class_name is not None:
|
||||
sign: int = self.Gen.TypeGenCType.spec_sign_of_annot(class_name)
|
||||
if sign != TSpec.TS_SIGN_UNKNOWN:
|
||||
arena_sn: TSpec.TypeSpecArena | t.CPtr = self.Gen.TypeGenBase.ensure_spec_arena()
|
||||
if arena_sn is not None:
|
||||
entry.Spec = TSpec.SpecWithSign(arena_sn, entry.Spec, sign)
|
||||
entry.Spec = TSpec.SpecWithSource(entry.Spec, class_name)
|
||||
if class_name is None:
|
||||
# 无注解名:不写入。原实现无条件 `entry.AnnotClassName = None` 会清空,
|
||||
# 但 VarEntry 槽位不复用(add_var 只递增),首次设置时原值恒为 None,
|
||||
# 故二者等价;重复调用且第二次为 None 的差异不存在于现有调用点。
|
||||
return 0
|
||||
arena_sn: TSpec.TypeSpecArena | t.CPtr = self.Gen.TypeGenBase.ensure_spec_arena()
|
||||
if arena_sn is None:
|
||||
return 1
|
||||
if entry.Spec is None:
|
||||
entry.Spec = TSpec.NewTypeSpec(arena_sn, TSpec.TS_UNKNOWN, 0,
|
||||
TSpec.TS_SIGN_UNKNOWN)
|
||||
if entry.Spec is None:
|
||||
return 1
|
||||
sign: int = self.Gen.TypeGenCType.spec_sign_of_annot(class_name)
|
||||
if sign != TSpec.TS_SIGN_UNKNOWN:
|
||||
entry.Spec = TSpec.SpecWithSign(arena_sn, entry.Spec, sign)
|
||||
entry.Spec = TSpec.SpecWithSource(entry.Spec, class_name)
|
||||
return 0
|
||||
|
||||
# ============================================================
|
||||
# var_annot_class_name - 变量条目注解类名的统一读取入口(S4 切读·类名块)
|
||||
#
|
||||
# Spec.SourceName 优先(注解侧由 set_var_annot_class_name 经 SpecWithSource 填),
|
||||
# 未设置时回退旧字段 AnnotClassName。变量侧类名恢复读取点统一走此入口。
|
||||
# 注解侧由 set_var_annot_class_name 经 SpecWithSource 写入 Spec.SourceName。
|
||||
# 变量侧类名恢复读取点统一走此入口。
|
||||
# ============================================================
|
||||
def var_annot_class_name(self, entry: GenTypes.VarEntry | t.CPtr) -> str:
|
||||
"""变量条目注解类名;未设置返回 None"""
|
||||
"""变量条目注解类名(Spec.SourceName);未设置返回 None"""
|
||||
if entry is None:
|
||||
return None
|
||||
if entry.Spec is not None:
|
||||
sn: str = TSpec.SpecSourceName(entry.Spec)
|
||||
if sn is not None:
|
||||
return sn
|
||||
return entry.AnnotClassName
|
||||
return TSpec.SpecSourceName(entry.Spec)
|
||||
|
||||
# ============================================================
|
||||
# set_var_ptr_element — 标记变量为"指针到 str/bytes"类型
|
||||
|
||||
Reference in new issue
Block a user