def iter_content(self): """ The index is here just ignored, because of all the appends, etc. lists/sets are too complicated too handle that. """ items = [] for array in evaluate.follow_call_list(self.var_args): if isinstance(array, evaluate.Instance) and len(array.var_args): temp = array.var_args[0][0] if isinstance(temp, ArrayInstance): # prevent recursions # TODO compare Modules if self.var_args.start_pos != temp.var_args.start_pos: items += temp.iter_content() else: debug.warning('ArrayInstance recursion', self.var_args) continue items += evaluate.get_iterator_types([array]) if self.var_args.parent_stmt is None: return [] # generated var_args should not be checked for arrays module = self.var_args.parent_stmt.get_parent_until() is_list = str(self.instance.name) == 'list' items += _check_array_additions(self.instance, module, is_list) return items
def iter_content(self): """ The index is here just ignored, because of all the appends, etc. lists/sets are too complicated too handle that. """ items = [] for stmt in self.var_args: for typ in evaluate.follow_statement(stmt): if isinstance(typ, er.Instance) and len(typ.var_args): array = typ.var_args[0] if isinstance(array, ArrayInstance): # prevent recursions # TODO compare Modules if self.var_args.start_pos != array.var_args.start_pos: items += array.iter_content() else: debug.warning("ArrayInstance recursion", self.var_args) continue items += evaluate.get_iterator_types([typ]) # TODO check if exclusion of tuple is a problem here. if isinstance(self.var_args, tuple) or self.var_args.parent is None: return [] # generated var_args should not be checked for arrays module = self.var_args.get_parent_until() is_list = str(self.instance.name) == "list" items += _check_array_additions(self.instance, module, is_list) return items
def iter_content(self): """ The index is here just ignored, because of all the appends, etc. lists/sets are too complicated too handle that. """ items = [] for stmt in self.var_args: for typ in evaluate.follow_statement(stmt): if isinstance(typ, er.Instance) and len(typ.var_args): array = typ.var_args[0] if isinstance(array, ArrayInstance): # prevent recursions # TODO compare Modules if self.var_args.start_pos != array.var_args.start_pos: items += array.iter_content() else: debug.warning('ArrayInstance recursion', self.var_args) continue items += evaluate.get_iterator_types([typ]) # TODO check if exclusion of tuple is a problem here. if isinstance(self.var_args, tuple) or self.var_args.parent is None: return [] # generated var_args should not be checked for arrays module = self.var_args.get_parent_until() is_list = str(self.instance.name) == 'list' items += _check_array_additions(self.instance, module, is_list) return items
def check_calls(calls, add_name): """ Calls are processed here. The part before the call is searched and compared with the original Array. """ result = [] for c in calls: call_path = list(c.generate_call_path()) separate_index = call_path.index(add_name) if add_name == call_path[-1] or separate_index == 0: # this means that there is no execution -> [].append # or the keyword is at the start -> append() continue backtrack_path = iter(call_path[:separate_index]) position = c.start_pos scope = c.get_parent_until(pr.IsScope) found = evaluate.follow_call_path(backtrack_path, scope, position) if not compare_array in found: continue params = call_path[separate_index + 1] if not params.values: continue # no params: just ignore it if add_name in ["append", "add"]: for param in params: result += evaluate.follow_statement(param) elif add_name in ["insert"]: try: second_param = params[1] except IndexError: continue else: result += evaluate.follow_statement(second_param) elif add_name in ["extend", "update"]: for param in params: iterators = evaluate.follow_statement(param) result += evaluate.get_iterator_types(iterators) return result
def check_calls(calls, add_name): """ Calls are processed here. The part before the call is searched and compared with the original Array. """ result = [] for c in calls: call_path = list(c.generate_call_path()) separate_index = call_path.index(add_name) if add_name == call_path[-1] or separate_index == 0: # this means that there is no execution -> [].append # or the keyword is at the start -> append() continue backtrack_path = iter(call_path[:separate_index]) position = c.start_pos scope = c.get_parent_until(pr.IsScope) found = evaluate.follow_call_path(backtrack_path, scope, position) if not compare_array in found: continue params = call_path[separate_index + 1] if not params.values: continue # no params: just ignore it if add_name in ['append', 'add']: for param in params: result += evaluate.follow_statement(param) elif add_name in ['insert']: try: second_param = params[1] except IndexError: continue else: result += evaluate.follow_statement(second_param) elif add_name in ['extend', 'update']: for param in params: iterators = evaluate.follow_statement(param) result += evaluate.get_iterator_types(iterators) return result