From 802377e9ab4ce517a0f4cddf78cf2af04df5caff Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Tue, 18 Aug 2026 08:59:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(ast):=20=E5=8A=A0=20Name/Attribute/Constan?= =?UTF-8?q?t/BinOp=20=E5=AD=97=E6=AE=B5=E8=AE=BF=E9=97=AE=E5=99=A8?= =?UTF-8?q?=EF=BC=8C=E7=BB=95=E5=BC=80=E8=B7=A8=E6=A8=A1=E5=9D=97=20stub?= =?UTF-8?q?=20=E5=AD=97=E6=AE=B5=E8=AE=BF=E9=97=AE=E9=99=B7=E9=98=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/ast/exprs.vp | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) 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 # ============================================================