Skip to content

Commit 12b490d

Browse files
committed
Extracted method for remove id for assignment case
1 parent 441fefd commit 12b490d

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

pyt/liveness.py

+17-12
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,27 @@ def is_condition(self, cfg_node):
3535
return True
3636
return False
3737

38+
def remove_id_assignment(self, JOIN, cfg_node):
39+
lvars = list()
40+
try:
41+
for expr in cfg_node.ast_node.targets:
42+
vv = VarsVisitor()
43+
vv.visit(expr)
44+
lvars.extend(vv.result)
45+
except AttributeError: # If it is AugAssign
46+
vv = VarsVisitor()
47+
vv.visit(cfg_node.ast_node.target)
48+
lvars.extend(vv.result)
49+
50+
for var in lvars:
51+
if var in self.lattice.get_elements(JOIN): # Check if var in JOIN
52+
JOIN = JOIN ^ self.lattice.el2bv[var]
53+
return JOIN
3854
def fixpointmethod(self, cfg_node):
3955

4056
if isinstance(cfg_node, EntryExitNode) and 'Exit' in cfg_node.label:
4157
constraint_table[cfg_node] = 0
4258
elif isinstance(cfg_node, AssignmentNode):
43-
lvars = list()
44-
try:
45-
for expr in cfg_node.ast_node.targets:
46-
vv = VarsVisitor()
47-
vv.visit(expr)
48-
lvars.extend(vv.result)
49-
except AttributeError:
50-
if cfg_node.ast_node:
51-
vv = VarsVisitor()
52-
vv.visit(cfg_node.ast_node.value)
53-
lvars.extend(vv.result)
54-
5559
JOIN = self.join(cfg_node)
5660

5761
for var in lvars:
@@ -61,6 +65,7 @@ def fixpointmethod(self, cfg_node):
6165
for var in cfg_node.right_hand_side_variables:
6266
JOIN = JOIN | self.lattice.el2bv[var]
6367

68+
JOIN = self.remove_id_assignment(JOIN, cfg_node)
6469
constraint_table[cfg_node] = JOIN
6570
elif self.is_condition(cfg_node):
6671

0 commit comments

Comments
 (0)