本文整理汇总了Python中_ast.Load方法的典型用法代码示例。如果您正苦于以下问题:Python _ast.Load方法的具体用法?Python _ast.Load怎么用?Python _ast.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_ast
的用法示例。
在下文中一共展示了_ast.Load方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_subscript
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_subscript(i, bytecode, context=None):
op = bytecode[i][2]
if op == STORE_SUBSCR:
# TOS1[TOS] = TOS2
i, index_expr = Statement.make_expr(i - 1, bytecode)
i, arr_expr = Statement.make_expr(i - 1, bytecode, context=_ast.Store())
i, rhs_expr = Statement.make_expr(i - 1, bytecode)
lhs_expr = _ast.Subscript(arr_expr, index_expr, _ast.Store())
return i, _ast.Assign([lhs_expr], rhs_expr)
else:
if context is None:
context = _ast.Load()
# BINARY_SUBSCR: TOS1[TOS] and DELETE_SUBSCR TOS1[TOS]
i, index_expr = Statement.make_expr(i - 1, bytecode)
i, arr_expr = Statement.make_expr(i - 1, bytecode)
return i, _ast.Subscript(arr_expr, index_expr, context)
示例2: make_const
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_const(i, bytecode):
arg = bytecode[i][3]
if isinstance(arg, basestring):
return i, _ast.Str(arg)
elif isinstance(arg, int) or isinstance(arg, float) or isinstance(arg, long):
return i, _ast.Num(arg)
elif isinstance(arg, dict):
return i, _ast.Dict(arg.keys(), arg.values())
elif isinstance(arg, set):
return i, _ast.Dict(arg)
elif isinstance(arg, tuple):
return i, _ast.Tuple(arg, _ast.Load())
elif isinstance(arg, list):
return i, _ast.List(arg, _ast.Load())
elif isinstance(arg, bytes):
return i, _ast.Bytes(arg)
return i, None
示例3: NAME
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def NAME(self, node):
"""
Handle occurrence of Name (which can be a load/store/delete access.)
"""
# Locate the name in locals / function / globals scopes.
if isinstance(node.ctx, (ast.Load, ast.AugLoad)):
self.handleNodeLoad(node)
if (node.id == 'locals' and isinstance(self.scope, FunctionScope)
and isinstance(node.parent, ast.Call)):
# we are doing locals() call in current scope
self.scope.usesLocals = True
elif isinstance(node.ctx, (ast.Store, ast.AugStore)):
self.handleNodeStore(node)
elif isinstance(node.ctx, ast.Del):
self.handleNodeDelete(node)
else:
# must be a Param context -- this only happens for names in function
# arguments, but these aren't dispatched through here
raise RuntimeError("Got impossible expression context: %r" % (node.ctx,))
示例4: _get_context
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def _get_context(node):
return CONTEXTS.get(type(node.ctx), astroid.Load)
示例5: make_expr
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_expr(i, bytecode, context=None):
if context is None:
context = _ast.Load()
op = bytecode[i][2]
if op == LOAD_CONST:
return Statement.make_const(i, bytecode)
elif op in (LOAD_GLOBAL, LOAD_NAME, LOAD_FAST, \
STORE_GLOBAL, STORE_NAME, STORE_FAST, \
DELETE_GLOBAL, DELETE_NAME, DELETE_FAST):
return Statement.make_name(i, bytecode, context=context)
elif op in (LOAD_ATTR, STORE_ATTR, DELETE_ATTR):
return Statement.make_attribute(i, bytecode, context=context)
elif op in CALL_OPCODES:
return Statement.make_call(i, bytecode)
elif op in BINARY_OP_OPCODES:
return Statement.make_binary_op(i, bytecode)
elif op in (BUILD_TUPLE, BUILD_LIST):
return Statement.make_tuple_list(i, bytecode)
elif op in (STORE_MAP, BUILD_MAP):
return Statement.make_dict(i, bytecode)
elif op in (STORE_SUBSCR, BINARY_SUBSCR):
return Statement.make_subscript(i, bytecode)
elif op in STORE_SLICE_OPCODES or op in DELETE_SLICE_OPCODES:
return Statement.make_store_delete_slice(i, bytecode)
elif op == BUILD_SLICE:
return Statement.make_slice(i, bytecode)
logger.debug("Unhandled >> EXPR:\n%s", show_bytecode(bytecode[:i + 1]))
# if we don't translate it, we generate a new named expr.
Statement.UNDEFINED_COUNT += 1
return i, _ast.Name('Undef_%d' % Statement.UNDEFINED_COUNT, _ast.Load())
示例6: make_assign_unpack
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_assign_unpack(i, bytecode, unpack_num=-1):
if unpack_num < 1:
logger.error("Could not find the number of unpacked items. ")
return i, None
store_exprs = []
value_exprs = []
store_state, value_state = True, False
while i >= 0:
op, arg = bytecode[i][2], bytecode[i][3]
if store_state:
if op == UNPACK_SEQUENCE:
store_state = False
prev_op = bytecode[i - 1][2] if i > 0 else -1
if prev_op == BUILD_TUPLE:
value_state = True
else:
i, value_exprs = Statement.make_expr(i - 1, bytecode)
break
elif op in STORE_OPCODES:
i, store_stmt = Statement.make_expr(i, bytecode, context=_ast.Store())
store_exprs.insert(0, store_stmt)
elif value_state:
i, value_stmt = Statement.make_expr(i, bytecode)
value_exprs.insert(0, value_stmt)
i -= 1
store_exprs = _ast.Tuple(store_exprs, _ast.Store())
if not isinstance(value_exprs, _ast.AST):
value_exprs = _ast.Tuple(value_exprs, _ast.Load())
return i, _ast.Assign([store_exprs], value_exprs)
示例7: make_assign_opt_unpack
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_assign_opt_unpack(i, bytecode):
store_exprs = []
value_exprs = []
store_state, value_state = True, False
while i >= 0:
op, arg = bytecode[i][2], bytecode[i][3]
if store_state:
if op == ROT_TWO:
prev_op = bytecode[i - 1][2] if i > 0 else -1
if prev_op == ROT_THREE:
i -= 1
value_state = True
store_state = False
elif op in STORE_OPCODES:
i, store_stmt = Statement.make_expr(i, bytecode, context=_ast.Store())
store_exprs.insert(0, store_stmt)
elif value_state:
i, value_stmt = Statement.make_expr(i, bytecode)
value_exprs.insert(0, value_stmt)
i -= 1
store_exprs = _ast.Tuple(store_exprs, _ast.Store())
if not isinstance(value_exprs, _ast.AST):
value_exprs = _ast.Tuple(value_exprs, _ast.Load())
return i, _ast.Assign([store_exprs], value_exprs)
# Only one case here for:
# a = b = z.d.f = foo()
# => AST: _ast.Assign(targets=[Tuple(a, b, z.d.f)], value=foo())
示例8: make_name
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def make_name(i, bytecode, context=None):
arg = bytecode[i][3]
if context is None:
context = _ast.Load()
return i, _ast.Name(arg, context)
示例9: visit_Attribute
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def visit_Attribute( self, node ):
self.decorators.append( node.attr )
#------------------------------------------------------------------------
# DetectLoadsAndStores
#------------------------------------------------------------------------
# AST traversal class which detects loads and stores within a concurrent
# block. Load detection is useful for generating the sensitivity list
# for @combinational blocks in the Simulator. Store detection is useful
# for determining 'reg' type variables during Verilog translation.
示例10: visit_Name
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def visit_Name( self, node ):
if not self.assign: return
if isinstance( node.ctx, _ast.Load ):
self.load += [ GetVariableName( self ).visit( node ) ]
elif isinstance( node.ctx, _ast.Store ):
self.store += [ GetVariableName( self ).visit( node ) ]
else:
print( type( node.ctx ) )
raise Exception( "Unsupported concurrent block code!" )
示例11: visit_Subscript
# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def visit_Subscript( self, node ):
if not self.assign: return
if isinstance( node.ctx, _ast.Load ):
self.load += [ GetVariableName( self ).visit( node ) ]
elif isinstance( node.ctx, _ast.Store ):
self.store += [ GetVariableName( self ).visit( node ) ]
else:
print( type( node.ctx ) )
raise Exception( "Unsupported concurrent block code!" )
# TODO: need this to detect writes to bit slices?
#def visit_Subscript( self, node ):
# if not self.assign: return
# if isinstance( node.ctx, _ast.Load ):
# self.load += [ GetVariableName( self ).visit( node ) ]
# elif isinstance( node.ctx, _ast.Store ):
# self.store += [ GetVariableName( self ).visit( node ) ]
# else:
# print( type( node.ctx ) )
# raise Exception( "Unsupported concurrent block code!" )
#------------------------------------------------------------------------
# GetVariableName
#------------------------------------------------------------------------
# Converts an AST branch, beginning with the indicated node, into it's
# corresponding Python name. Meant to be called as a utility visitor
# by another AST visitor, which should pass a reference to itself as
# a parameter.