finish refactoring task 1 and 2

This commit is contained in:
Jan-Niclas Loosen
2026-03-08 17:21:09 +01:00
parent 605eaf3278
commit 438447e6de
4 changed files with 65 additions and 79 deletions

View File

@@ -25,7 +25,7 @@ class BackwardAnalysis:
self.__funcs: dict[str, tuple] = dict(cfg_build.FUNCTIONS)
self.__func_parent, self._func_params = self.__collect_function_metadata()
self.__func_scope: dict[int, str] = self.__compute_function_scope()
self.func_scope: dict[int, str] = self.__compute_function_scope()
self.__extract_uses_and_defs()
# Walk the AST and collect function-parent and parameter information.
@@ -90,7 +90,7 @@ class BackwardAnalysis:
def __extract_uses_and_defs(self) -> None:
for node in self.cfg.nodes():
nid = node.id
func = self.__func_scope.get(nid)
func = self.func_scope.get(nid)
ast = node.ast_node
uses: set[Var] = set()
@@ -102,17 +102,17 @@ class BackwardAnalysis:
defs.add((ast.f_name, param))
elif ast is not None:
if isinstance(ast, syntax.ID):
resolved = self.__resolve_var(func, ast.name)
resolved = self.resolve_var(func, ast.name)
uses.add(resolved)
elif isinstance(ast, syntax.ASSIGN):
resolved = self.__resolve_var(func, ast.var.name)
resolved = self.resolve_var(func, ast.var.name)
defs.add(resolved)
self.uses[nid] = uses
self.defs[nid] = defs
# Resolve a variables name and scope by walking up the hierarchy
def __resolve_var(self, func: str | None, name: str) -> Var:
def resolve_var(self, func: str | None, name: str) -> Var:
if func is None:
return GLOBAL_SCOPE, name