From af64f735ed9f0e0f4eefa32908821c5e72715e84 Mon Sep 17 00:00:00 2001 From: marsninja Date: Tue, 21 Nov 2023 00:48:22 +0800 Subject: [PATCH] mod code doesnt need scope --- jaclang/jac/passes/main/def_use_pass.py | 3 ++- jaclang/jac/passes/main/sym_tab_build_pass.py | 8 +++--- jaclang/jac/tests/test_workspace.py | 26 ++++++++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/jaclang/jac/passes/main/def_use_pass.py b/jaclang/jac/passes/main/def_use_pass.py index 6ba7850ab..a7698b6d9 100644 --- a/jaclang/jac/passes/main/def_use_pass.py +++ b/jaclang/jac/passes/main/def_use_pass.py @@ -125,7 +125,8 @@ def enter_atom_trailer(self, node: ast.AtomTrailer) -> None: right: AtomType, is_scope_contained: bool, """ - self.chain_use_lookup(self.unwind_atom_trailer(node)) + chain = self.unwind_atom_trailer(node) + self.chain_use_lookup(chain) def unwind_atom_trailer(self, node: ast.AtomTrailer) -> list[ast.AstSymbolNode]: """Sub objects. diff --git a/jaclang/jac/passes/main/sym_tab_build_pass.py b/jaclang/jac/passes/main/sym_tab_build_pass.py index 664cc9962..afb9c5530 100644 --- a/jaclang/jac/passes/main/sym_tab_build_pass.py +++ b/jaclang/jac/passes/main/sym_tab_build_pass.py @@ -73,13 +73,11 @@ def use_lookup( """Link to symbol.""" if self.seen(node): return node.sym_link - deep = False if not sym_table: sym_table = node.sym_tab - deep = True if sym_table: node.sym_link = ( - sym_table.lookup(name=node.sym_name, deep=deep) if sym_table else None + sym_table.lookup(name=node.sym_name, deep=True) if sym_table else None ) # If successful lookup mark linked, add to table uses, and link others if node.sym_link: @@ -300,7 +298,7 @@ def enter_module_code(self, node: ast.ModuleCode) -> None: name: Optional[Name], body: CodeBlock, """ - self.push_scope("module_code", node) + # self.push_scope("module_code", node) self.sync_node_to_scope(node) def exit_module_code(self, node: ast.ModuleCode) -> None: @@ -309,7 +307,7 @@ def exit_module_code(self, node: ast.ModuleCode) -> None: doc: Optional[Token], body: 'CodeBlock', """ - self.pop_scope() + # self.pop_scope() def enter_py_inline_code(self, node: ast.PyInlineCode) -> None: """Sub objects. diff --git a/jaclang/jac/tests/test_workspace.py b/jaclang/jac/tests/test_workspace.py index 7760d8084..d5d9cdb96 100644 --- a/jaclang/jac/tests/test_workspace.py +++ b/jaclang/jac/tests/test_workspace.py @@ -40,7 +40,6 @@ def test_get_uses_basic(self) -> None: def test_man_code_dir(self) -> None: """Test of circle workspace.""" loc = os.path.join(os.path.dirname(__file__)) - # print(loc) ws = Workspace(path=loc + "/../../../examples/manual_code") key = [i for i in ws.modules.keys() if "circle.jac" in i][0] # print(ws.modules[key].ir.sym_tab.pp()) @@ -65,3 +64,28 @@ def test_man_code_dir(self) -> None: "print", ]: self.assertIn(i, out) + + # def test_decl_impl(self) -> None: + # """Test of circle workspace.""" + # loc = os.path.join(os.path.dirname(__file__)) + # ws = Workspace(path=loc + "/../../../examples/manual_code") + # key = [i for i in ws.modules.keys() if "circle_clean.jac" in i][0] + # out = "" + # for i in ws.get_uses(key): + # out += i.pp(depth=2) + # for i in [ + # "math", + # "calculate_area", + # "RAD", + # "expected_area", + # "Circle", + # "c", + # "ShapeType", + # "float", + # "radius", + # "CIRCLE", + # "Shape", + # "__init__", + # "print", + # ]: + # self.assertIn(i, out)