Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions code_to_data_dependency_graph.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ast


def get_deps(code):
def get_deps(code: str) -> Tuple[Dict[str, int], Dict[str, Set[str]]]:
body = ast.parse(code)
_, statements = next(ast.iter_fields(body))

# Line no. at which each identifier was first seen
declaration_line_num_map = {}
ddg = {}
declaration_line_num_map: Dict[str, int] = {}
ddg: Dict[str, Set[str]] = {}

def update_decls(lhs_vars_input, num):
lhs_var_nodes = []
Expand Down Expand Up @@ -51,7 +51,7 @@ class MethodLevelDDGs:
def __init__(self, code):
self.parsed_ast = ast.parse(code)

def get_methods(self):
def get_methods(self) -> List[ast.FunctionDef]:
fn_nodes = []

class FnVisitor(ast.NodeVisitor):
Expand Down Expand Up @@ -90,7 +90,7 @@ def visit_Assign(self, node):
return ddg


def fn_ddgs(code):
def fn_ddgs(code: str) -> Dict[str, Dict[str, Set[str]]]:
method_level_ddgs = MethodLevelDDGs(code)
methods = method_level_ddgs.get_methods()
ddgs = {method.name: method_level_ddgs.recursive_ddg(method) for method in methods}
Expand Down
6 changes: 4 additions & 2 deletions var_ddg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class MyVisitor:
def __init__(self, path):
def __init__(self, path: str):
self.GLOBAL_FN = ast.FunctionDef(name='_global_')

# FunctionDef -> set(x, y) such that x reads y
Expand Down Expand Up @@ -67,8 +67,10 @@ def ast_visit(self, node, level=0):
if is_fn:
self.fn_stack.pop()

def construct_ddg(self):
def construct_ddg(self) -> None:
self.ast_visit(self.tree)

def get_function_level_ddg(self):
return {fn.name: value for fn, value in self.fn_to_ddg_map.items()}
def get_function_level_ddg(self) -> Dict[ast.FunctionDef, Set[Tuple[str, str]]]:
return {fn.name: value for fn, value in self.fn_to_ddg_map.items()}