const_propagate.py 文件源码

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

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

        if not isinstance(node, ast.Name) or not isinstance(node.ctx, ast.Load):
            return
        name = node.id
        if name not in self.local_variables:
            # the Namespace object only tracks local variables
            return

        value = self.namespace.get(name)
        if value is UNSET:
            return

        new_node = self.new_constant(node, value)
        if new_node is None:
            return

        self.log(node, "constant propagation: replace %s with %s",
                 node.id, compact_ascii(value), add_line=True)
        return new_node
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号