diff --git a/jaclang/compiler/passes/main/import_pass.py b/jaclang/compiler/passes/main/import_pass.py index 64f726baa..aac33b8cf 100644 --- a/jaclang/compiler/passes/main/import_pass.py +++ b/jaclang/compiler/passes/main/import_pass.py @@ -14,7 +14,7 @@ from jaclang.compiler.passes import Pass from jaclang.compiler.passes.main import SubNodeTabPass, SymTabBuildPass from jaclang.utils.log import logging - +from jaclang.compiler.constant import SymbolType logger = logging.getLogger(__name__) @@ -287,6 +287,14 @@ def import_py_module( self.import_table[file_to_raise] = mod self.attach_mod_to_node(parent_node, mod) SymTabBuildPass(input_ir=mod, prior=self) + parent_node.sym_tab.insert( + ast.AstSymbolNode( + sym_name=imported_mod_name, + name_spec=mod.kid[0].name_spec, + sym_category=SymbolType.MOD_VAR, + ), + access_spec=None, + ) return mod else: raise self.ice(f"Failed to import python module {mod_path}") diff --git a/jaclang/compiler/passes/main/sym_tab_build_pass.py b/jaclang/compiler/passes/main/sym_tab_build_pass.py index eb6e35a2a..a29392127 100644 --- a/jaclang/compiler/passes/main/sym_tab_build_pass.py +++ b/jaclang/compiler/passes/main/sym_tab_build_pass.py @@ -196,7 +196,20 @@ def exit_import(self, node: ast.Import) -> None: """ if not node.is_absorb: for i in node.items.items: - i.sym_tab.def_insert(i, single_decl="import item") + if not isinstance(i, ast.ModuleItem): + continue + if not i.from_mod_path.sub_module: + continue + lookup = i.from_mod_path.sub_module.sym_tab.lookup(i.name.value) + if lookup: + lookup.add_use(i.name_spec) + node.sym_tab.insert(lookup.decl, lookup.access) + else: + i.sym_tab.def_insert(i, single_decl="import item") + + # if not node.is_absorb: + # for i in node.items.items: + # i.sym_tab.def_insert(i, single_decl="import item") elif node.is_absorb and node.is_jac: source = node.items.items[0] if not isinstance(source, ast.ModulePath) or not source.sub_module: @@ -206,6 +219,8 @@ def exit_import(self, node: ast.Import) -> None: ) else: node.sym_tab.inherit_sym_tab(source.sub_module.sym_tab) + else: + print("elseeeeeee") def enter_module_path(self, node: ast.ModulePath) -> None: """Sub objects. diff --git a/jaclang/utils/treeprinter.py b/jaclang/utils/treeprinter.py index d4265e39d..be79b4dfd 100644 --- a/jaclang/utils/treeprinter.py +++ b/jaclang/utils/treeprinter.py @@ -277,7 +277,7 @@ def _build_symbol_tree_common( if sym.decl and sym.decl.loc.first_line > 0: SymbolTree( - node_name=f"decl: line {sym.decl.loc.first_line}, col {sym.decl.loc.col_start}", + node_name=f"decl: line {sym.decl.loc.first_line}, col {sym.decl.loc.col_start} {sym.decl.loc.mod_path}", parent=symbol_node, ) defn = SymbolTree(node_name="defn", parent=symbol_node)