diff --git a/includes/ast/exprs.vp b/includes/ast/exprs.vp index 366fffc..eaac740 100644 --- a/includes/ast/exprs.vp +++ b/includes/ast/exprs.vp @@ -53,6 +53,34 @@ class Name(ExprNode): return pos +def name_get_id(node: Name | t.CPtr) -> str: + """获取 Name.id 字段(跨模块访问器,stub 字段访问陷阱防护)""" + if node is None: + return None + return node.id + + +def constant_get_str_val(node: Constant | t.CPtr) -> str: + """获取 Constant.str_val 字段(跨模块访问器)""" + if node is None: + return None + return node.str_val + + +def binop_get_left(node: BinOp | t.CPtr) -> AST | t.CPtr: + """获取 BinOp.left 字段(跨模块访问器)""" + if node is None: + return None + return node.left + + +def binop_get_right(node: BinOp | t.CPtr) -> AST | t.CPtr: + """获取 BinOp.right 字段(跨模块访问器)""" + if node is None: + return None + return node.right + + # ============================================================ # Constant nodes (subtype marked by const_kind) # ============================================================ @@ -943,6 +971,27 @@ class Attribute(ExprNode): return pos +# ============================================================ +# 字段访问器(跨模块 stub 字段访问陷阱防护) +# +# 其他模块(如 TypeGenCType)直接访问 ast.Attribute 的字段时, +# TPC 可能按 stub 类型生成错误 GEP(读垃圾地址 → 0xC0000005 崩溃)。 +# 本模块是完整类型,字段偏移正确;跨模块调用方用这些访问器。 +# ============================================================ +def attribute_get_value(node: Attribute | t.CPtr) -> AST | t.CPtr: + """获取 Attribute.value 字段(跨模块访问器)""" + if node is None: + return None + return node.value + + +def attribute_get_attr(node: Attribute | t.CPtr) -> str: + """获取 Attribute.attr 字段(跨模块访问器)""" + if node is None: + return None + return node.attr + + # ============================================================ # Subscript Node # ============================================================