def visit_Assign(self, node): obj_list = [obj for values in self.obj_list.values() for obj in values] for target in node.targets: ignoreAssignment = False if isinstance(target, ast.Subscript): ignoreAssignment = True break tgt = [target] if isinstance(target, ast.Tuple): tgt = target.elts t_value = [] for t in tgt: t_value.append(".".join(get_node_value(t))) target = ','.join(t_value) if not ignoreAssignment: if self.scope == "module": target = GLOBAL_PREFIX + target self.kill_obj_after_reassignment(target) if isinstance(node.value, ast.Call): src_func_name = get_node_value(node.value.func, obj_list) fn_name = ".".join(src_func_name) if fn_name not in self.func_list: srclist = self.get_source_list(src_func_name) for func_name in srclist: self.add_node_to_graph( GraphNode(func_name, '--becomes--', target, node.lineno, node.col_offset)) self.obj_list[self.scope].append(target) return self.generic_visit(node)
def visit_Assign(self, node): obj_list = [obj for values in self.obj_list.values() for obj in values] for target in node.targets: ignoreAssignment=False if isinstance(target, ast.Subscript): ignoreAssignment = True break tgt = [target] if isinstance(target, ast.Tuple): tgt = target.elts t_value = [] for t in tgt: t_value.append(".".join(get_node_value(t))) target = ','.join(t_value) if not ignoreAssignment: if self.scope == "module": target = GLOBAL_PREFIX + target self.kill_obj_after_reassignment(target) if isinstance(node.value, ast.Call): src_func_name = get_node_value(node.value.func, obj_list) fn_name = ".".join(src_func_name) if fn_name not in self.func_list: srclist = self.get_source_list(src_func_name) for func_name in srclist: self.add_node_to_graph( GraphNode(func_name, '--becomes--', target, node.lineno, node.col_offset)) self.obj_list[self.scope].append(target) return self.generic_visit(node)
def visit_With(self, node): with_expr = ".".join(get_node_value(node.context_expr)) scope = "_".join(['with', with_expr]) self.scope = scope self.obj_list[self.scope] = [] if isinstance(node.context_expr, ast.Call): target = ".".join(get_node_value(node.optional_vars)) if len(target) != 0: self.add_node_to_graph( GraphNode(with_expr, '--becomes--', target, node.lineno, node.col_offset)) self.obj_list[self.scope].append(target) self.generic_visit(node) self.clear_obj_list(scope)
def visit_FunctionDef(self, node): scope = '_'.join(['function', node.name]) self.obj_list[scope] = [] self.scope = scope for arg in node.args.args: self.obj_list[scope].append(".".join( get_node_value(arg, prefix=ARG_PREFIX))) self.generic_visit(node) self.clear_obj_list(scope)
def visit_Attribute(self, node): obj_list = [obj for values in self.obj_list.values() for obj in values] attr_func_name = get_node_value(node, obj_list) if len(attr_func_name) != 0: if ARG_PREFIX not in attr_func_name[0] \ and attr_func_name[0] in obj_list: self.add_node_to_graph( GraphNode(".".join(attr_func_name[:-1]), '--calls--', attr_func_name[-1], node.lineno, node.col_offset)) return self.generic_visit(node)
def visit_FunctionDef(self, node): """Overloaded functions have same name""" fn_name = node.name arg_list = [] if node.args.args: for arg in node.args.args: if arg == 'self': fn_name = arg + '.' + fn_name else: arg_list.append('.'.join(get_node_value(arg))) self.func_list[node.name].append(arg_list) return self.generic_visit(node)