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

Function handle_function

persper/analytics/call_graph/c.py:9–34  ·  view source on GitHub ↗

Given a node, return function name and function range (start & end lineno)

(func_node)

Source from the content-addressed store, hash-verified

7
8
9def handle_function(func_node):
10 """Given a <function> node,
11 return function name and function range (start & end lineno)"""
12
13 name_node = func_node.find('srcml:name', ns)
14 func_name, start_line = handle_name(name_node)
15 if not func_name or not start_line:
16 print('Function name/start not found!') # very unlikely to happen
17 return None, None, None
18
19 block_node = func_node.find('srcml:block', ns)
20 if block_node is None:
21 try:
22 block_node = func_node.xpath('./following-sibling::srcml:block',
23 namespaces=ns)[0]
24 except:
25 print("Block node not found (in func {})".format(func_name))
26 return func_name, None, None
27 try:
28 pos_node = block_node.find('pos:position', ns)
29 end_line = int(pos_node.attrib[line_attr])
30 except:
31 print("Block node doesn't have position node inside!")
32 return func_name, None, None
33
34 return func_name, start_line, end_line
35
36
37def handle_name(name_node):

Callers 2

update_graphFunction · 0.70
get_func_ranges_cFunction · 0.70

Calls 1

handle_nameFunction · 0.70

Tested by

no test coverage detected