def call_return_alias(self, node): func = node.func aliases = set() if isinstance(func, ast.Attribute): _, signature = methods.get(func.attr, functions.get(func.attr, [(None, None)])[0]) if signature and signature.return_alias: aliases = signature.return_alias(node) elif isinstance(func, ast.Name): func_aliases = self.result[func].aliases for func_alias in func_aliases: signature = None if isinstance(func_alias, ast.FunctionDef): _, signature = functions.get( func_alias.name, [(None, None)])[0] if signature and signature.return_alias: aliases.update(signature.return_alias(node)) elif hasattr(func_alias, 'return_alias'): aliases.update(func_alias.return_alias(node)) else: pass # better thing to do ? [self.add(a) for a in aliases if a not in self.result] return aliases or self.expand_unknown(node)
def call_return_alias(self, node): func = node.func aliases = set() if isinstance(func, ast.Attribute): _, signature = methods.get(func.attr, functions.get(func.attr, [(None, None)])[0]) if signature: aliases = signature.return_alias(node) elif isinstance(func, ast.Name): func_aliases = self.result[func].aliases for func_alias in func_aliases: signature = None if isinstance(func_alias, ast.FunctionDef): _, signature = functions.get( func_alias.name, [(None, None)])[0] if signature: aliases.update(signature.return_alias(node)) elif hasattr(func_alias, 'return_alias'): aliases.update(func_alias.return_alias(node)) else: pass # better thing to do ? [self.add(a) for a in aliases if a not in self.result] return aliases or self.expand_unknown(node)
def call_return_alias(self, node): def interprocedural_aliases(func, args): arg_aliases = [self.result[arg] or {arg} for arg in args] return_aliases = set() for args_combination in product(*arg_aliases): return_aliases.update( func.return_alias(args_combination)) return {expand_subscript(ra) for ra in return_aliases} def expand_subscript(node): if isinstance(node, ast.Subscript): if isinstance(node.value, ContainerOf): return node.value.containee return node def full_args(func, call): args = call.args if isinstance(func, ast.FunctionDef): extra = len(func.args.args) - len(args) if extra: tail = [deepcopy(n) for n in func.args.defaults[extra:]] for arg in tail: self.visit(arg) args = args + tail return args func = node.func aliases = set() if node.keywords: # too soon, we don't support keywords in interprocedural_aliases pass elif isinstance(func, ast.Attribute): _, signature = methods.get(func.attr, functions.get(func.attr, [(None, None)])[0]) if signature: args = full_args(signature, node) aliases = interprocedural_aliases(signature, args) elif isinstance(func, ast.Name): func_aliases = self.result[func] for func_alias in func_aliases: if hasattr(func_alias, 'return_alias'): args = full_args(func_alias, node) aliases.update(interprocedural_aliases(func_alias, args)) else: pass # better thing to do ? [self.add(a) for a in aliases if a not in self.result] return aliases or self.expand_unknown(node)