當前位置: 首頁>>代碼示例>>Python>>正文


Python ast.RShift方法代碼示例

本文整理匯總了Python中ast.RShift方法的典型用法代碼示例。如果您正苦於以下問題:Python ast.RShift方法的具體用法?Python ast.RShift怎麽用?Python ast.RShift使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ast的用法示例。


在下文中一共展示了ast.RShift方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: visit_BinOp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_BinOp(self, node):
        if isinstance(node.op, ast.Mod) and self.context == _context.PRINT:
            self.visit(node.left)
            self.write(", ")
            self.visit(node.right)
        else:
            if isinstance(node.op, ast.RShift):
                # Additional cast to signed of the full expression
                # this is apparently required by cver - not sure if it
                # is actually required by standard Verilog.
                # It shouldn't hurt however.
                if node.signed:
                    self.write("$signed")
            self.context = None
            if node.signed:
                self.context = _context.SIGNED
            self.write("(")
            self.visit(node.left)
            self.write(" %s " % opmap[type(node.op)])
            self.visit(node.right)
            self.write(")")
            self.context = None 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:24,代碼來源:_toVerilog.py

示例2: visit_AugAssign

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_AugAssign(self, node):
        # XXX apparently no signed context required for augmented assigns
        left, op, right = node.target, node.op, node.value
        isFunc = False
        pre, suf = "", ""
        if isinstance(op, (ast.Add, ast.Sub, ast.Mult, ast.Mod, ast.FloorDiv)):
            pre, suf = self.inferBinaryOpCast(node, left, right, op)
        elif isinstance(op, (ast.LShift, ast.RShift)):
            isFunc = True
            pre, suf = self.inferShiftOpCast(node, left, right, op)
        self.visit(left)
        self.write(" := ")
        self.write(pre)
        if isFunc:
            self.write("%s(" % opmap[type(op)])
        self.visit(left)
        if isFunc:
            self.write(", ")
        else:
            self.write(" %s " % opmap[type(op)])
        self.visit(right)
        if isFunc:
            self.write(")")
        self.write(suf)
        self.write(";") 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:27,代碼來源:_toVHDL.py

示例3: augassign_rewrite

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def augassign_rewrite(it: Tokenizer):
    return {
        '+=': ast.Add,
        '-=': ast.Sub,
        '*=': ast.Mult,
        '/=': ast.Div,
        '//=': ast.FloorDiv,
        '@=': ast.MatMult,
        '%=': ast.Mod,
        '&=': ast.BitAnd,
        '|=': ast.BitOr,
        '^=': ast.BitXor,
        '<<=': ast.LShift,
        '>>=': ast.RShift,
        '**=': ast.Pow,
    }[it.value] 
開發者ID:Xython,項目名稱:YAPyPy,代碼行數:18,代碼來源:helper.py

示例4: visit_BinOp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_BinOp(self, node):
        'Replace bitwise operation with function call'
        self.generic_visit(node)
        if isinstance(node.op, ast.BitAnd):
            return ast.Call(ast.Name('mand', ast.Load()),
                            [node.left, node.right], [], None, None)
        if isinstance(node.op, ast.BitOr):
            return ast.Call(ast.Name('mor', ast.Load()),
                            [node.left, node.right], [], None, None)
        if isinstance(node.op, ast.BitXor):
            return ast.Call(ast.Name('mxor', ast.Load()),
                            [node.left, node.right], [], None, None)
        if isinstance(node.op, ast.LShift):
            return ast.Call(ast.Name('mlshift', ast.Load()),
                            [node.left, node.right], [], None, None)
        if isinstance(node.op, ast.RShift):
            return ast.Call(ast.Name('mrshift', ast.Load()),
                            [node.left, node.right], [], None, None)
        return node 
開發者ID:quarkslab,項目名稱:sspam,代碼行數:21,代碼來源:asttools.py

示例5: convert_annotation

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def convert_annotation(self, annotation, vars):
        if isinstance(annotation, ast.Name) and annotation.id.islower():
            if annotation.id not in vars:
                vars[annotation.id] = hm_ast.TypeVariable()
            return vars[annotation.id]
        elif isinstance(annotation, ast.Name):
            return hm_ast.TypeOperator(annotation.id, [])
        elif isinstance(annotation, ast.BinOp) and isinstance(annotation.op, ast.RShift):
            if isinstance(annotation.left, ast.Name):
                # A >> B
                left = [annotation.left, annotation.right]
            else:
                # (A, Z) >> B
                left = annotation.left.elts + [annotation.right]
            return hm_ast.Multi_Function([self.convert_annotation(l, vars) for l in left])
        elif isinstance(annotation, ast.BinOp) and isinstance(annotation.op, ast.BinOr):
            # A | B
            left, right = [self.convert_annotation(a, vars) for a in [annotation.left, annotation.right]]
            return hm_ast.Union(left, right)
        elif isinstance(annotation, ast.List):
            # [A]
            return hm_ast.List(self.convert_annotation(annotation.elts[0], vars))
        else:
            return None 
