inline.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:fatoptimizer 作者: vstinner 项目源码 文件源码
def visit_Call(self, node):
        if not self.config.inlining:
            return

        # FIXME: renaming variables to avoid clashes
        # or do something like:
        #   .saved_locals = locals()
        #   set params to args
        #   body of called function
        #   locals() = .saved_locals
        #   how to things that aren't just a return
        #   how to handle early return
        # FIXME: what guards are needed?
        # etc
        expansion = self.can_inline(node)
        if not expansion:
            return node
        funcdef = expansion.funcdef
        # Substitute the Call with the expression of the single return stmt
        # within the callee.
        # This assumes a single Return or Pass stmt
        stmt = funcdef.body[0]
        if isinstance(stmt, ast.Return):
            returned_expr = funcdef.body[0].value
            # Rename params/args
            v = RenameVisitor(node, funcdef, expansion.actual_pos_args)
            new_expr = v.visit(returned_expr)
        else:
            assert isinstance(stmt, ast.Pass)
            new_expr = self.new_constant(stmt, None)
        return new_expr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号