def op_POP_BLOCK(self, inst, delitem=None): blk = self.syntax_blocks.pop() if delitem is not None: delete = ir.Del(delitem, loc=self.loc) self.current_block.append(delete) if blk in self._block_actions: del self._block_actions[blk]
def _patch_var_disposal(self, var_name, use_map, disposal_blocks): """ Insert ir.Del statements into each of the *disposal_blocks* for variable *var_name*, at the appropriate points in the blocks. """ for b in disposal_blocks: # Either this is an original use point and we will insert after # that statement, or it's a computed one and we will insert # at the beginning of the block. stmt = use_map.get(b) ir_block = self.blocks[b] if stmt is None: ir_block.prepend(ir.Del(var_name, loc=ir_block.loc)) else: # If the variable is used in an exiting statement # (e.g. raise or return), we don't insert anything. if not stmt.is_exit: ir_block.insert_after(ir.Del(var_name, loc=stmt.loc), stmt)
def test_del(self): a = ir.Del(self.var_a.name, self.loc1) b = ir.Del(self.var_a.name, self.loc1) c = ir.Del(self.var_a.name, self.loc2) d = ir.Del(self.var_b.name, self.loc1) self.check(a, same=[b, c], different=[d])