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

Function get_func_ranges_cpp

persper/graphs/cpp_tools.py:8–33  ·  view source on GitHub ↗
(src, fname)

Source from the content-addressed store, hash-verified

6from persper.graphs.write_graph_to_dot import write_G_to_dot_with_pr
7
8def get_func_ranges_cpp(src, fname):
9 re_signature = re.compile("""^(?P<return_type>\w+(\s*[\*\&])?)\s+
10 ((?P<class_name>\w+)::)?
11 (?P<func_name>\w+)\s*
12 \([^;]+$
13 """, re.VERBOSE )
14 func_ids = []
15 func_ranges = []
16 ptr = -1
17 num_lines = 0
18 for lineno, line in enumerate(src.split('\n'), 1):
19 num_lines += 1
20 m = re_signature.search(line)
21 if m:
22 d = m.groupdict()
23 if d['class_name']:
24 func_ids.append('{}::{}'.format(d['class_name'], d['func_name']))
25 else:
26 func_ids.append(d['func_name'])
27 if ptr != -1:
28 func_ranges.append([ptr, lineno - 1])
29 ptr = lineno
30 if ptr != -1:
31 func_ranges.append([ptr, num_lines])
32
33 return func_ids, func_ranges
34
35def fname_filter_cpp(fname):
36 return fname.endswith('.cc') or fname.endswith('.cpp')

Callers 2

test_detect_changeFunction · 0.90
test_detect_changeFunction · 0.90

Calls

no outgoing calls

Tested by 2

test_detect_changeFunction · 0.72
test_detect_changeFunction · 0.72