Skip to content

Commit

Permalink
sym_type moved to expr
Browse files Browse the repository at this point in the history
  • Loading branch information
ThakeeNathees committed Sep 12, 2024
1 parent cb82ff2 commit 24f9b30
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 28 deletions.
45 changes: 22 additions & 23 deletions jac/jaclang/compiler/absyntree.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,28 @@ class Expr(AstNode):

def __init__(self) -> None:
"""Initialize expression node."""
self.expr_type = ""
self._sym_type: str = "NoType"
self._type_sym_tab: Optional[SymbolTable] = None

@property
def sym_type(self) -> str:
"""Get symbol type."""
return self._sym_type

@sym_type.setter
def sym_type(self, sym_type: str) -> None:
"""Set symbol type."""
self._sym_type = sym_type

@property
def type_sym_tab(self) -> Optional[SymbolTable]:
"""Get type symbol table."""
return self._type_sym_tab

@type_sym_tab.setter
def type_sym_tab(self, type_sym_tab: SymbolTable) -> None:
"""Set type symbol table."""
self._type_sym_tab = type_sym_tab


class AtomExpr(Expr, AstSymbolStubNode):
Expand Down Expand Up @@ -439,8 +460,6 @@ def __init__(self) -> None:
self._sym_name: str = ""
self._sym_category: SymbolType = SymbolType.UNKNOWN
self._py_ctx_func: Type[ast3.AST] = ast3.Load
self._sym_type: str = "NoType"
self._type_sym_tab: Optional[SymbolTable] = None
AtomExpr.__init__(self)

@property
Expand Down Expand Up @@ -479,26 +498,6 @@ def py_ctx_func(self, py_ctx_func: Type[ast3.AST]) -> None:
"""Set python context function."""
self._py_ctx_func = py_ctx_func

@property
def sym_type(self) -> str:
"""Get symbol type."""
return self._sym_type

@sym_type.setter
def sym_type(self, sym_type: str) -> None:
"""Set symbol type."""
self._sym_type = sym_type

@property
def type_sym_tab(self) -> Optional[SymbolTable]:
"""Get type symbol table."""
return self._type_sym_tab

@type_sym_tab.setter
def type_sym_tab(self, type_sym_tab: SymbolTable) -> None:
"""Set type symbol table."""
self._type_sym_tab = type_sym_tab

@property
def sem_token(self) -> Optional[tuple[SemTokType, SemTokMod]]:
"""Resolve semantic token."""
Expand Down
4 changes: 1 addition & 3 deletions jac/jaclang/compiler/passes/main/fuse_typeinfo_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ def enter_node(self, node: ast.AstNode) -> None:
if hasattr(self, f"enter_{pascal_to_snake(type(node).__name__)}"):
getattr(self, f"enter_{pascal_to_snake(type(node).__name__)}")(node)

# TODO: Make (AstSymbolNode::name_spec.sym_typ and Expr::expr_type) the same
# TODO: Introduce AstTypedNode to be a common parent for Expr and AstSymbolNode
if isinstance(node, ast.Expr):
self.enter_expr(node)

Expand Down Expand Up @@ -257,7 +255,7 @@ def enter_expr(self: FuseTypeInfoPass, node: ast.Expr) -> None:
mypy_node = node.gen.mypy_ast[0]
if mypy_node in self.node_type_hash:
mytype: MyType = self.node_type_hash[mypy_node]
node.expr_type = self.__call_type_handler(mytype) or ""
node.sym_type = self.__call_type_handler(mytype) or ""

# Set they symbol type for collection expression.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ def test_type_coverage(self) -> None:
self.assertIn("HasVar - species - Type: builtins.str", out)
self.assertIn("myDog - Type: type_info.Dog", out)
self.assertIn("Body - Type: type_info.Dog.Body", out)
self.assertEqual(out.count("Type: builtins.str"), 39)
self.assertEqual(out.count("Type: builtins.str"), 29)
for i in lis:
self.assertNotIn(i, out)
2 changes: 1 addition & 1 deletion jac/jaclang/utils/treeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def __node_repr_in_tree(node: AstNode) -> str:
out += f" SymbolPath: {symbol}"
return out
elif isinstance(node, ast.Expr):
return f"{node.__class__.__name__} - Type: {node.expr_type}"
return f"{node.__class__.__name__} - Type: {node.sym_type}"
else:
return f"{node.__class__.__name__}, {access}"

Expand Down

0 comments on commit 24f9b30

Please sign in to comment.