finish refactoring task 1 and 2
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user