開發者ID:alehander92,項目名稱:Airtight,代碼行數:26,代碼來源:converter.py

示例6: visit_BinOp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_BinOp(self, node: ast.BinOp) -> ast.AST:
        """BinOp nodes are bit-shifts and general operators like add, divide, etc."""
        self.generic_visit(node)
        log_header = f"visit_BinOp: {self.src_file}:"

        # default case for this node, can be BinOpBC or BinOpBS
        ast_class = "BinOp"
        op_type = type(node.op)

        # binop_bit_cmp_types: Set[type] = {ast.BitAnd, ast.BitOr, ast.BitXor}
        if op_type in {ast.BitAnd, ast.BitOr, ast.BitXor}:
            ast_class = "BinOpBC"

        # binop_bit_shift_types: Set[type] = {ast.LShift, ast.RShift}
        if op_type in {ast.LShift, ast.RShift}:
            ast_class = "BinOpBS"

        node_span = NodeSpan(node)
        idx = LocIndex(
            ast_class=ast_class,
            lineno=node_span.lineno,
            col_offset=node_span.col_offset,
            op_type=op_type,
            end_lineno=node_span.end_lineno,
            end_col_offset=node_span.end_col_offset,
        )

        self.locs.add(idx)

        if idx == self.target_idx and self.mutation and not self.readonly:
            LOGGER.debug("%s mutating idx: %s with %s", log_header, self.target_idx, self.mutation)
            return ast.copy_location(
                ast.BinOp(left=node.left, op=self.mutation(), right=node.right), node
            )

        LOGGER.debug("%s (%s, %s): no mutations applied.", log_header, node.lineno, node.col_offset)
        return node 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:39,代碼來源:transformers.py

示例7: visit_BinOp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_BinOp(self, node):
        if isinstance(node.op, (ast.LShift, ast.RShift)):
            self.shiftOp(node)
        elif isinstance(node.op, (ast.BitAnd, ast.BitOr, ast.BitXor)):
            self.BitOp(node)
        else:
            self.BinOp(node) 
開發者ID:myhdl,項目名稱:myhdl,代碼行數:9,代碼來源:_toVHDL.py

示例8: shift_expr_rewrite

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def shift_expr_rewrite(head, tail):
    if tail:
        for op, each in tail:
            head = ast.BinOp(head,
                             {
                                 '>>': ast.RShift,
                                 '<<': ast.LShift
                             }[op.value](), each, **loc @ op)
    return head 
開發者ID:Xython,項目名稱:YAPyPy,代碼行數:11,代碼來源:helper.py

示例9: visit_Call

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_Call(self, node):
        'Replace custom function with bitwise operators'
        self.generic_visit(node)
        if isinstance(node.func, ast.Name):
            if len(node.args) == 2:
                if node.func.id == "mand":
                    op = ast.BitAnd()
                elif node.func.id == "mxor":
                    op = ast.BitXor()
                elif node.func.id == "mor":
                    op = ast.BitOr()
                elif node.func.id == "mlshift":
                    op = ast.LShift()
                elif node.func.id == "mrshift":
                    op = ast.RShift()
                else:
                    return node

                return ast.BinOp(node.args[0],
                                 op,
                                 node.args[1])

            elif len(node.args) == 1 and node.func.id == "mnot":
                arg = node.args[0]
                self.generic_visit(node)
                return ast.UnaryOp(ast.Invert(), arg)

        return self.generic_visit(node) 
開發者ID:quarkslab,項目名稱:sspam,代碼行數:30,代碼來源:asttools.py

示例10: __init__

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def __init__( s, component ):
    super().__init__( component )
    s.loop_var_env = set()
    s.tmp_var_env = set()

    # opmap maps an ast operator to its RTLIR counterpart.
    s.opmap = {
      # Bool operators
      # Note: we do not support boolean operators because Python does
      # not allow overloading And and Or operators. Using them in
      # expressions might lead to inconsistent semantics.
      # ast.And    : bir.And(),       ast.Or     : bir.Or(),
      # Unary operators
      # Note: ast.Not is disallowed because it is a boolean operator
      # ast.Not    : bir.Not(),
      ast.Invert : bir.Invert(),
      ast.UAdd   : bir.UAdd(),      ast.USub   : bir.USub(),
      # Binary operators
      ast.Add    : bir.Add(),       ast.Sub    : bir.Sub(),
      ast.Mult   : bir.Mult(),      ast.Div    : bir.Div(),
      ast.Mod    : bir.Mod(),       ast.Pow    : bir.Pow(),
      ast.LShift : bir.ShiftLeft(), ast.RShift : bir.ShiftRightLogic(),
      ast.BitOr  : bir.BitOr(),     ast.BitAnd : bir.BitAnd(),
      ast.BitXor : bir.BitXor(),
      # Compare bir.bir.operators
      ast.Eq     : bir.Eq(),        ast.NotEq  : bir.NotEq(),
      ast.Lt     : bir.Lt(),        ast.LtE    : bir.LtE(),
      ast.Gt     : bir.Gt(),        ast.GtE    : bir.GtE()
    }

  # Override 
