def test_all_adjacent(self): ast = AugmentedAST(nx.MultiDiGraph(nx.complete_graph(10)), parent_types_of_variable_nodes=frozenset(['test_type'])) nx.set_node_attributes(ast._graph, 'SimpleName', 'type') nx.set_node_attributes(ast._graph, 'test_type', 'parentType') nx.set_edge_attributes(ast._graph, 'LAST_READ', 'type') for node in ast.nodes: self.assertCountEqual(ast.get_all_variable_usages(node[0]), ast._graph.nodes)
def add_AugmentedAST(self, ast: AugmentedAST) -> None: instances = [] included_nodes = set() for node, data in ast.nodes_that_represent_variables: if node not in included_nodes: real_var_name = data['identifier'] locations = ast.get_all_variable_usages(node) for loc in locations: assert ast[loc]['identifier'] == real_var_name included_nodes.update(locations) instances.append((real_var_name, locations)) self.graphs_and_instances.append((ast, tuple(instances)))
def add_AugmentedAST(self, ast: AugmentedAST) -> None: instances = [] visited_nodes = set() for node, data in ast.nodes_that_represent_variables: if node not in visited_nodes: location_list = ast.get_all_variable_usages(node) if len(location_list) > 1: for var_use in location_list: idx = location_list.index(var_use) other_uses = tuple(location_list[:idx] + location_list[idx + 1:]) instances.append((var_use, other_uses)) visited_nodes.update(location_list) self.graphs_and_instances.append((ast, tuple(instances)))