Esempio n. 1
0
    def visit_AugAssign(self, node):
        """ Update range value for augassigned variables.

        >>> import ast
        >>> from pythran import passmanager, backend
        >>> node = ast.parse("def foo(): a = 2; a -= 1")
        >>> pm = passmanager.PassManager("test")
        >>> res = pm.gather(RangeValues, node)
        >>> res['a']
        Range(low=1, high=2)
        """
        if isinstance(node.target, ast.Name):
            self.result[node.target.id].update(combine(self.result[node.target.id], self.visit(node.value), node.op))
Esempio n. 2
0
    def visit_AugAssign(self, node):
        """ Update range value for augassigned variables.

        >>> import ast
        >>> from pythran import passmanager, backend
        >>> node = ast.parse("def foo(): a = 2; a -= 1")
        >>> pm = passmanager.PassManager("test")
        >>> res = pm.gather(RangeValues, node)
        >>> res['a']
        Range(low=1, high=2)
        """
        if isinstance(node.target, ast.Name):
            self.result[node.target.id].update(
                combine(self.result[node.target.id], self.visit(node.value),
                        node.op))
Esempio n. 3
0
    def visit_BinOp(self, node):
        """ Combine operands ranges for given operator.

        >>> import ast
        >>> from pythran import passmanager, backend
        >>> node = ast.parse('''
        ... def foo():
        ...     a = 2
        ...     c = 3
        ...     d = a - c''')
        >>> pm = passmanager.PassManager("test")
        >>> res = pm.gather(RangeValues, node)
        >>> res['d']
        Range(low=-1, high=-1)
        """
        return combine(self.visit(node.left), self.visit(node.right), node.op)
Esempio n. 4
0
    def visit_BinOp(self, node):
        """ Combine operands ranges for given operator.

        >>> import ast
        >>> from pythran import passmanager, backend
        >>> node = ast.parse('''
        ... def foo():
        ...     a = 2
        ...     c = 3
        ...     d = a - c''')
        >>> pm = passmanager.PassManager("test")
        >>> res = pm.gather(RangeValues, node)
        >>> res['d']
        Range(low=-1, high=-1)
        """
        return combine(self.visit(node.left), self.visit(node.right), node.op)