1""" Gathers variables that have value modification in the given node. """
2
3from pythran.passmanager import NodeAnalysis
4
5import gast as ast
6
7
8class IsAssigned(NodeAnalysis):
9
10    """
11    Gather variable that change in given node.
12
13    It doesn't check constness as it is use for integer so we don't care about
14    arguments effects as it is use by value.
15    """
16
17    def __init__(self):
18        """ Basic initialiser. """
19        self.result = list()
20        super(IsAssigned, self).__init__()
21
22    def visit_Name(self, node):
23        """ Stored variable have new value. """
24        if isinstance(node.ctx, ast.Store):
25            self.result.append(node)
26
27    def visit_Tuple(self, node):
28        if isinstance(node.ctx, ast.Store):
29
30            def rec(n):
31                if isinstance(n, ast.Name):
32                    self.result.append(n)
33                elif isinstance(n, ast.Tuple):
34                    for elt in n.elts:
35                        rec(elt)
36            rec(node)
37