開發者ID:pymtl,項目名稱:pymtl3,代碼行數:33,代碼來源:BehavioralRTLIRGenL2Pass.py

示例11: visit_BinOp

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def visit_BinOp(self, node: ast.BinOp) -> Any:
        """Recursively visit the left and right operand, respectively, and apply the operation on the results."""
        # pylint: disable=too-many-branches
        left = self.visit(node=node.left)
        right = self.visit(node=node.right)

        if isinstance(node.op, ast.Add):
            result = left + right
        elif isinstance(node.op, ast.Sub):
            result = left - right
        elif isinstance(node.op, ast.Mult):
            result = left * right
        elif isinstance(node.op, ast.Div):
            result = left / right
        elif isinstance(node.op, ast.FloorDiv):
            result = left // right
        elif isinstance(node.op, ast.Mod):
            result = left % right
        elif isinstance(node.op, ast.Pow):
            result = left**right
        elif isinstance(node.op, ast.LShift):
            result = left << right
        elif isinstance(node.op, ast.RShift):
            result = left >> right
        elif isinstance(node.op, ast.BitOr):
            result = left | right
        elif isinstance(node.op, ast.BitXor):
            result = left ^ right
        elif isinstance(node.op, ast.BitAnd):
            result = left & right
        elif isinstance(node.op, ast.MatMult):
            result = left @ right
        else:
            raise NotImplementedError("Unhandled op of {}: {}".format(node, node.op))

        self.recomputed_values[node] = result
        return result 
開發者ID:Parquery,項目名稱:icontract,代碼行數:39,代碼來源:_recompute.py

示例12: binop

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def binop(self, block, node, var=None):
    if var is None:
      var = self.add_variable(None)
    left = self.expression(block, node.left)
    right = self.expression(block, node.right)
    if isinstance(node.op, ast.Add):
      op = Operator.add
    elif isinstance(node.op, ast.Sub):
      op = Operator.subtract
    elif isinstance(node.op, ast.Mult):
      op = Operator.multiply
    elif isinstance(node.op, ast.Div):
      op = Operator.divide
    elif isinstance(node.op, ast.FloorDiv):
      op = Operator.divide_int
    elif isinstance(node.op, ast.Mod):
      op = Operator.mod
    elif isinstance(node.op, ast.Pow):
      op = Operator.pow
    elif isinstance(node.op, ast.BitAnd):
      op = Operator.bit_and
    elif isinstance(node.op, ast.BitOr):
      op = Operator.bit_or
    elif isinstance(node.op, ast.BitXor):
      op = Operator.bit_xor
    elif isinstance(node.op, ast.LShift):
      op = Operator.shift_left
    elif isinstance(node.op, ast.RShift):
      op = Operator.shift_right
    else:
      raise Exception('Unexpected BinOp (%s)'%(node.op.__class__))
    operation = BinaryOperation(left, op, right)
    assignment = Assignment(var, operation)
    block.add(assignment)
    return var

  #Parses a unary uperation (AST UnaryOp) 
開發者ID:undefx,項目名稱:vecpy,代碼行數:39,代碼來源:parser.py

示例13: p_augassign_10

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def p_augassign_10(p):
    '''augassign : RIGHTSHIFTEQUAL'''
    #                            1
    p[0] = ast.RShift(rule=inspect.currentframe().f_code.co_name, **p[1][1]) 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例14: p_shift_expr_star_2

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def p_shift_expr_star_2(p):
    '''shift_expr_star : RIGHTSHIFT arith_expr'''
    #                             1          2
    p[0] = [ast.RShift(rule=inspect.currentframe().f_code.co_name, **p[1][1]), p[2]] 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:6,代碼來源:hgawk_grammar.py

示例15: p_shift_expr_star_4

# 需要導入模塊: import ast [as 別名]
# 或者: from ast import RShift [as 別名]
def p_shift_expr_star_4(p):
    '''shift_expr_star : shift_expr_star RIGHTSHIFT arith_expr'''
    #                                  1          2          3
    p[0] = p[1] + [ast.RShift(rule=inspect.currentframe().f_code.co_name, **p[2][1]), p[3]]

# arith_expr: term (('+'|'-') term)* 
開發者ID:histogrammar,項目名稱:histogrammar-python,代碼行數:8,代碼來源:hgawk_grammar.py


注:本文中的ast.RShift方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。