MCPcopy Create free account
hub / github.com/Persper/code-analytics / update_graph

Function update_graph

persper/analytics/call_graph/c.py:70–104  ·  view source on GitHub ↗
(ccgraph, ast_list, change_stats)

Source from the content-addressed store, hash-verified

68
69
70def update_graph(ccgraph, ast_list, change_stats):
71 for ast in ast_list:
72 filename = ast.attrib['filename']
73 for function in ast.findall('./srcml:function', namespaces=ns):
74 caller_name, _, _ = handle_function(function)
75 if not caller_name:
76 continue
77
78 if caller_name not in ccgraph:
79 ccgraph.add_node(caller_name, [filename])
80 else:
81 files = ccgraph.nodes()[caller_name]['files']
82 if filename not in files:
83 ccgraph.update_node_files(caller_name, files + [filename])
84
85 for call in function.xpath('.//srcml:call', namespaces=ns):
86 try:
87 callee_name = handle_call(call)
88 except NotFunctionCallError:
89 continue
90 except:
91 print("Callee name not found (in %s)" % caller_name)
92 continue
93
94 if callee_name not in ccgraph:
95 # Pass [] to files argument since we don't know
96 # which file this node belongs to
97 ccgraph.add_node(callee_name, [])
98 ccgraph.add_edge(caller_name, callee_name)
99
100 for func, fstat in change_stats.items():
101 if func not in ccgraph:
102 print("%s in change_stats but not in ccgraph" % func_name)
103 continue
104 ccgraph.update_node_history(func, fstat['adds'], fstat['dels'])
105
106
107def get_func_ranges_c(root):

Callers 1

update_graphMethod · 0.90

Calls 8

add_nodeMethod · 0.80
nodesMethod · 0.80
update_node_filesMethod · 0.80
add_edgeMethod · 0.80
itemsMethod · 0.80
update_node_historyMethod · 0.80
handle_functionFunction · 0.70
handle_callFunction · 0.70

Tested by

no test coverage detected