我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用_ast.Subscript()。
def STORE_SLICE_3(self, instr): 'obj[lower:upper] = expr' upper = self.ast_stack.pop() lower = self.ast_stack.pop() value = self.ast_stack.pop() expr = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=lower, step=None, upper=upper, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Store(), **kw) if isinstance(expr, _ast.AugAssign): assign = expr result = cmp_ast(expr.target, subscr) assert result else: assign = _ast.Assign(targets=[subscr], value=expr, **kw) self.ast_stack.append(assign)
def STORE_SUBSCR(self, instr): index = self.ast_stack.pop() value = self.ast_stack.pop() expr = self.ast_stack.pop() expr = self.process_ifexpr(expr) if isinstance(expr, _ast.AugAssign): self.ast_stack.append(expr) else: kw = dict(lineno=instr.lineno, col_offset=0) index = self.format_slice(index, kw) subscr = _ast.Subscript(value=value, slice=index, ctx=_ast.Store(), **kw) assign = _ast.Assign(targets=[subscr], value=expr, **kw) self.ast_stack.append(assign)
def BINARY_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.Load(), **kw) self.ast_stack.append(subscr)
def SLICE_0(self, instr): 'obj[:]' 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.Load(), **kw) self.ast_stack.append(subscr)
def SLICE_1(self, instr): 'obj[lower:]' lower = self.ast_stack.pop() value = self.ast_stack.pop() 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.Load(), **kw) self.ast_stack.append(subscr)
def SLICE_2(self, instr): 'obj[:stop]' upper = self.ast_stack.pop() value = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=None, step=None, upper=upper, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Load(), **kw) self.ast_stack.append(subscr)
def SLICE_3(self, instr): 'obj[lower:upper]' upper = self.ast_stack.pop() lower = self.ast_stack.pop() value = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=lower, step=None, upper=upper, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Load(), **kw) self.ast_stack.append(subscr)
def STORE_SLICE_1(self, instr): 'obj[lower:] = expr' lower = self.ast_stack.pop() value = self.ast_stack.pop() expr = self.ast_stack.pop() 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.Store(), **kw) assign = _ast.Assign(targets=[subscr], value=expr, **kw) self.ast_stack.append(assign)
def STORE_SLICE_2(self, instr): 'obj[:upper] = expr' upper = self.ast_stack.pop() value = self.ast_stack.pop() expr = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=None, step=None, upper=upper, **kw) subscr = _ast.Subscript(value=value, slice=slice, ctx=_ast.Store(), **kw) assign = _ast.Assign(targets=[subscr], value=expr, **kw) self.ast_stack.append(assign)
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.ast_stack.pop() value = self.ast_stack.pop() 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.ast_stack.append(delete)
def DELETE_SLICE_3(self, instr): 'obj[lower:upper] = expr' upper = self.ast_stack.pop() lower = self.ast_stack.pop() value = self.ast_stack.pop() kw = dict(lineno=instr.lineno, col_offset=0) slice = _ast.Slice(lower=lower, step=None, upper=upper, **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_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 visit_Assign(self, node): if len(node.targets) > 1: raise SyntaxError("GPUMAP: multiple assignment not supported") target_types = map(lambda target: type(target), node.targets) if tuple in target_types or list in target_types: raise SyntaxError("GPUMAP: No unpacking allowed") target = node.targets[0] # assignment into object field output = "" value = self.visit(node.value) # assignment into variable if isinstance(target, _ast.Name): # assignment into new variable # not sure about the type just yet.. # see if it's a primitive if target.id not in self.local_vars: # binops and boolops return primitives if isinstance(node.value, _ast.Num) or isinstance(node.value, _ast.Compare) or isinstance(node.value, _ast.BinOp) \ or isinstance(node.value, _ast.BoolOp) or isinstance(node.value, _ast.NameConstant): output += "auto " # check if referenced list contains primitives elif isinstance(node.value, _ast.Subscript): list_name = value[:value.find("[")] try: idx = self.func_repr.args.index(list_name) t = self.func_repr.arg_types[idx] item_type = t[t.find("<") + 1: t.find(">")] if item_type in map(lambda t: t.__name__, primitive_map.keys()): output += "auto " else: output += "auto&& " except: raise RuntimeError("THIS SHOULD NEVER HAPPEN") else: # check if it's an existing variable try: idx = self.func_repr.args.index(value) t = self.func_repr.arg_types[idx] if t in primitive_map: output += "auto " else: output += "auto&& " except ValueError: output += "auto&& " self.local_vars[target.id] = None output += self.visit(target) output += " = " + value return output