fix(stmt): with 的 asname 注解类名带模块前缀,修复跨模块方法调用解析

translate_with 提取 context 类名时只取裸类名(MemPool),跨模块调用
(如 pool.alloc)的 AnnotClassName 回退需模块限定名(memhub.MemPool)
才能按模块查 SHA1,裸名导致方法调用判定失败、落入"跨模块调用找不到
模块 SHA1"误报。改为与 AnnAssign 的 extract_class_name_from_annotation
一致:Attribute func(memhub.MemPool)生成 "memhub.MemPool" 注解类名。
This commit is contained in:
TermiNexus committed 2026-08-13 07:12:27 +08:00
1 parent a6d1a6f9ae
commit f1530aac91
1 file changed
+14 -2
+14 -2
View File
@@ -255,14 +255,26 @@ class StmtGenMixin:
trans._funcs, trans._func_count, trans)
if ctx_val is None:
continue
# 提取类名:Call(func=Attribute("memhub"."MemPool") / Name("MemPool"))
# 提取类名(注解类名,Attribute 时带模块前缀,如 "memhub.MemPool"——
# 与 AnnAssign 的 extract_class_name_from_annotation 一致,跨模块
# 方法调用靠 AnnotClassName 回退按模块名查 SHA1)
cls_name: str = None
ce: ast.AST | t.CPtr = item.context_expr
if ce.kind() == ast.ASTKind.Call:
cfn: ast.AST | t.CPtr = ((ast.Call | t.CPtr)(ce)).func
if cfn is not None:
if cfn.kind() == ast.ASTKind.Attribute:
cls_name = ((ast.Attribute | t.CPtr)(cfn)).attr
ca: ast.Attribute | t.CPtr = (ast.Attribute | t.CPtr)(cfn)
if ca.value is not None and ca.value.kind() == ast.ASTKind.Name:
cmn: ast.Name | t.CPtr = (ast.Name | t.CPtr)(ca.value)
if cmn.id is not None:
ml2: t.CSizeT = string.strlen(cmn.id) + string.strlen(ca.attr) + 2
mbuf: str = pool.alloc(ml2)
if mbuf is not None:
viperlib.snprintf(mbuf, ml2, "%s.%s", cmn.id, ca.attr)
cls_name = mbuf
if cls_name is None:
cls_name = ca.attr
elif cfn.kind() == ast.ASTKind.Name:
cls_name = ((ast.Name | t.CPtr)(cfn)).id
# context 对象存入 __with_ctx(方法调用解析 self 用)