def get_paths(self):
# If there's only one node
if nx.number_of_nodes(self.graph) == 1:
self.shortest_path = self.longest_path = [self.function_start]
return [[self.function_start]]
# If there aren't any obvious exit blocks
if len(self.exit_blocks) == 0:
return
# We need to go through all the possible paths from
# function start to each of exit blocks
all_paths = []
longest_path_len = 0
shortest_path_len = None
for ret in self.exit_blocks:
paths = (nx.all_simple_paths(self.graph, source = self.function_start, target = ret))
for path in paths:
if len(path) > longest_path_len:
longest_path_len = len(path)
self.longest_path = path
if not shortest_path_len or len(path) < shortest_path_len:
shortest_path_len = len(path)
self.shortest_path = path
all_paths.extend(paths)
return all_paths
评论列表
文章目录