当前位置: 首页>>代码示例>>Python>>正文


Python _ast.Load方法代码示例

本文整理汇总了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) 
开发者ID:neuroo,项目名称:equip,代码行数:19,代码来源:stmt.py

示例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 
开发者ID:neuroo,项目名称:equip,代码行数:19,代码来源:stmt.py

示例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,)) 
开发者ID:zrzka,项目名称:blackmamba,代码行数:21,代码来源:checker.py

示例4: _get_context

# 需要导入模块: import _ast [as 别名]
# 或者: from _ast import Load [as 别名]
def _get_context(node):
    return CONTEXTS.get(type(node.ctx), astroid.Load) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:4,代码来源:rebuilder.py

示例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()) 
开发者ID:neuroo,项目名称:equip,代码行数:35,代码来源:stmt.py

示例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) 
开发者ID:neuroo,项目名称:equip,代码行数:36,代码来源:stmt.py

示例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()) 
开发者ID:neuroo,项目名称:equip,代码行数:34,代码来源:stmt.py

示例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) 
开发者ID:neuroo,项目名称:equip,代码行数:7,代码来源:stmt.py

示例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. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:12,代码来源:ast_visitor.py

示例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!" ) 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:11,代码来源:ast_visitor.py

示例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. 
开发者ID:cornell-brg,项目名称:pymtl,代码行数:31,代码来源:ast_visitor.py


注:本文中的_ast.Load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。