tlarsson commited on
Commit
3145636
·
verified ·
1 Parent(s): 5598c37

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. utility.py +24 -4
app.py CHANGED
@@ -64,7 +64,7 @@ app.layout = html.Div([
64
  ),
65
  dcc.Checklist(
66
  id="function-detail-toggle",
67
- options=[{"label": "Show Function-Level Detail", "value": "show"}],
68
  value=[],
69
  labelStyle={"display": "block", "fontWeight": "normal"},
70
  style={"marginTop": "5px"}
 
64
  ),
65
  dcc.Checklist(
66
  id="function-detail-toggle",
67
+ options=[{"label": "Show Function-Level Detail in Summaray tab", "value": "show"}],
68
  value=[],
69
  labelStyle={"display": "block", "fontWeight": "normal"},
70
  style={"marginTop": "5px"}
utility.py CHANGED
@@ -1,5 +1,17 @@
1
  import ast
2
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def parse_functions_from_files(file_dict):
4
  functions = {}
5
  defined_funcs = set()
@@ -28,16 +40,20 @@ def parse_functions_from_files(file_dict):
28
  for node in ast.walk(tree):
29
  if isinstance(node, ast.FunctionDef):
30
  func_name = node.name
31
- args, returns, calls = [], [], []
32
  local_assignments = {}
33
  reads_state, writes_state = set(), set()
 
34
  for arg in node.args.args:
35
  arg_type = ast.unparse(arg.annotation) if arg.annotation else "?"
36
  args.append(f"{arg.arg}: {arg_type}")
 
 
 
 
 
37
  for sub in ast.walk(node):
38
- if isinstance(sub, ast.Call) and isinstance(sub.func, ast.Name):
39
- if sub.func.id in defined_funcs: calls.append(sub.func.id)
40
- elif isinstance(sub, ast.Assign):
41
  for target in sub.targets:
42
  if isinstance(target, ast.Name):
43
  local_assignments[target.id] = infer_type_from_value(sub.value)
@@ -50,6 +66,7 @@ def parse_functions_from_files(file_dict):
50
  else:
51
  label = ast.unparse(sub.value)
52
  returns.append(f"{label}: {local_assignments.get(label, infer_type_from_value(sub.value))}")
 
53
  functions[func_name] = {
54
  "args": args,
55
  "returns": returns,
@@ -58,8 +75,11 @@ def parse_functions_from_files(file_dict):
58
  "reads_state": sorted(reads_state),
59
  "writes_state": sorted(writes_state)
60
  }
 
61
  return functions
62
 
 
 
63
  def get_reachable_functions(start, graph):
64
  visited, stack = set(), [start]
65
  while stack:
 
1
  import ast
2
 
3
+ import ast
4
+
5
+ class CallCollector(ast.NodeVisitor):
6
+ def __init__(self, defined_funcs):
7
+ self.calls = []
8
+ self.defined_funcs = defined_funcs
9
+
10
+ def visit_Call(self, node):
11
+ if isinstance(node.func, ast.Name) and node.func.id in self.defined_funcs:
12
+ self.calls.append(node.func.id)
13
+ self.generic_visit(node)
14
+
15
  def parse_functions_from_files(file_dict):
16
  functions = {}
17
  defined_funcs = set()
 
40
  for node in ast.walk(tree):
41
  if isinstance(node, ast.FunctionDef):
42
  func_name = node.name
43
+ args, returns = [], []
44
  local_assignments = {}
45
  reads_state, writes_state = set(), set()
46
+
47
  for arg in node.args.args:
48
  arg_type = ast.unparse(arg.annotation) if arg.annotation else "?"
49
  args.append(f"{arg.arg}: {arg_type}")
50
+
51
+ collector = CallCollector(defined_funcs)
52
+ collector.visit(node)
53
+ calls = collector.calls
54
+
55
  for sub in ast.walk(node):
56
+ if isinstance(sub, ast.Assign):
 
 
57
  for target in sub.targets:
58
  if isinstance(target, ast.Name):
59
  local_assignments[target.id] = infer_type_from_value(sub.value)
 
66
  else:
67
  label = ast.unparse(sub.value)
68
  returns.append(f"{label}: {local_assignments.get(label, infer_type_from_value(sub.value))}")
69
+
70
  functions[func_name] = {
71
  "args": args,
72
  "returns": returns,
 
75
  "reads_state": sorted(reads_state),
76
  "writes_state": sorted(writes_state)
77
  }
78
+
79
  return functions
80
 
81
+
82
+
83
  def get_reachable_functions(start, graph):
84
  visited, stack = set(), [start]
85
  while stack: