fix(tpc): 方法调用虚分派——变量与模块短名同名时不误入模块函数路径(base.kind 折叠根因)
This commit is contained in:
1 parent
db80178d2e
commit
60dbdfe8d2
2 files changed
+6
-3
No files matched your search
@@ -1038,6 +1038,9 @@ def _parse_atom(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
|||||||
if _match_op(ps, TokOp.LBrace):
|
if _match_op(ps, TokOp.LBrace):
|
||||||
return _parse_brace(ps)
|
return _parse_brace(ps)
|
||||||
|
|
||||||
|
stdio.printf("[DBG-atom-fail] line=%d col=%d type=%d str='%s' op_id=%d\n",
|
||||||
|
_cur_lineno(ps), _cur_col(ps), _cur_type(ps),
|
||||||
|
_cur_str(ps) if _cur_str(ps) is not None else "(null)", _cur_op(ps))
|
||||||
ps.error_count += 1
|
ps.error_count += 1
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1576,7 +1579,7 @@ def _parse_type_ann(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
|||||||
ptr_level: t.CInt = 0
|
ptr_level: t.CInt = 0
|
||||||
# 回收垃圾节点(_parse_test 对后缀 * / ** 的消费产物)
|
# 回收垃圾节点(_parse_test 对后缀 * / ** 的消费产物)
|
||||||
if base.kind() == ASTKind.BinOp:
|
if base.kind() == ASTKind.BinOp:
|
||||||
gb: ast.BinOp | t.CPtr = (ast.BinOp | t.CPtr)(base)
|
gb: BinOp | t.CPtr = (BinOp | t.CPtr)(base)
|
||||||
if gb.op == OpKind.Mult and gb.right is None:
|
if gb.op == OpKind.Mult and gb.right is None:
|
||||||
ptr_level += 1
|
ptr_level += 1
|
||||||
base = gb.left
|
base = gb.left
|
||||||
@@ -1585,7 +1588,7 @@ def _parse_type_ann(ps: Parser | t.CPtr) -> AST | t.CPtr:
|
|||||||
ptr_level += 2
|
ptr_level += 2
|
||||||
base = gb.left
|
base = gb.left
|
||||||
elif gb.right.kind() == ASTKind.UnaryOp:
|
elif gb.right.kind() == ASTKind.UnaryOp:
|
||||||
gu: ast.UnaryOp | t.CPtr = (ast.UnaryOp | t.CPtr)(gb.right)
|
gu: UnaryOp | t.CPtr = (UnaryOp | t.CPtr)(gb.right)
|
||||||
if gu.op == OpKind.Deref and gu.operand is None:
|
if gu.op == OpKind.Deref and gu.operand is None:
|
||||||
ptr_level += 3
|
ptr_level += 3
|
||||||
base = gb.left
|
base = gb.left
|
||||||
|
|||||||
@@ -2787,7 +2787,7 @@ class ExprCallHandle(BaseHandle):
|
|||||||
ModuleName = Node.func.value.id
|
ModuleName = Node.func.value.id
|
||||||
imported = getattr(self.Trans, '_ImportedModules', set())
|
imported = getattr(self.Trans, '_ImportedModules', set())
|
||||||
actual_module = self.Trans.SymbolTable.resolve_alias(ModuleName)
|
actual_module = self.Trans.SymbolTable.resolve_alias(ModuleName)
|
||||||
if ModuleName in imported or actual_module in imported:
|
if (ModuleName in imported or actual_module in imported) and ModuleName not in Gen.var_struct_class:
|
||||||
mangled_name = Gen._mangle_func_name(MethodName, actual_module)
|
mangled_name = Gen._mangle_func_name(MethodName, actual_module)
|
||||||
if Gen._has_function(mangled_name):
|
if Gen._has_function(mangled_name):
|
||||||
CallArgs = []
|
CallArgs = []
|
||||||
|
|||||||
Reference in new issue
Block a user