def make_delete(i, bytecode): logger.debug("Delete: \n%s", show_bytecode(bytecode)) op = bytecode[i][2] if op == DELETE_SUBSCR: i, subscr_expr = Statement.make_subscript(i, bytecode, context=_ast.Del()) return i, _ast.Delete([subscr_expr]) else: i, attr_expr = Statement.make_expr(i, bytecode, context=_ast.Del()) return i, _ast.Delete([attr_expr]) return i, None
def DELETE_ATTR(self, instr): expr = self.ast_stack.pop() attr = _ast.Attribute(value=expr, attr=instr.arg, ctx=_ast.Del(), lineno=instr.lineno, col_offset=0) delete = _ast.Delete(targets=[attr], lineno=instr.lineno, col_offset=0) self.ast_stack.append(delete)
def DELETE_FAST(self, instr): name = _ast.Name(id=instr.arg, ctx=_ast.Del(), lineno=instr.lineno, col_offset=0) delete = _ast.Delete(targets=[name], lineno=instr.lineno, col_offset=0) self.ast_stack.append(delete)
def DELETE_FAST(self, instr): name = _ast.Name(id=instr.arg, ctx=_ast.Del(), lineno=instr.lineno, col_offset=0) delete = _ast.Delete(targets=[name], lineno=instr.lineno, col_offset=0) self.push_ast_item(delete)
def DELETE_SLICE_0(self, instr): 'obj[:] = expr' value = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=None, step=None, upper=None, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Del(), **kw) delete = _ast.Delete(targets=[subscr], **kw) self.ast_stack.append(delete)
def DELETE_SLICE_1(self, instr): 'obj[lower:] = expr' lower = self.pop_ast_item() value = self.pop_ast_item() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=lower, step=None, upper=None, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Del(), **kw) delete = _ast.Delete(targets=[subscr], **kw) self.push_ast_item(delete)
def DELETE_ATTR(self, instr): expr = self.pop_ast_item() attr = _ast.Attribute(value=expr, attr=instr.arg, ctx=_ast.Del(), lineno=instr.lineno, col_offset=0) delete = _ast.Delete(targets=[attr], lineno=instr.lineno, col_offset=0) self.push_ast_item(delete)
def DELETE_SUBSCR(self, instr): index = self.ast_stack.pop() value = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) index = self.format_slice(index, kw) subscr = _ast.Subscript(value=value, slice=index, ctx=_ast.Del(), **kw) delete = _ast.Delete(targets=[subscr], **kw) self.ast_stack.append(delete)
def make_store_delete_slice(i, bytecode, context=None): op = bytecode[i][2] is_delete = op in DELETE_SLICE_OPCODES if context is None: context = _ast.Store() if not is_delete else _ast.Del() lhs_expr = None if op in (STORE_SLICE_0, DELETE_SLICE_0): i, lhs_expr = Statement.make_expr(i - 1, bytecode, context=context) lhs_expr = _ast.Subscript(lhs_expr, _ast.Slice(None, None, None), _ast.Store()) elif op in (STORE_SLICE_1, STORE_SLICE_2, DELETE_SLICE_1, DELETE_SLICE_2): i, index_expr = Statement.make_expr(i - 1, bytecode) i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context) args = [None] * 3 index_index = 0 if op in (STORE_SLICE_1, DELETE_SLICE_1) else 1 args[index_index] = index_expr lhs_expr = _ast.Subscript(arr_expr, _ast.Slice(*args), _ast.Store()) else: i, end_index_expr = Statement.make_expr(i - 1, bytecode) i, start_index_expr = Statement.make_expr(i - 1, bytecode) i, arr_expr = Statement.make_expr(i - 1, bytecode, context=context) lhs_expr = _ast.Subscript(arr_expr, _ast.Slice(start_index_expr, end_index_expr, None), _ast.Store()) if is_delete: return i, _ast.Delete([lhs_expr]) else: i, rhs_expr = Statement.make_expr(i - 1, bytecode) return i, _ast.Assign([lhs_expr], rhs_expr)