From 8755386a019179f425f558adf3f7d3edcf713f07 Mon Sep 17 00:00:00 2001 From: kugesan1105 Date: Mon, 26 Aug 2024 20:02:12 +0530 Subject: [PATCH] fix: missing uses for atom_trailer --- .../passes/main/fuse_typeinfo_pass.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py index 8e44c5313..fb59ba44f 100644 --- a/jaclang/compiler/passes/main/fuse_typeinfo_pass.py +++ b/jaclang/compiler/passes/main/fuse_typeinfo_pass.py @@ -6,7 +6,7 @@ from __future__ import annotations -from typing import Callable, TypeVar +from typing import Callable, Optional, TypeVar import jaclang.compiler.absyntree as ast from jaclang.compiler.passes import Pass @@ -489,3 +489,28 @@ def exit_atom_trailer(self, node: ast.AtomTrailer) -> None: right, ast.IndexSlice ): # TODO check why IndexSlice produce an issue right.name_spec.sym = left.type_sym_tab.lookup(right.sym_name) + + def find_tab(tab: ast.SymbolTable, name: str) -> Optional[ast.SymbolTable]: + """Recursively find symbol table from sym dotted name.""" + tab_list = name.split(".") + if len(tab_list) == 1: + return tab + else: + if tab_list[0] == tab.name: + return find_tab(tab, ".".join(tab_list[1:])) + else: + for child in tab.kid: + if child.name == tab_list[0]: + return find_tab(child, ".".join(tab_list[1:])) + return None + + for name_node in node.as_attr_list: + tab = ( + find_tab(self.ir.sym_tab, name_node.sym.sym_dotted_name) + if name_node.sym + else None + ) + if tab: + find_symbol = tab.lookup(name_node.sym_name) + if find_symbol and name_node not in find_symbol.uses: + find_symbol.add_use(name_node.name_spec)