Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
Sample approach to add moduleitem symbol to main symboltable
Browse files Browse the repository at this point in the history
  • Loading branch information
kugesan1105 committed Sep 6, 2024
1 parent 9ad2d4f commit 30bff64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 9 additions & 1 deletion jaclang/compiler/passes/main/import_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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}")
Expand Down
6 changes: 0 additions & 6 deletions jaclang/compiler/passes/main/sym_tab_build_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,17 @@ def exit_import(self, node: ast.Import) -> None:
sub_module: Optional[Module],
"""
if not node.is_absorb:
# if node.from_loc:
# print('--',node.from_loc.sym_name )
for i in node.items.items:
# print('i.symname ----',i.sym_name)
if not isinstance(i, ast.ModuleItem):
# print('-mod path----',i.sym_name)
continue
if not i.from_mod_path.sub_module:
# print('-no sub mod----',i.sym_name)
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")
# print(i.sym_name)

# if not node.is_absorb:
# for i in node.items.items:
Expand Down

0 comments on commit 30bff64

Please sign in to comment.